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