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