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