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