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