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