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