updates.
[silc.git] / configure.ad
1 #
2 #  configure.ad
3 #
4 #  Author: Pekka Riikonen <priikone@silcnet.org>
5 #
6 #  Copyright (C) 2000 - 2005 Pekka Riikonen
7 #
8 #  This program is free software; you can redistribute it and/or modify
9 #  it under the terms of the GNU General Public License as published by
10 #  the Free Software Foundation; version 2 of the License.
11 #
12 #  This program is distributed in the hope that it will be useful,
13 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #  GNU General Public License for more details.
16 #
17
18 AD_INIT
19 AC_CANONICAL_SYSTEM
20 AM_INIT_AUTOMAKE
21 AC_PREREQ(2.52)
22 AC_CONFIG_HEADERS(silcdefs.h)
23
24 AC_PROG_INSTALL
25 AC_PROG_MAKE_SET
26
27 AC_PROG_LN_S
28 AC_PROG_EGREP
29 AC_SUBST(LN_S)
30 AC_PATH_PROG(sedpath, sed)
31
32 #ifdef SILC_DIST_COMPILER
33 # Put here any platform specific stuff
34 #
35 case "$target" in
36   *-*-freebsd*)
37     check_threads=true
38     ;;
39   *-*-*bsd*)
40     check_threads=false
41     ;;
42   *)
43     check_threads=true
44     ;;
45 esac
46
47 # 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 else
294   # Other compilers
295   case "$target" in
296     alpha*-dec-osf*)
297       SILC_ADD_CFLAGS(-g3 -O2, SILC_ADD_CFLAGS(-g3 -O, SILC_ADD_CFLAGS(-O)))
298       ;;
299     *)
300       SILC_ADD_CFLAGS(-g)
301       SILC_ADD_CFLAGS(-O2, SILC_ADD_CFLAGS(-O))
302       ;;
303   esac
304
305   # Intel C++ Compiler needs -restrict
306   if test "x$CC" = "xicc"; then
307     SILC_ADD_CFLAGS(-restrict)
308   fi
309 fi
310
311 #
312 # Workaround a bug in GCC 2.x which causes memory exhaustion
313 # when compiling sha1 with optimizations on UltraSPARC.
314 #
315 FIX_SHA1='#'
316 if test "$GCC" -a "$host_cpu" = "sparc64"; then
317   AC_MSG_CHECKING(whether to enable GCC 2.x workaround for SHA1)
318   AC_TRY_COMPILE(
319     [
320       #if defined(__sparc64__) && (__GNUC__ == 2)
321       #else
322       choke me
323       #endif
324     ],
325     [],
326     [
327       FIX_SHA1=''
328       AC_MSG_RESULT(yes)
329     ],
330       AC_MSG_RESULT(no)
331     )
332 fi
333 AC_SUBST(FIX_SHA1)
334 #endif SILC_DIST_COMPILER
335
336 ##
337 ##  Installation
338 ##
339
340 # Default installation destination
341 #
342 #ifdef SILC_DIST_AUTODIST
343 AC_PREFIX_DEFAULT(/usr/local)
344 #else !SILC_DIST_AUTODIST
345 AC_PREFIX_DEFAULT(/usr/local/silc)
346 #endif SILC_DIST_AUTODIST
347 if test "x$prefix" != xNONE; then
348   silc_prefix="$prefix"
349 else
350   silc_prefix="$ac_default_prefix"
351 fi
352
353 #ifndef SILC_DIST_AUTODIST
354 # etc directory
355 #
356 if test "x$sysconfdir" != 'x${prefix}/etc'; then
357   ETCDIR="$sysconfdir"
358 else
359   ETCDIR="$silc_prefix/etc"
360 fi
361
362 AC_ARG_WITH(etcdir,
363   [[  --with-etcdir=DIR       directory for system files [/etc/silc]]],
364   [
365     case "$withval" in
366       no|yes)
367         ;;
368       *)
369         ETCDIR="$withval"
370         ;;
371     esac
372   ])
373 AC_SUBST(ETCDIR)
374 AC_DEFINE_UNQUOTED([SILC_ETCDIR], "$ETCDIR", [SILC_ETCDIR])
375
376 # doc directory
377 #
378 DOCDIR="$silc_prefix/doc"
379 AC_ARG_WITH(docdir,
380   [[  --with-docdir=DIR       directory for SILC documentation [PREFIX/doc]]],
381   [
382     case "$withval" in
383       no|yes)
384         ;;
385       *)
386         DOCDIR="$withval"
387         ;;
388     esac
389   ])
390 AC_SUBST(DOCDIR)
391 AC_DEFINE_UNQUOTED([SILC_DOCDIR], "$DOCDIR", [SILC_DOCDIR])
392 #endif SILC_DIST_AUTODIST
393
394 #ifdef SILC_DIST_CLIENT
395 # help directory
396 #
397 HELPDIR="$silc_prefix/help"
398 AC_ARG_WITH(helpdir,
399   [[  --with-helpdir=DIR      directory for SILC help files [PREFIX/help]]],
400   [
401     case "$withval" in
402       no|yes)
403         ;;
404       *)
405        HELPDIR="$withval"
406        ;;
407     esac
408   ])
409 AC_SUBST(HELPDIR)
410 AC_DEFINE_UNQUOTED([SILC_HELPDIR], "$HELPDIR", [SILC_HELPDIR])
411 #endif SILC_DIST_CLIENT
412
413 #ifdef SILC_DIST_SIM
414 # SIM modules directory
415 #
416 MODULESDIR="$silc_prefix/modules"
417 AC_ARG_WITH(simdir,
418   [[  --with-simdir=DIR       directory for SIM modules [PREFIX/modules]]],
419   [
420     case "$withval" in
421       no|yes)
422         ;;
423       *)
424         MODULESDIR="$withval"
425         ;;
426     esac
427   ])
428 AC_SUBST(MODULESDIR)
429 AC_DEFINE_UNQUOTED([SILC_MODULESDIR], "$MODULESDIR", [SILC_MODULESDIR])
430 #endif SILC_DIST_SIM
431
432 #ifdef SILC_DIST_COMPILER
433 ##
434 ##  With/without checkings
435 ##
436
437 #
438 # SILC library checking
439 compile_libs=true
440
441 #ifndef SILC_DIST_TOOLKIT
442 AC_ARG_WITH(silc-includes, 
443   [  --with-silc-includes=DIR SILC Toolkit includes [search in DIR]],
444   [ac_silc_includes="$withval"], [ac_silc_includes="no"])
445 AC_ARG_WITH(silc-libs,
446   [  --with-silc-libs=DIR     SILC Toolkit libraries [search in DIR]],
447   [ac_silc_libs="$withval"], [ac_silc_libs="no"])
448
449 if test -n "$with_silc_includes" || test -n "$with_silc_libs"; then
450
451   # Manually provided libs
452   if test "$ac_silc_includes" != "no"; then
453     compile_libs=false
454     SILC_LIB_INCLUDES="-I$ac_silc_includes"
455   fi
456   if test "$ac_silc_libs" != "no"; then
457     compile_libs=false
458     LIBS="$LIBS -L$ac_silc_libs"
459   fi
460
461   # Check libs to link against
462   f=`$EGREP __SILC_HAVE_PTHREAD $ac_silc_includes/silcincludes.h`
463   if test -n "$f"; then
464     LIBS="$LIBS -lpthread"
465     check_threads=false
466     has_threads=true
467   fi
468   f=`$EGREP __SILC_HAVE_SIM $ac_silc_includes/silcincludes.h`
469   if test -n "$f"; then
470     LIBS="$LIBS -ldl"
471   fi
472
473 else
474   # pkg-config check
475   PKG_CHECK_MODULES(SILC, silc, compile_libs=false, compile_libs=true)
476   PKG_CHECK_MODULES(SILCCLIENT, silcclient, compile_libs=false, compile_libs=true)
477
478   if test x$compile_libs = xfalse; then
479     LIBS="$LIBS $SILC_LIBS"
480     CFLAGS="$CFLAGS $SILC_CFLAGS"
481     LIBS="$LIBS $SILCCLIENT_LIBS"
482     CFLAGS="$CFLAGS $SILCCLIENT_CFLAGS"
483   fi
484 fi
485 #endif SILC_DIST_TOOLKIT
486
487 # SOCKS4 support checking
488 #
489 SAVE_LIBS="$LIBS"
490 SAVE_CFLAGS="$CFLAGS"
491 SAVE_LDFLAGS="$LDFLAGS"
492 AC_MSG_CHECKING(whether to support SOCKS4)
493 AC_ARG_WITH(socks4,
494   [[  --with-socks4[=DIR]     with SOCKS4 support [search in DIR/lib and DIR/include]]],
495   [
496     case "$withval" in
497       no)
498         AC_MSG_RESULT(no)
499         ;;
500       *)
501         AC_MSG_RESULT(yes)
502         socks=4
503
504         if test -d "$withval/include"; then
505           CFLAGS="$CFLAGS -I$withval/include"
506         fi
507         if test -d "$withval/lib"; then
508           LDFLAGS="$LDFLAGS -L$withval/lib"
509         fi
510
511         LIBS="-lsocks $LIBS"
512         ;;
513     esac
514
515     AC_TRY_LINK([],
516       [
517         Rconnect();
518       ], [],
519       [
520         AC_MSG_ERROR(Could not find SOCKS4 library.)
521         LIBS="$SAVE_LIBS"
522         CFLAGS="$SAVE_CFLAGS"
523         LDFLAGS="$SAVE_LDFLAGS"
524       ])
525   ],
526     AC_MSG_RESULT(no)
527   )
528
529 # SOCKS5 support checking
530 #
531 SAVE_LIBS="$LIBS"
532 SAVE_CFLAGS="$CFLAGS"
533 SAVE_LDFLAGS="$LDFLAGS"
534 AC_MSG_CHECKING(whether to support SOCKS5)
535 AC_ARG_WITH(socks5,
536   [[  --with-socks5[=DIR]     with SOCKS5 support [search in DIR/lib and DIR/include]]],
537   [
538     case "$withval" in
539       no)
540         AC_MSG_RESULT(no)
541         ;;
542       *)
543         AC_MSG_RESULT(yes)
544         socks=5
545
546         if test -d "$withval/include"; then
547           CFLAGS="$CFLAGS -I$withval/include"
548         fi
549         if test -d "$withval/lib"; then
550           LDFLAGS="$LDFLAGS -L$withval/lib"
551         fi
552
553         LIBS="-lsocks5 $LIBS"
554         ;;
555     esac
556
557     AC_TRY_LINK([],
558       [
559         SOCKSconnect();
560       ], [],
561       [
562         AC_MSG_ERROR(Could not find SOCKS5 library.)
563         LIBS="$SAVE_LIBS"
564         CFLAGS="$SAVE_CFLAGS"
565         LDFLAGS="$SAVE_LDFLAGS"
566       ])
567   ],
568     AC_MSG_RESULT(no)
569   )
570
571 if test "x$socks" = "x4"; then
572   AC_DEFINE([SOCKS], [], [Socks])
573   CFLAGS="$CFLAGS -Dconnect=Rconnect -Dgetsockname=Rgetsockname -Dbind=Rbind -Daccept=Raccept -Dlisten=Rlisten -Dselect=Rselect"
574 fi
575
576 if test "x$socks" = "x5"; then
577   AC_DEFINE([SOCKS], [], [Socks])
578   AC_DEFINE([SOCKS5], [], [Socks5])
579   AC_DEFINE([Rconnect], [SOCKSconnect], [Socks])
580   AC_DEFINE([Rgetsockname], [SOCKSgetsockname], [Socks])
581   AC_DEFINE([Rgetpeername], [SOCKSgetpeername], [Socks])
582   AC_DEFINE([Rbind], [SOCKSbind], [Socks])
583   AC_DEFINE([Raccept], [SOCKSaccept], [Socks])
584   AC_DEFINE([Rlisten], [SOCKSlisten], [Socks])
585   AC_DEFINE([Rselect], [SOCKSselect], [Socks])
586   AC_DEFINE([Rrecvfrom], [SOCKSrecvfrom], [Socks])
587   AC_DEFINE([Rsendto], [SOCKSsendto], [Socks])
588   AC_DEFINE([Rrecv], [SOCKSrecv], [Socks])
589   AC_DEFINE([Rsend], [SOCKSsend], [Socks])
590   AC_DEFINE([Rread], [SOCKSread], [Socks])
591   AC_DEFINE([Rwrite], [SOCKSwrite], [Socks])
592   AC_DEFINE([Rrresvport], [SOCKSrresvport], [Socks])
593   AC_DEFINE([Rshutdown], [SOCKSshutdown], [Socks])
594   AC_DEFINE([Rlisten], [SOCKSlisten], [Socks])
595   AC_DEFINE([Rclose], [SOCKSclose], [Socks])
596   AC_DEFINE([Rdup], [SOCKSdup], [Socks])
597   AC_DEFINE([Rdup2], [SOCKSdup2], [Socks])
598   AC_DEFINE([Rfclose], [SOCKSfclose], [Socks])
599   AC_DEFINE([Rgethostbyname], [SOCKSgethostbyname], [Socks])
600 fi
601
602 #ifdef SILC_DIST_MATH
603 # MP library checking. First check whether user wants to use GMP and use
604 # it if found. If not or not defined then compile the MPI library in the
605 # source tree.
606 #
607 mp_gmp=false
608 SAVE_LIBS="$LIBS"
609 SAVE_CFLAGS="$CFLAGS"
610 SAVE_LDFLAGS="$LDFLAGS"
611 AC_MSG_CHECKING(whether to search for GMP)
612 AC_ARG_WITH(gmp,
613   [[  --with-gmp[=DIR]        use GMP instead of MPI [search in DIR/lib and DIR/include]]],
614   [
615     case "$withval" in
616       no)
617         AC_MSG_RESULT(no)
618         ;;
619       *)
620         AC_MSG_RESULT(yes)
621
622         if test -d "$withval/include"; then
623           CFLAGS="$CFLAGS -I$withval/include"
624         fi
625         if test -d "$withval/lib"; then
626           LDFLAGS="$LDFLAGS -L$withval/lib"
627         fi
628
629         LIBS="-lgmp $LIBS"
630         ;;
631     esac
632
633     AC_CHECK_LIB(gmp, __gmpz_init,
634       [
635         mp_gmp=true
636         AC_DEFINE([SILC_MP_GMP], [], [GMP])
637         AC_MSG_RESULT(Using GMP as a MP library.)
638       ],
639       [
640         LIBS="$SAVE_LIBS"
641         CFLAGS="$SAVE_CFLAGS"
642         LDFLAGS="$SAVE_LDFLAGS"
643       ])
644   ],
645     AC_MSG_RESULT(no)
646   )
647
648 AM_CONDITIONAL(SILC_MP_GMP, test x$mp_gmp = xtrue)
649 AM_CONDITIONAL(SILC_MP_NSS_MPI, test x$mp_gmp = xfalse)
650 if test x$mp_gmp = xfalse; then
651   AC_DEFINE([SILC_MP_NSS_MPI], [], [MPI])
652   AC_MSG_RESULT(Using NSS MPI as a MP library.)
653 fi
654 #endif SILC_DIST_MATH
655
656 # iconv support
657 #
658 check_iconv=true
659 has_iconv=false
660 SAVE_LIBS="$LIBS"
661 SAVE_CFLAGS="$CFLAGS"
662 SAVE_LDFLAGS="$LDFLAGS"
663 SAVE_CPPFLAGS="$CPPFLAGS"
664 AC_MSG_CHECKING(whether to implicit search for libiconv)
665 AC_ARG_WITH(iconv,
666   [[  --with-iconv[=DIR]      use libiconv [search in DIR/include and DIR/lib]]],
667   [
668     case "${withval}" in
669       no)
670         AC_MSG_RESULT(no)
671         AC_CHECK_HEADERS(iconv.h,
672           [
673             AC_CHECK_FUNC(iconv, has_iconv=true)
674           ])
675         check_iconv=false
676         ;;
677       *)
678         AC_MSG_RESULT(yes)
679         if test -d $withval/include; then
680           CPPFLAGS="$CPPFLAGS -I$withval/include"
681           CFLAGS="$CFLAGS -I$withval/include"
682         fi
683         if test -d $withval/lib; then
684           LDFLAGS="$LDFLAGS -L$withval/lib"
685         fi
686         ;;
687     esac
688   ],
689   [
690     AC_MSG_RESULT(no)
691     AC_CHECK_HEADERS(iconv.h,
692       [
693         AC_CHECK_FUNCS(iconv,
694           [
695             has_iconv=true
696             check_iconv=false
697           ])
698       ])
699   ])
700
701 if test x$check_iconv = xtrue; then
702   AC_MSG_RESULT(Searching for iconv...)
703
704   # XXX
705   unset ac_cv_header__iconv_h_ ac_cv_header_iconv_h || true
706
707   AC_CHECK_HEADERS(iconv.h,
708     [
709       LIBS="$LIBS -liconv"
710       AC_MSG_CHECKING(for iconv in -liconv)
711       AC_TRY_LINK(
712         [
713           #include <stdlib.h>
714           #include <iconv.h>
715         ],
716         [
717           iconv_t cd = iconv_open("", "");
718           iconv(cd, NULL, NULL, NULL, NULL);
719           iconv_close(cd);
720         ],
721         [
722           echo "yes"
723           AC_DEFINE([HAVE_ICONV], [], [Define if you have the iconv() function.])
724           has_iconv=true
725           check_iconv=false
726         ],
727         [
728           echo "no"
729           LIBS="$SAVE_LIBS"
730           CFLAGS="$SAVE_CFLAGS"
731           LDFLAGS="$SAVE_LDFLAGS"
732           CPPFLAGS="$SAVE_CPPFLAGS"
733         ])
734      ])
735 fi
736
737 if test x$check_iconv = xtrue; then
738   # search for iconv library..
739   SAVE_LIBS="$LIBS"
740   SAVE_CFLAGS="$CFLAGS"
741   SAVE_LDFLAGS="$LDFLAGS"
742   SAVE_CPPFLAGS="$CPPFLAGS"
743
744   for dir in `echo "/usr/local /usr/pkg /usr/contrib"`; do
745     if test x$has_iconv = xfalse; then
746       AC_MSG_RESULT(searching in $dir...)
747
748       if test -d $dir/include; then
749         CPPFLAGS="$CPPFLAGS -I$dir/include"
750         CFLAGS="$CFLAGS -I$dir/include"
751       fi
752       if test -d $dir/lib; then
753         LDFLAGS="$LDFLAGS -L$dir/lib"
754       fi
755
756       # XXX
757       unset ac_cv_header__iconv_h_ ac_cv_header_iconv_h || true
758
759       AC_CHECK_HEADERS(iconv.h,
760         [
761           LIBS="$LIBS -liconv"
762           AC_MSG_CHECKING(for iconv in -liconv)
763           AC_TRY_LINK(
764             [
765               #include <stdlib.h>
766               #include <iconv.h>
767             ],
768             [
769               iconv_t cd = iconv_open("", "");
770               iconv(cd, NULL, NULL, NULL, NULL);
771               iconv_close(cd);
772             ],
773             [
774               echo "yes"
775               has_iconv=true
776               AC_DEFINE([HAVE_ICONV], [], [Define if you have the iconv() function.])
777             ],
778             [
779               echo "no"
780               has_iconv=false
781
782               LIBS="$SAVE_LIBS"
783               CFLAGS="$SAVE_CFLAGS"
784               LDFLAGS="$SAVE_LDFLAGS"
785               CPPFLAGS="$SAVE_CPPFLAGS"
786             ])
787          ],
788          [
789            CFLAGS="$SAVE_CFLAGS"
790            LDFLAGS="$SAVE_LDFLAGS"
791            CPPFLAGS="$SAVE_CPPFLAGS"
792          ])
793       fi
794     done
795 fi
796
797 if test x$has_iconv = xtrue; then
798   # (1) Some implementations of iconv won't convert from UTF-8 to UTF-8.
799   # (2) In glibc-2.1.2 and earlier there is a bug that messes up ob and
800   #     obl when args 2 and 3 are 0 (fixed in glibc-2.1.3).
801   #
802   AC_CACHE_CHECK([whether this iconv is good enough], ac_iconv_good,
803     AC_TRY_RUN(
804       [
805         #include <iconv.h>
806         int main() {
807           iconv_t cd;
808         changequote(, )dnl
809           char buf[4];
810         changequote([, ])dnl
811           char *ob;
812           size_t obl;
813           ob = buf, obl = sizeof(buf);
814           return ((cd = iconv_open("UTF-8", "UTF-8")) != (iconv_t)(-1) &&
815                  (iconv(cd, 0, 0, &ob, &obl) ||
816                  !(ob == buf && obl == sizeof(buf)) ||
817                  iconv_close(cd)));
818         }
819       ],
820       [
821         ac_iconv_good=yes
822       ],
823       [
824         ac_iconv_good=no
825       ],
826       [
827         ac_iconv_good=yes
828       ])
829     )
830
831   if test x$ac_iconv_good = xno; then
832     AC_MSG_RESULT(Try using libiconv instead.)
833   fi
834 fi
835
836 # POSIX threads support
837 #
838 AC_MSG_CHECKING(whether to search for POSIX threads)
839 AC_ARG_WITH(pthreads,
840   [[  --with-pthreads[=DIR]   use POSIX threads [search in DIR/include and DIR/lib]]],
841   [
842     case "${withval}" in
843       no)
844         check_threads=false
845         ;;
846       *)
847         if test -d $withval/include; then
848           CPPFLAGS="$CPPFLAGS -I$withval/include"
849           CFLAGS="$CFLAGS -I$withval/include"
850         fi
851         if test -d $withval/lib; then
852           LDFLAGS="$LDFLAGS -L$withval/lib"
853         fi
854
855         check_threads=true
856         ;;
857     esac
858   ])
859
860 if test x$check_threads = xtrue; then
861   has_threads=false
862   SAVE_LIBS="$LIBS"
863   SAVE_CFLAGS="$CFLAGS"
864   SAVE_LDFLAGS="$LDFLAGS"
865   SAVE_CPPFLAGS="$CPPFLAGS"
866
867   AC_MSG_RESULT(yes)
868   AC_CHECK_HEADERS(pthread.h,
869     [
870       LIBS="$LIBS -lpthread"
871       AC_CHECK_LIB(pthread, pthread_attr_init, has_threads=true,
872         [
873           # FreeBSD
874           case "${target}" in
875             *-*-freebsd*)
876               LIBS="$SAVE_LIBS -pthread"
877               AC_CHECK_LIB(c_r, pthread_attr_init, has_threads=true, LIBS="$SAVE_LIBS")
878               ;;
879             *)
880               LIBS="$SAVE_LIBS"
881               ;;
882           esac
883         ])
884     ],
885     [
886       # search for pthread library..
887       for dir in `echo "/usr/local /usr/pkg /usr/contrib /usr/pkg/pthreads /usr/local/pthreads"`; do
888         if test x$has_threads = xfalse; then
889           AC_MSG_RESULT(searching in $dir...)
890
891           if test -d $dir/include; then
892             CPPFLAGS="$CPPFLAGS -I$dir/include"
893             CFLAGS="$CFLAGS -I$dir/include"
894           fi
895           if test -d $dir/lib; then
896             LDFLAGS="$LDFLAGS -L$dir/lib"
897           fi
898
899           # XXX
900           unset ac_cv_header__pthread_h_ ac_cv_header_pthread_h || true
901
902           AC_CHECK_HEADERS(pthread.h,
903             [
904               LIBS="$LIBS -lpthread"
905               AC_CHECK_LIB(pthread, pthread_attr_init, has_threads=true,
906                 [
907                   has_threads=false
908
909                   LIBS="$SAVE_LIBS"
910                   CFLAGS="$SAVE_CFLAGS"
911                   LDFLAGS="$SAVE_LDFLAGS"
912                   CPPFLAGS="$SAVE_CPPFLAGS"
913                 ])
914             ],
915             [
916               CFLAGS="$SAVE_CFLAGS"
917               LDFLAGS="$SAVE_LDFLAGS"
918               CPPFLAGS="$SAVE_CPPFLAGS"
919             ])
920         fi
921       done
922     ])
923 else
924   AC_MSG_RESULT(no)
925   has_threads=false
926 fi
927
928 __SILC_HAVE_PTHREAD=""
929 AM_CONDITIONAL(SILC_THREADS, test x$has_threads = xtrue)
930 if test x$has_threads = xtrue; then
931   CFLAGS="$CFLAGS -D_REENTRANT"
932
933   # XXX possibly incomplete
934   case "${target}" in
935     *-*-aix*)
936       CFLAGS="$CFLAGS -D_THREAD_SAFE"
937       if test x"$GCC" = xyes; then
938         CFLAGS="$CFLAGS -mthreads"
939       fi
940       ;;
941     *-*-freebsd*)
942       CFLAGS="$CFLAGS -D_THREAD_SAFE"
943       ;;
944     *-*-sysv5uw7*)  # UnixWare 7
945       if test "$GCC" != "yes"; then
946         CFLAGS="$CFLAGS -Kthread"
947       else
948         CFLAGS="$CFLAGS -pthread"
949       fi
950       ;;
951     *-dg-dgux*)  # DG/UX
952       CFLAGS="$CFLAGS -D_POSIX4A_DRAFT10_SOURCE"
953       ;;
954    esac
955
956   AC_CHECK_FUNC(pthread_create)
957   AC_DEFINE([SILC_HAVE_PTHREAD], [], [HAVE_PTHREAD])
958   AC_DEFINE([SILC_THREADS], [], [HAVE_THREAD])
959   __SILC_HAVE_PTHREAD="#define __SILC_HAVE_PTHREAD 1"
960 fi
961
962 # Native WIN32 compilation under cygwin
963 #
964 AC_MSG_CHECKING(whether to compile native WIN32 code)
965 AC_ARG_WITH(win32,
966   [  --with-win32            compile native WIN32 (MinGW) code (-mno-cygwin)],
967   [
968     AC_MSG_RESULT(yes)
969     AC_DEFINE([SILC_WIN32], [], [SILC_WIN32])
970     win32_support=true
971     CFLAGS="-mno-cygwin $CFLAGS"
972     LIBS="$LIBS -lwsock32"
973   ],
974   [
975     AC_MSG_RESULT(no)
976   ])
977 AM_CONDITIONAL(SILC_WIN32, test x$win32_support = xtrue)
978
979 # Native EPOC support (disabled by default)
980 #
981 AM_CONDITIONAL(SILC_EPOC, test xfalse = xtrue)
982
983 # Native BeOS support (disabled by default)
984 #
985 AM_CONDITIONAL(SILC_BEOS, test xfalse = xtrue)
986
987 # Native OS2 support (disabled by default)
988 #
989 AM_CONDITIONAL(SILC_OS2, test xfalse = xtrue)
990
991 #ifdef SILC_DIST_TOOLKIT
992 # --without-irssi
993 #
994 without_irssi=false
995 AC_MSG_CHECKING(whether to compile Irssi SILC Client)
996 AC_ARG_WITH(irssi,
997   [  --without-irssi         compile without Irssi SILC Client],
998   [
999     AC_MSG_RESULT(no)
1000     without_irssi=true
1001   ],
1002   [
1003     AC_MSG_RESULT(yes)
1004   ])
1005
1006 # --without-silcd
1007 #
1008 without_silcd=false
1009 AC_MSG_CHECKING(whether to compile SILC Server)
1010 AC_ARG_WITH(silcd,
1011   [  --without-silcd         compile without SILC Server],
1012   [
1013     AC_MSG_RESULT(no)
1014     without_silcd=true
1015   ],
1016   [
1017     AC_MSG_RESULT(yes)
1018   ])
1019 #endif SILC_DIST_TOOLKIT
1020
1021 #ifdef SILC_DIST_CLIENT
1022 # Irssi perl support
1023 #
1024 AC_ARG_WITH(perl,
1025   [[  --with-perl[=yes|no|module]  Build with Perl support - also specifies
1026                                if it should be built into main silc binary
1027                                (static, default) or as a module]])
1028 #endif SILC_DIST_CLIENT
1029
1030 libtoolfix=true
1031 AC_MSG_CHECKING(whether to do libtoolfix)
1032 AC_ARG_WITH(libtoolfix,
1033   [  --without-libtoolfix    Do not fix libtool, for package builders],
1034   [
1035     AC_MSG_RESULT(no)
1036     libtoolfix=false
1037   ],
1038   [
1039     AC_MSG_RESULT(yes)
1040   ])
1041
1042 AC_SUBST(ETCDIR)
1043 AC_DEFINE_UNQUOTED([SILC_ETCDIR], "$ETCDIR", [SILC_ETCDIR])
1044
1045 #endif SILC_DIST_COMPILER
1046
1047 ##
1048 ##  Misc
1049 ##
1050
1051 # Make enable-shared aware
1052 AM_CONDITIONAL(SILC_ENABLE_SHARED, test "$enable_shared" = yes)
1053
1054 # Other configure scripts
1055 #
1056
1057 #ifdef SILC_DIST_TOOLKIT
1058 if test x$without_irssi = xfalse; then
1059 #endif SILC_DIST_TOOLKIT
1060 #ifdef SILC_DIST_CLIENT
1061   AC_CONFIG_SUBDIRS(irssi)
1062   irssi="yes"
1063 #endif SILC_DIST_CLIENT
1064 #ifdef SILC_DIST_TOOLKIT
1065 fi
1066 #endif SILC_DIST_TOOLKIT
1067
1068 SILC_TOP_SRCDIR=`pwd`
1069
1070 # Included configure scripts
1071 AD_INCLUDE_CONFIGURE
1072
1073 #ifdef SILC_DIST_COMPILER
1074 #
1075 # Substitutions
1076 #
1077 AC_SUBST(SILC_TOP_SRCDIR)
1078 AC_SUBST(LIBS)
1079 AC_SUBST(SILC_LIB_INCLUDES)
1080 AC_SUBST(__SILC_HAVE_PTHREAD)
1081 AC_SUBST(__SILC_HAVE_SIM)
1082 AC_SUBST(__SILC_ENABLE_DEBUG)
1083
1084 #
1085 # Fix the libtool to support run-time configuration.  This allows us
1086 # to in run-time specify when to compile shared/static libraries without
1087 # need to reconfigure the entire libtool.
1088 #
1089 if test x$libtoolfix = xtrue; then
1090   ./libtoolfix $SILC_TOP_SRCDIR/ltmain.sh
1091 fi
1092 AM_CONDITIONAL(SILC_LIBTOOLFIX, test x$libtoolfix = xtrue)
1093
1094 INCLUDE_DEFINES_INT="include \$(top_srcdir)/Makefile.defines_int"
1095 AC_SUBST(INCLUDE_DEFINES_INT)
1096
1097 #endif SILC_DIST_COMPILER
1098
1099 #
1100 # Makefile outputs
1101 #
1102 AC_CONFIG_FILES(
1103 Makefile
1104 #ifdef SILC_DIST_DOC
1105 doc/Makefile
1106 #endif SILC_DIST_DOC
1107 #ifdef SILC_DIST_COMPILER
1108 Makefile.defines
1109 Makefile.defines_int
1110 includes/Makefile
1111 includes/silcversion.h
1112 includes/silcincludes.h
1113 #endif SILC_DIST_COMPILER
1114 #ifdef SILC_DIST_APPS
1115 apps/Makefile
1116 #endif SILC_DIST_APPS
1117 )
1118
1119 #ifdef SILC_DIST_TOOLKIT
1120 if test x$without_irssi = xfalse ; then
1121 #endif SILC_DIST_TOOLKIT
1122 #ifdef SILC_DIST_CLIENT
1123   AC_CONFIG_FILES(
1124 irssi/Makefile.defines
1125 irssi/Makefile.defines_int
1126 )
1127 #endif SILC_DIST_CLIENT
1128 #ifdef SILC_DIST_TOOLKIT
1129 fi
1130 #endif SILC_DIST_TOOLKIT
1131
1132 #ifdef SILC_DIST_TOOLKIT
1133 AC_CONFIG_FILES(
1134 silc/Makefile
1135 win32/Makefile
1136 win32/libsilc/Makefile
1137 win32/libsilcclient/Makefile
1138 tutorial/Makefile
1139 tutorial/Makefile.defines
1140 tutorial/Makefile.defines_int
1141 )
1142 #endif SILC_DIST_TOOLKIT
1143
1144 AC_OUTPUT
1145
1146 #ifdef SILC_DIST_COMPILER
1147 s_bindir=`eval echo $bindir`;s_bindir=`eval echo $s_bindir`
1148 s_sbindir=`eval echo $sbindir`;s_sbindir=`eval echo $s_sbindir`
1149 s_mandir=`eval echo $mandir`;s_mandir=`eval echo $s_mandir`
1150 s_includedir=`eval echo $includedir`;s_includedir=`eval echo $s_includedir`
1151
1152 echo ""
1153 echo "$PACKAGE Configuration Summary:"
1154 echo "---------------------------"
1155 echo " Target host ...................: $target"
1156 echo " Compiler ......................: $CC"
1157 echo " CFLAGS ........................: $CFLAGS"
1158 echo " LDFLAGS .......................: $LDFLAGS"
1159 echo " LIBS ..........................: $LIBS"
1160 echo ""
1161 echo " Installation prefix ...........: $prefix"
1162 echo " bin directory .................: $s_bindir"
1163 echo " sbin directory ................: $s_sbindir"
1164 echo " etc directory .................: $ETCDIR"
1165 echo " man directory .................: $s_mandir"
1166 echo " doc directory .................: $DOCDIR"
1167 #ifdef SILC_DIST_CLIENT
1168 echo " help directory ................: $HELPDIR"
1169 #endif SILC_DIST_CLIENT
1170 #ifdef SILC_DIST_SERVER
1171 echo " logs directory ................: $LOGSDIR"
1172 #endif SILC_DIST_SERVER
1173 #ifdef SILC_DIST_SIM
1174 echo " SIM directory .................: $MODULESDIR"
1175 #endif SILC_DIST_SIM
1176 #ifdef SILC_DIST_INCLUDES
1177 echo " include directory .............: $s_includedir"
1178 #endif SILC_DIST_INCLUDES
1179 echo ""
1180
1181 #ifdef SILC_DIST_TOOLKIT
1182 if test x$without_irssi = xtrue; then
1183   irssi="no"
1184 fi
1185 if test x$without_silcd = xtrue; then
1186   silcd="no"
1187 fi
1188 #endif SILC_DIST_TOOLKIT
1189
1190 #ifdef SILC_DIST_CLIENT
1191 echo " Compile SILC Client ...........: $irssi"
1192 #endif SILC_DIST_CLIENT
1193
1194 #ifdef SILC_DIST_SERVER
1195 echo " Compile SILC Server ...........: $silcd"
1196 echo " Server configuration file .....: $summary_silcd_configfile"
1197 echo " Server PID file ...............: $PIDFILE"
1198 #endif SILC_DIST_SERVER
1199
1200 #ifdef SILC_DIST_SIM
1201 if test x$sim_support = xfalse; then
1202   sim_support="no"
1203 else
1204   sim_support="yes"
1205 fi
1206 echo " SIM support ...................: $sim_support"
1207 #endif SILC_DIST_SIM
1208
1209 echo " IPv6 support ..................: $summary_ipv6"
1210
1211 if test x$has_iconv = xfalse; then
1212   iconv_support="no"
1213 else
1214   iconv_support="yes"
1215 fi
1216 echo " Iconv support .................: $iconv_support"
1217
1218 if test x$want_asm = xfalse; then
1219   summary_asm="no"
1220 else
1221   summary_asm="yes"
1222 fi
1223 echo " Assembler optimizations .......: $summary_asm"
1224
1225 #ifdef SILC_DIST_MATH
1226 mp="MPI"
1227 if test x$mp_gmp = xtrue; then
1228   mp="GMP"
1229 fi
1230 echo " Arithmetic library ............: $mp"
1231 #endif SILC_DIST_MATH
1232
1233 threads="no"
1234 if test x$has_threads = xtrue; then
1235   threads="yes"
1236 fi
1237 echo " Multi-threads support .........: $threads"
1238 echo " Debugging enabled .............: $summary_debug"
1239 echo ""
1240 echo "Compile the sources with 'make' or 'gmake' command."
1241 #endif SILC_DIST_COMPILER
1242