kingst-la2016: fix segfault that often occurs when a capture is aborted
[libsigrok.git] / configure.ac
1 ##
2 ## This file is part of the libsigrok project.
3 ##
4 ## Copyright (C) 2010-2012 Bert Vermeulen <bert@biot.com>
5 ## Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.com>
6 ##
7 ## This program is free software: you can redistribute it and/or modify
8 ## it under the terms of the GNU General Public License as published by
9 ## the Free Software Foundation, either version 3 of the License, or
10 ## (at your option) any later version.
11 ##
12 ## This program is distributed in the hope that it will be useful,
13 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ## GNU General Public License for more details.
16 ##
17 ## You should have received a copy of the GNU General Public License
18 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 ##
20
21 # We require at least autoconf 2.63 (AC_INIT format changed there).
22 AC_PREREQ([2.63])
23
24 AC_INIT([libsigrok], [0.6.0],
25         [sigrok-devel@lists.sourceforge.net],
26         [libsigrok], [http://www.sigrok.org])
27 AC_CONFIG_MACRO_DIR([m4])
28 AC_CONFIG_AUX_DIR([autostuff])
29 AC_CONFIG_HEADERS([config.h include/libsigrok/version.h])
30
31 # We require at least automake 1.11 (needed for 'silent rules').
32 AM_INIT_AUTOMAKE([1.11 -Wall -Werror no-define nostdinc subdir-objects check-news color-tests])
33 AM_SILENT_RULES([yes])
34 m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
35
36 AC_CANONICAL_HOST
37
38 # Checks for programs.
39 AC_PROG_CC
40 AC_PROG_CXX
41 AC_PROG_INSTALL
42 AC_PROG_LN_S
43
44 # Required for per-target flags or subdir-objects with C sources.
45 AM_PROG_CC_C_O
46
47 # Set the standard the C library headers should conform to.
48 AH_VERBATIM([_POSIX_C_SOURCE], [/* The targeted POSIX standard. */
49 #ifndef _POSIX_C_SOURCE
50 # define _POSIX_C_SOURCE 200112L
51 #endif])
52
53 # Get compiler versions.
54 SR_PROG_VERSION([$CC], [sr_cc_version])
55 SR_PROG_VERSION([$CXX], [sr_cxx_version])
56
57 # Check for optional make features.
58 SR_PROG_MAKE_ORDER_ONLY
59
60 # Initialize libtool.
61 LT_INIT
62
63 # Set up the libsigrok version defines.
64 SR_PKG_VERSION_SET([SR_PACKAGE_VERSION], [AC_PACKAGE_VERSION])
65
66 # Library version for libsigrok (NOT the same as the package version).
67 # Carefully read the libtool docs before updating these numbers!
68 # The algorithm for determining which number to change (and how) is nontrivial!
69 # http://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info
70 # Format: current:revision:age.
71 SR_LIB_VERSION_SET([SR_LIB_VERSION], [4:0:0])
72
73 AM_CONDITIONAL([WIN32], [test -z "${host_os##mingw*}" || test -z "${host_os##cygwin*}"])
74
75 #############################
76 ##  Optional dependencies  ##
77 #############################
78
79 AC_LANG([C])
80
81 # Initialize pkg-config.
82 # We require at least 0.22, as "Requires.private" behaviour changed there.
83 PKG_PROG_PKG_CONFIG([0.22])
84
85 # Keep track of all checked modules so we can list them at the end.
86 SR_PKG_CHECK_SUMMARY([sr_pkglibs_summary])
87
88 # Collect the pkg-config module names of all dependencies in SR_PKGLIBS.
89 # These are used to derive the compiler flags and for the "Requires.private"
90 # field in the generated libsigrok.pc file.
91 SR_VAR_OPT_PKG([SR_PKGLIBS], [sr_deps_avail])
92 SR_PKGLIBS_TESTS=
93 SR_PKGLIBS_CXX=
94 SR_PKGLIBS_PYTHON=
95 SR_PKGLIBS_RUBY=
96 SR_EXTRA_LIBS=
97 SR_EXTRA_CXX_LIBS=
98
99 SR_ARG_OPT_PKG([libserialport], [LIBSERIALPORT], ,
100         [libserialport >= 0.1.1])
101
102 SR_ARG_OPT_PKG([libftdi], [LIBFTDI], , [libftdi1 >= 1.0])
103
104 # pkg-config file names: MinGW/MacOSX: hidapi; Linux: hidapi-hidraw/-libusb
105 SR_ARG_OPT_PKG([libhidapi], [LIBHIDAPI], ,
106         [hidapi >= 0.8.0], [hidapi-hidraw >= 0.8.0], [hidapi-libusb >= 0.8.0])
107
108 SR_ARG_OPT_PKG([libbluez], [LIBBLUEZ], , [bluez >= 4.0])
109
110 SR_ARG_OPT_PKG([libnettle], [LIBNETTLE], , [nettle])
111
112 # FreeBSD comes with an "integrated" libusb-1.0-style USB API.
113 # This means libusb-1.0 is always available; no need to check for it.
114 # On Windows, require the latest version we can get our hands on,
115 # until the new generic event handling has seen an official release.
116 AS_CASE([$host_os],
117         [freebsd*], [sr_libusb_req='libusb-1.0' sr_have_libusb=yes],
118         [mingw*], [sr_libusb_req='libusb-1.0 >= 1.0.20'],
119         [sr_libusb_req='libusb-1.0 >= 1.0.16'])
120
121 SR_ARG_OPT_PKG([libusb], [LIBUSB_1_0], [NEED_USB],
122         [$sr_libusb_req])
123
124 SR_ARG_OPT_PKG([librevisa], [LIBREVISA], [NEED_VISA],
125         [librevisa >= 0.0.20130412])
126
127 SR_ARG_OPT_PKG([libgpib], [LIBGPIB], [NEED_GPIB],
128         [libgpib])
129
130 SR_ARG_OPT_CHECK([libieee1284], [LIBIEEE1284],, [
131         sr_save_LIBS=$LIBS
132         LIBS="-lieee1284 $LIBS"
133         AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <ieee1284.h>]],
134                                 [[(void) ieee1284_open(0, 0, 0);]])],
135                 [sr_have_libieee1284=yes], [sr_have_libieee1284=no])
136         LIBS=$sr_save_LIBS
137 ])
138 AS_IF([test "x$sr_have_libieee1284" = xyes],
139         [SR_PREPEND([SR_EXTRA_LIBS], [-lieee1284])])
140
141 SR_ARG_OPT_PKG([libgio], [LIBGIO], , [gio-2.0 >= 2.24.0])
142
143 # See if any of the (potentially platform specific) libs are available
144 # which provide some means of Bluetooth communication.
145 AS_IF([test "x$sr_have_libbluez" = xyes],
146         sr_have_bluetooth=yes, sr_have_bluetooth=no)
147 AS_IF([test "x$sr_have_bluetooth" = xyes],
148         [AC_DEFINE([HAVE_BLUETOOTH], [1], [Specifies whether Bluetooth communication is supported.])])
149 AS_IF([test "x$sr_have_bluetooth" = xyes],
150         [SR_APPEND([sr_deps_avail], [bluetooth_comm])])
151
152 AS_IF([test "x$sr_have_libserialport" = xyes -o "x$sr_have_libhidapi" = xyes -o "x$sr_have_bluetooth" = xyes],
153         sr_have_serial_comm=yes, sr_have_serial_comm=no)
154 AS_IF([test "x$sr_have_serial_comm" = xyes],
155         [AC_DEFINE([HAVE_SERIAL_COMM], [1], [Specifies whether serial communication is supported.])])
156 AS_IF([test "x$sr_have_serial_comm" = xyes],
157         [SR_APPEND([sr_deps_avail], [serial_comm])])
158 AM_CONDITIONAL([NEED_SERIAL], [test "x$sr_have_serial_comm" = xyes])
159
160 ######################
161 ##  Feature checks  ##
162 ######################
163
164 # The Check unit testing framework is optional. Disable if not found.
165 SR_PKG_CHECK([check], [SR_PKGLIBS_TESTS], [check >= 0.9.4])
166 AM_CONDITIONAL([HAVE_CHECK], [test "x$sr_have_check" = xyes])
167
168 # Enable the C99 standard if possible, and enforce the use
169 # of SR_API to explicitly mark all public API functions.
170 SR_EXTRA_CFLAGS=
171 SR_CHECK_COMPILE_FLAGS([SR_EXTRA_CFLAGS], [C99], [-std=c99 -c99 -AC99 -qlanglvl=extc99])
172 SR_CHECK_COMPILE_FLAGS([SR_EXTRA_CFLAGS], [visibility], [-fvisibility=hidden])
173
174 SR_ARG_ENABLE_WARNINGS([SR_WFLAGS], [-Wall], [-Wall -Wextra -Wmissing-prototypes])
175
176 # Check host characteristics.
177 AC_SYS_LARGEFILE
178 AC_C_BIGENDIAN
179
180 AC_CHECK_HEADERS([sys/mman.h], [SR_APPEND([sr_deps_avail], [sys_mman_h])])
181 AC_CHECK_HEADERS([sys/ioctl.h], [SR_APPEND([sr_deps_avail], [sys_ioctl_h])])
182 AC_CHECK_HEADERS([sys/timerfd.h], [SR_APPEND([sr_deps_avail], [sys_timerfd_h])])
183
184 # We need to link against the Winsock2 library for SCPI over TCP.
185 AS_CASE([$host_os], [mingw*], [SR_PREPEND([SR_EXTRA_LIBS], [-lws2_32])])
186
187 # libm (the standard math library) is always needed.
188 SR_SEARCH_LIBS([SR_EXTRA_LIBS], [pow], [m])
189
190 # RPC is only needed for VXI support.
191 AC_CACHE_CHECK([for SunRPC support], [sr_cv_have_sunrpc],
192         [AC_LINK_IFELSE([AC_LANG_PROGRAM(
193                         [[#include <rpc/rpc.h>]m4_newline[CLIENT *rpc_test(void);]],
194                         [[(void) clnt_create("", 0, 0, "");]])],
195                 [RPC_CFLAGS=""; RPC_LIBS=""; sr_cv_have_sunrpc=yes],
196                 [sr_cv_have_sunrpc=no])])
197 PKG_CHECK_MODULES([TIRPC],
198         [libtirpc],
199         [RPC_CFLAGS=$TIRPC_CFLAGS; SR_PREPEND([SR_EXTRA_LIBS], [$TIRPC_LIBS]); sr_cv_have_tirpc=yes],
200         [sr_cv_have_tirpc=no])
201 AS_IF([test "x$sr_cv_have_sunrpc" = xyes -o "x$sr_cv_have_tirpc" = xyes],
202         [sr_cv_have_rpc=yes], [sr_cv_have_rpc=no])
203
204 AC_SUBST(RPC_CFLAGS)
205 AC_SUBST(RPC_LIBS)
206
207 AS_IF([test "x$sr_cv_have_rpc" = xyes],
208         [AC_DEFINE([HAVE_RPC], [1], [Specifies whether we have RPC support (either by SunRPC or libtirpc).])])
209
210 # VXI support is only compiled if RPC support was found.
211 AM_CONDITIONAL([NEED_RPC], [test "x$sr_cv_have_rpc" = xyes])
212
213 # Check for compiler support of 128 bit integers
214 AC_CHECK_TYPES([__int128_t, __uint128_t], [], [], [])
215
216 ########################
217 ##  Hardware drivers  ##
218 ########################
219
220 # Keep track of all drivers so we can list them at the end.
221 SR_VAR_SUMMARY([sr_driver_summary])
222
223 # Check whether the sr_deps_avail list contains all of the arguments.
224 # Unavailable dependencies are collected in sr_deps_missing.
225 sr_check_driver_deps() {
226         sr_deps_missing=
227         for sr_dep
228         do
229                 AS_CASE([" $sr_deps_avail "], [*" $sr_dep "*],,
230                         [SR_APPEND([sr_deps_missing], [', '], [$sr_dep])])
231         done
232         test -z "$sr_deps_missing" || return 1
233 }
234
235 AC_ARG_ENABLE([all-drivers],
236         [AS_HELP_STRING([--enable-all-drivers],
237                         [enable all drivers by default [default=yes]])],
238         [], [enable_all_drivers=yes])
239
240 ## _SR_DRIVER(Device name, driver-name, var-name, [dependencies...])
241 m4_define([_SR_DRIVER], [
242         AC_ARG_ENABLE([$2],
243                 [AS_HELP_STRING([--enable-$2], [enable $1 support])],
244                 [$3=$enableval], [$3=$enable_all_drivers])
245
246         AS_IF([test "x[$]$3" = xyes], [sr_hw_info=yes[]m4_ifval([$4], [
247                 sr_check_driver_deps $4 \
248                         || $3=no sr_hw_info="no (missing: $sr_deps_missing)"
249         ])], [sr_hw_info='no (disabled)'])
250         sr_driver_summary_append "$2" "$sr_hw_info"
251
252         AM_CONDITIONAL([$3], [test "x[$]$3" = xyes])
253         AM_COND_IF([$3], [AC_DEFINE([HAVE_$3], [1], [Whether to support $1 device.]) AC_DEFINE([HAVE_DRIVERS], [1], [Whether at least one driver is enabled.])])
254 ])
255
256 ## SR_DRIVER(Device name, driver-name, [dependencies...])
257 m4_define([SR_DRIVER],
258         [_SR_DRIVER([$1], [$2], m4_expand([AS_TR_CPP([HW_$2])]), [$3])])
259
260 SR_DRIVER([Agilent DMM], [agilent-dmm], [serial_comm])
261 SR_DRIVER([Appa 55II], [appa-55ii], [serial_comm])
262 SR_DRIVER([Arachnid Labs Re:load Pro], [arachnid-labs-re-load-pro], [serial_comm])
263 SR_DRIVER([ASIX SIGMA/SIGMA2], [asix-sigma], [libftdi])
264 SR_DRIVER([Atten PPS3xxx], [atten-pps3xxx], [serial_comm])
265 SR_DRIVER([BayLibre ACME], [baylibre-acme], [sys_timerfd_h])
266 SR_DRIVER([BeagleLogic], [beaglelogic], [sys_mman_h sys_ioctl_h])
267 SR_DRIVER([CEM DT-885x], [cem-dt-885x], [serial_comm])
268 SR_DRIVER([Center 3xx], [center-3xx], [serial_comm])
269 SR_DRIVER([ChronoVu LA], [chronovu-la], [libusb libftdi])
270 SR_DRIVER([Colead SLM], [colead-slm], [serial_comm])
271 SR_DRIVER([Conrad DIGI 35 CPU], [conrad-digi-35-cpu], [serial_comm])
272 SR_DRIVER([dcttech usbrelay], [dcttech-usbrelay], [libhidapi])
273 SR_DRIVER([demo], [demo])
274 SR_DRIVER([DreamSourceLab DSLogic], [dreamsourcelab-dslogic], [libusb])
275 SR_DRIVER([Fluke 45], [fluke-45])
276 SR_DRIVER([Fluke DMM], [fluke-dmm], [serial_comm])
277 SR_DRIVER([FTDI LA], [ftdi-la], [libusb libftdi])
278 SR_DRIVER([fx2lafw], [fx2lafw], [libusb])
279 SR_DRIVER([GMC MH 1x/2x], [gmc-mh-1x-2x], [serial_comm])
280 SR_DRIVER([GW Instek GDS-800], [gwinstek-gds-800], [serial_comm])
281 SR_DRIVER([GW Instek GPD], [gwinstek-gpd], [serial_comm])
282 SR_DRIVER([Hameg HMO], [hameg-hmo], [serial_comm])
283 SR_DRIVER([Hantek 4032L], [hantek-4032l], [libusb])
284 SR_DRIVER([Hantek 6xxx], [hantek-6xxx], [libusb])
285 SR_DRIVER([Hantek DSO], [hantek-dso], [libusb])
286 SR_DRIVER([HP 3457A], [hp-3457a])
287 SR_DRIVER([HP 3478A], [hp-3478a], [libgpib])
288 SR_DRIVER([hp-59306a], [hp-59306a])
289 SR_DRIVER([Hung-Chang DSO-2100], [hung-chang-dso-2100], [libieee1284])
290 SR_DRIVER([Ikalogic Scanalogic-2], [ikalogic-scanalogic2], [libusb])
291 SR_DRIVER([Ikalogic Scanaplus], [ikalogic-scanaplus], [libftdi])
292 SR_DRIVER([IPDBG LA], [ipdbg-la])
293 SR_DRIVER([ITECH IT8500], [itech-it8500], [serial_comm])
294 SR_DRIVER([Kecheng KC-330B], [kecheng-kc-330b], [libusb])
295 SR_DRIVER([KERN scale], [kern-scale], [serial_comm])
296 SR_DRIVER([Kingst LA2016], [kingst-la2016], [libusb])
297 SR_DRIVER([Korad KAxxxxP], [korad-kaxxxxp], [serial_comm])
298 SR_DRIVER([Lascar EL-USB], [lascar-el-usb], [libusb])
299 SR_DRIVER([LeCroy LogicStudio], [lecroy-logicstudio], [libusb])
300 SR_DRIVER([LeCroy X-Stream], [lecroy-xstream])
301 SR_DRIVER([Manson HCS-3xxx], [manson-hcs-3xxx], [serial_comm])
302 SR_DRIVER([Mastech MS6514], [mastech-ms6514], [serial_comm])
303 SR_DRIVER([maynuo-m97], [maynuo-m97])
304 SR_DRIVER([MIC 985xx], [mic-985xx], [serial_comm])
305 SR_DRIVER([Microchip PICkit2], [microchip-pickit2], [libusb])
306 SR_DRIVER([Mooshimeter DMM], [mooshimeter-dmm], [bluetooth_comm libgio])
307 SR_DRIVER([Motech LPS 30x], [motech-lps-30x], [serial_comm])
308 SR_DRIVER([Norma DMM], [norma-dmm], [serial_comm])
309 SR_DRIVER([OpenBench Logic Sniffer], [openbench-logic-sniffer], [serial_comm])
310 SR_DRIVER([PCE PCE-322A], [pce-322a], [serial_comm])
311 SR_DRIVER([Pipistrello-OLS], [pipistrello-ols], [libftdi])
312 SR_DRIVER([RDTech DPSxxxx/DPHxxxx], [rdtech-dps], [serial_comm])
313 SR_DRIVER([RDTech UMXX], [rdtech-um], [serial_comm])
314 SR_DRIVER([RDTech TCXX], [rdtech-tc], [serial_comm libnettle])
315 SR_DRIVER([Rigol DS], [rigol-ds])
316 SR_DRIVER([Rigol DG], [rigol-dg])
317 SR_DRIVER([Rohde&Schwarz SME-0x], [rohde-schwarz-sme-0x], [serial_comm])
318 SR_DRIVER([Saleae Logic16], [saleae-logic16], [libusb])
319 SR_DRIVER([Saleae Logic Pro], [saleae-logic-pro], [libusb])
320 SR_DRIVER([SCPI DMM], [scpi-dmm])
321 SR_DRIVER([SCPI PPS], [scpi-pps])
322 SR_DRIVER([serial DMM], [serial-dmm], [serial_comm])
323 SR_DRIVER([serial LCR], [serial-lcr], [serial_comm])
324 SR_DRIVER([Siglent SDS], [siglent-sds])
325 SR_DRIVER([Sysclk LWLA], [sysclk-lwla], [libusb])
326 SR_DRIVER([Sysclk SLA5032], [sysclk-sla5032], [libusb])
327 SR_DRIVER([Teleinfo], [teleinfo], [serial_comm])
328 SR_DRIVER([Testo], [testo], [libusb])
329 SR_DRIVER([Tondaj SL-814], [tondaj-sl-814], [serial_comm])
330 SR_DRIVER([UNI-T DMM], [uni-t-dmm], [libusb])
331 SR_DRIVER([UNI-T UT181A], [uni-t-ut181a], [serial_comm])
332 SR_DRIVER([UNI-T UT32x], [uni-t-ut32x], [serial_comm])
333 SR_DRIVER([Yokogawa DL/DLM], [yokogawa-dlm])
334 SR_DRIVER([ZEROPLUS Logic Cube], [zeroplus-logic-cube], [libusb])
335 SR_DRIVER([ZKETECH EBD-USB], [zketech-ebd-usb], [serial_comm])
336
337 ###############################
338 ##  Language bindings setup  ##
339 ###############################
340
341 AC_LANG([C++])
342 SR_ARG_ENABLE_WARNINGS([SR_WXXFLAGS], [-Wall], [-Wall -Wextra])
343
344 AC_ARG_ENABLE([bindings],
345         [AS_HELP_STRING([--enable-bindings], [build language bindings [default=yes]])],
346         [], [enable_bindings=yes])
347
348 AC_ARG_ENABLE([cxx],
349         [AS_HELP_STRING([--enable-cxx], [build C++ bindings [default=yes]])],
350         [], [enable_cxx=$enable_bindings])
351
352 AC_ARG_ENABLE([python],
353         [AS_HELP_STRING([--enable-python], [build Python bindings [default=yes]])],
354         [], [enable_python=$enable_bindings])
355
356 AC_ARG_ENABLE([ruby],
357         [AS_HELP_STRING([--enable-ruby], [build Ruby bindings [default=yes]])],
358         [], [enable_ruby=$enable_bindings])
359
360 AC_ARG_ENABLE([java],
361         [AS_HELP_STRING([--enable-java], [build Java bindings [default=yes]])],
362         [], [enable_java=$enable_bindings])
363
364 ####################
365 ##  C++ bindings  ##
366 ####################
367
368 sr_cxx_missing=
369
370 # Check if the C++ compiler supports the C++11 standard.
371 AX_CXX_COMPILE_STDCXX([11], [noext], [optional])
372 AS_IF([test "x$HAVE_CXX11" != x1],
373         [SR_APPEND([sr_cxx_missing], [', '], ['C++11'])])
374
375 # The C++ bindings need glibmm.
376 SR_PKG_CHECK([glibmm], [SR_PKGLIBS_CXX], [glibmm-2.4 >= 2.32.0])
377 AS_IF([test "x$sr_have_glibmm" != xyes],
378         [SR_APPEND([sr_cxx_missing], [', '], [glibmm])])
379
380 # The C++ bindings use Doxygen to parse libsigrok symbols.
381 AC_CHECK_PROG([HAVE_DOXYGEN], [doxygen], [yes], [no])
382 AS_IF([test "x$HAVE_DOXYGEN" != xyes],
383         [SR_APPEND([sr_cxx_missing], [', '], [Doxygen])])
384
385 # Link C++ code with gnustl_shared if it exists (Android)
386 SR_SEARCH_LIBS([SR_EXTRA_CXX_LIBS], [__cxa_throw], [gnustl_shared])
387
388 # Python is needed for the C++ bindings.
389 AM_PATH_PYTHON([2.7],
390         [HAVE_PYTHON=yes],
391         [HAVE_PYTHON=no
392         SR_APPEND([sr_cxx_missing], [', '], [Python])])
393
394 AS_IF([test -z "$sr_cxx_missing"],
395         [BINDINGS_CXX=$enable_cxx], [BINDINGS_CXX=no])
396 AM_CONDITIONAL([BINDINGS_CXX], [test "x$BINDINGS_CXX" = xyes])
397
398 # C++ bindings want stoi and stod.
399 AM_COND_IF([BINDINGS_CXX], [
400         AC_CACHE_CHECK([for stoi and stod], [sr_cv_have_stoi_stod],
401                 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <string>]],
402                                 [[(void) std::stoi("1"); (void) std::stod("1.0");]])],
403                         [sr_cv_have_stoi_stod=yes], [sr_cv_have_stoi_stod=no])])
404         AS_IF([test "x$sr_cv_have_stoi_stod" = xyes],
405                 [AC_DEFINE([HAVE_STOI_STOD], [1],
406                         [Specifies whether we have the stoi and stod functions.])])
407 ])
408
409 #######################
410 ##  Python bindings  ##
411 #######################
412
413 AS_IF([test "x$BINDINGS_CXX" = xyes],
414         [sr_python_missing=],
415         [sr_python_missing='C++ bindings'])
416
417 # Extract major and minor version number of the Python interpreter.
418 sr_pymajor=${PYTHON_VERSION%%.*}
419 sr_pyminor=${PYTHON_VERSION#*.}
420
421 # The Python bindings need Python development files. Check for either
422 # Python 3 or Python 2 headers depending on the interpreter version.
423 SR_PKG_CHECK([python_dev], [SR_PKGLIBS_PYTHON],
424         [python = $PYTHON_VERSION],
425         [python$sr_pymajor = $PYTHON_VERSION],
426         [python$sr_pymajor$sr_pyminor = $PYTHON_VERSION],
427         [python-$PYTHON_VERSION = $PYTHON_VERSION])
428
429 AS_IF([test "x$sr_have_python_dev" != xyes],
430         [SR_APPEND([sr_python_missing], [', '], [Headers])])
431
432 # PyGObject is needed for the Python bindings.
433 SR_PKG_CHECK([pygobject], [SR_PKGLIBS_PYTHON], [pygobject-3.0 >= 3.0.0])
434 AS_IF([test "x$sr_have_pygobject" != xyes],
435         [SR_APPEND([sr_python_missing], [', '], [PyGObject])])
436
437 PKG_CHECK_EXISTS([pygobject-3.0 < 3.7.91],
438         [AC_DEFINE([PYGOBJECT_FLAGS_SIGNED], [1],
439                 [Whether last argument to pyg_flags_get_value() is signed.])])
440
441 # The Python bindings need the setuptools and numpy Python modules.
442 # We'll let it go through even if the AX macro wasn't found, as the
443 # Python modules may still be there.
444 m4_ifdef([AX_PYTHON_MODULE], [
445         AX_PYTHON_MODULE([setuptools])
446         AX_PYTHON_MODULE([numpy])
447 ], [
448         HAVE_PYMOD_SETUPTOOLS=yes
449         HAVE_PYMOD_NUMPY=yes
450         m4_warn([unsupported],
451                 [Missing macro AX_PYTHON_MODULE: no check for setuptools and numpy])
452 ])
453 AS_IF([test "x$HAVE_PYMOD_SETUPTOOLS" != xyes],
454         [SR_APPEND([sr_python_missing], [', '], [setuptools])])
455 AS_IF([test "x$HAVE_PYMOD_NUMPY" != xyes],
456         [SR_APPEND([sr_python_missing], [', '], [numpy])])
457
458 # The Python bindings use SWIG to generate code.
459 AC_CHECK_PROGS([SWIG], [swig swig4.0 swig3.0 swig2.0])
460 AS_IF([test "x$SWIG" != x],
461     AC_MSG_CHECKING([for $SWIG version])
462     [SWIG_VERSION=`$SWIG -version 2>&1 | sed -n 's/SWIG Version //p'`]
463     AC_MSG_RESULT([$SWIG_VERSION]))
464 AS_IF([test "x$SWIG" = x],
465         [SR_APPEND([sr_python_missing], [', '], [SWIG])])
466
467 AS_IF([test -z "$sr_python_missing"],
468         [BINDINGS_PYTHON=$enable_python], [BINDINGS_PYTHON=no])
469 AM_CONDITIONAL([BINDINGS_PYTHON], [test "x$BINDINGS_PYTHON" = xyes])
470
471 #####################
472 ##  Ruby bindings  ##
473 #####################
474
475 AS_IF([test "x$BINDINGS_CXX" = xyes],
476         [sr_ruby_missing=],
477         [sr_ruby_missing='C++ bindings'])
478
479 AC_PATH_PROGS(RUBY, ["${RUBY-ruby}"], [])
480 AS_IF([test "x$RUBY" != x],
481         AC_MSG_CHECKING([for Ruby version])
482     [RUBY_VERSION=`$RUBY -e 'puts RUBY_VERSION'`]
483     AC_MSG_RESULT([$RUBY_VERSION])
484     [RUBY_DLEXT=`$RUBY -rrbconfig -e 'puts RbConfig::CONFIG[["DLEXT"]]'`]
485     AC_SUBST(RUBY_DLEXT))
486
487 AS_IF([test "x$RUBY" = x],
488         [SR_APPEND([sr_ruby_missing], [', '], [Ruby])])
489
490 # Extract major and minor version number of the Ruby interpreter.
491 sr_rbmajor=${RUBY_VERSION%%.*}
492 sr_rbminor=${RUBY_VERSION#*.}
493 sr_rbminor=${sr_rbminor%%.*}
494
495 # The Ruby bindings need Ruby development files.
496 SR_PKG_CHECK([ruby_dev], [SR_PKGLIBS_RUBY],
497         [ruby >= 2.5.0],
498         [ruby-$sr_rbmajor.$sr_rbminor >= 2.5.0])
499
500 AS_IF([test "x$sr_have_ruby_dev" != xyes],
501         [SR_APPEND([sr_ruby_missing], [', '], [Headers])])
502
503 # The Ruby bindings use SWIG >= 3.0.8 to generate code.
504 AS_IF([test "x$SWIG" = x],
505         [SR_APPEND([sr_ruby_missing], [', '], [SWIG])],
506         [AS_VERSION_COMPARE($SWIG_VERSION, "3.0.8",
507                 [SR_APPEND([sr_ruby_missing], [', '], ['SWIG >= 3.0.8'])])])
508
509 AS_IF([test -z "$sr_ruby_missing"],
510         [BINDINGS_RUBY=$enable_ruby], [BINDINGS_RUBY=no])
511 AM_CONDITIONAL([BINDINGS_RUBY], [test "x$BINDINGS_RUBY" = xyes])
512
513 ####################
514 ##  Java bindings ##
515 ####################
516
517 AS_IF([test "x$BINDINGS_CXX" = xyes],
518         [sr_java_missing=],
519         [sr_java_missing='C++ bindings'])
520
521 # The Java bindings use SWIG to generate code.
522 AS_IF([test "x$SWIG" = x],
523         [SR_APPEND([sr_java_missing], [', '], [SWIG])])
524
525 # Find Java compiler and JNI includes for Java bindings.
526 AC_CHECK_PROG([HAVE_JAVAC], [javac], [yes], [no])
527 AS_IF([test "x$HAVE_JAVAC" = xno],
528         [SR_APPEND([sr_java_missing], [', '], [JavaC])])
529
530 AC_ARG_WITH([jni-include-path],
531         [AS_HELP_STRING([[--with-jni-include-path=DIR-LIST (space-separated)]],
532                 [specify JNI include directories [default=detect]])],
533         [JNI_INCLUDE_DIRS=" $withval"], [JNI_INCLUDE_DIRS=])
534
535 JNI_CPPFLAGS=
536 AS_IF([test "x$enable_java$HAVE_JAVAC" = xyesyes], [
537         AX_PROG_JAVAC
538         AS_IF([test -z "$JNI_INCLUDE_DIRS" && test "x$cross_compiling" != xyes], [
539                 ## Work around the totally broken logic in AX_JNI_INCLUDE_DIR:
540                 ## If we can find jni.h without any special search path, skip
541                 ## the execution of the broken macro to increase our chances of
542                 ## success.
543                 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <jni.h>]], [])],,
544                         [AX_JNI_INCLUDE_DIR])
545         ])
546 ])
547 for sr_dir in $JNI_INCLUDE_DIRS
548 do
549         SR_APPEND([JNI_CPPFLAGS], ["-I$sr_dir"])
550 done
551 AC_SUBST([JNI_CPPFLAGS])
552
553 sr_save_cppflags=$CPPFLAGS
554 SR_APPEND([CPPFLAGS], [$JNI_CPPFLAGS])
555 AC_CHECK_HEADER([jni.h],,
556         [SR_APPEND([sr_java_missing], [', '], ['JNI headers'])])
557 CPPFLAGS=$sr_save_cppflags
558
559 AS_IF([test -z "$sr_java_missing"],
560         [BINDINGS_JAVA=$enable_java], [BINDINGS_JAVA=no])
561 AM_CONDITIONAL([BINDINGS_JAVA], [test "x$BINDINGS_JAVA" = xyes])
562
563 ##############################
564 ##  Finalize configuration  ##
565 ##############################
566
567 # Add mandatory dependencies to module list.
568 SR_APPEND([SR_PKGLIBS], ['libzip >= 0.10'])
569 AC_SUBST([SR_PKGLIBS])
570
571 # Retrieve the compile and link flags for all modules combined.
572 # Also, bail out at this point if any module dependency is not met.
573 PKG_CHECK_MODULES([LIBSIGROK], [glib-2.0 >= 2.32.0 $SR_PKGLIBS])
574 PKG_CHECK_MODULES([TESTS], [$SR_PKGLIBS_TESTS glib-2.0 $SR_PKGLIBS])
575
576 # SR_PKGLIBS_CXX may be empty, so only invoke these checks when
577 # the C++ bindings are enabled.
578 AM_COND_IF([BINDINGS_CXX], [
579         PKG_CHECK_MODULES([LIBSIGROKCXX], [$SR_PKGLIBS_CXX])
580         PKG_CHECK_MODULES([PYSIGROK], [$SR_PKGLIBS_PYTHON $SR_PKGLIBS_CXX])
581         PKG_CHECK_MODULES([RBSIGROK], [$SR_PKGLIBS_RUBY $SR_PKGLIBS_CXX], [AC_SUBST(RBSIGROK_EXTDIR, "lib/$($PKG_CONFIG --variable=sitearch $SR_PKGLIBS_RUBY)/$($PKG_CONFIG --variable=RUBY_BASE_NAME $SR_PKGLIBS_RUBY)/vendor_ruby/$($PKG_CONFIG --variable=ruby_version $SR_PKGLIBS_RUBY)")])
582 ])
583
584 # Check for specific libusb features, now that we know the CFLAGS.
585 AC_LANG([C])
586 sr_save_cflags=$CFLAGS
587 sr_save_libs=$LIBS
588 CFLAGS="$LIBSIGROK_CFLAGS $CFLAGS"
589 LIBS="$LIBSIGROK_LIBS $LIBS"
590 AC_CHECK_TYPES([libusb_os_handle],
591         [sr_have_libusb_os_handle=yes], [sr_have_libusb_os_handle=no],
592         [[#include <libusb.h>]])
593 AC_CHECK_FUNCS([zip_discard])
594 LIBS=$sr_save_libs
595 CFLAGS=$sr_save_cflags
596
597 AM_COND_IF([NEED_USB], [AS_CASE([$sr_have_libusb_os_handle:$host_os], [no:mingw*],
598         [AC_MSG_ERROR([Windows builds require the event-abstraction branch of libusb])])])
599
600 sr_glib_version=`$PKG_CONFIG --modversion glib-2.0 2>&AS_MESSAGE_LOG_FD`
601 sr_libzip_version=`$PKG_CONFIG --modversion libzip 2>&AS_MESSAGE_LOG_FD`
602
603 AC_DEFINE_UNQUOTED([CONF_LIBZIP_VERSION], ["$sr_libzip_version"],
604         [Build-time version of libzip.])
605 AC_DEFINE_UNQUOTED([CONF_HOST], ["$host"],
606         [The canonical host libsigrok will run on.])
607
608 AC_CONFIG_FILES([Makefile libsigrok.pc bindings/cxx/libsigrokcxx.pc])
609
610 AC_OUTPUT
611
612 # Prepare bindings report messages.
613 m4_define([SR_PREPARE_BINDING_REPORT], [
614         sr_report_$1=
615         test -z "$sr_$1_missing" || sr_report_$1=" (missing: $sr_$1_missing)"
616         test "x$enable_$1" = xyes || sr_report_$1=' (disabled)'
617 ])
618 m4_map_args([SR_PREPARE_BINDING_REPORT], [cxx], [python], [ruby], [java])
619
620 cat >&AS_MESSAGE_FD <<_EOF
621
622 libsigrok configuration summary:
623  - Package version................. $SR_PACKAGE_VERSION
624  - Library ABI version............. $SR_LIB_VERSION
625  - Prefix.......................... $prefix
626  - Building on..................... $build
627  - Building for.................... $host
628  - Building shared / static........ $enable_shared / $enable_static
629
630 Compile configuration:
631  - C compiler...................... $CC
632  - C compiler version.............. $sr_cc_version
633  - C compiler flags................ $CFLAGS
634  - Additional C compiler flags..... $SR_EXTRA_CFLAGS
635  - C compiler warnings............. $SR_WFLAGS
636  - C++ compiler.................... $CXX
637  - C++ compiler version............ $sr_cxx_version
638  - C++ compiler flags.............. $CXXFLAGS
639  - C++ compiler warnings........... $SR_WXXFLAGS
640  - Linker flags.................... $LDFLAGS
641
642 Detected libraries (required):
643  - glib-2.0 >= 2.32.0.............. $sr_glib_version
644  - libzip >= 0.10.................. $sr_libzip_version
645
646 Detected libraries (optional):
647 $sr_pkglibs_summary
648 Enabled hardware drivers:
649 $sr_driver_summary
650 Enabled serial communication transports:
651   - serial comm ................... $sr_have_serial_comm
652   - libserialport ................. $sr_have_libserialport
653   - hidapi ........................ $sr_have_libhidapi
654   - bluetooth ..................... $sr_have_bluetooth
655   - bluez ......................... $sr_have_libbluez
656
657 Enabled SCPI backends:
658  - TCP............................. yes
659  - SunRPC ......................... $sr_cv_have_sunrpc
660  - TI-RPC ......................... $sr_cv_have_tirpc
661  - RPC............................. $sr_cv_have_rpc
662  - serial.......................... $sr_have_serial_comm
663  - VISA............................ $sr_have_librevisa
664  - GPIB............................ $sr_have_libgpib
665  - USBTMC.......................... $sr_have_libusb
666
667 Enabled language bindings:
668  - C++............................. $BINDINGS_CXX$sr_report_cxx
669  - Python.......................... $BINDINGS_PYTHON$sr_report_python
670  - Ruby............................ $BINDINGS_RUBY$sr_report_ruby
671  - Java............................ $BINDINGS_JAVA$sr_report_java
672
673 _EOF
674
675 # Emit a warning if the C++ bindings are not being built.
676 AM_COND_IF([BINDINGS_CXX], [], [
677 cat >&AS_MESSAGE_FD <<_EOF
678 ===============================================================================
679 WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
680 ===============================================================================
681 ===                                                                         ===
682 ===         The libsigrok C++ bindings are not being built since you        ===
683 ===             are missing one or more dependencies (see above)!           ===
684 ===                                                                         ===
685 ===      This means you won't be able to compile frontends that require     ===
686 ===  the C++ bindings (such as PulseView)! You also won't be able to build  ===
687 ===     other bindings and frontends using those (such as sigrok-meter)!    ===
688 ===                                                                         ===
689 ===============================================================================
690 WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
691 ===============================================================================
692
693 _EOF
694 ])