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