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