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