Log output fix.
[autodist.git] / configure.ad
1 #
2 #  configure.ad
3 #
4 #  Author: Pekka Riikonen <priikone@silcnet.org>
5 #
6 #  Copyright (C) 2000 - 2005 Pekka Riikonen
7 #
8 #  This program is free software; you can redistribute it and/or modify
9 #  it under the terms of the GNU General Public License as published by
10 #  the Free Software Foundation; version 2 of the License.
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
18 AD_INIT
19 AC_CANONICAL_SYSTEM
20 AM_INIT_AUTOMAKE
21 AC_PREREQ(2.52)
22 AC_CONFIG_HEADERS(silcdefs.h)
23
24 AC_PROG_INSTALL
25 AC_PROG_MAKE_SET
26
27 AC_PROG_LN_S
28 AC_PROG_EGREP
29 AC_SUBST(LN_S)
30 AC_PATH_PROG(sedpath, sed)
31
32 #ifdef SILC_DIST_COMPILER
33 # Put here any platform specific stuff
34 #
35 case "$target" in
36   *-*-freebsd*)
37     check_threads=true
38     ;;
39   *-*-*bsd*)
40     check_threads=false
41     ;;
42   *)
43     check_threads=true
44     ;;
45 esac
46
47 # Control compiler optimizations
48 CFLAGS=`echo $CFLAGS | sed 's/-O[ 0123456789s]*//g'`
49
50 AC_PROG_CC
51 AC_C_INLINE
52 AC_C_CONST
53
54 __SILC_HAVE_PTHREAD=""
55 __SILC_HAVE_SIM=""
56 __SILC_ENABLE_DEBUG=""
57
58 AC_PROG_RANLIB
59 AC_DISABLE_SHARED
60 AC_PROG_LIBTOOL
61
62 # Header checking
63 #
64 AC_HEADER_STDC
65 AC_HEADER_TIME
66 AC_HEADER_STAT
67
68 # More header checking
69 #
70 AC_CHECK_HEADERS(unistd.h string.h getopt.h errno.h fcntl.h assert.h)
71 AC_CHECK_HEADERS(sys/types.h sys/stat.h sys/time.h stddef.h)
72 AC_CHECK_HEADERS(netinet/in.h netinet/tcp.h xti.h netdb.h sys/resource.h)
73 AC_CHECK_HEADERS(pwd.h grp.h termcap.h paths.h)
74 AC_CHECK_HEADERS(ncurses.h signal.h ctype.h utime.h)
75 AC_CHECK_HEADERS(arpa/inet.h sys/mman.h limits.h termios.h locale.h langinfo.h)
76
77 # Data type checking
78 #
79 AC_TYPE_SIGNAL
80 AC_TYPE_SIZE_T
81 AC_TYPE_MODE_T
82 AC_TYPE_UID_T
83 AC_TYPE_PID_T
84
85 AC_CHECK_SIZEOF(long long, 0)
86 AC_SUBST(SILC_SIZEOF_LONG_LONG, $ac_cv_sizeof_long_long)
87 AC_CHECK_SIZEOF(long, 0)
88 AC_SUBST(SILC_SIZEOF_LONG, $ac_cv_sizeof_long)
89 AC_CHECK_SIZEOF(int, 0)
90 AC_SUBST(SILC_SIZEOF_INT, $ac_cv_sizeof_int)
91 AC_CHECK_SIZEOF(short, 0)
92 AC_SUBST(SILC_SIZEOF_SHORT, $ac_cv_sizeof_short)
93 AC_CHECK_SIZEOF(char, 0)
94 AC_SUBST(SILC_SIZEOF_CHAR, $ac_cv_sizeof_char)
95 AC_CHECK_SIZEOF(void *, 0)
96 AC_SUBST(SILC_SIZEOF_VOID_P, $ac_cv_sizeof_void_p)
97
98 # Function and library checking
99 #
100 AC_CHECK_FUNC(gethostbyname, [],
101   [
102     AC_CHECK_LIB(nsl, gethostbyname, LIBS="$LIBS -lnsl")
103     AC_CHECK_FUNC(res_gethostbyname, [],
104        AC_CHECK_LIB(resolv, res_gethostbyname, LIBS="$LIBS -lresolv")
105     )
106   ])
107 AC_CHECK_FUNC(socket, [],
108   AC_CHECK_LIB(socket, socket, LIBS="$LIBS -lsocket")
109 )
110 AC_CHECK_FUNCS(gethostname gethostbyaddr getservbyname getservbyport)
111 AC_CHECK_FUNCS(select listen bind shutdown close connect setsockopt)
112 AC_CHECK_FUNCS(time ctime utime gettimeofday getrusage)
113 AC_CHECK_FUNCS(chmod fcntl stat fstat getenv putenv strerror)
114 AC_CHECK_FUNCS(getpid getgid getsid getpgid getpgrp getuid)
115 AC_CHECK_FUNCS(setgroups initgroups nl_langinfo)
116 AC_CHECK_FUNCS(strchr strstr strcpy strncpy memcpy memset memmove)
117
118 #ifdef SILC_DIST_SIM
119 # SIM support checking
120 # XXX These needs to be changed as more supported platforms appear.
121 # XXX This probably needs to be made platform dependant check.
122 #
123 sim_support=false
124 AC_MSG_CHECKING(for SIM support)
125 AC_MSG_RESULT()
126 AC_CHECK_HEADERS(dlfcn.h,
127   [
128     AC_CHECK_LIB(dl, dlopen,
129       [
130         AC_DEFINE([SILC_SIM], [], [HAVE_SIM])
131         sim_support=true
132         LIBS="$LIBS -ldl"
133       ],
134       [
135         AC_CHECK_LIB(c, dlopen,
136           [
137             AC_DEFINE([SILC_SIM], [], [HAVE_SIM])
138             sim_support=true
139           ])
140       ])
141    ])
142
143 AM_CONDITIONAL(SILC_SIM, test x$sim_support = xtrue)
144 if test x$sim_support = xtrue; then
145   AC_MSG_RESULT(Enabled SIM support.)
146   __SILC_HAVE_SIM="#define __SILC_HAVE_SIM 1"
147 else
148   AC_MSG_RESULT(No SIM support found.)
149 fi
150 #endif SILC_DIST_SIM
151
152 # lib/contrib conditionals
153 #
154 AC_CHECK_HEADER(regex.h,
155   [
156     AC_DEFINE([HAVE_REGEX], [], [HAVE_REGEX])
157     have_regex=1
158   ], have_regex=0
159 )
160 AM_CONDITIONAL(HAVE_REGEX, test x$have_regex = x1)
161
162 AC_CHECK_FUNC(getopt_long,
163   [
164     AC_DEFINE([HAVE_GETOPT_LONG], [], [HAVE_GETOPT_LONG])
165     have_getopt_long=1
166   ], have_getopt_long=0
167 )
168
169 AC_CHECK_FUNC(getopt,
170   [
171     AC_DEFINE([HAVE_GETOPT], [], [HAVE_GETOPT])
172     have_getopt=1
173   ], have_getopt=0
174 )
175
176 ##
177 ##  Enable/disable checking
178 ##
179
180 # IPv6 support
181 #
182 AC_MSG_CHECKING(whether to enable IPv6 support)
183 AC_ARG_ENABLE(ipv6,
184   [  --enable-ipv6           enable IPv6 support],
185   [
186     case "${enableval}" in
187       yes)
188         want_ipv6=true
189         check_ipv6=false
190         summary_ipv6="yes"
191         AC_DEFINE([HAVE_IPV6], [], [HAVE_IPV6])
192         AC_MSG_RESULT(yes)
193         ;;
194       *)
195         want_ipv6=false
196         check_ipv6=false
197         summary_ipv6="no"
198         AC_MSG_RESULT(no)
199         ;;
200     esac
201   ],
202     check_ipv6=true
203   )
204
205 if test x$check_ipv6 = xtrue; then
206   summary_ipv6="no"
207   AC_TRY_COMPILE(
208     [
209       #ifdef HAVE_SYS_TYPES_H
210       #include <sys/types.h>
211       #endif
212       #ifdef HAVE_NETINET_TCP_H
213       #include <netinet/tcp.h>
214       #endif
215       #ifdef HAVE_NETDB_H
216       #include <netdb.h>
217       #endif
218       #include <sys/socket.h>
219       #ifdef HAVE_NETINET_IN_H
220       #include <netinet/in.h>
221       #endif
222     ],
223     [
224       struct sockaddr_in6 sin6;
225       int family = AF_INET6;
226     ],
227     [
228       AC_DEFINE([HAVE_IPV6], [], [HAVE_IPV6])
229       AC_MSG_RESULT(yes)
230       summary_ipv6="yes"
231     ],
232       AC_MSG_RESULT(no)
233     )
234 fi
235
236 # Debug checking
237 #
238 AC_MSG_CHECKING(whether to enable debugging)
239 summary_debug="no"
240 __SILC_ENABLE_DEBUG=""
241 AC_ARG_ENABLE(debug,
242   [  --enable-debug          enable debugging],
243   [
244     case "${enableval}" in
245       yes)
246         AC_MSG_RESULT(yes)
247         AC_DEFINE([SILC_DEBUG], [], [enable-debug])
248         summary_debug="yes"
249         __SILC_ENABLE_DEBUG="#define __SILC_ENABLE_DEBUG 1"
250         ;;
251       *)
252         AC_MSG_RESULT(no)
253         ;;
254     esac
255   ],
256   [
257     AC_MSG_RESULT(no)
258   ])
259
260 # Disable all assembler optimizations
261 #
262 AC_MSG_CHECKING(whether to enable assembler optimizations)
263 want_asm=true
264 AC_ARG_ENABLE(asm,
265   [  --disable-asm           do not use assembler optimizations],
266   [
267     AC_MSG_RESULT(no)
268     want_asm=false
269   ],
270   [
271     AC_MSG_RESULT(yes)
272     want_asm=true
273   ])
274
275 ##
276 ## Compiler and compiler flag checks
277 ##
278
279 # Function to check if compiler flag works
280 # Usage: SILC_ADD_CFLAGS(FLAGS, [ACTION-IF-FAILED])
281 AC_DEFUN([SILC_ADD_CFLAGS],
282 [ tmp_CFLAGS="$CFLAGS"
283   CFLAGS="$CFLAGS $1"
284   AC_MSG_CHECKING(whether $CC accepts $1 flag)
285   AC_TRY_LINK([], [], [AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)
286                                        CFLAGS="$tmp_CFLAGS"
287                                        $2])
288   unset tmp_CFLAGS
289 ])
290
291 # Function to check if compiler flag works, destination specifiable
292 # Usage: SILC_ADD_CC_FLAGS(VAR, FLAGS, [ACTION-IF-FAILED])
293 AC_DEFUN([SILC_ADD_CC_FLAGS],
294 [ tmp_CFLAGS="$1_CFLAGS"
295   $1_CFLAGS="${$1_CFLAGS} $2"
296   AC_MSG_CHECKING(whether $CC accepts $2 flag)
297   AC_TRY_LINK([], [], [AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)
298                                        $1_CFLAGS="$tmp_CFLAGS"
299                                        $3])
300   unset tmp_CFLAGS
301 ])
302
303 if test "$GCC"; then
304   # GCC specific options
305   if test "x$summary_debug" = "xyes"; then
306     SILC_ADD_CFLAGS(-g -O)
307   else
308     SILC_ADD_CFLAGS(-g -O2)
309   fi
310   SILC_ADD_CFLAGS(-Wall -finline-functions)
311   SILC_ADD_CFLAGS(-Wno-pointer-sign)
312 else
313   # Other compilers
314   case "$target" in
315     alpha*-dec-osf*)
316       SILC_ADD_CFLAGS(-g3 -O2, SILC_ADD_CFLAGS(-g3 -O, SILC_ADD_CFLAGS(-O)))
317       ;;
318     mips*-sgi-irix*)
319       SILC_ADD_CFLAGS(-g3 -O2, SILC_ADD_CFLAGS(-g3 -O, SILC_ADD_CFLAGS(-O)))
320       ;;
321     *)
322       SILC_ADD_CFLAGS(-g)
323       SILC_ADD_CFLAGS(-O2, SILC_ADD_CFLAGS(-O))
324       ;;
325   esac
326
327   # Intel C++ Compiler needs -restrict
328   if test "x$CC" = "xicc"; then
329     SILC_ADD_CFLAGS(-restrict)
330   fi
331 fi
332
333 #
334 # Workaround a bug in GCC 2.x which causes memory exhaustion
335 # when compiling sha1 with optimizations on UltraSPARC.
336 #
337 FIX_SHA1='#'
338 if test "$GCC" -a "$host_cpu" = "sparc64"; then
339   AC_MSG_CHECKING(whether to enable GCC 2.x workaround for SHA1)
340   AC_TRY_COMPILE(
341     [
342       #if defined(__sparc64__) && (__GNUC__ == 2)
343       #else
344       choke me
345       #endif
346     ],
347     [],
348     [
349       FIX_SHA1=''
350       AC_MSG_RESULT(yes)
351     ],
352       AC_MSG_RESULT(no)
353     )
354 fi
355 AC_SUBST(FIX_SHA1)
356 #endif SILC_DIST_COMPILER
357
358 ##
359 ##  Installation
360 ##
361
362 # Default installation destination
363 #
364 #ifdef SILC_DIST_AUTODIST
365 AC_PREFIX_DEFAULT(/usr/local)
366 #else !SILC_DIST_AUTODIST
367 AC_PREFIX_DEFAULT(/usr/local/silc)
368 #endif SILC_DIST_AUTODIST
369 if test "x$prefix" != xNONE; then
370   silc_prefix="$prefix"
371 else
372   silc_prefix="$ac_default_prefix"
373 fi
374
375 #ifndef SILC_DIST_AUTODIST
376 # etc directory
377 #
378 if test "x$sysconfdir" != 'x${prefix}/etc'; then
379   ETCDIR="$sysconfdir"
380 else
381   ETCDIR="$silc_prefix/etc"
382 fi
383
384 AC_ARG_WITH(etcdir,
385   [[  --with-etcdir=DIR       directory for system files [/etc/silc]]],
386   [
387     case "$withval" in
388       no|yes)
389         ;;
390       *)
391         ETCDIR="$withval"
392         ;;
393     esac
394   ])
395 AC_SUBST(ETCDIR)
396 AC_DEFINE_UNQUOTED([SILC_ETCDIR], "$ETCDIR", [SILC_ETCDIR])
397
398 # doc directory
399 #
400 DOCDIR="$silc_prefix/doc"
401 AC_ARG_WITH(docdir,
402   [[  --with-docdir=DIR       directory for SILC documentation [PREFIX/doc]]],
403   [
404     case "$withval" in
405       no|yes)
406         ;;
407       *)
408         DOCDIR="$withval"
409         ;;
410     esac
411   ])
412 AC_SUBST(DOCDIR)
413 AC_DEFINE_UNQUOTED([SILC_DOCDIR], "$DOCDIR", [SILC_DOCDIR])
414 #endif SILC_DIST_AUTODIST
415
416 #ifdef SILC_DIST_COMPILER
417 ##
418 ##  With/without checkings
419 ##
420
421 #
422 # SILC library checking
423 compile_libs=true
424 LIBSUBDIR=lib
425
426 #ifndef SILC_DIST_TOOLKIT
427 AC_ARG_WITH(silc-includes,
428   [  --with-silc-includes=DIR SILC Toolkit includes [search in DIR]],
429   [ac_silc_includes="$withval"], [ac_silc_includes="no"])
430 AC_ARG_WITH(silc-libs,
431   [  --with-silc-libs=DIR     SILC Toolkit libraries [search in DIR]],
432   [ac_silc_libs="$withval"], [ac_silc_libs="no"])
433
434 if test -n "$with_silc_includes" || test -n "$with_silc_libs"; then
435
436   # Manually provided libs
437   if test "$ac_silc_includes" != "no"; then
438     compile_libs=false
439     SILC_LIB_INCLUDES="-I$ac_silc_includes"
440     LIBSUBDIR=
441   fi
442   if test "$ac_silc_libs" != "no"; then
443     compile_libs=false
444     LIBSUBDIR=
445     LIBS="$LIBS -L$ac_silc_libs"
446   fi
447
448   # Check libs to link against
449   f=`$EGREP __SILC_HAVE_PTHREAD $ac_silc_includes/silcincludes.h`
450   if test -n "$f"; then
451     LIBS="$LIBS -lpthread"
452     check_threads=false
453     has_threads=true
454   fi
455   f=`$EGREP __SILC_HAVE_SIM $ac_silc_includes/silcincludes.h`
456   if test -n "$f"; then
457     LIBS="$LIBS -ldl"
458   fi
459
460 else
461   # pkg-config check
462   PKG_CHECK_MODULES(SILC, silc, compile_libs=false, compile_libs=true)
463 #ifdef SILC_DIST_CLIENTLIB
464   PKG_CHECK_MODULES(SILCCLIENT, silcclient, compile_libs=false, compile_libs=true)
465 #endif SILC_DIST_CLIENTLIB
466
467   if test x$compile_libs = xfalse; then
468     LIBSUBDIR=
469     LIBS="$LIBS $SILC_LIBS"
470     CFLAGS="$CFLAGS $SILC_CFLAGS"
471 #ifdef SILC_DIST_CLIENTLIB
472     LIBS="$LIBS $SILCCLIENT_LIBS"
473     CFLAGS="$CFLAGS $SILCCLIENT_CFLAGS"
474 #endif SILC_DIST_CLIENTLIB
475   fi
476 fi
477 #endif SILC_DIST_TOOLKIT
478
479 AC_SUBST(LIBSUBDIR)
480
481 # SOCKS4 support checking
482 #
483 SAVE_LIBS="$LIBS"
484 SAVE_CFLAGS="$CFLAGS"
485 SAVE_LDFLAGS="$LDFLAGS"
486 AC_MSG_CHECKING(whether to support SOCKS4)
487 AC_ARG_WITH(socks4,
488   [[  --with-socks4[=DIR]     with SOCKS4 support [search in DIR/lib and DIR/include]]],
489   [
490     case "$withval" in
491       no)
492         AC_MSG_RESULT(no)
493         ;;
494       *)
495         AC_MSG_RESULT(yes)
496         socks=4
497
498         if test -d "$withval/include"; then
499           CFLAGS="$CFLAGS -I$withval/include"
500         fi
501         if test -d "$withval/lib"; then
502           LDFLAGS="$LDFLAGS -L$withval/lib"
503         fi
504
505         LIBS="-lsocks $LIBS"
506         ;;
507     esac
508
509     AC_TRY_LINK([],
510       [
511         Rconnect();
512       ], [],
513       [
514         AC_MSG_ERROR(Could not find SOCKS4 library.)
515         LIBS="$SAVE_LIBS"
516         CFLAGS="$SAVE_CFLAGS"
517         LDFLAGS="$SAVE_LDFLAGS"
518       ])
519   ],
520     AC_MSG_RESULT(no)
521   )
522
523 # SOCKS5 support checking
524 #
525 SAVE_LIBS="$LIBS"
526 SAVE_CFLAGS="$CFLAGS"
527 SAVE_LDFLAGS="$LDFLAGS"
528 AC_MSG_CHECKING(whether to support SOCKS5)
529 AC_ARG_WITH(socks5,
530   [[  --with-socks5[=DIR]     with SOCKS5 support [search in DIR/lib and DIR/include]]],
531   [
532     case "$withval" in
533       no)
534         AC_MSG_RESULT(no)
535         ;;
536       *)
537         AC_MSG_RESULT(yes)
538         socks=5
539
540         if test -d "$withval/include"; then
541           CFLAGS="$CFLAGS -I$withval/include"
542         fi
543         if test -d "$withval/lib"; then
544           LDFLAGS="$LDFLAGS -L$withval/lib"
545         fi
546
547         LIBS="-lsocks5 $LIBS"
548         ;;
549     esac
550
551     AC_TRY_LINK([],
552       [
553         SOCKSconnect();
554       ], [],
555       [
556         AC_MSG_ERROR(Could not find SOCKS5 library.)
557         LIBS="$SAVE_LIBS"
558         CFLAGS="$SAVE_CFLAGS"
559         LDFLAGS="$SAVE_LDFLAGS"
560       ])
561   ],
562     AC_MSG_RESULT(no)
563   )
564
565 if test "x$socks" = "x4"; then
566   AC_DEFINE([SOCKS], [], [Socks])
567   CFLAGS="$CFLAGS -Dconnect=Rconnect -Dgetsockname=Rgetsockname -Dbind=Rbind -Daccept=Raccept -Dlisten=Rlisten -Dselect=Rselect"
568 fi
569
570 if test "x$socks" = "x5"; then
571   AC_DEFINE([SOCKS], [], [Socks])
572   AC_DEFINE([SOCKS5], [], [Socks5])
573   AC_DEFINE([Rconnect], [SOCKSconnect], [Socks])
574   AC_DEFINE([Rgetsockname], [SOCKSgetsockname], [Socks])
575   AC_DEFINE([Rgetpeername], [SOCKSgetpeername], [Socks])
576   AC_DEFINE([Rbind], [SOCKSbind], [Socks])
577   AC_DEFINE([Raccept], [SOCKSaccept], [Socks])
578   AC_DEFINE([Rlisten], [SOCKSlisten], [Socks])
579   AC_DEFINE([Rselect], [SOCKSselect], [Socks])
580   AC_DEFINE([Rrecvfrom], [SOCKSrecvfrom], [Socks])
581   AC_DEFINE([Rsendto], [SOCKSsendto], [Socks])
582   AC_DEFINE([Rrecv], [SOCKSrecv], [Socks])
583   AC_DEFINE([Rsend], [SOCKSsend], [Socks])
584   AC_DEFINE([Rread], [SOCKSread], [Socks])
585   AC_DEFINE([Rwrite], [SOCKSwrite], [Socks])
586   AC_DEFINE([Rrresvport], [SOCKSrresvport], [Socks])
587   AC_DEFINE([Rshutdown], [SOCKSshutdown], [Socks])
588   AC_DEFINE([Rlisten], [SOCKSlisten], [Socks])
589   AC_DEFINE([Rclose], [SOCKSclose], [Socks])
590   AC_DEFINE([Rdup], [SOCKSdup], [Socks])
591   AC_DEFINE([Rdup2], [SOCKSdup2], [Socks])
592   AC_DEFINE([Rfclose], [SOCKSfclose], [Socks])
593   AC_DEFINE([Rgethostbyname], [SOCKSgethostbyname], [Socks])
594 fi
595
596 #ifdef SILC_DIST_MATH
597 # MP library checking. First check whether user wants to use GMP and use
598 # it if found. If not or not defined then compile the default library in the
599 # source tree.
600 #
601 mp_gmp=false
602 SAVE_LIBS="$LIBS"
603 SAVE_CFLAGS="$CFLAGS"
604 SAVE_LDFLAGS="$LDFLAGS"
605 AC_MSG_CHECKING(whether to search for GMP)
606 AC_ARG_WITH(gmp,
607   [[  --with-gmp[=DIR]        use GMP instead of SILC Math [search in DIR/lib and DIR/include]]],
608   [
609     case "$withval" in
610       no)
611         AC_MSG_RESULT(no)
612         ;;
613       *)
614         AC_MSG_RESULT(yes)
615
616         if test -d "$withval/include"; then
617           CFLAGS="$CFLAGS -I$withval/include"
618         fi
619         if test -d "$withval/lib"; then
620           LDFLAGS="$LDFLAGS -L$withval/lib"
621         fi
622
623         LIBS="-lgmp $LIBS"
624         ;;
625     esac
626
627     AC_CHECK_LIB(gmp, __gmpz_init,
628       [
629         mp_gmp=true
630         AC_DEFINE([SILC_MP_GMP], [], [GMP])
631         AC_MSG_RESULT(Using GMP as a MP library.)
632       ],
633       [
634         LIBS="$SAVE_LIBS"
635         CFLAGS="$SAVE_CFLAGS"
636         LDFLAGS="$SAVE_LDFLAGS"
637       ])
638   ],
639     AC_MSG_RESULT(no)
640   )
641
642 AM_CONDITIONAL(SILC_MP_GMP, test x$mp_gmp = xtrue)
643 AM_CONDITIONAL(SILC_MP_SILCMATH, test x$mp_gmp = xfalse)
644 if test x$mp_gmp = xfalse; then
645   AC_DEFINE([SILC_MP_SILCMAP], [], [SILCMATH])
646   AC_MSG_RESULT(Using SILC Math as a MP library.)
647 fi
648 #endif SILC_DIST_MATH
649
650 # iconv support
651 #
652 check_iconv=true
653 has_iconv=false
654 SAVE_LIBS="$LIBS"
655 SAVE_CFLAGS="$CFLAGS"
656 SAVE_LDFLAGS="$LDFLAGS"
657 SAVE_CPPFLAGS="$CPPFLAGS"
658 AC_MSG_CHECKING(whether to implicit search for libiconv)
659 AC_ARG_WITH(iconv,
660   [[  --with-iconv[=DIR]      use libiconv [search in DIR/include and DIR/lib]]],
661   [
662     case "${withval}" in
663       no)
664         AC_MSG_RESULT(no)
665         AC_CHECK_HEADERS(iconv.h,
666           [
667             AC_CHECK_FUNC(iconv, has_iconv=true)
668           ])
669         check_iconv=false
670         ;;
671       *)
672         AC_MSG_RESULT(yes)
673         if test -d $withval/include; then
674           CPPFLAGS="$CPPFLAGS -I$withval/include"
675           CFLAGS="$CFLAGS -I$withval/include"
676         fi
677         if test -d $withval/lib; then
678           LDFLAGS="$LDFLAGS -L$withval/lib"
679         fi
680         ;;
681     esac
682   ],
683   [
684     AC_MSG_RESULT(no)
685     AC_CHECK_HEADERS(iconv.h,
686       [
687         AC_CHECK_FUNCS(iconv,
688           [
689             has_iconv=true
690             check_iconv=false
691           ])
692       ])
693   ])
694
695 if test x$check_iconv = xtrue; then
696   AC_MSG_RESULT(Searching for iconv...)
697
698   # XXX
699   unset ac_cv_header__iconv_h_ ac_cv_header_iconv_h || true
700
701   AC_CHECK_HEADERS(iconv.h,
702     [
703       LIBS="$LIBS -liconv"
704       AC_MSG_CHECKING(for iconv in -liconv)
705       AC_TRY_LINK(
706         [
707           #include <stdlib.h>
708           #include <iconv.h>
709         ],
710         [
711           iconv_t cd = iconv_open("", "");
712           iconv(cd, NULL, NULL, NULL, NULL);
713           iconv_close(cd);
714         ],
715         [
716           echo "yes"
717           AC_DEFINE([HAVE_ICONV], [], [Define if you have the iconv() function.])
718           has_iconv=true
719           check_iconv=false
720         ],
721         [
722           echo "no"
723           LIBS="$SAVE_LIBS"
724           CFLAGS="$SAVE_CFLAGS"
725           LDFLAGS="$SAVE_LDFLAGS"
726           CPPFLAGS="$SAVE_CPPFLAGS"
727         ])
728      ])
729 fi
730
731 if test x$check_iconv = xtrue; then
732   # search for iconv library..
733   SAVE_LIBS="$LIBS"
734   SAVE_CFLAGS="$CFLAGS"
735   SAVE_LDFLAGS="$LDFLAGS"
736   SAVE_CPPFLAGS="$CPPFLAGS"
737
738   for dir in `echo "/usr/local /usr/pkg /usr/contrib"`; do
739     if test x$has_iconv = xfalse; then
740       AC_MSG_RESULT(searching in $dir...)
741
742       if test -d $dir/include; then
743         CPPFLAGS="$CPPFLAGS -I$dir/include"
744         CFLAGS="$CFLAGS -I$dir/include"
745       fi
746       if test -d $dir/lib; then
747         LDFLAGS="$LDFLAGS -L$dir/lib"
748       fi
749
750       # XXX
751       unset ac_cv_header__iconv_h_ ac_cv_header_iconv_h || true
752
753       AC_CHECK_HEADERS(iconv.h,
754         [
755           LIBS="$LIBS -liconv"
756           AC_MSG_CHECKING(for iconv in -liconv)
757           AC_TRY_LINK(
758             [
759               #include <stdlib.h>
760               #include <iconv.h>
761             ],
762             [
763               iconv_t cd = iconv_open("", "");
764               iconv(cd, NULL, NULL, NULL, NULL);
765               iconv_close(cd);
766             ],
767             [
768               echo "yes"
769               has_iconv=true
770               AC_DEFINE([HAVE_ICONV], [], [Define if you have the iconv() function.])
771             ],
772             [
773               echo "no"
774               has_iconv=false
775
776               LIBS="$SAVE_LIBS"
777               CFLAGS="$SAVE_CFLAGS"
778               LDFLAGS="$SAVE_LDFLAGS"
779               CPPFLAGS="$SAVE_CPPFLAGS"
780             ])
781          ],
782          [
783            CFLAGS="$SAVE_CFLAGS"
784            LDFLAGS="$SAVE_LDFLAGS"
785            CPPFLAGS="$SAVE_CPPFLAGS"
786          ])
787       fi
788     done
789 fi
790
791 if test x$has_iconv = xtrue; then
792   # (1) Some implementations of iconv won't convert from UTF-8 to UTF-8.
793   # (2) In glibc-2.1.2 and earlier there is a bug that messes up ob and
794   #     obl when args 2 and 3 are 0 (fixed in glibc-2.1.3).
795   #
796   AC_CACHE_CHECK([whether this iconv is good enough], ac_iconv_good,
797     AC_TRY_RUN(
798       [
799         #include <iconv.h>
800         int main() {
801           iconv_t cd;
802         changequote(, )dnl
803           char buf[4];
804         changequote([, ])dnl
805           char *ob;
806           size_t obl;
807           ob = buf, obl = sizeof(buf);
808           return ((cd = iconv_open("UTF-8", "UTF-8")) != (iconv_t)(-1) &&
809                  (iconv(cd, 0, 0, &ob, &obl) ||
810                  !(ob == buf && obl == sizeof(buf)) ||
811                  iconv_close(cd)));
812         }
813       ],
814       [
815         ac_iconv_good=yes
816       ],
817       [
818         ac_iconv_good=no
819       ],
820       [
821         ac_iconv_good=yes
822       ])
823     )
824
825   if test x$ac_iconv_good = xno; then
826     AC_MSG_RESULT(Try using libiconv instead.)
827   fi
828 fi
829
830 # POSIX threads support
831 #
832 AC_MSG_CHECKING(whether to search for POSIX threads)
833 AC_ARG_WITH(pthreads,
834   [[  --with-pthreads[=DIR]   use POSIX threads [search in DIR/include and DIR/lib]]],
835   [
836     case "${withval}" in
837       no)
838         check_threads=false
839         ;;
840       *)
841         if test -d $withval/include; then
842           CPPFLAGS="$CPPFLAGS -I$withval/include"
843           CFLAGS="$CFLAGS -I$withval/include"
844         fi
845         if test -d $withval/lib; then
846           LDFLAGS="$LDFLAGS -L$withval/lib"
847         fi
848
849         check_threads=true
850         ;;
851     esac
852   ])
853
854 if test x$check_threads = xtrue; then
855   has_threads=false
856   SAVE_LIBS="$LIBS"
857   SAVE_CFLAGS="$CFLAGS"
858   SAVE_LDFLAGS="$LDFLAGS"
859   SAVE_CPPFLAGS="$CPPFLAGS"
860
861   AC_MSG_RESULT(yes)
862   AC_CHECK_HEADERS(pthread.h,
863     [
864       LIBS="$LIBS -lpthread"
865       AC_CHECK_LIB(pthread, pthread_attr_init, has_threads=true,
866         [
867           # FreeBSD
868           case "${target}" in
869             *-*-freebsd*)
870               LIBS="$SAVE_LIBS -pthread"
871               AC_CHECK_LIB(c_r, pthread_attr_init, has_threads=true, LIBS="$SAVE_LIBS")
872               ;;
873             *)
874               LIBS="$SAVE_LIBS"
875               ;;
876           esac
877         ])
878     ],
879     [
880       # search for pthread library..
881       for dir in `echo "/usr/local /usr/pkg /usr/contrib /usr/pkg/pthreads /usr/local/pthreads"`; do
882         if test x$has_threads = xfalse; then
883           AC_MSG_RESULT(searching in $dir...)
884
885           if test -d $dir/include; then
886             CPPFLAGS="$CPPFLAGS -I$dir/include"
887             CFLAGS="$CFLAGS -I$dir/include"
888           fi
889           if test -d $dir/lib; then
890             LDFLAGS="$LDFLAGS -L$dir/lib"
891           fi
892
893           # XXX
894           unset ac_cv_header__pthread_h_ ac_cv_header_pthread_h || true
895
896           AC_CHECK_HEADERS(pthread.h,
897             [
898               LIBS="$LIBS -lpthread"
899               AC_CHECK_LIB(pthread, pthread_attr_init, has_threads=true,
900                 [
901                   has_threads=false
902
903                   LIBS="$SAVE_LIBS"
904                   CFLAGS="$SAVE_CFLAGS"
905                   LDFLAGS="$SAVE_LDFLAGS"
906                   CPPFLAGS="$SAVE_CPPFLAGS"
907                 ])
908             ],
909             [
910               CFLAGS="$SAVE_CFLAGS"
911               LDFLAGS="$SAVE_LDFLAGS"
912               CPPFLAGS="$SAVE_CPPFLAGS"
913             ])
914         fi
915       done
916     ])
917 else
918   AC_MSG_RESULT(no)
919   has_threads=false
920 fi
921
922 __SILC_HAVE_PTHREAD=""
923 AM_CONDITIONAL(SILC_THREADS, test x$has_threads = xtrue)
924 if test x$has_threads = xtrue; then
925   CFLAGS="$CFLAGS -D_REENTRANT"
926
927   # XXX possibly incomplete
928   case "${target}" in
929     *-*-aix*)
930       CFLAGS="$CFLAGS -D_THREAD_SAFE"
931       if test x"$GCC" = xyes; then
932         CFLAGS="$CFLAGS -mthreads"
933       fi
934       ;;
935     *-*-freebsd*)
936       CFLAGS="$CFLAGS -D_THREAD_SAFE"
937       ;;
938     *-*-sysv5uw7*)  # UnixWare 7
939       if test "$GCC" != "yes"; then
940         CFLAGS="$CFLAGS -Kthread"
941       else
942         CFLAGS="$CFLAGS -pthread"
943       fi
944       ;;
945     *-dg-dgux*)  # DG/UX
946       CFLAGS="$CFLAGS -D_POSIX4A_DRAFT10_SOURCE"
947       ;;
948    esac
949
950   AC_CHECK_FUNC(pthread_create)
951   AC_DEFINE([SILC_HAVE_PTHREAD], [], [HAVE_PTHREAD])
952   AC_DEFINE([SILC_THREADS], [], [HAVE_THREAD])
953   __SILC_HAVE_PTHREAD="#define __SILC_HAVE_PTHREAD 1"
954 fi
955
956 # Native WIN32 compilation under cygwin
957 #
958 AC_MSG_CHECKING(whether to compile native WIN32 code)
959 AC_ARG_WITH(win32,
960   [  --with-win32            compile native WIN32 (MinGW) code (-mno-cygwin)],
961   [
962     AC_MSG_RESULT(yes)
963     AC_DEFINE([SILC_WIN32], [], [SILC_WIN32])
964     win32_support=true
965     CFLAGS="-mno-cygwin $CFLAGS"
966     LIBS="$LIBS -lwsock32"
967   ],
968   [
969     AC_MSG_RESULT(no)
970   ])
971 AM_CONDITIONAL(SILC_WIN32, test x$win32_support = xtrue)
972
973 # Native EPOC support (disabled by default)
974 #
975 AM_CONDITIONAL(SILC_EPOC, test xfalse = xtrue)
976
977 # Native BeOS support (disabled by default)
978 #
979 AM_CONDITIONAL(SILC_BEOS, test xfalse = xtrue)
980
981 # Native OS2 support (disabled by default)
982 #
983 AM_CONDITIONAL(SILC_OS2, test xfalse = xtrue)
984
985 #ifdef SILC_DIST_TOOLKIT
986 # --with-irssi
987 #
988 without_irssi=true
989 AC_MSG_CHECKING(whether to compile Irssi SILC Client)
990 AC_ARG_WITH(irssi,
991   [  --with-irssi            compile with Irssi SILC Client],
992   [
993     AC_MSG_RESULT(yes)
994     without_irssi=false
995   ],
996   [
997     AC_MSG_RESULT(no)
998     without_irssi=true
999   ])
1000
1001 # --with-silcd
1002 #
1003 without_silcd=true
1004 AC_MSG_CHECKING(whether to compile SILC Server)
1005 AC_ARG_WITH(silcd,
1006   [  --with-silcd            compile with SILC Server],
1007   [
1008     AC_MSG_RESULT(yes)
1009     without_silcd=false
1010   ],
1011   [
1012     AC_MSG_RESULT(no)
1013     without_silcd=true
1014   ])
1015 #endif SILC_DIST_TOOLKIT
1016
1017 libtoolfix=true
1018 AC_MSG_CHECKING(whether to do libtoolfix)
1019 AC_ARG_WITH(libtoolfix,
1020   [  --without-libtoolfix    Do not fix libtool, for package builders],
1021   [
1022     AC_MSG_RESULT(no)
1023     libtoolfix=false
1024   ],
1025   [
1026     AC_MSG_RESULT(yes)
1027   ])
1028
1029 AC_SUBST(ETCDIR)
1030 AC_DEFINE_UNQUOTED([SILC_ETCDIR], "$ETCDIR", [SILC_ETCDIR])
1031 #endif SILC_DIST_COMPILER
1032
1033 ##
1034 ##  Misc
1035 ##
1036
1037 # Make enable-shared aware
1038 AM_CONDITIONAL(SILC_ENABLE_SHARED, test "$enable_shared" = yes)
1039
1040 SILC_TOP_SRCDIR=`pwd`
1041
1042 # Included configure scripts
1043 AD_INCLUDE_CONFIGURE
1044
1045 #ifdef SILC_DIST_COMPILER
1046 #
1047 # Substitutions
1048 #
1049 AC_SUBST(SILC_TOP_SRCDIR)
1050 AC_SUBST(LIBS)
1051 AC_SUBST(SILC_LIB_INCLUDES)
1052 AC_SUBST(__SILC_HAVE_PTHREAD)
1053 AC_SUBST(__SILC_HAVE_SIM)
1054 AC_SUBST(__SILC_ENABLE_DEBUG)
1055
1056 #
1057 # Fix the libtool to support run-time configuration.  This allows us
1058 # to in run-time specify when to compile shared/static libraries without
1059 # need to reconfigure the entire libtool.
1060 #
1061 if test x$libtoolfix = xtrue; then
1062   ./libtoolfix $SILC_TOP_SRCDIR/ltmain.sh
1063 fi
1064 AM_CONDITIONAL(SILC_LIBTOOLFIX, test x$libtoolfix = xtrue)
1065
1066 INCLUDE_DEFINES_INT="include \$(top_srcdir)/Makefile.defines_int"
1067 AC_SUBST(INCLUDE_DEFINES_INT)
1068
1069 #endif SILC_DIST_COMPILER
1070
1071 #
1072 # Makefile outputs
1073 #
1074 AC_CONFIG_FILES(
1075 Makefile
1076 #ifdef SILC_DIST_DOC
1077 doc/Makefile
1078 #endif SILC_DIST_DOC
1079 #ifdef SILC_DIST_COMPILER
1080 Makefile.defines
1081 Makefile.defines_int
1082 includes/Makefile
1083 includes/silcversion.h
1084 includes/silcincludes.h
1085 #endif SILC_DIST_COMPILER
1086 #ifdef SILC_DIST_APPS
1087 apps/Makefile
1088 #endif SILC_DIST_APPS
1089 )
1090
1091 #ifdef SILC_DIST_TOOLKIT
1092 AC_CONFIG_FILES(
1093 win32/Makefile
1094 win32/libsilc/Makefile
1095 win32/libsilcclient/Makefile
1096 tutorial/Makefile
1097 tutorial/Makefile.defines
1098 tutorial/Makefile.defines_int
1099 )
1100 #endif SILC_DIST_TOOLKIT
1101
1102 AC_OUTPUT
1103
1104 #ifdef SILC_DIST_COMPILER
1105 s_bindir=`eval echo $bindir`;s_bindir=`eval echo $s_bindir`
1106 s_sbindir=`eval echo $sbindir`;s_sbindir=`eval echo $s_sbindir`
1107 s_mandir=`eval echo $mandir`;s_mandir=`eval echo $s_mandir`
1108 s_includedir=`eval echo $includedir`;s_includedir=`eval echo $s_includedir`
1109
1110 echo ""
1111 echo "$PACKAGE Configuration Summary:"
1112 echo "---------------------------"
1113 echo " Target host ...................: $target"
1114 echo " Compiler ......................: $CC"
1115 echo " CFLAGS ........................: $CFLAGS"
1116 echo " LDFLAGS .......................: $LDFLAGS"
1117 echo " LIBS ..........................: $LIBS"
1118 echo ""
1119 echo " Installation prefix ...........: $prefix"
1120 echo " bin directory .................: $s_bindir"
1121 echo " sbin directory ................: $s_sbindir"
1122 echo " etc directory .................: $ETCDIR"
1123 echo " man directory .................: $s_mandir"
1124 echo " doc directory .................: $DOCDIR"
1125 #ifdef SILC_DIST_CLIENT
1126 echo " help directory ................: $HELPDIR"
1127 #endif SILC_DIST_CLIENT
1128 #ifdef SILC_DIST_SERVER
1129 echo " logs directory ................: $LOGSDIR"
1130 #endif SILC_DIST_SERVER
1131 #ifdef SILC_DIST_SIM
1132 echo " SIM directory .................: $MODULESDIR"
1133 #endif SILC_DIST_SIM
1134 #ifdef SILC_DIST_INCLUDES
1135 echo " include directory .............: $s_includedir"
1136 #endif SILC_DIST_INCLUDES
1137 echo ""
1138
1139 #ifdef SILC_DIST_TOOLKIT
1140 if test x$without_irssi = xtrue; then
1141   irssi="no"
1142 fi
1143 if test x$without_silcd = xtrue; then
1144   silcd="no"
1145 fi
1146 #endif SILC_DIST_TOOLKIT
1147
1148 #ifdef SILC_DIST_CLIENT
1149 echo " Compile SILC Client ...........: $irssi"
1150 #endif SILC_DIST_CLIENT
1151
1152 #ifdef SILC_DIST_SERVER
1153 echo " Compile SILC Server ...........: $silcd"
1154 if test x$without_silcd = xfalse; then
1155 echo " Server configuration file .....: $summary_silcd_configfile"
1156 echo " Server PID file ...............: $PIDFILE"
1157 fi
1158 #endif SILC_DIST_SERVER
1159
1160 #ifdef SILC_DIST_SIM
1161 if test x$sim_support = xfalse; then
1162   sim_support="no"
1163 else
1164   sim_support="yes"
1165 fi
1166 echo " SIM support ...................: $sim_support"
1167 #endif SILC_DIST_SIM
1168
1169 echo " IPv6 support ..................: $summary_ipv6"
1170
1171 if test x$has_iconv = xfalse; then
1172   iconv_support="no"
1173 else
1174   iconv_support="yes"
1175 fi
1176 echo " Iconv support .................: $iconv_support"
1177
1178 if test x$want_asm = xfalse; then
1179   summary_asm="no"
1180 else
1181   summary_asm="yes"
1182 fi
1183 echo " Assembler optimizations .......: $summary_asm"
1184
1185 #ifdef SILC_DIST_MATH
1186 if test x$mp_gmp = xtrue; then
1187   echo " Arithmetic library ............: GMP"
1188 fi
1189 #endif SILC_DIST_MATH
1190
1191 threads="no"
1192 if test x$has_threads = xtrue; then
1193   threads="yes"
1194 fi
1195 echo " Multi-threads support .........: $threads"
1196 echo " Debugging enabled .............: $summary_debug"
1197 echo ""
1198 echo "Compile the sources with 'make' or 'gmake' command."
1199 #endif SILC_DIST_COMPILER