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