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