autoconf update.
[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         AC_DEFINE(HAVE_IPV6)
180         AC_MSG_RESULT(yes)
181         ;;
182       *)
183         want_ipv6=false
184         check_ipv6=false
185         AC_MSG_RESULT(no)
186         ;;
187     esac
188   ],
189     check_ipv6=true
190   )
191
192 if test x$check_ipv6 = xtrue; then
193   AC_TRY_COMPILE(
194     [
195       #ifdef HAVE_NETINET_TCP_H
196       #include <netinet/tcp.h>
197       #endif
198       #ifdef HAVE_NETDB_H
199       #include <netdb.h>
200       #endif
201       #include <sys/socket.h>
202       #ifdef HAVE_NETDB_IN_H
203       #include <netinet/in.h>
204       #endif
205     ],
206     [
207       struct sockaddr_in6 sin6;
208       int family = AF_INET6;
209     ],
210     [
211       AC_DEFINE(HAVE_IPV6)
212       AC_MSG_RESULT(yes)
213     ],
214       AC_MSG_RESULT(no)
215     )
216 fi
217
218 # Debug checking
219 #
220 AC_MSG_CHECKING(whether to enable debugging)
221 AC_ARG_ENABLE(debug,
222   [  --enable-debug          enable debugging],
223   [
224     case "${enableval}" in
225       yes)
226         AC_MSG_RESULT(yes)
227         AC_DEFINE(SILC_DEBUG)
228         CFLAGS="-O -g $CFLAGS"
229         ;;
230       *)
231         AC_MSG_RESULT(no)
232         CFLAGS="-O2 -g $CFLAGS"
233         ;;
234     esac
235   ],
236   [
237     CFLAGS="-O2 -g $CFLAGS"
238     AC_MSG_RESULT(no)
239   ])
240
241 # Stack trace checking
242 #
243 AC_MSG_CHECKING(whether to enable stack tracing)
244 AC_ARG_ENABLE(stack-trace,
245   [  --enable-stack-trace    enable memory stack trace],
246   [
247     case "${enableval}" in
248     yes)
249       AC_MSG_RESULT(yes)
250       AC_DEFINE(SILC_STACKTRACE)
251       ;;
252     *)
253       AC_MSG_RESULT(no)
254       ;;
255     esac
256   ],
257     AC_MSG_RESULT(no)
258   )
259
260 # Disable all assembler optimizations
261 #
262 AC_MSG_CHECKING(whether to enable assembler optimizations)
263 AC_ARG_ENABLE(asm,
264   [  --disable-asm           do not use assembler optimizations],
265   [
266     AC_MSG_RESULT(no)
267   ],
268   [
269     AC_MSG_RESULT(yes)
270   ])
271
272
273 ##
274 ##  Installation
275 ##
276
277 # Default installation destination
278 #
279 AC_PREFIX_DEFAULT(/usr/local/silc)
280 if test "x$prefix" != xNONE; then
281   silc_prefix="$prefix"
282 else
283   silc_prefix="$ac_default_prefix"
284 fi
285
286 # etc directory
287 #
288 if test "x$sysconfdir" != 'x${prefix}/etc'; then
289   ETCDIR="$sysconfdir"
290 else
291   ETCDIR="$silc_prefix/etc"
292 fi
293
294 AC_ARG_WITH(etcdir,
295   [[  --with-etcdir=DIR       directory for system files [/etc/silc]]],
296   [
297     case "$withval" in
298       no)
299         ;;
300       *)
301         ETCDIR="$withval"
302         ;;
303     esac
304   ])
305 AC_SUBST(ETCDIR)
306 AC_DEFINE_UNQUOTED(SILC_ETCDIR, "$ETCDIR")
307
308 # help directory
309 #
310 HELPDIR="$silc_prefix/help"
311 AC_ARG_WITH(helpdir,
312   [[  --with-helpdir=DIR      directory for SILC help files [PREFIX/help]]],
313   [
314     case "$withval" in
315       no)
316         ;;
317       *)
318        HELPDIR="$withval"
319        ;;
320     esac
321   ])
322 AC_SUBST(HELPDIR)
323 AC_DEFINE_UNQUOTED(SILC_HELPDIR, "$HELPDIR")
324
325 # doc directory
326 #
327 DOCDIR="$silc_prefix/doc"
328 AC_ARG_WITH(docdir,
329   [[  --with-docdir=DIR       directory for SILC documentation [PREFIX/doc]]],
330   [
331     case "$withval" in
332       no)
333         ;;
334       *)
335         DOCDIR="$withval"
336         ;;
337     esac
338   ])
339 AC_SUBST(DOCDIR)
340 AC_DEFINE_UNQUOTED(SILC_DOCDIR, "$DOCDIR")
341
342 # SIM modules directory
343 #
344 MODULESDIR="$silc_prefix/modules"
345 AC_ARG_WITH(simdir,
346   [[  --with-simdir=DIR       directory for SIM modules [PREFIX/modules]]],
347   [
348     case "$withval" in
349       no)
350         ;;
351       *)
352         MODULESDIR="$withval"
353         ;;
354     esac
355   ])
356 AC_SUBST(MODULESDIR)
357 AC_DEFINE_UNQUOTED(SILC_MODULESDIR, "$MODULESDIR")
358
359 # Logs directory
360 #
361 LOGSDIR="$silc_prefix/logs"
362 AC_ARG_WITH(logsdir,
363   [[  --with-logsdir=DIR      directory for SILC Server logs [PREFIX/logs]]],
364   [
365     case "$withval" in
366       no)
367         ;;
368       *)
369         LOGSDIR="$withval"
370         ;;
371     esac
372   ])
373 AC_SUBST(LOGSDIR)
374 AC_DEFINE_UNQUOTED(SILC_LOGSDIR, "$LOGSDIR")
375
376 # silcd config file checking
377 #
378 AC_ARG_WITH(silcd-config-file,
379   [[  --with-silcd-config-file=FILE  use FILE as default configuration file
380                                  for SILC Server [/etc/silc/silcd.conf]]],
381     AC_DEFINE_UNQUOTED(SILC_SERVER_CONFIG_FILE, "$withval")
382   )
383
384 # silcd pid file checking
385 #
386 if test "x$localstatedir" != 'x${prefix}/var'; then
387   PIDFILE="$localstatedir/silcd.pid"
388 else
389   PIDFILE="$silc_prefix/var/silcd.pid"
390 fi
391
392 AC_ARG_WITH(silcd-pid-file,
393   [[  --with-silcd-pid-file=FILE     use FILE as default pid file for SILC
394                                  Server [/var/run/silcd.pid]]],
395   [
396     case "$withval" in
397       no)
398         ;;
399       *)
400         PIDFILE="$withval"
401         ;;
402     esac
403   ])
404 AC_SUBST(PIDFILE)
405
406
407 ##
408 ##  With/without checkings
409 ##
410
411 # SOCKS4 support checking
412 #
413 AC_MSG_CHECKING(whether to support SOCKS4)
414 AC_ARG_WITH(socks4,
415   [[  --with-socks4[=DIR]     with SOCKS4 support [search in DIR/lib and DIR/include]]],
416   [
417     case "$withval" in
418       no)
419         AC_MSG_RESULT(no)
420         ;;
421       *)
422         AC_MSG_RESULT(yes)
423         socks=4
424     
425         if test -d "$withval/include"; then
426           CFLAGS="$CFLAGS -I$withval/include"
427         else
428           CFLAGS="$CFLAGS -I$withval"
429         fi
430         if test -d "$withval/lib"; then
431           withval="-L$withval/lib -lsocks"
432         else
433           withval="-L$withval -lsocks"
434         fi
435     
436         LIBS="$withval $LIBS"
437         AC_TRY_LINK([],
438           [
439             Rconnect();
440           ], [],
441           [
442             AC_MSG_ERROR(Could not find SOCKS4 library.)
443           ])
444         ;;
445     esac
446   ],
447     AC_MSG_RESULT(no)
448   )
449
450 # SOCKS5 support checking
451 #
452 AC_MSG_CHECKING(whether to support SOCKS5)
453 AC_ARG_WITH(socks5,
454   [[  --with-socks5[=DIR]     with SOCKS5 support [search in DIR/lib and DIR/include]]],
455   [
456     case "$withval" in
457       no)
458         AC_MSG_RESULT(no)
459         ;;
460       *)
461         AC_MSG_RESULT(yes)
462         socks=5
463
464         if test -d "$withval/include"; then
465           CFLAGS="$CFLAGS -I$withval/include"
466         else
467           CFLAGS="$CFLAGS -I$withval"
468         fi
469         if test -d "$withval/lib"; then
470           withval="-L$withval/lib -lsocks5"
471         else
472           withval="-L$withval -lsocks5"
473         fi
474
475         LIBS="$withval $LIBS"
476         AC_TRY_LINK([],
477           [
478             SOCKSconnect();
479           ], [],
480           [
481             AC_MSG_ERROR(Could not find SOCKS5 library.)
482           ])
483         ;;
484     esac
485   ],
486     AC_MSG_RESULT(no)
487   )
488
489 if test "x$socks" = "x4"; then
490   AC_DEFINE(SOCKS)
491   CFLAGS="$CFLAGS -Dconnect=Rconnect -Dgetsockname=Rgetsockname -Dbind=Rbind -Daccept=Raccept -Dlisten=Rlisten -Dselect=Rselect"
492 fi
493
494 if test "x$socks" = "x5"; then
495   AC_DEFINE(SOCKS)
496   AC_DEFINE(SOCKS5)
497   AC_DEFINE(Rconnect, SOCKSconnect)
498   AC_DEFINE(Rgetsockname, SOCKSgetsockname)
499   AC_DEFINE(Rgetpeername, SOCKSgetpeername)
500   AC_DEFINE(Rbind, SOCKSbind)
501   AC_DEFINE(Raccept, SOCKSaccept)
502   AC_DEFINE(Rlisten, SOCKSlisten)
503   AC_DEFINE(Rselect, SOCKSselect)
504   AC_DEFINE(Rrecvfrom, SOCKSrecvfrom)
505   AC_DEFINE(Rsendto, SOCKSsendto)
506   AC_DEFINE(Rrecv, SOCKSrecv)
507   AC_DEFINE(Rsend, SOCKSsend)
508   AC_DEFINE(Rread, SOCKSread)
509   AC_DEFINE(Rwrite, SOCKSwrite)
510   AC_DEFINE(Rrresvport, SOCKSrresvport)
511   AC_DEFINE(Rshutdown, SOCKSshutdown)
512   AC_DEFINE(Rlisten, SOCKSlisten)
513   AC_DEFINE(Rclose, SOCKSclose)
514   AC_DEFINE(Rdup, SOCKSdup)
515   AC_DEFINE(Rdup2, SOCKSdup2)
516   AC_DEFINE(Rfclose, SOCKSfclose)
517   AC_DEFINE(Rgethostbyname, SOCKSgethostbyname)
518 fi
519
520 # MP library checking. First check whether user wants to use GMP and use
521 # it if found. If not or not defined then compile the MPI library in the
522 # source tree.
523 #
524 mp_gmp=false
525 AC_MSG_CHECKING(whether to search for GMP)
526 AC_ARG_WITH(gmp,
527   [[  --with-gmp[=DIR]        use GMP instead of MPI [search in DIR/lib and DIR/include]]],
528   [
529     case "$withval" in
530       no)
531         AC_MSG_RESULT(no)
532         ;;
533       *)
534         AC_MSG_RESULT(yes)
535     
536         if test -d "$withval/include"; then
537           CFLAGS="$CFLAGS -I$withval/include"
538         else
539           CFLAGS="$CFLAGS -I$withval"
540         fi
541         if test -d "$withval/lib"; then
542           withval="-L$withval/lib -lgmp"
543         else
544           withval="-L$withval -lgmp"
545         fi
546     
547         LIBS="$withval $LIBS"
548         AC_CHECK_LIB(gmp, __gmpz_init,
549           [
550             mp_gmp=true
551             AC_DEFINE(SILC_MP_GMP)
552             AC_MSG_RESULT(Using GMP as a MP library.)
553           ])
554         ;;
555     esac
556   ],
557     AC_MSG_RESULT(no)
558   )
559
560 AM_CONDITIONAL(SILC_MP_GMP, test x$mp_gmp = xtrue)
561 AM_CONDITIONAL(SILC_MP_NSS_MPI, test x$mp_gmp = xfalse)
562 if test x$mp_gmp = xfalse; then
563   AC_DEFINE(SILC_MP_NSS_MPI)
564   AC_MSG_RESULT(Using NSS MPI as a MP library.)
565 fi
566
567 # iconv support
568 #
569 check_iconv=true
570 has_iconv=false
571 AC_MSG_CHECKING(whether to implicit search for libiconv)
572 AC_ARG_WITH(iconv,
573   [[  --with-iconv[=DIR]      use libiconv [search in DIR/include and DIR/lib]]],
574   [
575     case "${withval}" in
576       no)
577         AC_MSG_RESULT(no)
578
579         AC_CHECK_HEADERS(iconv.h, AC_CHECK_FUNC(iconv, has_iconv=true))
580         check_iconv=false
581         ;;
582       *)
583         AC_MSG_RESULT(yes)
584
585         if test -d $withval/include; then
586           CPPFLAGS="$CPPFLAGS -I$withval/include"
587           CFLAGS="$CFLAGS -I$withval/include"
588         fi
589         if test -d $withval/lib; then
590           LDFLAGS="$LDFLAGS -L$withval/lib"
591         fi
592     esac
593   ],
594   [
595     AC_MSG_RESULT(no)
596
597     AC_CHECK_HEADERS(iconv.h, AC_CHECK_FUNCS(iconv,
598                                 [
599                                   has_iconv=true
600                                   check_iconv=false
601                                  ]))
602   ])
603
604 if test x$check_iconv = xtrue; then
605   AC_MSG_RESULT(starting search...)
606
607   # XXX
608   unset ac_cv_header__iconv_h_ ac_cv_header_iconv_h || true
609
610   AC_CHECK_HEADERS(iconv.h,
611     [
612       LIBS="$LIBS -liconv"
613       AC_MSG_CHECKING(for iconv in -liconv)
614       AC_TRY_LINK(
615         [
616           #include <stdlib.h>
617           #include <iconv.h>
618         ],
619         [
620           iconv_t cd = iconv_open("", "");
621           iconv(cd, NULL, NULL, NULL, NULL);
622           iconv_close(cd);
623         ],
624         [
625           echo "yes"
626           AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
627           has_iconv=true 
628           check_iconv=true 
629         ])
630      ])
631 fi
632
633 if test x$check_iconv = xtrue; then
634   # search for iconv library..
635   SAVE_CPPFLAGS="$CPPFLAGS"
636   SAVE_CFLAGS="$CFLAGS"
637   SAVE_LDFLAGS="$LDFLAGS"
638     
639   for dir in `echo "/usr/local /usr/pkg /usr/contrib"`; do
640     if test x$has_iconv = xfalse; then
641       AC_MSG_RESULT(searching in $dir...)
642     
643       CPPFLAGS="$SAVE_CPPFLAGS"
644       CFLAGS="$SAVE_CFLAGS"
645       LDFLAGS="$SAVE_LDFLAGS"
646       
647       if test -d $dir/include; then
648         CPPFLAGS="$CPPFLAGS -I$dir/include"
649         CFLAGS="$CFLAGS -I$dir/include"
650       fi
651       if test -d $dir/lib; then
652         LDFLAGS="$LDFLAGS -L$dir/lib"
653       fi
654     
655       # XXX
656       unset ac_cv_header__iconv_h_ ac_cv_header_iconv_h || true
657       
658       AC_CHECK_HEADERS(iconv.h,
659         [
660           LIBS="$LIBS -liconv"
661           AC_MSG_CHECKING(for iconv in -liconv)
662           AC_TRY_LINK(
663             [
664               #include <stdlib.h>
665               #include <iconv.h>
666             ],
667             [
668               iconv_t cd = iconv_open("", "");
669               iconv(cd, NULL, NULL, NULL, NULL);
670               iconv_close(cd);
671             ],
672             [
673               echo "yes"
674               has_iconv=true 
675               AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
676             ],
677             [
678               has_iconv=false
679             ])
680          ])
681       fi
682     done
683 fi
684
685 if test x$has_iconv = xtrue; then
686   # (1) Some implementations of iconv won't convert from UTF-8 to UTF-8.
687   # (2) In glibc-2.1.2 and earlier there is a bug that messes up ob and
688   #     obl when args 2 and 3 are 0 (fixed in glibc-2.1.3).
689   #
690   AC_CACHE_CHECK([whether this iconv is good enough], ac_iconv_good,
691     AC_TRY_RUN(
692       [
693         #include <iconv.h>
694         int main() {
695           iconv_t cd;
696         changequote(, )dnl
697           char buf[4];
698         changequote([, ])dnl
699           char *ob;
700           size_t obl;
701           ob = buf, obl = sizeof(buf);
702           return ((cd = iconv_open("UTF-8", "UTF-8")) != (iconv_t)(-1) &&
703                  (iconv(cd, 0, 0, &ob, &obl) ||
704                  !(ob == buf && obl == sizeof(buf)) ||
705                  iconv_close(cd)));
706         }
707       ],
708       [
709         ac_iconv_good=yes
710       ],
711       [
712         ac_iconv_good=no
713       ],
714       [
715         ac_iconv_good=yes
716       ])
717     )
718
719   if test x$ac_iconv_good = xno; then
720     AC_MSG_ERROR(Try using libiconv instead.)
721   fi
722 fi
723
724 # POSIX threads support
725 #
726 has_threads=false
727 AC_MSG_CHECKING(whether to search for POSIX threads)
728 AC_ARG_WITH(pthreads,
729   [[  --with-pthreads[=DIR]   use POSIX threads [search in DIR/include and DIR/lib]]],
730   [ 
731     case "${withval}" in
732       no)
733         check_threads=false
734         ;;
735       *)
736         if test -d $withval/include; then
737           CPPFLAGS="$CPPFLAGS -I$withval/include"
738           CFLAGS="$CFLAGS -I$withval/include"
739         fi
740         if test -d $withval/lib; then
741           LDFLAGS="$LDFLAGS -L$withval/lib"
742         fi
743
744         check_threads=true
745         ;;
746     esac
747   ])
748
749 if test x$check_threads = xtrue; then
750   AC_MSG_RESULT(yes)
751   AC_CHECK_HEADERS(pthread.h,
752     [
753       SAVE_LIBS="$LIBS"
754       LIBS="$LIBS -lpthread"
755       AC_CHECK_LIB(pthread, pthread_attr_init, has_threads=true,
756         [
757           # FreeBSD
758           case "${target}" in
759             *-*-freebsd*)
760               LIBS="$SAVE_LIBS -pthread"
761               AC_CHECK_LIB(c_r, pthread_attr_init, has_threads=true)
762               ;;
763           esac
764         ])
765     ],
766     [
767       # search for pthread library..
768       SAVE_CPPFLAGS="$CPPFLAGS"
769       SAVE_CFLAGS="$CFLAGS"
770       SAVE_LDFLAGS="$LDFLAGS"
771
772       for dir in `echo "/usr/local /usr/pkg /usr/contrib /usr/pkg/pthreads /usr/local/pthreads"`; do
773         if test x$has_threads = xfalse; then
774           AC_MSG_RESULT(searching in $dir...)
775   
776           CPPFLAGS="$SAVE_CPPFLAGS"
777           CFLAGS="$SAVE_CFLAGS"
778           LDFLAGS="$SAVE_LDFLAGS"
779   
780           if test -d $dir/include; then
781             CPPFLAGS="$CPPFLAGS -I$dir/include"
782             CFLAGS="$CFLAGS -I$dir/include"
783           fi
784           if test -d $dir/lib; then
785             LDFLAGS="$LDFLAGS -L$dir/lib"
786           fi
787
788           # XXX
789           unset ac_cv_header__pthread_h_ ac_cv_header_pthread_h || true
790
791           AC_CHECK_HEADERS(pthread.h,
792             [ 
793               LIBS="$LIBS -lpthread"
794               AC_CHECK_LIB(pthread, pthread_attr_init, has_threads=true,
795                                                        has_threads=false)
796             ])
797         fi
798       done
799     ])
800 else
801   AC_MSG_RESULT(no)
802   has_threads=false
803 fi
804
805 AM_CONDITIONAL(SILC_THREADS, test x$has_threads = xtrue)
806 if test x$has_threads = xtrue; then
807   CFLAGS="$CFLAGS -D_REENTRANT"
808
809   # XXX possibly incomplete
810   case "${target}" in
811     *-*-aix*)
812       CFLAGS="$CFLAGS -D_THREAD_SAFE"
813       if test x"$GCC" = xyes; then
814         CFLAGS="$CFLAGS -mthreads"
815       fi
816       ;;
817     *-*-freebsd*)
818       CFLAGS="$CFLAGS -D_THREAD_SAFE"
819       ;;
820     *-*-sysv5uw7*)  # UnixWare 7
821       if test "$GCC" != "yes"; then
822         CFLAGS="$CFLAGS -Kthread"
823       else
824         CFLAGS="$CFLAGS -pthread"
825       fi
826       ;;
827     *-dg-dgux*)  # DG/UX
828       CFLAGS="$CFLAGS -D_POSIX4A_DRAFT10_SOURCE"
829       ;;
830    esac
831
832   AC_CHECK_FUNC(pthread_create)
833   AC_DEFINE(SILC_HAVE_PTHREAD)
834   AC_DEFINE(SILC_THREADS)
835 fi
836
837 # Native WIN32 compilation under cygwin
838 #
839 AC_MSG_CHECKING(whether to compile native WIN32 code)
840 AC_ARG_WITH(win32,
841   [  --with-win32            compile native WIN32 code (-mno-cygwin)],
842   [
843     AC_MSG_RESULT(yes)
844     AC_DEFINE(SILC_WIN32)
845     win32_support=true
846     CFLAGS="-mno-cygwin $CFLAGS"
847     LIBS="$LIBS -lwsock32"
848   ],
849   [
850     AC_MSG_RESULT(no)
851   ])
852 AM_CONDITIONAL(SILC_WIN32, test x$win32_support = xtrue)
853
854 # Native EPOC support (disabled by default)
855 #
856 AM_CONDITIONAL(SILC_EPOC, test xfalse = xtrue)
857
858 # Native BeOS support (disabled by default)
859 #
860 AM_CONDITIONAL(SILC_BEOS, test xfalse = xtrue)
861
862 # Native OS2 support (disabled by default)
863 #
864 AM_CONDITIONAL(SILC_OS2, test xfalse = xtrue)
865
866 # --without-irssi
867 #
868 without_irssi=false
869 AC_MSG_CHECKING(whether to compile Irssi SILC Client)
870 AC_ARG_WITH(irssi,
871   [  --without-irssi         compile without Irssi SILC Client],
872   [
873     AC_MSG_RESULT(no)
874     without_irssi=true
875     SILC_DIST_SUBDIRS=`echo $SILC_DIST_SUBDIRS | $sedpath -e 's/irssi//'`
876   ],
877   [
878     AC_MSG_RESULT(yes)
879   ])
880
881 # --without-silcd
882 #
883 without_silcd=false
884 AC_MSG_CHECKING(whether to compile SILC Server)
885 AC_ARG_WITH(silcd,
886   [  --without-silcd         compile without SILC Server],
887   [
888     AC_MSG_RESULT(no)
889     without_silcd=true
890     SILC_DIST_SUBDIRS=`echo $SILC_DIST_SUBDIRS | $sedpath -e 's/silcd//'`
891   ],
892   [
893     AC_MSG_RESULT(yes)
894   ])
895
896
897 ##
898 ##  Misc
899 ##
900
901 # Other configure scripts
902 #
903 if test x$without_irssi = xfalse; then
904   if test "x$silc_dist" = "xsilc-client" ||
905      test "x$silc_dist" = "xsilc-toolkit"; then
906     AC_CONFIG_SUBDIRS(irssi)
907   fi
908 fi
909
910 AC_CONFIG_SUBDIRS(lib/silcmath/mpi)
911 #AC_CONFIG_SUBDIRS(lib/zlib)
912
913 SILC_TOP_SRCDIR=`pwd`
914 AC_SUBST(SILC_TOP_SRCDIR)
915 #SILC_INSTALL_PREFIX=$ac_default_prefix
916 #AC_SUBST(SILC_INSTALL_PREFIX)
917 AC_SUBST(LIBS)
918 INCLUDE_DEFINES_INT="include \$(top_srcdir)/Makefile.defines_int"
919 AC_SUBST(INCLUDE_DEFINES_INT)
920 AC_SUBST(SILC_DIST_SUBDIRS)
921
922 # Makefile outputs
923 #
924 AC_CONFIG_FILES(
925 Makefile
926 Makefile.defines
927 Makefile.defines_int
928 doc/Makefile
929 includes/Makefile
930 lib/Makefile
931 lib/contrib/Makefile
932 lib/silccore/Makefile
933 lib/silccrypt/Makefile
934 lib/silcmath/Makefile
935 lib/silcmath/mpi/Makefile.defines
936 lib/silcmath/mpi/Makefile.defines_int
937 lib/silcsim/Makefile
938 lib/silcske/Makefile
939 lib/silcutil/Makefile
940 lib/silcutil/unix/Makefile
941 lib/silcutil/win32/Makefile
942 lib/silcutil/beos/Makefile
943 lib/silcutil/os2/Makefile
944 lib/silcutil/epoc/Makefile
945 lib/silcsftp/Makefile
946 lib/silcsftp/tests/Makefile
947 doc/example_silcd.conf
948 )
949
950 if test "x$silc_dist" = "xsilc-client" ||
951    test "x$silc_dist" = "xsilc-toolkit"; then
952   AC_CONFIG_FILES(lib/silcclient/Makefile)
953 fi
954
955 if test x$without_irssi = xfalse ; then
956   if test "x$silc_dist" = "xsilc-client" ||
957      test "x$silc_dist" = "xsilc-toolkit"; then
958     AC_CONFIG_FILES(
959 irssi/Makefile.defines
960 irssi/Makefile.defines_int
961 )
962   fi
963 fi
964
965 if test x$without_silcd = xfalse ; then
966   if test "x$silc_dist" = "xsilc-server" ||
967      test "x$silc_dist" = "xsilc-toolkit"; then
968     AC_CONFIG_FILES(
969 silcd/Makefile
970 )
971   fi
972 fi
973
974 if test "x$silc_dist" = "xsilc-toolkit"; then
975   AC_CONFIG_FILES(
976 silc/Makefile
977 win32/Makefile
978 win32/libsilc/Makefile
979 win32/libsilcclient/Makefile
980 )
981 fi
982
983 AC_OUTPUT