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