]> git.sur5r.net Git - openocd/blob - configure.in
Define _GNU_SOURCE in config.h, remove definitions from source files.
[openocd] / configure.in
1 AC_PREREQ(2.60)
2 AC_INIT([openocd], [0.2.0-in-development],
3         [OpenOCD Mailing List <openocd-development@lists.berlios.de>])
4 AC_CONFIG_SRCDIR([src/openocd.c])
5
6 AC_CANONICAL_HOST
7
8 AC_SEARCH_LIBS([ioperm], [ioperm])
9 AC_SEARCH_LIBS([dlopen], [dl])
10
11 AC_CHECK_HEADERS(arpa/inet.h)
12 AC_CHECK_HEADERS(elf.h)
13 AC_CHECK_HEADERS(dirent.h)
14 AC_CHECK_HEADERS(fcntl.h)
15 AC_CHECK_HEADERS(ifaddrs.h)
16 AC_CHECK_HEADERS(jtag_minidriver.h)
17 AC_CHECK_HEADERS(malloc.h)
18 AC_CHECK_HEADERS(netdb.h)
19 AC_CHECK_HEADERS(netinet/in.h)
20 AC_CHECK_HEADERS(netinet/tcp.h)
21 AC_CHECK_HEADERS(net/if.h)
22 AC_CHECK_HEADERS(pthread.h)
23 AC_CHECK_HEADERS(strings.h)
24 AC_CHECK_HEADERS(sys/ioctl.h)
25 AC_CHECK_HEADERS(sys/param.h)
26 AC_CHECK_HEADERS(sys/poll.h)
27 AC_CHECK_HEADERS(sys/select.h)
28 AC_CHECK_HEADERS(sys/socket.h)
29 AC_CHECK_HEADERS(sys/stat.h)
30 AC_CHECK_HEADERS(sys/time.h)
31 AC_CHECK_HEADERS(sys/types.h)
32 AC_CHECK_HEADERS(unistd.h)
33
34 AC_HEADER_ASSERT
35 AC_HEADER_STDBOOL
36 AC_HEADER_TIME
37
38 AC_C_BIGENDIAN
39
40 AC_CHECK_FUNCS(strndup)
41 AC_CHECK_FUNCS(strnlen)
42 AC_CHECK_FUNCS(gettimeofday)
43 AC_CHECK_FUNCS(usleep)
44 AC_CHECK_FUNCS(vasprintf)
45
46 build_bitbang=no
47 build_bitq=no
48 is_cygwin=no
49 is_mingw=no
50 is_win32=no
51 is_darwin=no
52 build_release=yes
53
54 AC_ARG_ENABLE(release,
55         AS_HELP_STRING([--enable-release], [Enable Release Build, default no]),
56         [build_release=$enableval], [build_release=no])
57
58 if test $cross_compiling = no; then
59         if test $build_release = no; then
60                 # check we can find guess-rev.sh
61                 AC_CHECK_FILE("$srcdir/guess-rev.sh", build_release=no, build_release=yes)
62         fi
63 fi
64
65 # We are not *ALWAYS* being installed in the standard place.
66 # We may be installed in a "tool-build" specific location.
67 # Normally with other packages - as part of a tool distro.
68 # Thus - we should search that 'libdir' also.
69 #
70 # And - if we are being installed there - the odds are
71 # The libraries unique to what we are are there too.
72 #
73
74 # Expand nd deal with NONE - just like configure will do later
75 OCDprefix=$prefix
76 OCDxprefix=$exec_prefix
77 test x"$OCDprefix"  = xNONE && OCDprefix=$ac_default_prefix
78 # Let make expand exec_prefix.
79 test x"$OCDxprefix" = xNONE && OCDxprefix="$OCDprefix"
80
81 # what matters is the "exec-prefix"
82 if test "$OCDxprefix" != "$ac_default_prefix"
83 then
84     # We are installing in a non-standard place
85     # Nonstandard --prefix and/or --exec-prefix
86     # We have an override of some sort.
87     # use build specific install library dir
88     
89     LDFLAGS="$LDFLAGS -L$OCDxprefix/lib"
90     # RPATH becomes an issue on Linux only
91     if test $host_os = linux-gnu || test $host_os = linux ; then
92         LDFLAGS="$LDFLAGS -Wl,-rpath,$OCDxprefix/lib"
93     fi
94     # The "INCDIR" is also usable
95     CFLAGS="$CFLAGS -I$includedir"
96 fi
97
98 AC_ARG_WITH(ftd2xx,
99    AS_HELP_STRING([--with-ftd2xx=<PATH>],[This option has been removed.]),
100 [
101 # Option Given.
102 cat << __EOF__
103
104 The option: --with-ftd2xx=<PATH> has been removed.
105 On Linux, the new option is:
106   
107   --with-ftd2xx-linux-tardir=/path/to/files
108
109 Where <path> is the path the the directory where the "tar.gz" file
110 from FTDICHIP.COM was unpacked, for example:
111
112   --with-ftd2xx-linux-tardir=/home/duane/libftd2xx-linux-tardir=/home/duane/libftd2xx0.4.16
113
114 On Cygwin/MingW32, the new option is:
115
116   --with-ftd2xx-win32-zipdir=/path/to/files
117
118 Where <path> is the path to the directory where the "zip" file from
119 FTDICHIP.COM was unpacked, for example:
120
121   --with-ftd2xx-win32-zipdir=/home/duane/ftd2xx.cdm.files
122
123 __EOF__
124
125    AC_MSG_ERROR([Sorry Cannot continue])
126 ],
127
128 # Option not given
129 true
130 ]
131 )
132
133 #========================================
134 # FTD2XXX support comes in 4 forms.
135 #    (1) win32 - via a zip file
136 #    (2) linux - via a tar file
137 #    (3) linux/cygwin/mingw - via libftdi
138 #    (4) darwin - installed under /usr/local
139 #
140 # In case (1) and (2) we need to know where the package was unpacked.
141
142 AC_ARG_WITH(ftd2xx-win32-zipdir,
143   AS_HELP_STRING([--with-ftd2xx-win32-zipdir],[Where (CYGWIN/MINGW) the zip file from ftdichip.com was unpacked <default=search>]),
144   [
145   # option present
146   if test -d $with_ftd2xx_win32_zipdir
147   then
148         with_ftd2xx_win32_zipdir=`cd $with_ftd2xx_win32_zipdir && pwd`
149         AC_MSG_NOTICE([Using: ftdichip.com library: $with_ftd2xx_win32_zipdir])
150   else
151         AC_MSG_ERROR([Parameter to --with-ftd2xx-win32-zipdir is not a dir: $with_ftd2xx_win32_zipdir])
152   fi
153   ],
154   [
155   # not given
156   true
157   ]
158 )
159
160 AC_ARG_WITH(ftd2xx-linux-tardir,
161   AS_HELP_STRING([--with-ftd2xx-linux-tardir], [Where (Linux/Unix) the tar file from ftdichip.com was unpacked <default=search>]),
162   [
163   # Option present
164   if test $is_win32 = yes ; then
165      AC_MSG_ERROR([The option: --with-ftd2xx-linux-tardir is only usable on linux])
166   fi
167   if test -d $with_ftd2xx_linux_tardir
168   then
169         with_ftd2xx_linux_tardir=`cd $with_ftd2xx_linux_tardir && pwd`
170         AC_MSG_NOTICE([Using: ftdichip.com library: $with_ftd2xx_linux_tardir])
171   else
172         AC_MSG_ERROR([Parameter to --with-ftd2xx-linux-tardir is not a dir: $with_ftd2xx_linux_tardir])
173   fi
174   ],
175   [
176   # Not given 
177   true
178   ]
179 )
180
181 AC_ARG_WITH(ftd2xx-lib,
182         AS_HELP_STRING([--with-ftd2xx-lib], [Use static or shared ftd2xx libs on default static]),
183 [
184 case "$withval" in
185 static)
186         with_ftd2xx_lib=$withval
187         ;;
188 shared)
189         with_ftd2xx_lib=$withval
190         ;;
191 *)
192         AC_MSG_ERROR([Option: --with-ftd2xx-lib=static or --with-ftd2xx-lib=shared not, $withval])
193         ;;
194 esac
195 ],
196 [
197         # Default is static - it is simpler :-(
198         with_ftd2xx_lib=static
199 ]
200 )
201
202 AC_ARG_ENABLE(gccwarnings,
203         AS_HELP_STRING([--disable-gccwarnings], [Disable compiler warnings]),
204         [gcc_warnings=$enableval], [gcc_warnings=yes])
205
206 AC_ARG_ENABLE(wextra,
207         AS_HELP_STRING([--disable-wextra], [Disable extra compiler warnings]),
208         [gcc_wextra=$enableval], [gcc_wextra=$gcc_warnings])
209
210 AC_ARG_ENABLE(werror,
211         AS_HELP_STRING([--disable-werror], [Do not treat warnings as errors]),
212         [gcc_werror=$enableval], [gcc_werror=$gcc_warnings])
213
214 # set default verbose options, overridden by following options
215 debug_jtag_io=no
216 debug_usb_io=no
217 debug_usb_comms=no
218
219 AC_ARG_ENABLE(verbose,
220         AS_HELP_STRING([--enable-verbose],
221                 [Enable verbose JTAG I/O messages (for debugging).]), 
222         [
223         debug_jtag_io=$enableval
224         debug_usb_io=$enableval
225         debug_usb_comms=$enableval
226         ], [])
227
228 AC_ARG_ENABLE(verbose_jtag_io,
229         AS_HELP_STRING([--enable-verbose-jtag-io],
230                 [Enable verbose JTAG I/O messages (for debugging).]), 
231         [debug_jtag_io=$enableval], [])
232 AC_ARG_ENABLE(verbose_usb_io,
233         AS_HELP_STRING([--enable-verbose-usb-io],
234                 [Enable verbose USB I/O messages (for debugging)]), 
235         [debug_usb_io=$enableval], [])
236 AC_ARG_ENABLE(verbose_usb_comms,
237         AS_HELP_STRING([--enable-verbose-usb-comms],
238                 [Enable verbose USB communication messages (for debugging)]), 
239         [debug_usb_comms=$enableval], [])
240
241 AC_MSG_CHECKING([whether to enable verbose JTAG I/O messages]);
242 AC_MSG_RESULT($debug_jtag_io)
243 if test $debug_jtag_io = yes; then
244   AC_DEFINE([_DEBUG_JTAG_IO_],[1], [Print verbose JTAG I/O messages])
245 fi
246
247 AC_MSG_CHECKING([whether to enable verbose USB I/O messages]);
248 AC_MSG_RESULT($debug_usb_io)
249 if test $debug_usb_io = yes; then
250   AC_DEFINE([_DEBUG_USB_IO_],[1], [Print verbose USB I/O messages])
251 fi
252
253 AC_MSG_CHECKING([whether to enable verbose USB communication messages]);
254 AC_MSG_RESULT($debug_usb_comms)
255 if test $debug_usb_comms = yes; then
256   AC_DEFINE([_DEBUG_USB_COMMS_],[1], [Print verbose USB communication messages])
257 fi
258
259
260 debug_malloc=no
261 AC_ARG_ENABLE(malloc_logging,
262         AS_HELP_STRING([--enable-malloc-logging],
263                 [Include free space in logging messages (requires malloc.h).]), 
264         [debug_malloc=$enableval], [])
265
266 AC_MSG_CHECKING([whether to enable malloc free space logging]);
267 AC_MSG_RESULT($debug_malloc)
268 if test $debug_malloc = yes; then
269   AC_DEFINE([_DEBUG_FREE_SPACE_],[1], [Include malloc free space in logging])
270 fi
271
272
273 AC_ARG_ENABLE(parport,
274   AS_HELP_STRING([--enable-parport], [Enable building the pc parallel port driver]), 
275   [build_parport=$enableval], [build_parport=no])
276
277 AC_ARG_ENABLE(dummy,
278   AS_HELP_STRING([--enable-dummy], [Enable building the dummy port driver]), 
279   [build_dummy=$enableval], [build_dummy=no])
280   
281 case "${host_cpu}" in 
282   i?86|x86*)
283     AC_ARG_ENABLE(parport_ppdev,
284       AS_HELP_STRING([--enable-parport_ppdev], [Enable use of ppdev (/dev/parportN) for parport]), 
285       [parport_use_ppdev=$enableval], [parport_use_ppdev=no])
286     ;;
287   *) 
288     parport_use_ppdev=yes
289     ;;
290 esac
291
292 AC_ARG_ENABLE(ft2232_libftdi,
293   AS_HELP_STRING([--enable-ft2232_libftdi], [Enable building support for FT2232 based devices using the libftdi driver, opensource alternate of FTD2XX]), 
294   [build_ft2232_libftdi=$enableval], [build_ft2232_libftdi=no])
295
296 AC_ARG_ENABLE(ft2232_ftd2xx,
297   AS_HELP_STRING([--enable-ft2232_ftd2xx], [Enable building support for FT2232 based devices using the FTD2XX driver from ftdichip.com]), 
298   [build_ft2232_ftd2xx=$enableval], [build_ft2232_ftd2xx=no])
299  
300 AC_ARG_ENABLE(amtjtagaccel,
301   AS_HELP_STRING([--enable-amtjtagaccel], [Enable building the Amontec JTAG-Accelerator driver]), 
302   [build_amtjtagaccel=$enableval], [build_amtjtagaccel=no])
303
304 AC_ARG_ENABLE(ecosboard,
305   AS_HELP_STRING([--enable-ecosboard], [Enable building support for eCosBoard based JTAG debugger]), 
306   [build_ecosboard=$enableval], [build_ecosboard=no])
307
308 AC_ARG_ENABLE(ioutil,
309   AS_HELP_STRING([--enable-ioutil], [Enable ioutil functions - useful for standalone OpenOCD implementations]), 
310   [build_ioutil=$enableval], [build_ioutil=no])
311
312 AC_ARG_ENABLE(httpd,
313   AS_HELP_STRING([--enable-httpd], [Enable builtin httpd server - useful for standalone OpenOCD implementations]), 
314   [build_httpd=$enableval], [build_httpd=no])
315
316 case "${host_cpu}" in 
317   arm*)
318     AC_ARG_ENABLE(ep93xx,
319       AS_HELP_STRING([--enable-ep93xx], [Enable building support for EP93xx based SBCs]), 
320       [build_ep93xx=$enableval], [build_ep93xx=no])
321
322     AC_ARG_ENABLE(at91rm9200,
323       AS_HELP_STRING([--enable-at91rm9200], [Enable building support for AT91RM9200 based SBCs]),
324       [build_at91rm9200=$enableval], [build_at91rm9200=no])
325     ;;
326     
327   *) 
328     build_ep93xx=no
329     build_at91rm9200=no
330     ;;
331 esac
332
333 AC_ARG_ENABLE(gw16012,
334   AS_HELP_STRING([--enable-gw16012], [Enable building support for the Gateworks GW16012 JTAG Programmer]),
335   [build_gw16012=$enableval], [build_gw16012=no])
336
337 AC_ARG_ENABLE(presto_libftdi,
338   AS_HELP_STRING([--enable-presto_libftdi], [Enable building support for ASIX Presto Programmer using the libftdi driver]),
339   [build_presto_libftdi=$enableval], [build_presto_libftdi=no])
340
341 AC_ARG_ENABLE(presto_ftd2xx,
342   AS_HELP_STRING([--enable-presto_ftd2xx], [Enable building support for ASIX Presto Programmer using the FTD2XX driver]),
343   [build_presto_ftd2xx=$enableval], [build_presto_ftd2xx=no])
344
345 AC_ARG_ENABLE(usbprog,
346   AS_HELP_STRING([--enable-usbprog], [Enable building support for the usbprog JTAG Programmer]),
347   [build_usbprog=$enableval], [build_usbprog=no])
348
349 AC_ARG_ENABLE(oocd_trace,
350   AS_HELP_STRING([--enable-oocd_trace], [Enable building support for the OpenOCD+trace ETM capture device]),
351   [build_oocd_trace=$enableval], [build_oocd_trace=no])
352
353 AC_ARG_ENABLE(jlink,
354   AS_HELP_STRING([--enable-jlink], [Enable building support for the Segger J-Link JTAG Programmer]),
355   [build_jlink=$enableval], [build_jlink=no])
356
357 AC_ARG_ENABLE(vsllink,
358   AS_HELP_STRING([--enable-vsllink], [Enable building support for the Versaloon-Link JTAG Programmer]),
359   [build_vsllink=$enableval], [build_vsllink=no])
360
361 AC_ARG_ENABLE(rlink,
362   AS_HELP_STRING([--enable-rlink], [Enable building support for the Raisonance RLink JTAG Programmer]),
363   [build_rlink=$enableval], [build_rlink=no])
364
365 AC_ARG_ENABLE(arm-jtag-ew,
366   AS_HELP_STRING([--enable-arm-jtag-ew], [Enable building support for the Olimex ARM-JTAG-EW Programmer]),
367   [build_armjtagew=$enableval], [build_armjtagew=no])
368
369 case $host in 
370   *-cygwin*) 
371     is_win32=yes
372
373     AC_ARG_ENABLE(parport_giveio,
374     AS_HELP_STRING([--enable-parport_giveio], [Enable use of giveio for parport instead of ioperm]), 
375     [parport_use_giveio=$enableval], [parport_use_giveio=no])
376         
377         AC_COMPILE_IFELSE(AC_LANG_PROGRAM([],[return __MINGW32__;]),[is_mingw=yes],[is_mingw=no])
378         if test $is_mingw = yes; then
379                 AC_DEFINE(IS_MINGW, 1, [1 if building for MinGW.])
380                 parport_use_giveio=yes
381                 is_cygwin=no
382         else
383                 is_cygwin=yes
384                 AC_DEFINE(IS_CYGWIN, 1, [1 if building for Cygwin.])
385         fi
386         
387     AC_DEFINE(IS_WIN32, 1, [1 if building for Win32.])
388     AC_DEFINE(IS_DARWIN, 0, [0 if not building for Darwin.])
389     ;; 
390   *-mingw*) 
391     is_mingw=yes
392     is_win32=yes
393
394     parport_use_giveio=yes
395
396     AC_DEFINE(IS_MINGW, 1, [1 if building for MinGW.])
397     AC_DEFINE(IS_WIN32, 1, [1 if building for Win32.])
398     AC_DEFINE(IS_DARWIN, 0, [0 if not building for Darwin.])
399     ;; 
400   *darwin*)
401     is_darwin=yes
402
403     parport_use_giveio=no
404
405     AC_DEFINE(IS_CYGWIN, 0, [0 if not building for Cygwin.])
406     AC_DEFINE(IS_WIN32, 0, [0 if not building for Win32.])
407     AC_DEFINE(IS_DARWIN, 1, [1 if building for Darwin.])
408     ;;
409   *) 
410         parport_use_giveio=no
411     AC_DEFINE(IS_CYGWIN, 0, [0 if not building for Cygwin.])
412     AC_DEFINE(IS_WIN32, 0, [0 if not building for Win32.])
413     AC_DEFINE(IS_DARWIN, 0, [0 if not building for Darwin.])
414     ;;
415 esac
416
417 if test $build_parport = yes; then
418   build_bitbang=yes
419   AC_DEFINE(BUILD_PARPORT, 1, [1 if you want parport.])
420 else
421   AC_DEFINE(BUILD_PARPORT, 0, [0 if you don't want parport.])
422 fi
423
424 if test $build_dummy = yes; then
425   build_bitbang=yes
426   AC_DEFINE(BUILD_DUMMY, 1, [1 if you want dummy driver.])
427 else
428   AC_DEFINE(BUILD_DUMMY, 0, [0 if you don't want dummy driver.])
429 fi
430
431 if test $build_ep93xx = yes; then
432   build_bitbang=yes
433   AC_DEFINE(BUILD_EP93XX, 1, [1 if you want ep93xx.])
434 else
435   AC_DEFINE(BUILD_EP93XX, 0, [0 if you don't want ep93xx.])
436 fi
437
438 if test $build_ecosboard = yes; then
439   build_bitbang=yes
440   AC_DEFINE(BUILD_ECOSBOARD, 1, [1 if you want eCosBoard.])
441 else
442   AC_DEFINE(BUILD_ECOSBOARD, 0, [0 if you don't want eCosBoard.])
443 fi
444
445 if test $build_ioutil = yes; then
446   AC_DEFINE(BUILD_IOUTIL, 1, [1 if you want ioutils.])
447 else
448   AC_DEFINE(BUILD_IOUTIL, 0, [0 if you don't want ioutils.])
449 fi
450
451 if test $build_httpd = yes; then
452   AC_DEFINE(BUILD_HTTPD, 1, [1 if you want httpd.])
453 else
454   AC_DEFINE(BUILD_HTTPD, 0, [0 if you don't want httpd.])
455 fi
456
457 if test $build_at91rm9200 = yes; then
458   build_bitbang=yes
459   AC_DEFINE(BUILD_AT91RM9200, 1, [1 if you want at91rm9200.])
460 else
461   AC_DEFINE(BUILD_AT91RM9200, 0, [0 if you don't want at91rm9200.])
462 fi
463
464 if test $parport_use_ppdev = yes; then
465   AC_DEFINE(PARPORT_USE_PPDEV, 1, [1 if you want parport to use ppdev.])
466 else
467   AC_DEFINE(PARPORT_USE_PPDEV, 0, [0 if you don't want parport to use ppdev.])
468 fi
469
470 if test $parport_use_giveio = yes; then
471   AC_DEFINE(PARPORT_USE_GIVEIO, 1, [1 if you want parport to use giveio.])
472 else
473   AC_DEFINE(PARPORT_USE_GIVEIO, 0, [0 if you don't want parport to use giveio.])
474 fi
475
476 if test $build_bitbang = yes; then
477   AC_DEFINE(BUILD_BITBANG, 1, [1 if you want a bitbang interface.])
478 else
479   AC_DEFINE(BUILD_BITBANG, 0, [0 if you don't want a bitbang interface.])
480 fi
481
482 if test $build_ft2232_libftdi = yes; then
483   AC_DEFINE(BUILD_FT2232_LIBFTDI, 1, [1 if you want libftdi ft2232.])
484 else
485   AC_DEFINE(BUILD_FT2232_LIBFTDI, 0, [0 if you don't want libftdi ft2232.])
486 fi
487
488 if test $build_ft2232_ftd2xx = yes; then
489   AC_DEFINE(BUILD_FT2232_FTD2XX, 1, [1 if you want ftd2xx ft2232.])
490 else
491   AC_DEFINE(BUILD_FT2232_FTD2XX, 0, [0 if you don't want ftd2xx ft2232.])
492 fi
493
494 if test $build_amtjtagaccel = yes; then
495   AC_DEFINE(BUILD_AMTJTAGACCEL, 1, [1 if you want the Amontec JTAG-Accelerator driver.])
496 else
497   AC_DEFINE(BUILD_AMTJTAGACCEL, 0, [0 if you don't want the Amontec JTAG-Accelerator driver.])
498 fi
499
500 if test $build_gw16012 = yes; then
501   AC_DEFINE(BUILD_GW16012, 1, [1 if you want the Gateworks GW16012 driver.])
502 else
503   AC_DEFINE(BUILD_GW16012, 0, [0 if you don't want the Gateworks GW16012 driver.])
504 fi
505
506 if test $build_presto_libftdi = yes; then
507   build_bitq=yes
508   AC_DEFINE(BUILD_PRESTO_LIBFTDI, 1, [1 if you want the ASIX PRESTO driver using libftdi.])
509 else
510   AC_DEFINE(BUILD_PRESTO_LIBFTDI, 0, [0 if you don't want the ASIX PRESTO driver using libftdi.])
511 fi
512
513 if test $build_presto_ftd2xx = yes; then
514   build_bitq=yes
515   AC_DEFINE(BUILD_PRESTO_FTD2XX, 1, [1 if you want the ASIX PRESTO driver using FTD2XX.])
516 else
517   AC_DEFINE(BUILD_PRESTO_FTD2XX, 0, [0 if you don't want the ASIX PRESTO driver using FTD2XX.])
518 fi
519
520 if test $build_bitq = yes; then
521   AC_DEFINE(BUILD_BITQ, 1, [1 if you want a bitq interface.])
522 else
523   AC_DEFINE(BUILD_BITQ, 0, [0 if you don't want a bitq interface.])
524 fi
525
526 if test $build_usbprog = yes; then
527   AC_DEFINE(BUILD_USBPROG, 1, [1 if you want the usbprog JTAG driver.])
528 else
529   AC_DEFINE(BUILD_USBPROG, 0, [0 if you don't want the usbprog JTAG driver.])
530 fi
531
532 if test $build_oocd_trace = yes; then
533   AC_DEFINE(BUILD_OOCD_TRACE, 1, [1 if you want the OpenOCD+trace ETM capture driver.])
534 else
535   AC_DEFINE(BUILD_OOCD_TRACE, 0, [0 if you don't want the OpenOCD+trace ETM capture driver.])
536 fi
537
538 if test $build_jlink = yes; then
539   AC_DEFINE(BUILD_JLINK, 1, [1 if you want the J-Link JTAG driver.])
540 else
541   AC_DEFINE(BUILD_JLINK, 0, [0 if you don't want the J-Link JTAG driver.])
542 fi
543
544 if test $build_vsllink = yes; then
545   AC_DEFINE(BUILD_VSLLINK, 1, [1 if you want the Versaloon-Link JTAG driver.])
546 else
547   AC_DEFINE(BUILD_VSLLINK, 0, [0 if you don't want the Versaloon-Link JTAG driver.])
548 fi
549
550 if test $build_rlink = yes; then
551   AC_DEFINE(BUILD_RLINK, 1, [1 if you want the RLink JTAG driver.])
552 else
553   AC_DEFINE(BUILD_RLINK, 0, [0 if you don't want the RLink JTAG driver.])
554 fi
555
556 if test $build_armjtagew = yes; then
557   AC_DEFINE(BUILD_ARMJTAGEW, 1, [1 if you want the ARM-JTAG-EW JTAG driver.])
558 else
559   AC_DEFINE(BUILD_ARMJTAGEW, 0, [0 if you don't want the ARM-JTAG-EW JTAG driver.])
560 fi
561
562 #-- Deal with MingW/Cygwin FTD2XX issues
563
564 if test $is_win32 = yes; then
565 if test "${with_ftd2xx_linux_tardir+set}" = set
566 then
567    AC_MSG_ERROR([The option: with_ftd2xx_linux_tardir is for LINUX only.])
568 fi
569
570 if test $build_ft2232_ftd2xx = yes -o $build_presto_ftd2xx = yes ; then
571 AC_MSG_CHECKING([for ftd2xx.lib exists (win32)])
572
573    # if we are given a zipdir...
574    if test "${with_ftd2xx_win32_zipdir+set}" = set
575    then
576       # Set the CFLAGS for "ftd2xx.h"
577       f=$with_ftd2xx_win32_zipdir/ftd2xx.h
578       if test ! -f $f ; then
579          AC_MSG_ERROR([File: $f cannot be found])
580       fi
581       CFLAGS="$CFLAGS -I$with_ftd2xx_win32_zipdir"
582
583       # And calculate the LDFLAGS for the machine
584       case "$host_cpu" in
585       i?86|x86_*)
586         LDFLAGS="$LDFLAGS -L$with_ftd2xx_win32_zipdir/i386"
587         LIBS="$LIBS -lftd2xx"
588         f=$with_ftd2xx_win32_zipdir/i386/ftd2xx.lib
589         ;;
590       amd64)
591         LDFLAGS="$LDFLAGS -L$with_ftd2xx_win32_zipdir/amd64"
592         LIBS="$LIBS -lftd2xx"
593         f=$with_ftd2xx_win32_zipdir/amd64/ftd2xx.lib
594         ;;
595       *)
596         AC_MSG_ERROR([Unknown Win32 host cpu: $host_cpu])
597         ;;
598        esac
599        if test ! -f $f ; then
600           AC_MSG_ERROR([Library: $f not found])
601        fi
602    else
603       LIBS="$LIBS -lftd2xx"
604       AC_MSG_WARN([ASSUMPTION: The (win32) FTDICHIP.COM files: ftd2xx.h and ftd2xx.lib are in a proper place])
605    fi
606 fi
607 fi
608
609 if test $is_darwin = yes ; then
610 if test "${with_ftd2xx_win32_zipdir+set}" = set
611 then
612    AC_MSG_ERROR([The option: --with-ftd2xx-win32-zipdir is for win32 only])
613 fi
614 if test "${with_ftd2xx_linux_tardir+set}" = set
615 then
616    AC_MSG_ERROR([The option: with_ftd2xx_linux_tardir is for LINUX only.])
617 fi
618
619 if test $build_ft2232_ftd2xx = yes -o $build_presto_ftd2xx = yes ; then
620    AC_MSG_CHECKING([for libftd2xx.a (darwin)])
621
622    if test ! -f /usr/local/include/ftd2xx.h ; then
623       AC_MSG_ERROR([ftd2xx library from FTDICHIP.com seems to be missing, cannot find: /usr/local/include/ftd2xx.h])
624    fi
625
626    CFLAGS="$CFLAGS -I/usr/local/include"
627    LDFLAGS="$LDFLAGS -L/usr/local/lib"
628    LIBS="$LIBS -lftd2xx"
629    AC_MSG_RESULT([-L/usr/local/lib -lftd2xx])
630 fi
631 fi
632
633 if test $is_win32 = no && test $is_darwin = no ; then
634
635 if test "${with_ftd2xx_win32_zipdir+set}" = set
636 then
637    AC_MSG_ERROR([The option: --with-ftd2xx-win32-zipdir is for win32 only])
638 fi
639
640 if test $build_ft2232_ftd2xx = yes -o $build_presto_ftd2xx = yes ; then
641    # Must be linux
642    if test $host_os != linux-gnu && test $host_os != linux ; then
643       AC_MSG_ERROR([The (linux) ftd2xx library from FTDICHIP.com is linux only. Try --enable-ft2232-libftdi instead])
644    fi
645    # Are we given a TAR directory?
646    if test "${with_ftd2xx_linux_tardir+set}" = set
647    then
648         AC_MSG_CHECKING([uninstalled ftd2xx distribution])
649         # The .H file is simple..
650         FTD2XX_H=$with_ftd2xx_linux_tardir/ftd2xx.h
651         if test ! -f "${FTD2XX_H}"; then
652            AC_MSG_ERROR([Option: --with-ftd2xx-linux-tardir appears wrong, cannot find: ${FTD2XX_H}])
653         fi
654         CFLAGS="$CFLAGS -I$with_ftd2xx_linux_tardir"
655         FTD2XX_LDFLAGS="-L$with_ftd2xx_linux_tardir"
656         FTD2XX_LIB="-lftd2xx"
657         if test $with_ftd2xx_lib != shared; then
658             # Test #1 - Future proof - if/when ftdichip fixes their distro.
659             # Try it with the simple ".a" suffix.
660             FTD2XX_LIB="$with_ftd2xx_linux_tardir/static_lib/libftd2xx.a"
661             if test -f "${FTD2XX_LIB}"; then
662                FTD2XX_LDFLAGS="${FTD2XX_LDFLAGS}/static_lib"
663             else
664                # Test Number2.
665                # Grr.. perhaps it exists as a version number?
666                FTD2XX_LIB="$with_ftd2xx_linux_tardir/static_lib/libftd2xx.a.*.*.*"
667                count=`ls ${FTD2XX_LIB} | wc -l`
668                if test $count -gt 1 ; then
669                   AC_MSG_ERROR([Multiple libftd2xx.a files found in: $with_ftd2xx_linux_tardir/static_lib sorry cannot handle this yet])
670                fi
671                if test $count -ne 1 ; then
672                   AC_MSG_ERROR([Not found: $f, option: --with-ftd2xx-linux-tardir appears to be wrong])
673                fi
674                # Because the "-l" rules do not understand version numbers...
675                # we will just stuff the absolute path onto the LIBS variable
676                FTD2XX_LIB="`ls ${FTD2XX_LIB}` -lpthread"
677                FTD2XX_LDFLAGS=""
678             fi
679         fi
680         LDFLAGS="${LDFLAGS} ${FTD2XX_LDFLAGS}"
681         LIBS="${LIBS} ${FTD2XX_LIB}"
682         AC_MSG_RESULT([${FTD2XX_LDFLAGS} ${FTD2XX_LIB}])
683    else
684         AC_CHECK_HEADER([ftd2xx.h],[],[
685                         AC_MSG_ERROR([You seem to be missing the FTD2xx driver header file.])
686                 ])
687         AC_SEARCH_LIBS([FT_GetLibraryVersion],[ftd2xx],,[
688                         AC_MSG_ERROR([You appear to be missing the FTD2xx driver library.])
689                 ],[])
690    fi
691 fi
692 fi
693
694 if test $build_ft2232_ftd2xx = yes -o $build_presto_ftd2xx = yes; then
695
696 # Before we go any further - make sure we can *BUILD* and *RUN*
697 # a simple app with the "ftd2xx.lib" file - in what ever form we where given
698 # We should be able to compile, link and run this test program now
699   AC_MSG_CHECKING([whether ftd2xx library works])
700
701 #
702 # Save the LDFLAGS for later..
703 LDFLAGS_SAVE=$LDFLAGS
704 CFLAGS_SAVE=$CFLAGS
705 _LDFLAGS=`eval echo $LDFLAGS`
706 _CFLAGS=`eval echo $CFLAGS`
707 LDFLAGS=$_LDFLAGS
708 CFLAGS=$_CFLAGS
709   AC_RUN_IFELSE(
710 [
711 #include "confdefs.h"
712 #if IS_WIN32
713 #include "windows.h"
714 #endif
715 #include <stdio.h>
716 #include <ftd2xx.h>
717
718 int
719 main( int argc, char **argv )
720 {
721         DWORD x;
722         FT_GetLibraryVersion( &x );
723         return 0;
724 }
725 ], [ AC_MSG_RESULT([Success!])] , [ AC_MSG_ERROR([Cannot build & run test program using ftd2xx.lib]) ] )
726 LDFLAGS=$LDFLAGS_SAVE
727 CFLAGS=$CFLAGS_SAVE
728 fi
729
730 if test $build_ft2232_libftdi = yes ; then
731    # We assume: the package is preinstalled in the proper place
732    # these present as 2 libraries..
733    LIBS="$LIBS -lftdi -lusb"
734    # 
735    # Try to build a small program.
736    AC_MSG_CHECKING([Build & Link with libftdi...])
737
738 LDFLAGS_SAVE=$LDFLAGS
739 CFLAGS_SAVE=$CFLAGS
740 _LDFLAGS=`eval echo $LDFLAGS`
741 _CFLAGS=`eval echo $CFLAGS`
742 LDFLAGS=$_LDFLAGS
743 CFLAGS=$_CFLAGS
744
745    AC_RUN_IFELSE(
746 [
747 #include <stdio.h>
748 #include <ftdi.h>
749
750 int
751 main( int argc, char **argv )
752 {
753         struct ftdi_context *p;
754         p = ftdi_new();
755         if( p != NULL ){
756             return 0;
757         } else {
758             fprintf( stderr, "calling ftdi_new() failed\n");
759             return 1;
760         }
761 }
762 ]
763
764 [ AC_MSG_RESULT([Success]) ]
765
766 [ AC_MSG_ERROR([Cannot build & run test program using libftdi]) ] )
767 # Restore the 'unexpanded ldflags'
768 LDFLAGS=$LDFLAGS_SAVE
769 CFLAGS=$CFLAGS_SAVE
770 fi
771
772 # check for usb.h when a driver will require it
773 if test $build_jlink = yes -o $build_vsllink = yes -o $build_usbprog = yes -o \
774         $build_rlink = yes -o $build_armjtagew = yes
775 then 
776   AC_CHECK_HEADERS([usb.h],[],
777         [AC_MSG_ERROR([usb.h is required to build some OpenOCD driver(s)])])
778 fi
779
780 AM_CONFIG_HEADER(config.h)
781 AM_INIT_AUTOMAKE([-Wall -Wno-portability])
782 AM_MAINTAINER_MODE
783
784 AM_CONDITIONAL(RELEASE, test $build_release = yes)
785 AM_CONDITIONAL(PARPORT, test $build_parport = yes)
786 AM_CONDITIONAL(DUMMY, test $build_dummy = yes)
787 AM_CONDITIONAL(GIVEIO, test $parport_use_giveio = yes)
788 AM_CONDITIONAL(EP93XX, test $build_ep93xx = yes)
789 AM_CONDITIONAL(ECOSBOARD, test $build_ecosboard = yes)
790 AM_CONDITIONAL(IOUTIL, test $build_ioutil = yes)
791 AM_CONDITIONAL(HTTPD, test $build_httpd = yes)
792 AM_CONDITIONAL(AT91RM9200, test $build_at91rm9200 = yes)
793 AM_CONDITIONAL(BITBANG, test $build_bitbang = yes)
794 AM_CONDITIONAL(FT2232_LIBFTDI, test $build_ft2232_libftdi = yes)
795 AM_CONDITIONAL(FT2232_FTD2XX, test $build_ft2232_ftd2xx = yes)
796 AM_CONDITIONAL(AMTJTAGACCEL, test $build_amtjtagaccel = yes)
797 AM_CONDITIONAL(GW16012, test $build_gw16012 = yes)
798 AM_CONDITIONAL(PRESTO_LIBFTDI, test $build_presto_libftdi = yes)
799 AM_CONDITIONAL(PRESTO_FTD2XX, test $build_presto_ftd2xx = yes)
800 AM_CONDITIONAL(USBPROG, test $build_usbprog = yes)
801 AM_CONDITIONAL(OOCD_TRACE, test $build_oocd_trace = yes)
802 AM_CONDITIONAL(JLINK, test $build_jlink = yes)
803 AM_CONDITIONAL(VSLLINK, test $build_vsllink = yes)
804 AM_CONDITIONAL(RLINK, test $build_rlink = yes)
805 AM_CONDITIONAL(ARMJTAGEW, test $build_armjtagew = yes)
806 AM_CONDITIONAL(IS_CYGWIN, test $is_cygwin = yes)
807 AM_CONDITIONAL(IS_MINGW, test $is_mingw = yes)
808 AM_CONDITIONAL(IS_WIN32, test $is_win32 = yes)
809 AM_CONDITIONAL(IS_DARWIN, test $is_darwin = yes)
810 AM_CONDITIONAL(BITQ, test $build_bitq = yes)
811
812 AC_LANG_C
813 AC_PROG_CC
814 AC_PROG_CC_C99
815 AM_PROG_CC_C_O
816 AC_PROG_RANLIB
817 AC_PROG_LIBTOOL
818
819 dnl configure checks required for Jim files (these are obsolete w/ C99)
820 AC_C_CONST
821 AC_TYPE_LONG_LONG_INT
822
823 # Look for environ alternatives.  Possibility #1: is environ in unistd.h or stdlib.h?
824 AC_MSG_CHECKING([for environ in unistd.h and stdlib.h])
825 AC_COMPILE_IFELSE([
826 #define _GNU_SOURCE
827 #include <unistd.h>
828 #include <stdlib.h>
829 int main(int argc, char **argv) { char **ep = environ; }
830   ], [
831     AC_MSG_RESULT([yes])
832     has_environ=yes
833   ], [
834     AC_MSG_RESULT([no])
835
836     # Possibility #2: can environ be found in an available library?
837     AC_MSG_CHECKING([for extern environ])
838     AC_LINK_IFELSE([
839 extern char **environ;
840 int main(int argc, char **argv) { char **ep = environ; }
841       ], [
842         AC_DEFINE(NEED_ENVIRON_EXTERN, [1], [Must declare 'environ' to use it.])
843         has_environ=yes
844       ], [
845         has_environ=no
846       ])
847     AC_MSG_RESULT([${has_environ}])
848   ])
849
850 if test "${has_environ}" != "yes" ; then
851      AC_MSG_FAILURE([Could not find 'environ' in unistd.h or available libraries.]) 
852 fi
853
854 AC_DEFINE([_GNU_SOURCE],[1],[Use GNU C library extensions (e.g. stdndup).])
855
856 # set default gcc warnings
857 GCC_WARNINGS="-Wall -Wstrict-prototypes -Wformat-security"
858 if test "${gcc_wextra}" = yes; then
859         GCC_WARNINGS="${GCC_WARNINGS} -Wextra -Wno-unused-parameter"
860         GCC_WARNINGS="${GCC_WARNINGS} -Wbad-function-cast"
861         GCC_WARNINGS="${GCC_WARNINGS} -Wcast-align"
862         GCC_WARNINGS="${GCC_WARNINGS} -Wredundant-decls"
863 fi
864 if test "${gcc_werror}" = yes; then
865         GCC_WARNINGS="${GCC_WARNINGS} -Werror"
866 fi
867
868 # overide default gcc cflags
869 if test $gcc_warnings = yes; then
870         CFLAGS="$CFLAGS $GCC_WARNINGS"
871 fi
872
873 # Setup for compiling build tools
874 AC_MSG_CHECKING([for a C compiler for build tools])
875 if test $cross_compiling = yes; then
876         AC_CHECK_PROGS(CC_FOR_BUILD, gcc cc)
877         CFLAGS_FOR_BUILD="-g -O2 $GCC_WARNINGS"
878 else
879         CC_FOR_BUILD=$CC
880         CFLAGS_FOR_BUILD=$CFLAGS
881 fi
882
883 AC_MSG_RESULT([$CC_FOR_BUILD])
884 AC_SUBST(CC_FOR_BUILD)
885 AC_SUBST(CFLAGS_FOR_BUILD)
886
887 AC_MSG_CHECKING([for suffix of executable build tools])
888 if test $cross_compiling = yes; then
889         cat >conftest.c <<\_______EOF
890 int main ()
891 {
892         exit (0);
893 }
894 _______EOF
895 for i in .exe ""; do
896     compile="$CC_FOR_BUILD conftest.c -o conftest$i"
897     if AC_TRY_EVAL(compile); then
898                 if (./conftest) 2>&AC_FD_CC; then
899                         EXEEXT_FOR_BUILD=$i
900                         break
901                         fi
902                 fi
903 done
904         rm -f conftest*
905         if test "${EXEEXT_FOR_BUILD+set}" != set; then
906                 AC_MSG_ERROR([Cannot determine suffix of executable build tools])
907         fi
908 else
909         EXEEXT_FOR_BUILD=$EXEEXT
910 fi
911 AC_MSG_RESULT([$EXEEXT_FOR_BUILD])
912 AC_SUBST(EXEEXT_FOR_BUILD)
913
914 AC_OUTPUT(Makefile src/Makefile src/helper/Makefile src/jtag/Makefile src/xsvf/Makefile src/svf/Makefile src/target/Makefile src/server/Makefile src/flash/Makefile src/pld/Makefile doc/Makefile)