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