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