]> git.sur5r.net Git - openocd/blob - configure.ac
ftdi: make ftdi_location command depend on libusb1 version
[openocd] / configure.ac
1 AC_PREREQ(2.64)
2 AC_INIT([openocd], [0.10.0-dev],
3   [OpenOCD Mailing List <openocd-devel@lists.sourceforge.net>])
4 AC_CONFIG_SRCDIR([src/openocd.c])
5
6 m4_include([config_subdir.m4])dnl
7
8 # check for makeinfo before calling AM_INIT_AUTOMAKE
9 AC_CHECK_PROG([MAKEINFO], [makeinfo], [makeinfo])
10 if test "x$MAKEINFO" = "x"; then
11   MAKEINFO='echo makeinfo missing; true'
12   AC_MSG_WARN([Info documentation will not be built.])
13 fi
14 AC_SUBST([MAKEINFO])
15
16 AM_INIT_AUTOMAKE([-Wall -Wno-portability dist-bzip2 dist-zip subdir-objects])
17
18 AC_CONFIG_HEADERS([config.h])
19 AH_BOTTOM([
20 #include <helper/system.h>
21 #include <helper/types.h>
22 #include <helper/replacements.h>
23 ])
24
25 AC_LANG_C
26 AC_PROG_CC
27 AC_PROG_CC_C99
28 AM_PROG_CC_C_O
29 AC_PROG_RANLIB
30 PKG_PROG_PKG_CONFIG([0.23])
31
32 dnl disable checks for C++, Fortran and GNU Java Compiler
33 m4_defun([_LT_AC_LANG_CXX_CONFIG], [:])
34 m4_defun([_LT_AC_LANG_F77_CONFIG], [:])
35 m4_defun([_LT_AC_LANG_GCJ_CONFIG], [:])
36 AC_DISABLE_SHARED
37 AC_PROG_LIBTOOL
38 AC_SUBST([LIBTOOL_DEPS])
39
40 dnl configure checks required for Jim files (these are obsolete w/ C99)
41 AC_C_CONST
42 AC_TYPE_LONG_LONG_INT
43
44 AC_SEARCH_LIBS([ioperm], [ioperm])
45 AC_SEARCH_LIBS([dlopen], [dl])
46
47 AC_CHECK_HEADERS([sys/socket.h])
48 AC_CHECK_HEADERS([arpa/inet.h], [], [], [dnl
49 #include <stdio.h>
50 #ifdef STDC_HEADERS
51 # include <stdlib.h>
52 # include <stddef.h>
53 #else
54 # ifdef HAVE_STDLIB_H
55 #  include <stdlib.h>
56 # endif
57 #endif
58 #ifdef HAVE_SYS_SOCKET_H
59 # include <sys/socket.h>
60 #endif
61 ])
62 AC_CHECK_HEADERS([elf.h])
63 AC_CHECK_HEADERS([dirent.h])
64 AC_CHECK_HEADERS([fcntl.h])
65 AC_CHECK_HEADERS([ifaddrs.h], [], [], [dnl
66 #include <stdio.h>
67 #ifdef STDC_HEADERS
68 # include <stdlib.h>
69 # include <stddef.h>
70 #else
71 # ifdef HAVE_STDLIB_H
72 #  include <stdlib.h>
73 # endif
74 #endif
75 #ifdef HAVE_SYS_SOCKET_H
76 # include <sys/socket.h>
77 #endif
78 ])
79 AC_CHECK_HEADERS([malloc.h])
80 AC_CHECK_HEADERS([netdb.h])
81 AC_CHECK_HEADERS([netinet/in.h], [], [], [dnl
82 #include <stdio.h>
83 #ifdef STDC_HEADERS
84 # include <stdlib.h>
85 # include <stddef.h>
86 #else
87 # ifdef HAVE_STDLIB_H
88 #  include <stdlib.h>
89 # endif
90 #endif
91 #ifdef HAVE_SYS_SOCKET_H
92 # include <sys/socket.h>
93 #endif
94 ])
95 AC_CHECK_HEADERS([netinet/tcp.h], [], [], [dnl
96 #include <stdio.h>
97 #ifdef STDC_HEADERS
98 # include <stdlib.h>
99 # include <stddef.h>
100 #else
101 # ifdef HAVE_STDLIB_H
102 #  include <stdlib.h>
103 # endif
104 #endif
105 #ifdef HAVE_SYS_SOCKET_H
106 # include <sys/socket.h>
107 #endif
108 ])
109 AC_CHECK_HEADERS([poll.h])
110 AC_CHECK_HEADERS([pthread.h])
111 AC_CHECK_HEADERS([strings.h])
112 AC_CHECK_HEADERS([sys/ioctl.h])
113 AC_CHECK_HEADERS([sys/param.h])
114 AC_CHECK_HEADERS([sys/select.h])
115 AC_CHECK_HEADERS([sys/stat.h])
116 AC_CHECK_HEADERS([sys/time.h])
117 AC_CHECK_HEADERS([sys/types.h])
118 AC_CHECK_HEADERS([unistd.h])
119 AC_CHECK_HEADERS([net/if.h], [], [], [dnl
120 #include <stdio.h>
121 #ifdef STDC_HEADERS
122 # include <stdlib.h>
123 # include <stddef.h>
124 #else
125 # ifdef HAVE_STDLIB_H
126 #  include <stdlib.h>
127 # endif
128 #endif
129 #ifdef HAVE_SYS_SOCKET_H
130 # include <sys/socket.h>
131 #endif
132 ])
133
134 AC_HEADER_ASSERT
135 AC_HEADER_STDBOOL
136 AC_HEADER_TIME
137
138 AC_C_BIGENDIAN
139
140 AC_CHECK_FUNCS([strndup])
141 AC_CHECK_FUNCS([strnlen])
142 AC_CHECK_FUNCS([gettimeofday])
143 AC_CHECK_FUNCS([usleep])
144 AC_CHECK_FUNCS([vasprintf])
145
146 build_bitbang=no
147 build_bitq=no
148 is_cygwin=no
149 is_mingw=no
150 is_win32=no
151 is_darwin=no
152
153 # guess-rev.sh only exists in the repository, not in the released archives
154 AC_MSG_CHECKING([whether to build a release])
155 if test -x $srcdir/guess-rev.sh ; then
156   build_release=no
157 else
158   build_release=yes
159 fi
160 AC_MSG_RESULT([$build_release])
161
162 AC_ARG_WITH(ftd2xx,
163    AS_HELP_STRING([--with-ftd2xx=<PATH>],[This option has been removed.]),
164   [
165 # Option Given.
166 cat << __EOF__
167
168 The option: --with-ftd2xx=<PATH> has been removed.
169 On Linux, the new option is:
170
171   --with-ftd2xx-linux-tardir=/path/to/files
172
173 Where <path> is the path the the directory where the "tar.gz" file
174 from FTDICHIP.COM was unpacked, for example:
175
176   --with-ftd2xx-linux-tardir=${HOME}/libftd2xx0.4.16
177
178 On Cygwin/MingW32, the new option is:
179
180   --with-ftd2xx-win32-zipdir=/path/to/files
181
182 Where <path> is the path to the directory where the "zip" file from
183 FTDICHIP.COM was unpacked, for example:
184
185   --with-ftd2xx-win32-zipdir=${HOME}/ftd2xx.cdm.files
186
187 __EOF__
188
189    AC_MSG_ERROR([Sorry Cannot continue])
190   ], [true])
191
192 # Adapter drivers
193 # 1st column -- configure option
194 # 2nd column -- description
195 # 3rd column -- symbol used for both config.h and automake
196 m4_define([ADAPTER_ARG], [m4_argn([1], $1)])
197 m4_define([ADAPTER_DESC], [m4_argn([2], $1)])
198 m4_define([ADAPTER_SYM], [m4_argn([3], $1)])
199 m4_define([ADAPTER_VAR], [enable_[]ADAPTER_ARG($1)])
200 m4_define([ADAPTER_OPT], [m4_translit(ADAPTER_ARG($1), [_], [-])])
201
202 m4_define([USB1_ADAPTERS],
203         [[[ftdi], [MPSSE mode of FTDI based devices], [FTDI]],
204         [[jlink], [Segger J-Link JTAG Programmer], [JLINK]],
205         [[stlink], [ST-Link JTAG Programmer], [HLADAPTER_STLINK]],
206         [[ti_icdi], [TI ICDI JTAG Programmer], [HLADAPTER_ICDI]],
207         [[ulink], [Keil ULINK JTAG Programmer], [ULINK]],
208         [[usb_blaster_2], [Altera USB-Blaster II Compatible], [USB_BLASTER_2]],
209         [[vsllink], [Versaloon-Link JTAG Programmer], [VSLLINK]]])
210
211 m4_define([USB_ADAPTERS],
212         [[[osbdm], [OSBDM (JTAG only) Programmer], [OSBDM]],
213         [[opendous], [eStick/opendous JTAG Programmer], [OPENDOUS]],
214         [[aice], [Andes JTAG Programmer], [AICE]]])
215
216 m4_define([USB0_ADAPTERS],
217         [[[usbprog], [USBProg JTAG Programmer], [USBPROG]],
218         [[rlink], [Raisonance RLink JTAG Programmer], [RLINK]],
219         [[armjtagew], [Olimex ARM-JTAG-EW Programmer], [ARMJTAGEW]]])
220
221 m4_define([HIDAPI_ADAPTERS],
222         [[[cmsis_dap], [CMSIS-DAP Compliant Debugger], [CMSIS_DAP]]])
223
224 #========================================
225 # FTD2XXX support comes in 4 forms.
226 #    (1) win32 - via a zip file
227 #    (2) linux - via a tar file
228 #    (3) linux/cygwin/mingw - via libftdi
229 #    (4) darwin - installed under /usr/local
230 #
231 # In case (1) and (2) we need to know where the package was unpacked.
232
233 AC_ARG_WITH(ftd2xx-win32-zipdir,
234   AS_HELP_STRING([--with-ftd2xx-win32-zipdir],[Where (CYGWIN/MINGW) the zip file from ftdichip.com was unpacked (default=search)]),
235   [
236   # option present
237   if test -d $with_ftd2xx_win32_zipdir
238   then
239     with_ftd2xx_win32_zipdir=`cd $with_ftd2xx_win32_zipdir && pwd`
240     AC_MSG_NOTICE([Using: ftdichip.com library: $with_ftd2xx_win32_zipdir])
241   else
242     AC_MSG_ERROR([Parameter to --with-ftd2xx-win32-zipdir is not a dir: $with_ftd2xx_win32_zipdir])
243   fi
244   ], [true])
245
246 AC_ARG_WITH(ftd2xx-linux-tardir,
247   AS_HELP_STRING([--with-ftd2xx-linux-tardir], [Where (Linux/Unix) the tar file from ftdichip.com was unpacked (default=search)]),
248   [
249   # Option present
250   if test $is_win32 = yes ; then
251      AC_MSG_ERROR([The option: --with-ftd2xx-linux-tardir is only usable on linux])
252   fi
253   if test -d $with_ftd2xx_linux_tardir
254   then
255     with_ftd2xx_linux_tardir=`cd $with_ftd2xx_linux_tardir && pwd`
256     AC_MSG_NOTICE([Using: ftdichip.com library: $with_ftd2xx_linux_tardir])
257   else
258     AC_MSG_ERROR([Parameter to --with-ftd2xx-linux-tardir is not a dir: $with_ftd2xx_linux_tardir])
259   fi
260   ], [true])
261
262 AC_ARG_WITH(ftd2xx-lib,
263   AS_HELP_STRING([--with-ftd2xx-lib],
264     [Use static or shared ftd2xx libs (default=static)]),
265   [
266   case "$withval" in
267   static)
268     with_ftd2xx_lib=$withval
269     ;;
270   shared)
271     with_ftd2xx_lib=$withval
272     ;;
273   *)
274     AC_MSG_ERROR([Option: --with-ftd2xx-lib=static or --with-ftd2xx-lib=shared not, $withval])
275     ;;
276   esac
277   ], [
278   # Default is static - it is simpler :-(
279   with_ftd2xx_lib=static
280   ])
281
282 AC_ARG_ENABLE([doxygen-html],
283   AS_HELP_STRING([--disable-doxygen-html],
284     [Disable building Doxygen manual as HTML.]),
285   [doxygen_as_html=$enableval], [doxygen_as_html=yes])
286 AC_SUBST([doxygen_as_html])
287 AC_MSG_CHECKING([whether to build Doxygen as HTML])
288 AC_MSG_RESULT([$doxygen_as_html])
289
290 AC_ARG_ENABLE([doxygen-pdf],
291   AS_HELP_STRING([--enable-doxygen-pdf],
292     [Enable building Doxygen manual as PDF.]),
293   [doxygen_as_pdf=$enableval], [doxygen_as_pdf=no])
294 AC_SUBST([doxygen_as_pdf])
295 AC_MSG_CHECKING([whether to build Doxygen as PDF])
296 AC_MSG_RESULT([$doxygen_as_pdf])
297
298 AC_ARG_ENABLE([gccwarnings],
299   AS_HELP_STRING([--disable-gccwarnings], [Disable compiler warnings]),
300   [gcc_warnings=$enableval], [gcc_warnings=yes])
301
302 AC_ARG_ENABLE([wextra],
303   AS_HELP_STRING([--disable-wextra], [Disable extra compiler warnings]),
304   [gcc_wextra=$enableval], [gcc_wextra=$gcc_warnings])
305
306 AC_ARG_ENABLE([werror],
307   AS_HELP_STRING([--disable-werror], [Do not treat warnings as errors]),
308   [gcc_werror=$enableval], [gcc_werror=$gcc_warnings])
309
310 # set default verbose options, overridden by following options
311 debug_jtag_io=no
312 debug_usb_io=no
313 debug_usb_comms=no
314
315 AC_ARG_ENABLE([verbose],
316   AS_HELP_STRING([--enable-verbose],
317       [Enable verbose JTAG I/O messages (for debugging).]),
318   [
319   debug_jtag_io=$enableval
320   debug_usb_io=$enableval
321   debug_usb_comms=$enableval
322   ], [])
323
324 AC_ARG_ENABLE([verbose_jtag_io],
325   AS_HELP_STRING([--enable-verbose-jtag-io],
326       [Enable verbose JTAG I/O messages (for debugging).]),
327   [debug_jtag_io=$enableval], [])
328
329 AC_ARG_ENABLE([verbose_usb_io],
330   AS_HELP_STRING([--enable-verbose-usb-io],
331       [Enable verbose USB I/O messages (for debugging)]),
332   [debug_usb_io=$enableval], [])
333
334 AC_ARG_ENABLE([verbose_usb_comms],
335   AS_HELP_STRING([--enable-verbose-usb-comms],
336       [Enable verbose USB communication messages (for debugging)]),
337   [debug_usb_comms=$enableval], [])
338
339 AC_MSG_CHECKING([whether to enable verbose JTAG I/O messages]);
340 AC_MSG_RESULT([$debug_jtag_io])
341 if test $debug_jtag_io = yes; then
342   AC_DEFINE([_DEBUG_JTAG_IO_],[1], [Print verbose JTAG I/O messages])
343 fi
344
345 AC_MSG_CHECKING([whether to enable verbose USB I/O messages]);
346 AC_MSG_RESULT([$debug_usb_io])
347 if test $debug_usb_io = yes; then
348   AC_DEFINE([_DEBUG_USB_IO_],[1], [Print verbose USB I/O messages])
349 fi
350
351 AC_MSG_CHECKING([whether to enable verbose USB communication messages]);
352 AC_MSG_RESULT([$debug_usb_comms])
353 if test $debug_usb_comms = yes; then
354   AC_DEFINE([_DEBUG_USB_COMMS_],[1], [Print verbose USB communication messages])
355 fi
356
357 debug_malloc=no
358 AC_ARG_ENABLE([malloc_logging],
359   AS_HELP_STRING([--enable-malloc-logging],
360       [Include free space in logging messages (requires malloc.h).]),
361   [debug_malloc=$enableval], [])
362
363 AC_MSG_CHECKING([whether to enable malloc free space logging]);
364 AC_MSG_RESULT([$debug_malloc])
365 if test $debug_malloc = yes; then
366   AC_DEFINE([_DEBUG_FREE_SPACE_],[1], [Include malloc free space in logging])
367 fi
368
369 AC_ARG_ENABLE([dummy],
370   AS_HELP_STRING([--enable-dummy], [Enable building the dummy port driver]),
371   [build_dummy=$enableval], [build_dummy=no])
372
373 m4_define([AC_ARG_ADAPTERS], [
374   m4_foreach([adapter], [$1],
375         [AC_ARG_ENABLE(ADAPTER_OPT([adapter]),
376                 AS_HELP_STRING([--enable-ADAPTER_OPT([adapter])],
377                         [Enable building support for the ]ADAPTER_DESC([adapter])[ (default is $2)]),
378                 [], [ADAPTER_VAR([adapter])=$2])
379   ])
380 ])
381
382 AC_ARG_ADAPTERS([USB1_ADAPTERS, USB_ADAPTERS, USB0_ADAPTERS, HIDAPI_ADAPTERS], [auto])
383
384 AC_ARG_ENABLE([parport],
385   AS_HELP_STRING([--enable-parport], [Enable building the pc parallel port driver]),
386   [build_parport=$enableval], [build_parport=no])
387
388 AC_ARG_ENABLE([parport_ppdev],
389   AS_HELP_STRING([--disable-parport-ppdev],
390       [Disable use of ppdev (/dev/parportN) for parport (for x86 only)]),
391     [parport_use_ppdev=$enableval], [parport_use_ppdev=yes])
392
393 AC_ARG_ENABLE([parport_giveio],
394     AS_HELP_STRING([--enable-parport-giveio],
395       [Enable use of giveio for parport (for CygWin only)]),
396     [parport_use_giveio=$enableval], [parport_use_giveio=])
397
398 AC_ARG_ENABLE([ft2232_libftdi], [], [
399 if test $enableval = yes; then
400   AC_MSG_ERROR([The ft2232 driver is deprecated, use --enable-ftdi to build its replacement, or force the old driver with --enable-legacy-ft2232_libftdi])
401 fi
402 ])
403
404 AC_ARG_ENABLE([ft2232_ftd2xx], [], [
405 if test $enableval = yes; then
406   AC_MSG_ERROR([The ft2232 driver is deprecated, use --enable-ftdi to build its replacement, or force the old driver with --enable-legacy-ft2232_ftd2xx])
407 fi
408 ])
409
410 AC_ARG_ENABLE([legacy-ft2232_libftdi],
411   AS_HELP_STRING([--enable-legacy-ft2232_libftdi], [(DEPRECATED) Enable building support for FT2232 based devices using the libftdi library]),
412   [build_ft2232_libftdi=$enableval], [build_ft2232_libftdi=no])
413
414 AC_ARG_ENABLE([legacy-ft2232_ftd2xx],
415   AS_HELP_STRING([--enable-legacy-ft2232_ftd2xx], [(DEPRECATED) Enable building support for FT2232 based devices using the D2XX library from ftdichip.com]),
416   [build_ft2232_ftd2xx=$enableval], [build_ft2232_ftd2xx=no])
417
418 AC_ARG_ENABLE([jtag_vpi],
419   AS_HELP_STRING([--enable-jtag_vpi], [Enable building support for JTAG VPI]),
420   [build_jtag_vpi=$enableval], [build_jtag_vpi=no])
421
422 AC_ARG_ENABLE([usb_blaster_libftdi],
423   AS_HELP_STRING([--enable-usb_blaster_libftdi], [Enable building support for the Altera USB-Blaster using the libftdi driver, opensource alternate of FTD2XX]),
424   [build_usb_blaster_libftdi=$enableval], [build_usb_blaster_libftdi=no])
425
426 AC_ARG_ENABLE([usb_blaster_ftd2xx],
427   AS_HELP_STRING([--enable-usb_blaster_ftd2xx], [Enable building support for the Altera USB-Blaster using the FTD2XX driver from ftdichip.com]),
428   [build_usb_blaster_ftd2xx=$enableval], [build_usb_blaster_ftd2xx=no])
429
430 AC_ARG_ENABLE([amtjtagaccel],
431   AS_HELP_STRING([--enable-amtjtagaccel], [Enable building the Amontec JTAG-Accelerator driver]),
432   [build_amtjtagaccel=$enableval], [build_amtjtagaccel=no])
433
434 AC_ARG_ENABLE([zy1000_master],
435   AS_HELP_STRING([--enable-zy1000-master], [Use ZY1000 JTAG master registers]),
436   [build_zy1000_master=$enableval], [build_zy1000_master=no])
437
438 AC_ARG_ENABLE([zy1000],
439   AS_HELP_STRING([--enable-zy1000], [Enable ZY1000 interface]),
440   [build_zy1000=$enableval], [build_zy1000=no])
441
442 AC_ARG_ENABLE([ioutil],
443   AS_HELP_STRING([--enable-ioutil], [Enable ioutil functions - useful for standalone OpenOCD implementations]),
444   [build_ioutil=$enableval], [build_ioutil=no])
445
446 case "${host_cpu}" in
447   arm*)
448     AC_ARG_ENABLE([ep93xx],
449       AS_HELP_STRING([--enable-ep93xx], [Enable building support for EP93xx based SBCs]),
450       [build_ep93xx=$enableval], [build_ep93xx=no])
451
452     AC_ARG_ENABLE([at91rm9200],
453       AS_HELP_STRING([--enable-at91rm9200], [Enable building support for AT91RM9200 based SBCs]),
454       [build_at91rm9200=$enableval], [build_at91rm9200=no])
455
456     AC_ARG_ENABLE([bcm2835gpio],
457       AS_HELP_STRING([--enable-bcm2835gpio], [Enable building support for bitbanging on BCM2835 (as found in Raspberry Pi)]),
458       [build_bcm2835gpio=$enableval], [build_bcm2835gpio=no])
459     ;;
460
461   *)
462     build_ep93xx=no
463     build_at91rm9200=no
464     build_bcm2835gpio=no
465     ;;
466 esac
467
468 AC_ARG_ENABLE([gw16012],
469   AS_HELP_STRING([--enable-gw16012], [Enable building support for the Gateworks GW16012 JTAG Programmer]),
470   [build_gw16012=$enableval], [build_gw16012=no])
471
472 AC_ARG_ENABLE([presto_libftdi],
473   AS_HELP_STRING([--enable-presto_libftdi], [Enable building support for ASIX Presto Programmer using the libftdi driver]),
474   [build_presto_libftdi=$enableval], [build_presto_libftdi=no])
475
476 AC_ARG_ENABLE([presto_ftd2xx],
477   AS_HELP_STRING([--enable-presto_ftd2xx], [Enable building support for ASIX Presto Programmer using the FTD2XX driver]),
478   [build_presto_ftd2xx=$enableval], [build_presto_ftd2xx=no])
479
480 AC_ARG_ENABLE([openjtag_ftd2xx],
481   AS_HELP_STRING([--enable-openjtag_ftd2xx], [Enable building support for the OpenJTAG Programmer with ftd2xx driver]),
482   [build_openjtag_ftd2xx=$enableval], [build_openjtag_ftd2xx=no])
483
484 AC_ARG_ENABLE([openjtag_ftdi],
485   AS_HELP_STRING([--enable-openjtag_ftdi], [Enable building support for the OpenJTAG Programmer with ftdi driver]),
486   [build_openjtag_ftdi=$enableval], [build_openjtag_ftdi=no])
487
488 AC_ARG_ENABLE([oocd_trace],
489   AS_HELP_STRING([--enable-oocd_trace],
490   [Enable building support for some prototype OpenOCD+trace ETM capture hardware]),
491   [build_oocd_trace=$enableval], [build_oocd_trace=no])
492
493 AC_ARG_ENABLE([buspirate],
494   AS_HELP_STRING([--enable-buspirate], [Enable building support for the Buspirate]),
495   [build_buspirate=$enableval], [build_buspirate=no])
496
497 AC_ARG_ENABLE([sysfsgpio],
498   AS_HELP_STRING([--enable-sysfsgpio], [Enable building support for programming driven via sysfs gpios.]),
499   [build_sysfsgpio=$enableval], [build_sysfsgpio=no])
500
501 AC_ARG_ENABLE([minidriver_dummy],
502   AS_HELP_STRING([--enable-minidriver-dummy], [Enable the dummy minidriver.]),
503   [build_minidriver_dummy=$enableval], [build_minidriver_dummy=no])
504
505 AC_ARG_ENABLE([internal-jimtcl],
506   AS_HELP_STRING([--disable-internal-jimtcl], [Disable building internal jimtcl]),
507   [use_internal_jimtcl=$enableval], [use_internal_jimtcl=yes])
508
509 AC_ARG_ENABLE([internal-libjaylink],
510   AS_HELP_STRING([--disable-internal-libjaylink],
511   [Disable building internal libjaylink]),
512   [use_internal_libjaylink=$enableval], [use_internal_libjaylink=yes])
513
514 build_minidriver=no
515 AC_MSG_CHECKING([whether to enable ZY1000 minidriver])
516 if test $build_zy1000 = yes; then
517   if test $build_minidriver = yes; then
518     AC_MSG_ERROR([Multiple minidriver options have been enabled.])
519   fi
520   AC_DEFINE([HAVE_JTAG_MINIDRIVER_H], [1],
521       [Define to 1 if you have the <jtag_minidriver.h> header file.])
522   build_minidriver=yes
523 fi
524 AC_MSG_RESULT([$build_zy1000])
525
526 AC_ARG_ENABLE([remote-bitbang],
527   AS_HELP_STRING([--enable-remote-bitbang], [Enable building support for the Remote Bitbang jtag driver]),
528   [build_remote_bitbang=$enableval], [build_remote_bitbang=no])
529
530 AC_MSG_CHECKING([whether to enable dummy minidriver])
531 if test $build_minidriver_dummy = yes; then
532   if test $build_minidriver = yes; then
533     AC_MSG_ERROR([Multiple minidriver options have been enabled.])
534   fi
535   build_minidriver=yes
536   AC_DEFINE([BUILD_MINIDRIVER_DUMMY], [1], [Use the dummy minidriver.])
537   AC_DEFINE([HAVE_JTAG_MINIDRIVER_H], [1],
538       [Define to 1 if you have the <jtag_minidriver.h> header file.])
539 fi
540 AC_MSG_RESULT([$build_minidriver_dummy])
541
542 AC_MSG_CHECKING([whether standard drivers can be built])
543 if test "$build_minidriver" = yes; then
544   AC_MSG_RESULT([no])
545   AC_MSG_WARN([Using the minidriver disables all other drivers.])
546   sleep 2
547 else
548   AC_MSG_RESULT([yes])
549 fi
550
551 case "${host_cpu}" in
552   i?86|x86*)
553     ;;
554   *)
555     if test x$parport_use_ppdev = xno; then
556       AC_MSG_WARN([--disable-parport-ppdev is not supported by the host CPU])
557     fi
558     parport_use_ppdev=yes
559     ;;
560 esac
561
562 case $host in
563   *-cygwin*)
564     is_win32=yes
565     parport_use_ppdev=no
566
567     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[return __MINGW32__;]])],
568       [is_mingw=yes],[is_mingw=no])
569     if test $is_mingw = yes; then
570       AC_DEFINE([IS_MINGW], [1], [1 if building for MinGW.])
571       if test x$parport_use_giveio = xno; then
572         AC_MSG_WARN([--disable-parport-giveio is not supported by MinGW32 hosts])
573       fi
574       parport_use_giveio=yes
575       is_cygwin=no
576     else
577       is_cygwin=yes
578       AC_DEFINE([IS_CYGWIN], [1], [1 if building for Cygwin.])
579       # sys/io.h needed under cygwin for parport access
580       if test $build_parport = yes; then
581         AC_CHECK_HEADERS([sys/io.h],[],AC_MSG_ERROR([Please install the cygwin ioperm package]))
582       fi
583     fi
584
585     AC_DEFINE([IS_WIN32], [1], [1 if building for Win32.])
586     AC_DEFINE([IS_DARWIN], [0], [0 if not building for Darwin.])
587     ;;
588   *-mingw*)
589     is_mingw=yes
590     is_win32=yes
591     parport_use_ppdev=no
592
593     if test x$parport_use_giveio = xno; then
594       AC_MSG_WARN([--disable-parport-giveio is not supported by MinGW32 hosts])
595     fi
596     parport_use_giveio=yes
597
598     if test x$build_buspirate = xyes; then
599       AC_MSG_ERROR([buspirate currently not supported by MinGW32 hosts])
600     fi
601
602     CFLAGS="$CFLAGS -D__USE_MINGW_ANSI_STDIO"
603
604     AC_DEFINE([IS_MINGW], [1], [1 if building for MinGW.])
605     AC_DEFINE([IS_WIN32], [1], [1 if building for Win32.])
606     AC_DEFINE([IS_DARWIN], [0], [0 if not building for Darwin.])
607     ;;
608   *darwin*)
609     is_darwin=yes
610
611     if test x$parport_use_giveio = xyes; then
612       AC_MSG_WARN([--enable-parport-giveio cannot be used by Darwin hosts])
613     fi
614     parport_use_giveio=no
615
616     AC_DEFINE([IS_CYGWIN], [0], [0 if not building for Cygwin.])
617     AC_DEFINE([IS_WIN32], [0], [0 if not building for Win32.])
618     AC_DEFINE([IS_DARWIN], [1], [1 if building for Darwin.])
619     ;;
620   *)
621     if test x$parport_use_giveio = xyes; then
622       AC_MSG_WARN([--enable-parport-giveio cannot be used by ]$host[ hosts])
623     fi
624     parport_use_giveio=no
625     AC_DEFINE([IS_CYGWIN], [0], [0 if not building for Cygwin.])
626     AC_DEFINE([IS_WIN32], [0], [0 if not building for Win32.])
627     AC_DEFINE([IS_DARWIN], [0], [0 if not building for Darwin.])
628     ;;
629 esac
630
631 if test $is_win32 = yes; then
632     AC_DEFINE([WIN32_LEAN_AND_MEAN], [1], [1 to exclude old conflicting definitions when building on Windows])
633 fi
634
635 if test $build_parport = yes; then
636   build_bitbang=yes
637   AC_DEFINE([BUILD_PARPORT], [1], [1 if you want parport.])
638 else
639   AC_DEFINE([BUILD_PARPORT], [0], [0 if you don't want parport.])
640 fi
641
642 if test $build_dummy = yes; then
643   build_bitbang=yes
644   AC_DEFINE([BUILD_DUMMY], [1], [1 if you want dummy driver.])
645 else
646   AC_DEFINE([BUILD_DUMMY], [0], [0 if you don't want dummy driver.])
647 fi
648
649 if test $build_ep93xx = yes; then
650   build_bitbang=yes
651   AC_DEFINE([BUILD_EP93XX], [1], [1 if you want ep93xx.])
652 else
653   AC_DEFINE([BUILD_EP93XX], [0], [0 if you don't want ep93xx.])
654 fi
655
656 if test $build_zy1000 = yes; then
657   AC_DEFINE([BUILD_ZY1000], [1], [1 if you want ZY1000.])
658 else
659   AC_DEFINE([BUILD_ZY1000], [0], [0 if you don't want ZY1000.])
660 fi
661
662 if test $build_zy1000_master = yes; then
663   AC_DEFINE([BUILD_ZY1000_MASTER], [1], [1 if you want ZY1000 JTAG master registers.])
664 else
665   AC_DEFINE([BUILD_ZY1000_MASTER], [0], [0 if you don't want ZY1000 JTAG master registers.])
666 fi
667
668 if test $build_at91rm9200 = yes; then
669   build_bitbang=yes
670   AC_DEFINE([BUILD_AT91RM9200], [1], [1 if you want at91rm9200.])
671 else
672   AC_DEFINE([BUILD_AT91RM9200], [0], [0 if you don't want at91rm9200.])
673 fi
674
675 if test $build_bcm2835gpio = yes; then
676   build_bitbang=yes
677   AC_DEFINE([BUILD_BCM2835GPIO], [1], [1 if you want bcm2835gpio.])
678 else
679   AC_DEFINE([BUILD_BCM2835GPIO], [0], [0 if you don't want bcm2835gpio.])
680 fi
681
682 if test x$parport_use_ppdev = xyes; then
683   AC_DEFINE([PARPORT_USE_PPDEV], [1], [1 if you want parport to use ppdev.])
684 else
685   AC_DEFINE([PARPORT_USE_PPDEV], [0], [0 if you don't want parport to use ppdev.])
686 fi
687
688 if test x$parport_use_giveio = xyes; then
689   AC_DEFINE([PARPORT_USE_GIVEIO], [1], [1 if you want parport to use giveio.])
690 else
691   AC_DEFINE([PARPORT_USE_GIVEIO], [0], [0 if you don't want parport to use giveio.])
692 fi
693
694 if test $build_bitbang = yes; then
695   AC_DEFINE([BUILD_BITBANG], [1], [1 if you want a bitbang interface.])
696 else
697   AC_DEFINE([BUILD_BITBANG], [0], [0 if you don't want a bitbang interface.])
698 fi
699
700 if test $build_ft2232_libftdi = yes; then
701   AC_DEFINE([BUILD_FT2232_LIBFTDI], [1], [1 if you want libftdi ft2232.])
702 else
703   AC_DEFINE([BUILD_FT2232_LIBFTDI], [0], [0 if you don't want libftdi ft2232.])
704 fi
705
706 if test $build_ft2232_ftd2xx = yes; then
707   AC_DEFINE([BUILD_FT2232_FTD2XX], [1], [1 if you want ftd2xx ft2232.])
708 else
709   AC_DEFINE([BUILD_FT2232_FTD2XX], [0], [0 if you don't want ftd2xx ft2232.])
710 fi
711
712 if test $build_usb_blaster_libftdi = yes; then
713   AC_DEFINE([BUILD_USB_BLASTER_LIBFTDI], [1], [1 if you want libftdi usb_blaster.])
714 else
715   AC_DEFINE([BUILD_USB_BLASTER_LIBFTDI], [0], [0 if you don't want libftdi usb_blaster.])
716 fi
717
718 if test $build_jtag_vpi = yes; then
719   AC_DEFINE([BUILD_JTAG_VPI], [1], [1 if you want JTAG VPI.])
720 else
721   AC_DEFINE([BUILD_JTAG_VPI], [0], [0 if you don't want JTAG VPI.])
722 fi
723
724 if test $build_usb_blaster_ftd2xx = yes; then
725   AC_DEFINE([BUILD_USB_BLASTER_FTD2XX], [1], [1 if you want ftd2xx usb_blaster.])
726 else
727   AC_DEFINE([BUILD_USB_BLASTER_FTD2XX], [0], [0 if you don't want ftd2xx usb_blaster.])
728 fi
729
730 if test $build_amtjtagaccel = yes; then
731   AC_DEFINE([BUILD_AMTJTAGACCEL], [1], [1 if you want the Amontec JTAG-Accelerator driver.])
732 else
733   AC_DEFINE([BUILD_AMTJTAGACCEL], [0], [0 if you don't want the Amontec JTAG-Accelerator driver.])
734 fi
735
736 if test $build_gw16012 = yes; then
737   AC_DEFINE([BUILD_GW16012], [1], [1 if you want the Gateworks GW16012 driver.])
738 else
739   AC_DEFINE([BUILD_GW16012], [0], [0 if you don't want the Gateworks GW16012 driver.])
740 fi
741
742 if test $build_presto_libftdi = yes; then
743   build_bitq=yes
744   AC_DEFINE([BUILD_PRESTO_LIBFTDI], [1], [1 if you want the ASIX PRESTO driver using libftdi.])
745 else
746   AC_DEFINE([BUILD_PRESTO_LIBFTDI], [0], [0 if you don't want the ASIX PRESTO driver using libftdi.])
747 fi
748
749 if test $build_presto_ftd2xx = yes; then
750   build_bitq=yes
751   AC_DEFINE([BUILD_PRESTO_FTD2XX], [1], [1 if you want the ASIX PRESTO driver using FTD2XX.])
752 else
753   AC_DEFINE([BUILD_PRESTO_FTD2XX], [0], [0 if you don't want the ASIX PRESTO driver using FTD2XX.])
754 fi
755
756 if test $build_bitq = yes; then
757   AC_DEFINE([BUILD_BITQ], [1], [1 if you want a bitq interface.])
758 else
759   AC_DEFINE([BUILD_BITQ], [0], [0 if you don't want a bitq interface.])
760 fi
761
762 AC_DEFINE([BUILD_OPENJTAG], [0], [0 if you don't want the OpenJTAG driver.])
763 AC_DEFINE([BUILD_OPENJTAG_FTD2XX], [0], [0 if you don't want the OpenJTAG driver with FTD2XX driver.])
764 AC_DEFINE([BUILD_OPENJTAG_LIBFTDI], [0], [0 if you don't want to build OpenJTAG driver with libftdi.])
765
766 if test $build_openjtag_ftd2xx = yes; then
767   AC_DEFINE([BUILD_OPENJTAG], [1], [1 if you want the OpenJTAG driver.])
768   AC_DEFINE([BUILD_OPENJTAG_FTD2XX], [1], [1 if you want the OpenJTAG driver with FTD2XX driver.])
769 fi
770 if test $build_openjtag_ftdi = yes; then
771   AC_DEFINE([BUILD_OPENJTAG], [1], [1 if you want the OpenJTAG drvier.])
772   AC_DEFINE([BUILD_OPENJTAG_LIBFTDI], [1], [1 if you want to build OpenJTAG with FTDI driver.])
773 fi
774
775 if test $build_oocd_trace = yes; then
776   AC_DEFINE([BUILD_OOCD_TRACE], [1], [1 if you want the OpenOCD+trace ETM capture driver.])
777 else
778   AC_DEFINE([BUILD_OOCD_TRACE], [0], [0 if you don't want the OpenOCD+trace ETM capture driver.])
779 fi
780
781 if test $build_buspirate = yes; then
782   AC_DEFINE([BUILD_BUSPIRATE], [1], [1 if you want the Buspirate JTAG driver.])
783 else
784   AC_DEFINE([BUILD_BUSPIRATE], [0], [0 if you don't want the Buspirate JTAG driver.])
785 fi
786
787 if test $use_internal_jimtcl = yes; then
788   if test -f "$srcdir/jimtcl/configure.ac"; then
789     AX_CONFIG_SUBDIR_OPTION([jimtcl], [--disable-install-jim])
790   else
791     AC_MSG_ERROR([jimtcl not found, run git submodule init and git submodule update.])
792   fi
793 fi
794
795 if test $use_internal_libjaylink = yes; then
796   if test -f "$srcdir/src/jtag/drivers/libjaylink/configure.ac"; then
797     ( cd $srcdir/src/jtag/drivers/libjaylink/ && ./autogen.sh )
798     AX_CONFIG_SUBDIR_OPTION([src/jtag/drivers/libjaylink],
799                 [--enable-subproject-build])
800   else
801     AC_MSG_ERROR([Internal libjaylink not found, run either 'git submodule init' and 'git submodule update' or disable internal libjaylink with --disable-internal-libjaylink.])
802   fi
803 else
804   PKG_CHECK_MODULES([libjaylink], [libjaylink >= 0.1],
805         [CFLAGS="$CFLAGS $libjaylink_CFLAGS"; LIBS="$LIBS $libjaylink_LIBS"; HAVE_LIBJAYLINK=yes], [HAVE_LIBJAYLINK=no])
806 fi
807
808 if test $build_remote_bitbang = yes; then
809   build_bitbang=yes
810   AC_DEFINE([BUILD_REMOTE_BITBANG], [1], [1 if you want the Remote Bitbang JTAG driver.])
811 else
812   AC_DEFINE([BUILD_REMOTE_BITBANG], [0], [0 if you don't want the Remote Bitbang JTAG driver.])
813 fi
814
815 if test $build_sysfsgpio = yes; then
816   build_bitbang=yes
817   AC_DEFINE([BUILD_SYSFSGPIO], [1], [1 if you want the SysfsGPIO driver.])
818 else
819   AC_DEFINE([BUILD_SYSFSGPIO], [0], [0 if you don't want SysfsGPIO driver.])
820 fi
821 #-- Deal with MingW/Cygwin FTD2XX issues
822
823 if test $is_win32 = yes; then
824 if test "${with_ftd2xx_linux_tardir+set}" = set
825 then
826   AC_MSG_ERROR([The option: with_ftd2xx_linux_tardir is for LINUX only.])
827 fi
828
829 if test $build_ft2232_ftd2xx = yes -o $build_presto_ftd2xx = yes -o $build_usb_blaster_ftd2xx = yes -o $build_openjtag_ftd2xx = yes; then
830   AC_MSG_CHECKING([for ftd2xx.lib exists (win32)])
831
832   # if we are given a zipdir...
833   if test "${with_ftd2xx_win32_zipdir+set}" = set
834   then
835     # Set the CFLAGS for "ftd2xx.h"
836     f=$with_ftd2xx_win32_zipdir/ftd2xx.h
837     if test ! -f $f ; then
838       AC_MSG_ERROR([File: $f cannot be found])
839     fi
840     CFLAGS="$CFLAGS -I$with_ftd2xx_win32_zipdir"
841
842     # And calculate the LDFLAGS for the machine
843     case "$host_cpu" in
844     i?86|x86_32)
845       LDFLAGS="$LDFLAGS -L$with_ftd2xx_win32_zipdir/i386"
846       LIBS="$LIBS -lftd2xx"
847       f=$with_ftd2xx_win32_zipdir/i386/ftd2xx.lib
848       ;;
849     amd64|x86_64)
850       LDFLAGS="$LDFLAGS -L$with_ftd2xx_win32_zipdir/amd64"
851       LIBS="$LIBS -lftd2xx"
852       f=$with_ftd2xx_win32_zipdir/amd64/ftd2xx.lib
853       ;;
854     *)
855       AC_MSG_ERROR([Unknown Win32 host cpu: $host_cpu])
856       ;;
857     esac
858     if test ! -f $f ; then
859          AC_MSG_ERROR([Library: $f not found])
860     fi
861   else
862     LIBS="$LIBS -lftd2xx"
863     AC_MSG_WARN([ASSUMPTION: The (win32) FTDICHIP.COM files: ftd2xx.h and ftd2xx.lib are in a proper place])
864   fi
865 fi
866 fi # win32
867
868 if test $is_darwin = yes ; then
869 if test "${with_ftd2xx_win32_zipdir+set}" = set
870 then
871    AC_MSG_ERROR([The option: --with-ftd2xx-win32-zipdir is for win32 only])
872 fi
873 if test "${with_ftd2xx_linux_tardir+set}" = set
874 then
875    AC_MSG_ERROR([The option: with_ftd2xx_linux_tardir is for LINUX only.])
876 fi
877
878 if test $build_ft2232_ftd2xx = yes -o $build_presto_ftd2xx = yes -o $build_usb_blaster_ftd2xx = yes ; then
879    AC_MSG_CHECKING([for libftd2xx.a (darwin)])
880
881    if test ! -f /usr/local/include/ftd2xx.h ; then
882       AC_MSG_ERROR([ftd2xx library from FTDICHIP.com seems to be missing, cannot find: /usr/local/include/ftd2xx.h])
883    fi
884
885    CFLAGS="$CFLAGS -I/usr/local/include"
886    LDFLAGS="$LDFLAGS -L/usr/local/lib"
887    LIBS="$LIBS -lftd2xx"
888    AC_MSG_RESULT([-L/usr/local/lib -lftd2xx])
889 fi
890 fi # darwin
891
892 if test $is_win32 = no && test $is_darwin = no ; then
893
894 if test "${with_ftd2xx_win32_zipdir+set}" = set
895 then
896    AC_MSG_ERROR([The option: --with-ftd2xx-win32-zipdir is for win32 only])
897 fi
898
899 if test $build_ft2232_ftd2xx = yes -o $build_presto_ftd2xx = yes -o $build_usb_blaster_ftd2xx = yes -o $build_openjtag_ftd2xx = yes; then
900    # Must be linux
901    if test $host_os != linux-gnu && test $host_os != linux ; then
902       AC_MSG_ERROR([The (linux) ftd2xx library from FTDICHIP.com is linux only. Try --enable-ft2232-libftdi instead])
903   fi
904   # Are we given a TAR directory?
905   if test "${with_ftd2xx_linux_tardir+set}" = set
906   then
907     AC_MSG_CHECKING([uninstalled ftd2xx distribution])
908     # The .H file is simple..
909     FTD2XX_H=$with_ftd2xx_linux_tardir/ftd2xx.h
910     if test ! -f "${FTD2XX_H}"; then
911     AC_MSG_ERROR([Option: --with-ftd2xx-linux-tardir appears wrong, cannot find: ${FTD2XX_H}])
912     fi
913     CFLAGS="$CFLAGS -I$with_ftd2xx_linux_tardir"
914     if test $with_ftd2xx_lib = shared; then
915        FTD2XX_LDFLAGS="-L$with_ftd2xx_linux_tardir"
916        FTD2XX_LIB="-lftd2xx"
917     else
918       # Test #1 - v1.0.x
919       case "$host_cpu" in
920       i?86|x86_32)
921               dir=build/i386;;
922       amd64|x86_64)
923               dir=build/x86_64;;
924       *)
925               dir=none;;
926       esac
927       if test -f "$with_ftd2xx_linux_tardir/$dir/libftd2xx.a"; then
928           FTD2XX_LDFLAGS="-L$with_ftd2xx_linux_tardir/$dir"
929           # Also needs -lrt
930           FTD2XX_LIB="-lftd2xx -lrt"
931       else
932         # Test Number2.
933         # Grr.. perhaps it exists as a version number?
934         FTD2XX_LIB="$with_ftd2xx_linux_tardir/static_lib/libftd2xx.a.*.*.*"
935         count=`ls ${FTD2XX_LIB} | wc -l`
936         if test $count -gt 1 ; then
937           AC_MSG_ERROR([Multiple libftd2xx.a files found in: $with_ftd2xx_linux_tardir/static_lib sorry cannot handle this yet])
938         fi
939         if test $count -ne 1 ; then
940           AC_MSG_ERROR([Not found: $f, option: --with-ftd2xx-linux-tardir appears to be wrong])
941         fi
942         # Because the "-l" rules do not understand version numbers...
943         # we will just stuff the absolute path onto the LIBS variable
944         FTD2XX_LIB="`ls ${FTD2XX_LIB}` -lpthread"
945         FTD2XX_LDFLAGS=""
946       fi
947     fi
948     LDFLAGS="${LDFLAGS} ${FTD2XX_LDFLAGS}"
949     LIBS="${FTD2XX_LIB} ${LIBS}"
950     AC_MSG_RESULT([${FTD2XX_LDFLAGS} ${FTD2XX_LIB}])
951   else
952     AC_CHECK_HEADER([ftd2xx.h],[],[
953         AC_MSG_ERROR([You seem to be missing the FTD2xx driver header file.])
954       ])
955     AC_SEARCH_LIBS([FT_GetLibraryVersion],[ftd2xx],,[
956         AC_MSG_ERROR([You appear to be missing the FTD2xx driver library.])
957       ],[-lrt -lusb-1.0])
958   fi
959 fi
960 fi # linux
961
962 if test $build_ft2232_ftd2xx = yes -o $build_presto_ftd2xx = yes -o $build_usb_blaster_ftd2xx = yes ; then
963
964 # Before we go any further - make sure we can *BUILD* and *RUN*
965 # a simple app with the "ftd2xx.lib" file - in what ever form we where given
966 # We should be able to compile, link and run this test program now
967 AC_MSG_CHECKING([whether ftd2xx library works])
968
969 #
970 # Save the LDFLAGS for later..
971 LDFLAGS_SAVE=$LDFLAGS
972 CFLAGS_SAVE=$CFLAGS
973 _LDFLAGS=`eval echo $LDFLAGS`
974 _CFLAGS=`eval echo $CFLAGS`
975 LDFLAGS=$_LDFLAGS
976 CFLAGS=$_CFLAGS
977
978 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
979 #include "confdefs.h"
980 #if IS_WIN32
981 #include "windows.h"
982 #endif
983 #include <stdio.h>
984 #include <ftd2xx.h>
985   ]], [[
986   DWORD x;
987   FT_GetLibraryVersion( &x );
988   ]])], [
989     AC_MSG_RESULT([Success!])
990   ], [
991     AC_MSG_ERROR([Cannot build & run test program using ftd2xx.lib])
992   ], [
993     AC_MSG_RESULT([Skipping as we are cross-compiling])
994   ])
995
996 AC_MSG_CHECKING([for ftd2xx highspeed device support])
997 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
998 #include "confdefs.h"
999 #if IS_WIN32
1000 #include "windows.h"
1001 #endif
1002 #include <stdio.h>
1003 #include <ftd2xx.h>
1004
1005 DWORD x = FT_DEVICE_4232H;
1006     ]], [])], [
1007       AC_DEFINE([BUILD_FT2232_HIGHSPEED], [1],
1008         [Support FT2232H/FT4232HS with FTD2XX or libftdi.])
1009       build_ft2232_highspeed=yes
1010     ], [
1011       build_ft2232_highspeed=no
1012     ])
1013   AC_MSG_RESULT([$build_ft2232_highspeed])
1014
1015   if test $build_ft2232_highspeed = no; then
1016     AC_MSG_WARN([You need a newer FTD2XX driver (version 2.04.16 or later).])
1017   fi
1018
1019 AC_MSG_CHECKING([for ftd2xx FT232H device support])
1020 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1021 #include "confdefs.h"
1022 #if IS_WIN32
1023 #include "windows.h"
1024 #endif
1025 #include <stdio.h>
1026 #include <ftd2xx.h>
1027
1028 DWORD x = FT_DEVICE_232H;
1029     ]], [])], [
1030       AC_DEFINE([HAS_ENUM_FT232H], [1],
1031         [Support FT232H with FTD2XX or libftdi.])
1032       has_enum_ft232h=yes
1033     ], [
1034       has_enum_ft232h=no
1035     ])
1036   AC_MSG_RESULT([$has_enum_ft232h])
1037
1038   if test $has_enum_ft232h = no; then
1039     AC_MSG_WARN([You need a newer FTD2XX driver (version 2.08.12 or later).])
1040   fi
1041
1042 LDFLAGS=$LDFLAGS_SAVE
1043 CFLAGS=$CFLAGS_SAVE
1044 fi
1045
1046 if test $build_ft2232_libftdi = yes -o $build_usb_blaster_libftdi = yes -o \
1047   $build_openjtag_ftdi = yes -o $build_presto_libftdi = yes; then
1048
1049   # we can have libftdi or libftdi1, so check it and use the latest one
1050   PKG_CHECK_MODULES([LIBFTDI], [libftdi1], [use_libftdi=yes], [use_libftdi=no])
1051   if test $use_libftdi = no; then
1052         PKG_CHECK_MODULES([LIBFTDI], [libftdi], [use_libftdi=yes], [use_libftdi=no])
1053   fi
1054   if test $use_libftdi = no; then
1055         AC_MSG_ERROR([The libftdi driver is not present on your system.])
1056   fi
1057
1058   #
1059   # Try to build a small program.
1060   AC_MSG_CHECKING([Build & Link with libftdi...])
1061
1062   LDFLAGS_SAVE=$LDFLAGS
1063   CFLAGS_SAVE=$CFLAGS
1064   LIBS_SAVE=$LIBS
1065   _LDFLAGS=`eval echo $LDFLAGS`
1066   _CFLAGS=`eval echo $CFLAGS`
1067   _LIBS=`eval echo $LIBS`
1068   LDFLAGS=$_LDFLAGS
1069   CFLAGS="$_CFLAGS $LIBFTDI_CFLAGS"
1070   LIBS="$_LIBS $LIBFTDI_LIBS"
1071
1072   AC_RUN_IFELSE([AC_LANG_PROGRAM([[
1073 #include <stdio.h>
1074 #include <ftdi.h>
1075   ]], [[
1076   struct ftdi_context *p;
1077   p = ftdi_new();
1078   if( p != NULL ){
1079       return 0;
1080   } else {
1081       fprintf( stderr, "calling ftdi_new() failed\n");
1082       return 1;
1083         }
1084     ]])], [
1085       AC_MSG_RESULT([Success])
1086     ], [
1087       AC_MSG_ERROR([Cannot build & run test program using libftdi])
1088     ], [
1089       AC_MSG_RESULT([Skipping as we are cross-compiling, trying build only])
1090       AC_SEARCH_LIBS([ftdi_new], [], [], [AC_MSG_ERROR([Cannot link with libftdi])])
1091     ])
1092
1093 AC_MSG_CHECKING([for libftdi highspeed device support])
1094 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1095 #include <stdio.h>
1096 #include <ftdi.h>
1097   ]], [[
1098 enum ftdi_chip_type x = TYPE_2232H;
1099     ]])], [
1100       AC_DEFINE([BUILD_FT2232_HIGHSPEED], [1],
1101         [Support FT2232H/FT4232HS with FTD2XX or libftdi.])
1102       build_ft2232_highspeed=yes
1103     ], [
1104       build_ft2232_highspeed=no
1105     ])
1106     AC_MSG_RESULT([$build_ft2232_highspeed])
1107
1108     if test $build_ft2232_highspeed = no; then
1109       AC_MSG_WARN([You need a newer libftdi version (0.16 or later).])
1110     fi
1111
1112 AC_MSG_CHECKING([for libftdi FT232H device support])
1113 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1114 #include <stdio.h>
1115 #include <ftdi.h>
1116   ]], [[
1117 enum ftdi_chip_type x = TYPE_232H;
1118     ]])], [
1119       AC_DEFINE([HAS_ENUM_FT232H], [1],
1120         [Support FT232H with FTD2XX or libftdi.])
1121       has_enum_ft232h=yes
1122     ], [
1123       has_enum_ft232h=no
1124     ])
1125     AC_MSG_RESULT([$has_enum_ft232h])
1126
1127     if test $has_enum_ft232h = no; then
1128       AC_MSG_WARN([You need a newer libftdi version (0.20 or later).])
1129     fi
1130
1131   # Restore the 'unexpanded ldflags'
1132   LDFLAGS=$LDFLAGS_SAVE
1133   CFLAGS=$CFLAGS_SAVE
1134   LIBS=$LIBS_SAVE
1135 fi
1136
1137 PKG_CHECK_MODULES([LIBUSB1], [libusb-1.0], [
1138         use_libusb1=yes
1139         AC_DEFINE([HAVE_LIBUSB1], [1], [Define if you have libusb-1.x])
1140         PKG_CHECK_EXISTS([libusb-1.0 >= 1.0.9],
1141                 [AC_DEFINE([HAVE_LIBUSB_ERROR_NAME], [1], [Define if your libusb has libusb_error_name()])],
1142                 [AC_MSG_WARN([libusb-1.x older than 1.0.9 detected, consider updating])])
1143         LIBUSB1_CFLAGS=`echo $LIBUSB1_CFLAGS | sed 's/-I/-isystem /'`
1144         AC_MSG_NOTICE([libusb-1.0 header bug workaround: LIBUSB1_CFLAGS changed to "$LIBUSB1_CFLAGS"])
1145         PKG_CHECK_EXISTS([libusb-1.0 >= 1.0.16],
1146                 [AC_DEFINE([HAVE_LIBUSB_GET_PORT_NUMBERS], [1], [Define if your libusb has libusb_get_port_numbers()])])
1147   ], [
1148         use_libusb1=no
1149         AC_MSG_WARN([libusb-1.x not found, trying legacy libusb-0.1 as a fallback; consider installing libusb-1.x instead])
1150 ])
1151
1152 PKG_CHECK_MODULES([LIBUSB0], [libusb], [use_libusb0=yes], [use_libusb0=no])
1153
1154 for hidapi_lib in hidapi hidapi-hidraw hidapi-libusb; do
1155         PKG_CHECK_MODULES([HIDAPI],[$hidapi_lib],[
1156                 use_hidapi=yes
1157                 break
1158         ],[
1159                 use_hidapi=no
1160         ])
1161 done
1162
1163 m4_define([PROCESS_ADAPTERS], [
1164   m4_foreach([adapter], [$1], [
1165         if test $2; then
1166                 if test $ADAPTER_VAR([adapter]) != no; then
1167                         AC_DEFINE([BUILD_]ADAPTER_SYM([adapter]), [1], [1 if you want the ]ADAPTER_DESC([adapter]).)
1168                 else
1169                         AC_DEFINE([BUILD_]ADAPTER_SYM([adapter]), [0], [0 if you do not want the ]ADAPTER_DESC([adapter]).)
1170                 fi
1171         else
1172                 if test $ADAPTER_VAR([adapter]) = yes; then
1173                         AC_MSG_ERROR([$3 is required for the ADAPTER_DESC([adapter])])
1174                 fi
1175                 ADAPTER_VAR([adapter])=no
1176         fi
1177         AM_CONDITIONAL(ADAPTER_SYM([adapter]), [test $ADAPTER_VAR([adapter]) != no])
1178   ])
1179 ])
1180
1181 PROCESS_ADAPTERS([USB1_ADAPTERS], [$use_libusb1 = yes], [libusb-1.x])
1182 PROCESS_ADAPTERS([USB_ADAPTERS], [$use_libusb1 = yes -o $use_libusb0 = yes], [libusb-1.x or libusb-0.1])
1183 PROCESS_ADAPTERS([USB0_ADAPTERS], [$use_libusb0 = yes], [libusb-0.1])
1184 PROCESS_ADAPTERS([HIDAPI_ADAPTERS], [$use_hidapi = yes], [hidapi])
1185
1186 if test $enable_stlink != no -o $enable_ti_icdi != no; then
1187         AC_DEFINE([BUILD_HLADAPTER], [1], [1 if you want the High Level JTAG driver.])
1188 else
1189         AC_DEFINE([BUILD_HLADAPTER], [0], [0 if you want the High Level JTAG driver.])
1190 fi
1191 AM_CONDITIONAL([HLADAPTER], [test $enable_stlink != no -o $enable_ti_icdi != no])
1192
1193 # Disable J-Link driver if internal libjaylink is disabled and libjaylink was
1194 # not found by pkg-config.
1195 if test $enable_jlink != no; then
1196   if test $use_internal_libjaylink$HAVE_LIBJAYLINK = nono; then
1197       enable_jlink=no
1198   fi
1199 fi
1200
1201 AM_CONDITIONAL([RELEASE], [test $build_release = yes])
1202 AM_CONDITIONAL([PARPORT], [test $build_parport = yes])
1203 AM_CONDITIONAL([DUMMY], [test $build_dummy = yes])
1204 AM_CONDITIONAL([GIVEIO], [test x$parport_use_giveio = xyes])
1205 AM_CONDITIONAL([EP93XX], [test $build_ep93xx = yes])
1206 AM_CONDITIONAL([ZY1000], [test $build_zy1000 = yes])
1207 AM_CONDITIONAL([ZY1000_MASTER], [test $build_zy1000_master = yes])
1208 AM_CONDITIONAL([IOUTIL], [test $build_ioutil = yes])
1209 AM_CONDITIONAL([AT91RM9200], [test $build_at91rm9200 = yes])
1210 AM_CONDITIONAL([BCM2835GPIO], [test $build_bcm2835gpio = yes])
1211 AM_CONDITIONAL([BITBANG], [test $build_bitbang = yes])
1212 AM_CONDITIONAL([FT2232_LIBFTDI], [test $build_ft2232_libftdi = yes])
1213 AM_CONDITIONAL([FT2232_DRIVER], [test $build_ft2232_ftd2xx = yes -o $build_ft2232_libftdi = yes])
1214 AM_CONDITIONAL([USB_BLASTER_LIBFTDI], [test $build_usb_blaster_libftdi = yes])
1215 AM_CONDITIONAL([USB_BLASTER_FTD2XX], [test $build_usb_blaster_ftd2xx = yes])
1216 AM_CONDITIONAL([JTAG_VPI], [test $build_jtag_vpi = yes -o $build_jtag_vpi = yes])
1217 AM_CONDITIONAL([USB_BLASTER_DRIVER], [test $build_usb_blaster_ftd2xx = yes -o $build_usb_blaster_libftdi = yes -o $enable_usb_blaster_2 != no])
1218 AM_CONDITIONAL([AMTJTAGACCEL], [test $build_amtjtagaccel = yes])
1219 AM_CONDITIONAL([GW16012], [test $build_gw16012 = yes])
1220 AM_CONDITIONAL([PRESTO_LIBFTDI], [test $build_presto_libftdi = yes])
1221 AM_CONDITIONAL([PRESTO_DRIVER], [test $build_presto_ftd2xx = yes -o $build_presto_libftdi = yes])
1222 AM_CONDITIONAL([OPENJTAG], [test $build_openjtag_ftd2xx = yes -o $build_openjtag_ftdi = yes])
1223 AM_CONDITIONAL([OOCD_TRACE], [test $build_oocd_trace = yes])
1224 AM_CONDITIONAL([REMOTE_BITBANG], [test $build_remote_bitbang = yes])
1225 AM_CONDITIONAL([BUSPIRATE], [test $build_buspirate = yes])
1226 AM_CONDITIONAL([SYSFSGPIO], [test $build_sysfsgpio = yes])
1227 AM_CONDITIONAL([USE_LIBUSB0], [test $use_libusb0 = yes])
1228 AM_CONDITIONAL([USE_LIBUSB1], [test $use_libusb1 = yes])
1229 AM_CONDITIONAL([IS_CYGWIN], [test $is_cygwin = yes])
1230 AM_CONDITIONAL([IS_MINGW], [test $is_mingw = yes])
1231 AM_CONDITIONAL([IS_WIN32], [test $is_win32 = yes])
1232 AM_CONDITIONAL([IS_DARWIN], [test $is_darwin = yes])
1233 AM_CONDITIONAL([BITQ], [test $build_bitq = yes])
1234 AM_CONDITIONAL([CMSIS_DAP], [test $use_hidapi = yes])
1235
1236 AM_CONDITIONAL([MINIDRIVER], [test $build_minidriver = yes])
1237 AM_CONDITIONAL([MINIDRIVER_DUMMY], [test $build_minidriver_dummy = yes])
1238
1239 AM_CONDITIONAL([INTERNAL_JIMTCL], [test $use_internal_jimtcl = yes])
1240 AM_CONDITIONAL([INTERNAL_LIBJAYLINK], [test $use_internal_libjaylink = yes])
1241
1242 # Look for environ alternatives.  Possibility #1: is environ in unistd.h or stdlib.h?
1243 AC_MSG_CHECKING([for environ in unistd.h and stdlib.h])
1244 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1245 #define _GNU_SOURCE
1246 #include <unistd.h>
1247 #include <stdlib.h>
1248   ]], [[char **ep = environ;]]
1249   )], [
1250     AC_MSG_RESULT([yes])
1251     has_environ=yes
1252   ], [
1253     AC_MSG_RESULT([no])
1254
1255     # Possibility #2: can environ be found in an available library?
1256     AC_MSG_CHECKING([for extern environ])
1257     AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1258     extern char **environ;
1259     ]], [[char **ep = environ;]]
1260       )], [
1261         AC_DEFINE(NEED_ENVIRON_EXTERN, [1], [Must declare 'environ' to use it.])
1262         has_environ=yes
1263       ], [
1264         has_environ=no
1265       ])
1266     AC_MSG_RESULT([${has_environ}])
1267   ])
1268
1269 if test "${has_environ}" != "yes" ; then
1270   AC_MSG_FAILURE([Could not find 'environ' in unistd.h or available libraries.])
1271 fi
1272
1273 AC_DEFINE([_GNU_SOURCE],[1],[Use GNU C library extensions (e.g. stdndup).])
1274
1275 # set default gcc warnings
1276 GCC_WARNINGS="-Wall -Wstrict-prototypes -Wformat-security -Wshadow"
1277 if test "${gcc_wextra}" = yes; then
1278   GCC_WARNINGS="${GCC_WARNINGS} -Wextra -Wno-unused-parameter"
1279   GCC_WARNINGS="${GCC_WARNINGS} -Wbad-function-cast"
1280   GCC_WARNINGS="${GCC_WARNINGS} -Wcast-align"
1281   GCC_WARNINGS="${GCC_WARNINGS} -Wredundant-decls"
1282 fi
1283 if test "${gcc_werror}" = yes; then
1284   GCC_WARNINGS="${GCC_WARNINGS} -Werror"
1285 fi
1286
1287 # overide default gcc cflags
1288 if test $gcc_warnings = yes; then
1289   CFLAGS="$CFLAGS $GCC_WARNINGS"
1290 fi
1291
1292 AC_CONFIG_FILES([
1293   Makefile
1294   src/Makefile
1295   src/helper/Makefile
1296   src/jtag/Makefile
1297   src/jtag/drivers/Makefile
1298   src/jtag/drivers/usb_blaster/Makefile
1299   src/jtag/hla/Makefile
1300   src/jtag/aice/Makefile
1301   src/transport/Makefile
1302   src/target/openrisc/Makefile
1303   src/xsvf/Makefile
1304   src/svf/Makefile
1305   src/target/Makefile
1306   src/rtos/Makefile
1307   src/server/Makefile
1308   src/flash/Makefile
1309   src/flash/nor/Makefile
1310   src/flash/nand/Makefile
1311   src/pld/Makefile
1312   doc/Makefile
1313 ])
1314 AC_OUTPUT
1315
1316 echo
1317 echo
1318 echo OpenOCD configuration summary
1319 echo --------------------------------------------------
1320 m4_foreach([adapter], [USB1_ADAPTERS, USB_ADAPTERS, USB0_ADAPTERS, HIDAPI_ADAPTERS],
1321         [s=m4_format(["%-40s"], ADAPTER_DESC([adapter]))
1322         case $ADAPTER_VAR([adapter]) in
1323                 auto)
1324                         echo "$s"yes '(auto)'
1325                         ;;
1326                 yes)
1327                         echo "$s"yes
1328                         ;;
1329                 no)
1330                         echo "$s"no
1331                         ;;
1332         esac
1333 ])
1334 echo
1335
1336 if test $build_ft2232_libftdi = yes -o $build_ft2232_ftd2xx = yes; then
1337         if test $enable_ftdi = no; then
1338                 AC_MSG_WARN([Building the deprecated 'ft2232' adapter driver but not its replacement!])
1339                 AC_MSG_WARN([Please consider using --enable-ftdi instead.])
1340         else
1341                 AC_MSG_WARN([Building the deprecated 'ft2232' adapter driver.])
1342         fi
1343 fi