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