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