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