Changed the low level errno routines public.
[runtime.git] / configure.ad
1 #
2 #  configure.ad
3 #
4 #  Author: Pekka Riikonen <priikone@silcnet.org>
5 #
6 #  Copyright (C) 2000 - 2008 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(runtimedefs.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 AC_PROG_CC
33 AM_PROG_AS
34 AC_C_INLINE
35 AC_C_CONST
36
37 AC_PROG_RANLIB
38 #ifdef SILC_DIST_INPLACE
39 AC_DISABLE_SHARED
40 #endif SILC_DIST_INPLACE
41 AC_PROG_LIBTOOL
42
43 SILC_TOP_SRCDIR=`pwd`
44
45 ##
46 ## Library versioning.
47 ##
48
49 # Do the releases and library versioning according to following rules:
50 #
51 #  - If any code has changed in library, increment RUNTIME_REVISION
52 #  - If API were added, removed or changed, set RUNTIME_REVISION to 0
53 #  - If API were added, removed or changed, increment RUNTIME_CURRENT
54 #  - If APi were added, increment RUNTIME_AGE
55 #  - If API were removed, set RUNTIME_AGE to 0
56 #
57
58 # Base version for library.
59 RUNTIME_BASE_VERSION=1.2
60
61 # libsilc versions
62 RUNTIME_CURRENT=1               # prev = 0
63 RUNTIME_REVISION=0              # prev = 0
64 RUNTIME_AGE=0                   # prev = 0
65
66 # Substitute the version numbers
67 AC_SUBST(RUNTIME_BASE_VERSION)
68 AC_SUBST(RUNTIME_CURRENT)
69 AC_SUBST(RUNTIME_REVISION)
70 AC_SUBST(RUNTIME_AGE)
71
72
73 ##
74 ##  Installation
75 ##
76
77 # Default installation destination
78 AC_PREFIX_DEFAULT(/usr/local)
79 if test "x$prefix" != xNONE; then
80   silc_prefix="$prefix"
81 else
82   silc_prefix="$ac_default_prefix"
83   prefix="$silc_prefix"
84 fi
85
86
87 ##
88 ## Detect CPU
89 ##
90
91 # Disable all CPU feature optimizations
92 AC_MSG_CHECKING(whether to enable CPU feature optimizations)
93 AC_ARG_ENABLE(cpu-optimizations,
94   [  --disable-cpu-optimizations  do not use any CPU feature optimizations],
95   [
96     AC_MSG_RESULT(no)
97     AC_DEFINE([SILC_NO_CPU_OPTIMIZATIONS], [], [SILC_NO_CPU_OPTIMIZATIONS])
98     want_cpu_optimizations=false
99   ],
100   [
101     AC_MSG_RESULT(yes)
102     want_cpu_optimizations=true
103   ])
104 AM_CONDITIONAL(SILC_NO_CPU_OPTIMIZATIONS,
105                test x$want_cpu_optimizations = xfalse)
106
107 SILC_SYSTEM_IS_SMP(AC_DEFINE([SILC_SMP], [], [SILC_SMP]), [],
108                    AC_DEFINE([SILC_SMP], [], [SILC_SMP]))
109 cpu_i386=false
110 cpu_i486=false
111 cpu_i586=false
112 cpu_i686=false
113 cpu_i786=false
114 cpu_x86_64=false
115 cpu_ppc=false
116 cpu_ia64=false
117 case "$host_cpu" in
118   # All following Intels are considered 32-bit CPUs.
119   i?86)
120     # All CPUs of today are considered i386 and i486 compatible */
121     AC_DEFINE([SILC_I386], [], [SILC_I386])
122     AC_DEFINE([SILC_I486], [], [SILC_I486])
123     cpu_i386=true
124     cpu_i486=true
125
126     if test "x$host_cpu" = "xi586"; then
127       AC_DEFINE([SILC_I586], [], [SILC_I586])
128       cpu_i586=true
129     fi
130
131     if test "x$host_cpu" = "xi686"; then
132       AC_DEFINE([SILC_I586], [], [SILC_I586])
133       AC_DEFINE([SILC_I686], [], [SILC_I686])
134       cpu_i586=true
135       cpu_i686=true
136     fi
137
138     if test "x$host_cpu" = "xi786"; then
139       AC_DEFINE([SILC_I586], [], [SILC_I586])
140       AC_DEFINE([SILC_I686], [], [SILC_I686])
141       AC_DEFINE([SILC_I786], [], [SILC_I786])
142       cpu_i586=true
143       cpu_i686=true
144       cpu_i786=true
145     fi
146
147     # Check for specific CPU features
148     SILC_CPU_FLAG(mmx, true, AC_DEFINE([SILC_CPU_MMX], [], [SILC_CPU_MMX]), [])
149     SILC_CPU_FLAG(sse2, true, AC_DEFINE([SILC_CPU_SSE2], [], [SILC_CPU_SSE2]), [])
150     SILC_CPU_FLAG(pni, true, AC_DEFINE([SILC_CPU_SSE3], [], [SILC_CPU_SSE3]), [])
151     SILC_CPU_FLAG(ssse3, true, AC_DEFINE([SILC_CPU_SSSE3], [], [SILC_CPU_SSSE3]), [])
152     SILC_CPU_FLAG(sse4, true, AC_DEFINE([SILC_CPU_SSE4], [], [SILC_CPU_SSE4]), [])
153     ;;
154
155   # Intel IA-64, 64-bit CPU (not x86_64 compatible)
156   ia64)
157     AC_DEFINE([SILC_IA64], [], [SILC_IA64])
158     cpu_ia64=true
159
160     # Check for specific CPU features
161     SILC_CPU_FLAG(mmx, true, AC_DEFINE([SILC_CPU_MMX], [], [SILC_CPU_MMX]), [])
162     SILC_CPU_FLAG(sse2, true, AC_DEFINE([SILC_CPU_SSE2], [], [SILC_CPU_SSE2]), [])
163     SILC_CPU_FLAG(pni, true, AC_DEFINE([SILC_CPU_SSE3], [], [SILC_CPU_SSE3]), [])
164     SILC_CPU_FLAG(ssse3, true, AC_DEFINE([SILC_CPU_SSSE3], [], [SILC_CPU_SSSE3]), [])
165     SILC_CPU_FLAG(sse4, true, AC_DEFINE([SILC_CPU_SSE4], [], [SILC_CPU_SSE4]), [])
166     ;;
167
168   # AMD/Intel x86_64, 64-bit CPU
169   x86_64)
170     AC_DEFINE([SILC_X86_64], [], [SILC_X86_64])
171     cpu_x86_64=true
172
173     # Check for specific CPU features
174     SILC_CPU_FLAG(mmx, true, AC_DEFINE([SILC_CPU_MMX], [], [SILC_CPU_MMX]), [])
175     SILC_CPU_FLAG(sse2, true, AC_DEFINE([SILC_CPU_SSE2], [], [SILC_CPU_SSE2]), [])
176     SILC_CPU_FLAG(pni, true, AC_DEFINE([SILC_CPU_SSE3], [], [SILC_CPU_SSE3]), [])
177     SILC_CPU_FLAG(ssse3, true, AC_DEFINE([SILC_CPU_SSSE3], [], [SILC_CPU_SSSE3]), [])
178     SILC_CPU_FLAG(sse4, true, AC_DEFINE([SILC_CPU_SSE4], [], [SILC_CPU_SSE4]), [])
179     ;;
180
181   # PowerPC, 32-bit and 64-bit CPUs
182   powerpc*)
183     AC_DEFINE([SILC_POWERPC], [], [SILC_POWERPC])
184     cpu_ppc=true
185     ;;
186 esac
187 AM_CONDITIONAL(SILC_I386, test x$cpu_i386 = xtrue)
188 AM_CONDITIONAL(SILC_I486, test x$cpu_i486 = xtrue)
189 AM_CONDITIONAL(SILC_I586, test x$cpu_i586 = xtrue)
190 AM_CONDITIONAL(SILC_I686, test x$cpu_i686 = xtrue)
191 AM_CONDITIONAL(SILC_7686, test x$cpu_i786 = xtrue)
192 AM_CONDITIONAL(SILC_X86_64, test x$cpu_x86_64 = xtrue)
193 AM_CONDITIONAL(SILC_POWERPC, test x$cpu_ppc = xtrue)
194 AM_CONDITIONAL(SILC_IA64, test x$cpu_ia64 = xtrue)
195
196 if test x$want_cpu_optimizations = xtrue; then
197   # Set some compiler options based on CPU
198   if test "x$CC" = "xicc"; then
199     # ICC flags
200     if test x$x_have_cpu_sse2 = xtrue; then
201       SILC_ADD_CFLAGS(-axW)
202     fi
203     if test x$x_have_cpu_sse3 = xtrue; then
204       SILC_ADD_CFLAGS(-axP)
205     fi
206     if test x$x_have_cpu_ssse3 = xtrue; then
207       SILC_ADD_CFLAGS(-axT)
208     fi
209     if test x$x_have_cpu_sse4 = xtrue; then
210       SILC_ADD_CFLAGS(-axS)
211     fi
212   else
213     # Other compilers
214     if test x$x_have_cpu_sse2 = xtrue; then
215       SILC_ADD_CFLAGS(-msse2)
216     fi
217     if test x$x_have_cpu_pni = xtrue; then
218       SILC_ADD_CFLAGS(-msse3)
219     fi
220     if test x$x_have_cpu_ssse3 = xtrue; then
221       SILC_ADD_CFLAGS(-mssse3)
222     fi
223     if test x$x_have_cpu_sse4 = xtrue; then
224       SILC_ADD_CFLAGS(-msse4)
225     fi
226   fi
227 fi
228
229
230 ##
231 ## Put here any platform specific stuff
232 ##
233
234 case "$target" in
235   *-*-linux*)
236     check_threads=true
237     CFLAGS=`echo $CFLAGS -D_GNU_SOURCE`
238     ;;
239   *-*-freebsd*)
240     check_threads=true
241     ;;
242   *-*-netbsd*)
243     check_threads=true
244     ;;
245   *-*-*bsd*)
246     check_threads=false
247     ;;
248   *)
249     check_threads=true
250     ;;
251 esac
252
253
254 ##
255 ## Header checking
256 ##
257 AC_HEADER_STDC
258 AC_HEADER_TIME
259 AC_HEADER_STAT
260
261 # More header checking
262 #
263 AC_CHECK_HEADERS(unistd.h string.h errno.h fcntl.h assert.h execinfo.h)
264 AC_CHECK_HEADERS(sys/types.h sys/stat.h sys/time.h stddef.h)
265 AC_CHECK_HEADERS(netinet/in.h netinet/tcp.h xti.h netdb.h sys/resource.h)
266 AC_CHECK_HEADERS(pwd.h grp.h termcap.h paths.h)
267 AC_CHECK_HEADERS(ncurses.h signal.h ctype.h utime.h dirent.h)
268 AC_CHECK_HEADERS(arpa/inet.h sys/mman.h limits.h termios.h locale.h langinfo.h)
269
270
271 ##
272 ## Data type checking
273 ##
274 AC_TYPE_SIGNAL
275 AC_TYPE_SIZE_T
276 AC_TYPE_MODE_T
277 AC_TYPE_UID_T
278 AC_TYPE_PID_T
279 AC_CHECK_SIZEOF(long long, 0)
280 AC_SUBST(SILC_SIZEOF_LONG_LONG, $ac_cv_sizeof_long_long)
281 AC_CHECK_SIZEOF(long, 0)
282 AC_SUBST(SILC_SIZEOF_LONG, $ac_cv_sizeof_long)
283 AC_CHECK_SIZEOF(int, 0)
284 AC_SUBST(SILC_SIZEOF_INT, $ac_cv_sizeof_int)
285 AC_CHECK_SIZEOF(short, 0)
286 AC_SUBST(SILC_SIZEOF_SHORT, $ac_cv_sizeof_short)
287 AC_CHECK_SIZEOF(char, 0)
288 AC_SUBST(SILC_SIZEOF_CHAR, $ac_cv_sizeof_char)
289 AC_CHECK_SIZEOF(void *, 0)
290 AC_SUBST(SILC_SIZEOF_VOID_P, $ac_cv_sizeof_void_p)
291 AC_CHECK_TYPES(long long)
292 AC_CHECK_TYPES(long double)
293
294 # Check for big-endian machines
295 AC_C_BIGENDIAN
296
297
298 ##
299 ## Compiler and compiler flag checks
300 ##
301
302 # Disable all compiler optimizations
303 AC_MSG_CHECKING(whether to enable compiler optimizations)
304 AC_ARG_ENABLE(optimizations,
305   [  --disable-optimizations do not use any compiler optimizations],
306   [
307     AC_MSG_RESULT(no)
308     AC_DEFINE([SILC_NO_CC_OPTIMIZATIONS], [], [SILC_NO_CC_OPTIMIZATIONS])
309     want_cc_optimizations=false
310   ],
311   [
312     AC_MSG_RESULT(yes)
313     want_cc_optimizations=true
314   ])
315 AM_CONDITIONAL(SILC_NO_CC_OPTIMIZATIONS, test x$want_cc_optimizations = xfalse)
316
317 if test "$GCC"; then
318   # GCC specific options
319   if test "x$summary_debug" = "xyes"; then
320     SILC_ADD_CFLAGS(-g)
321   else
322     SILC_ADD_CFLAGS(-g)
323   fi
324   SILC_ADD_CFLAGS(-Wall -finline-functions)
325   SILC_ADD_CFLAGS(-Wno-pointer-sign)
326 else
327   # Other compilers
328   case "$target" in
329     alpha*-dec-osf*)
330       SILC_ADD_CFLAGS(-g3)
331       ;;
332     mips*-sgi-irix*)
333       SILC_ADD_CFLAGS(-g3)
334       ;;
335     *)
336       SILC_ADD_CFLAGS(-g)
337       ;;
338   esac
339
340   # Intel C++ Compiler flags
341   if test "x$CC" = "xicc"; then
342     SILC_ADD_CFLAGS(-restrict)
343     SILC_ADD_CFLAGS(-finline-functions)
344
345     # Don't define __GNUC__ except for system includes
346     SILC_ADD_CFLAGS(-gcc-sys)
347   fi
348 fi
349
350 if test x$want_cc_optimizations = xtrue; then
351   if test "$GCC"; then
352     # GCC specific options
353     if test "x$summary_debug" = "xyes"; then
354       SILC_ADD_CFLAGS(-O)
355     else
356       SILC_ADD_CFLAGS(-O2)
357     fi
358   else
359     # Other compilers
360     case "$target" in
361       alpha*-dec-osf*)
362         SILC_ADD_CFLAGS(-O2, SILC_ADD_CFLAGS(-O))
363         ;;
364       mips*-sgi-irix*)
365         SILC_ADD_CFLAGS(-O2, SILC_ADD_CFLAGS(-O))
366         ;;
367       *)
368         SILC_ADD_CFLAGS(-O2, SILC_ADD_CFLAGS(-O))
369         ;;
370     esac
371   fi
372 fi
373
374
375 ##
376 ## Function and libary checking
377 ##
378 AC_CHECK_FUNCS(gethostname gethostbyaddr getservbyname getservbyport)
379 AC_CHECK_FUNCS(poll select listen bind shutdown close connect setsockopt)
380 AC_CHECK_FUNCS(setrlimit time ctime utime gettimeofday getrusage)
381 AC_CHECK_FUNCS(chmod fcntl stat fstat getenv putenv strerror)
382 AC_CHECK_FUNCS(getpid getgid getsid getpgid getpgrp getuid sched_yield)
383 AC_CHECK_FUNCS(setgroups initgroups nl_langinfo nanosleep)
384 AC_CHECK_FUNCS(strchr snprintf strstr strcpy strncpy memcpy memset memmove)
385 AC_CHECK_FUNCS(setenv getenv putenv unsetenv clearenv backtrace)
386
387 # Check getopt_long
388 AC_CHECK_FUNC(getopt_long,
389   [
390     AC_DEFINE([HAVE_GETOPT_LONG], [], [HAVE_GETOPT_LONG])
391     have_getopt_long=1
392   ], have_getopt_long=0
393 )
394
395 # Check gethostbyname
396 AC_CHECK_FUNC(gethostbyname, [],
397   [
398     AC_CHECK_LIB(nsl, gethostbyname, LIBS="$LIBS -lnsl")
399     AC_CHECK_FUNC(res_gethostbyname, [],
400        AC_CHECK_LIB(resolv, res_gethostbyname, LIBS="$LIBS -lresolv")
401     )
402   ])
403
404 # Check socket
405 AC_CHECK_FUNC(socket, [],
406   AC_CHECK_LIB(socket, socket, LIBS="$LIBS -lsocket")
407 )
408
409 # Check clock_gettime
410 AC_CHECK_FUNC(clock_gettime, [],
411   [
412     AC_CHECK_LIB(rt, clock_gettime,
413                  [ LIBS="$LIBS -lrt"
414                    AC_DEFINE([HAVE_CLOCK_GETTIME], [], [HAVE_CLOCK_GETTIME])])
415   ])
416
417 # Check for epoll_wait and verify that epoll_create works
418 AC_CHECK_FUNC(epoll_wait,
419   [
420     AC_RUN_IFELSE(
421       [
422         #include <sys/epoll.h>
423         int main()
424         {
425           int ret = epoll_create(5);
426           if (ret < 0)
427             return 1;
428           close(ret);
429           return 0;
430         }
431       ],
432       [
433         AC_DEFINE([HAVE_EPOLL_WAIT], [1], [HAVE_EPOLL_WAIT])
434       ],
435     )
436   ])
437
438 # Check for va_copy
439 va_copy=false
440 AC_MSG_CHECKING(for va_copy)
441 AC_TRY_COMPILE(
442   [
443     #include <stdarg.h>
444     #include <stdlib.h>
445   ],
446   [
447     int t(int x, ...)
448     {
449       va_list va, cp;
450       va_start(va, x);
451       va_copy(cp, va);
452       if (va_arg(cp, int) != 0xff11)
453         return 1;
454       va_end(va);
455       va_end(cp);
456       return 0;
457     }
458     int main()
459     {
460       return t(0, 0xff11);
461     }
462   ],
463   [
464     AC_DEFINE([HAVE_VA_COPY], [], [HAVE_VA_COPY])
465     AC_MSG_RESULT(yes)
466     va_copy=true
467   ],
468   [
469     AC_MSG_RESULT(no)
470     va_copy=false
471   ]
472 )
473
474 if test x$va_copy = xfalse; then
475   AC_MSG_CHECKING(for __va_copy)
476   AC_TRY_COMPILE(
477   [
478     #include <stdarg.h>
479     #include <stdlib.h>
480   ],
481   [
482     int t(int x, ...)
483     {
484       va_list va, cp;
485       va_start(va, x);
486       __va_copy(cp, va);
487       if (va_arg(cp, int) != 0xff11)
488         return 1;
489       va_end(va);
490       va_end(cp);
491       return 0;
492     }
493     int main()
494     {
495       return t(0, 0xff11);
496     }
497   ],
498   [
499     AC_DEFINE([HAVE___VA_COPY], [], [HAVE___VA_COPY])
500     AC_MSG_RESULT(yes)
501     va_copy=true
502   ],
503   [
504     AC_MSG_RESULT(no)
505     va_copy=false
506   ]
507   )
508 fi
509
510 if test x$va_copy = xfalse; then
511   AC_RUN_IFELSE(
512     [
513       #include <stdarg.h>
514       #include <stdlib.h>
515       int t(int x, ...)
516       {
517         va_list va, cp;
518         va_start(va, x);
519         cp = va;
520         if (va_arg(cp, int) != 0xff11)
521           return 1;
522         va_end(va);
523         va_end(cp);
524         return 0;
525       }
526       int main()
527       {
528         return t(0, 0xff11);
529       }
530     ],
531     [va_copy=false],
532     [
533       AC_DEFINE([SILC_VA_COPY_ARRAY], [], [SILC_VA_COPY_ARRAY])
534     ],
535     [va=copy=false]
536   )
537 fi
538
539 # Check for timezone and tm_gmtoff for timezone information
540 AC_MSG_CHECKING(whether system has timezone)
541 AC_RUN_IFELSE(
542   [
543     #include <stdio.h>
544     #include <time.h>
545     int main()
546     {
547       timezone = 0;
548       return 0;
549     }
550   ],
551   [ AC_MSG_RESULT(yes)
552     AC_DEFINE([HAVE_TIMEZONE], [], [HAVE_TIMEZONE]) ],
553   [ AC_MSG_RESULT(no) ],
554   [ AC_MSG_RESULT(no) ]
555 )
556 AC_MSG_CHECKING(whether system has tm_gmtoff)
557 AC_RUN_IFELSE(
558   [
559     #include <stdio.h>
560     #include <time.h>
561     int main()
562     {
563       struct tm tm;
564       tm.tm_gmtoff = 0;
565       return 0;
566     }
567   ],
568   [ AC_MSG_RESULT(yes)
569     AC_DEFINE([HAVE_TM_GMTOFF], [], [HAVE_TM_GMTOFF]) ],
570   [ AC_MSG_RESULT(no) ],
571   [ AC_MSG_RESULT(no) ]
572 )
573 AC_MSG_CHECKING(whether system has __tm_gmtoff)
574 AC_RUN_IFELSE(
575   [
576     #include <stdio.h>
577     #include <time.h>
578     int main()
579     {
580       struct tm tm;
581       tm.__tm_gmtoff = 0;
582       return 0;
583     }
584   ],
585   [ AC_MSG_RESULT(yes)
586     AC_DEFINE([HAVE___TM_GMTOFF], [], [HAVE___TM_GMTOFF]) ],
587   [ AC_MSG_RESULT(no) ],
588   [ AC_MSG_RESULT(no) ]
589 )
590 AC_MSG_CHECKING(whether system has __tm_gmtoff__)
591 AC_RUN_IFELSE(
592   [
593     #include <stdio.h>
594     #include <time.h>
595     int main()
596     {
597       struct tm tm;
598       tm.__tm_gmtoff__ = 0;
599       return 0;
600     }
601   ],
602   [ AC_MSG_RESULT(yes)
603     AC_DEFINE([HAVE___TM_GMTOFF__], [], [HAVE___TM_GMTOFF__]) ],
604   [ AC_MSG_RESULT(no) ],
605   [ AC_MSG_RESULT(no) ]
606 )
607
608 # Check for dlopen() and friends
609 AC_CHECK_HEADERS(dlfcn.h,
610   [
611     AC_CHECK_LIB(dl, dlopen,
612       [
613         AC_DEFINE([HAVE_DLOPEN], [], [HAVE_DLOPEN])
614         LIBS="$LIBS -ldl"
615       ],
616       [
617         AC_CHECK_LIB(c, dlopen,
618           [
619             AC_DEFINE([HAVE_DLOPEN], [], [HAVE_DLOPEN])
620           ])
621       ])
622   ])
623
624 __SILC_ENABLE_DEBUG=""
625
626 runtimever=`echo $VERSION | sed 's/\./ /g'`
627 maj=0
628 min=0
629 bld=0
630 for v in $runtimever
631 do
632   if test $maj -eq 0; then
633     maj=$v
634     continue
635   fi
636   if test $min -eq 0; then
637     min=$v
638     continue
639   fi
640   if test $bld -eq 0; then
641     bld=$v
642     continue
643   fi
644 done
645 __RUNTIME_PACKAGE_VERSION="#define __SILC_RUNTIME_VERSION SILC_VERSION($maj,$min,$bld)"
646
647
648 ##
649 ##  Enable/disable checking
650 ##
651
652 # IPv6 support
653 AC_MSG_CHECKING(whether to enable IPv6 support)
654 AC_ARG_ENABLE(ipv6,
655   [  --enable-ipv6           enable IPv6 support],
656   [
657     case "${enableval}" in
658       yes)
659         want_ipv6=true
660         check_ipv6=false
661         summary_ipv6="yes"
662         AC_DEFINE([HAVE_IPV6], [], [HAVE_IPV6])
663         AC_MSG_RESULT(yes)
664         ;;
665       *)
666         want_ipv6=false
667         check_ipv6=false
668         summary_ipv6="no"
669         AC_MSG_RESULT(no)
670         ;;
671     esac
672   ],
673     check_ipv6=true
674   )
675
676 if test x$check_ipv6 = xtrue; then
677   summary_ipv6="no"
678   AC_TRY_COMPILE(
679     [
680       #ifdef HAVE_SYS_TYPES_H
681       #include <sys/types.h>
682       #endif
683       #ifdef HAVE_NETINET_TCP_H
684       #include <netinet/tcp.h>
685       #endif
686       #ifdef HAVE_NETDB_H
687       #include <netdb.h>
688       #endif
689       #include <sys/socket.h>
690       #ifdef HAVE_NETINET_IN_H
691       #include <netinet/in.h>
692       #endif
693     ],
694     [
695       struct sockaddr_in6 sin6;
696       int family = AF_INET6;
697     ],
698     [
699       AC_DEFINE([HAVE_IPV6], [], [HAVE_IPV6])
700       AC_MSG_RESULT(yes)
701       summary_ipv6="yes"
702     ],
703       AC_MSG_RESULT(no)
704     )
705 fi
706
707 # Memory alignment.  User can specify what alignment memory allocation and
708 # SilcStack allocation use.  Default is system default alignemnt.
709 AC_ARG_WITH(alignment,
710   [  --with-alignment=NUMBER Memory alignment in bytes],
711   [
712     AC_DEFINE_UNQUOTED([SILC_ALIGNMENT], [$withval], [SILC_ALIGNMENT])
713     AC_MSG_RESULT(Memory allocation alignment is $withval bytes)
714   ],
715   [
716     AC_DEFINE([SILC_ALIGNMENT], SILC_SIZEOF_VOID_P, [SILC_ALIGNMENT])
717   ])
718
719 # Stack trace checking
720 AC_MSG_CHECKING(whether to enable stack tracing)
721 AC_ARG_ENABLE(stack-trace,
722   [  --enable-stack-trace    enable memory stack trace],
723   [
724     case "${enableval}" in
725     yes)
726       AC_MSG_RESULT(yes)
727       AC_DEFINE([SILC_STACKTRACE], [], [SILC_STACKTRACE])
728       CFLAGS="$CFLAGS -rdynamic"
729       ;;
730     *)
731       AC_MSG_RESULT(no)
732       ;;
733     esac
734   ],
735     AC_MSG_RESULT(no)
736   )
737
738 #ifdef SILC_DIST_INPLACE
739 #
740 # Profiling options (never delivered to distributions)
741 #
742 AC_MSG_CHECKING(whether to enable gprof)
743 AC_ARG_ENABLE(gprof,
744   [  --enable-gprof          enable gprof profiling],
745   [
746     case "${enableval}" in
747       yes)
748         AC_MSG_RESULT(yes)
749         SILC_ADD_CFLAGS(-pg)
750         LIBS="$LIBS -pg"
751         ;;
752       *)
753         AC_MSG_RESULT(no)
754         ;;
755     esac
756   ],
757   [
758     AC_MSG_RESULT(no)
759   ])
760
761 AC_MSG_CHECKING(whether to enable gcov)
762 AC_ARG_ENABLE(gcov,
763   [  --enable-gcov           enable gcov],
764   [
765     case "${enableval}" in
766       yes)
767         AC_MSG_RESULT(yes)
768         SILC_ADD_CFLAGS(-fprofile-arcs)
769         LIBS="$LIBS -lgcov"
770         ;;
771       *)
772         AC_MSG_RESULT(no)
773         ;;
774     esac
775   ],
776   [
777     AC_MSG_RESULT(no)
778   ])
779 #endif SILC_DIST_INPLACE
780
781 # Debug checking
782 AC_MSG_CHECKING(whether to enable debugging)
783 summary_debug="no"
784 __SILC_ENABLE_DEBUG=""
785 AC_ARG_ENABLE(debug,
786   [  --enable-debug          enable debugging],
787   [
788     case "${enableval}" in
789       yes)
790         AC_MSG_RESULT(yes)
791         AC_DEFINE([SILC_DEBUG], [], [enable-debug])
792         summary_debug="yes"
793         __SILC_ENABLE_DEBUG="#define __SILC_ENABLE_DEBUG 1"
794         ;;
795       *)
796         AC_MSG_RESULT(no)
797         ;;
798     esac
799   ],
800   [
801     AC_MSG_RESULT(no)
802   ])
803
804 # Disable all assembler optimizations
805 AC_MSG_CHECKING(whether to enable assembler optimizations)
806 AC_ARG_ENABLE(asm,
807   [  --disable-asm           do not use assembler optimizations],
808   [
809     AC_MSG_RESULT(no)
810     AC_DEFINE([SILC_NO_ASM], [], [SILC_NO_ASM])
811     want_asm=false
812   ],
813   [
814     AC_MSG_RESULT(yes)
815     want_asm=true
816   ])
817 AM_CONDITIONAL(SILC_NO_ASM, test x$want_asm = xfalse)
818
819 # Check for assembler
820 SILC_ASSEMBLER=""
821 have_assembler=false
822 if test x$want_asm = xtrue; then
823   AC_PATH_PROG([NASM], [nasm], [no])
824   if test "x$NASM" != "xno"; then
825     if test x$cpu_x86_64 = xtrue; then
826       SILC_ASSEMBLER="$NASM -O2 -felf64"
827     else
828       SILC_ASSEMBLER="$NASM -O2 -felf"
829     fi
830     have_assembler=true
831   fi
832
833   AC_PATH_PROG([YASM], [yasm], [no])
834   if test "x$YASM" != "xno"; then
835     if test x$cpu_x86_64 = xtrue; then
836       SILC_ASSEMBLER="$YASM -Xgnu -felf64"
837     else
838       SILC_ASSEMBLER="$YASM -Xgnu -felf"
839     fi
840     have_assembler=true
841   fi
842 fi
843 AC_SUBST(SILC_ASSEMBLER)
844
845
846 ##
847 ##  With/without checkings
848 ##
849
850 LIBSUBDIR=lib
851 LDFLAGS="-L\$(silc_top_srcdir)/lib $LDFLAGS"
852
853 SILC_LIB_INCLUDES="$SILC_LIB_INCLUDES -I$SILC_TOP_SRCDIR/lib/contrib"
854 SILC_LIB_INCLUDES="$SILC_LIB_INCLUDES -I$SILC_TOP_SRCDIR/lib/silcutil"
855
856
857 # Check for iconv support
858 check_iconv=true
859 has_iconv=false
860 SAVE_LIBS="$LIBS"
861 SAVE_CFLAGS="$CFLAGS"
862 SAVE_LDFLAGS="$LDFLAGS"
863 SAVE_CPPFLAGS="$CPPFLAGS"
864 AC_MSG_CHECKING(whether to implicit search for libiconv)
865 AC_ARG_WITH(iconv,
866   [[  --with-iconv[=DIR]      use libiconv [search in DIR/include and DIR/lib]]],
867   [
868     case "${withval}" in
869       no)
870         AC_MSG_RESULT(no)
871         AC_CHECK_HEADERS(iconv.h,
872           [
873             AC_CHECK_FUNC(iconv, has_iconv=true)
874           ])
875         check_iconv=false
876         ;;
877       *)
878         AC_MSG_RESULT(yes)
879         if test -d $withval/include; then
880           CPPFLAGS="$CPPFLAGS -I$withval/include"
881           CFLAGS="$CFLAGS -I$withval/include"
882         fi
883         if test -d $withval/lib; then
884           LDFLAGS="$LDFLAGS -L$withval/lib"
885         fi
886         ;;
887     esac
888   ],
889   [
890     AC_MSG_RESULT(no)
891     AC_CHECK_HEADERS(iconv.h,
892       [
893         AC_CHECK_FUNCS(iconv,
894           [
895             has_iconv=true
896             check_iconv=false
897           ])
898       ])
899   ])
900
901 if test x$check_iconv = xtrue; then
902   AC_MSG_RESULT(Searching for iconv...)
903
904   # XXX
905   unset ac_cv_header__iconv_h_ ac_cv_header_iconv_h || true
906
907   AC_CHECK_HEADERS(iconv.h,
908     [
909       LIBS="$LIBS -liconv"
910       AC_MSG_CHECKING(for iconv in -liconv)
911       AC_TRY_LINK(
912         [
913           #include <stdlib.h>
914           #include <iconv.h>
915         ],
916         [
917           iconv_t cd = iconv_open("", "");
918           iconv(cd, NULL, NULL, NULL, NULL);
919           iconv_close(cd);
920         ],
921         [
922           echo "yes"
923           AC_DEFINE([HAVE_ICONV], [], [Define if you have the iconv() function.])
924           has_iconv=true
925           check_iconv=false
926         ],
927         [
928           echo "no"
929           LIBS="$SAVE_LIBS"
930           CFLAGS="$SAVE_CFLAGS"
931           LDFLAGS="$SAVE_LDFLAGS"
932           CPPFLAGS="$SAVE_CPPFLAGS"
933         ])
934      ])
935 fi
936
937 if test x$check_iconv = xtrue; then
938   # search for iconv library..
939   SAVE_LIBS="$LIBS"
940   SAVE_CFLAGS="$CFLAGS"
941   SAVE_LDFLAGS="$LDFLAGS"
942   SAVE_CPPFLAGS="$CPPFLAGS"
943
944   for dir in `echo "/usr/local /usr/pkg /usr/contrib"`; do
945     if test x$has_iconv = xfalse; then
946       AC_MSG_RESULT(searching in $dir...)
947
948       if test -d $dir/include; then
949         CPPFLAGS="$CPPFLAGS -I$dir/include"
950         CFLAGS="$CFLAGS -I$dir/include"
951       fi
952       if test -d $dir/lib; then
953         LDFLAGS="$LDFLAGS -L$dir/lib"
954       fi
955
956       # XXX
957       unset ac_cv_header__iconv_h_ ac_cv_header_iconv_h || true
958
959       AC_CHECK_HEADERS(iconv.h,
960         [
961           LIBS="$LIBS -liconv"
962           AC_MSG_CHECKING(for iconv in -liconv)
963           AC_TRY_LINK(
964             [
965               #include <stdlib.h>
966               #include <iconv.h>
967             ],
968             [
969               iconv_t cd = iconv_open("", "");
970               iconv(cd, NULL, NULL, NULL, NULL);
971               iconv_close(cd);
972             ],
973             [
974               echo "yes"
975               has_iconv=true
976               AC_DEFINE([HAVE_ICONV], [], [Define if you have the iconv() function.])
977             ],
978             [
979               echo "no"
980               has_iconv=false
981
982               LIBS="$SAVE_LIBS"
983               CFLAGS="$SAVE_CFLAGS"
984               LDFLAGS="$SAVE_LDFLAGS"
985               CPPFLAGS="$SAVE_CPPFLAGS"
986             ])
987          ],
988          [
989            CFLAGS="$SAVE_CFLAGS"
990            LDFLAGS="$SAVE_LDFLAGS"
991            CPPFLAGS="$SAVE_CPPFLAGS"
992          ])
993       fi
994     done
995 fi
996
997 if test x$has_iconv = xtrue; then
998   # (1) Some implementations of iconv won't convert from UTF-8 to UTF-8.
999   # (2) In glibc-2.1.2 and earlier there is a bug that messes up ob and
1000   #     obl when args 2 and 3 are 0 (fixed in glibc-2.1.3).
1001   #
1002   AC_CACHE_CHECK([whether this iconv is good enough], ac_iconv_good,
1003     AC_TRY_RUN(
1004       [
1005         #include <iconv.h>
1006         int main() {
1007           iconv_t cd;
1008         changequote(, )dnl
1009           char buf[4];
1010         changequote([, ])dnl
1011           char *ob;
1012           size_t obl;
1013           ob = buf, obl = sizeof(buf);
1014           return ((cd = iconv_open("UTF-8", "UTF-8")) != (iconv_t)(-1) &&
1015                  (iconv(cd, 0, 0, &ob, &obl) ||
1016                  !(ob == buf && obl == sizeof(buf)) ||
1017                  iconv_close(cd)));
1018         }
1019       ],
1020       [
1021         ac_iconv_good=yes
1022       ],
1023       [
1024         ac_iconv_good=no
1025       ],
1026       [
1027         ac_iconv_good=yes
1028       ])
1029     )
1030
1031   if test x$ac_iconv_good = xno; then
1032     AC_MSG_RESULT(Try using libiconv instead.)
1033   fi
1034 fi
1035
1036 # Check for POSIX threads support
1037 AC_MSG_CHECKING(whether to search for POSIX threads)
1038 AC_ARG_WITH(pthreads,
1039   [[  --with-pthreads[=DIR]   use POSIX threads [search in DIR/include and DIR/lib]]],
1040   [
1041     case "${withval}" in
1042       no)
1043         check_threads=false
1044         ;;
1045       *)
1046         if test -d $withval/include; then
1047           CPPFLAGS="$CPPFLAGS -I$withval/include"
1048           CFLAGS="$CFLAGS -I$withval/include"
1049         fi
1050         if test -d $withval/lib; then
1051           LDFLAGS="$LDFLAGS -L$withval/lib"
1052         fi
1053
1054         check_threads=true
1055         ;;
1056     esac
1057   ])
1058
1059 if test x$check_threads = xtrue; then
1060   has_threads=false
1061   SAVE_LIBS="$LIBS"
1062   SAVE_CFLAGS="$CFLAGS"
1063   SAVE_LDFLAGS="$LDFLAGS"
1064   SAVE_CPPFLAGS="$CPPFLAGS"
1065
1066   AC_MSG_RESULT(yes)
1067   AC_CHECK_HEADERS(pthread.h,
1068     [
1069       LIBS="$LIBS -lpthread"
1070       AC_CHECK_LIB(pthread, pthread_attr_init, has_threads=true,
1071         [
1072           # FreeBSD
1073           case "${target}" in
1074             *-*-freebsd*)
1075               LIBS="$SAVE_LIBS -pthread"
1076               AC_CHECK_LIB(c_r, pthread_attr_init, has_threads=true, LIBS="$SAVE_LIBS")
1077               ;;
1078             *)
1079               LIBS="$SAVE_LIBS"
1080               ;;
1081           esac
1082         ])
1083     ],
1084     [
1085       # search for pthread library..
1086       for dir in `echo "/usr/local /usr/pkg /usr/contrib /usr/pkg/pthreads /usr/local/pthreads"`; do
1087         if test x$has_threads = xfalse; then
1088           AC_MSG_RESULT(searching in $dir...)
1089
1090           if test -d $dir/include; then
1091             CPPFLAGS="$CPPFLAGS -I$dir/include"
1092             CFLAGS="$CFLAGS -I$dir/include"
1093           fi
1094           if test -d $dir/lib; then
1095             LDFLAGS="$LDFLAGS -L$dir/lib"
1096           fi
1097
1098           # XXX
1099           unset ac_cv_header__pthread_h_ ac_cv_header_pthread_h || true
1100
1101           AC_CHECK_HEADERS(pthread.h,
1102             [
1103               LIBS="$LIBS -lpthread"
1104               AC_CHECK_LIB(pthread, pthread_attr_init, has_threads=true,
1105                 [
1106                   has_threads=false
1107
1108                   LIBS="$SAVE_LIBS"
1109                   CFLAGS="$SAVE_CFLAGS"
1110                   LDFLAGS="$SAVE_LDFLAGS"
1111                   CPPFLAGS="$SAVE_CPPFLAGS"
1112                 ])
1113             ],
1114             [
1115               CFLAGS="$SAVE_CFLAGS"
1116               LDFLAGS="$SAVE_LDFLAGS"
1117               CPPFLAGS="$SAVE_CPPFLAGS"
1118             ])
1119         fi
1120       done
1121     ])
1122 else
1123   AC_MSG_RESULT(no)
1124   has_threads=false
1125 fi
1126
1127 __SILC_HAVE_PTHREAD=""
1128 AM_CONDITIONAL(SILC_THREADS, test x$has_threads = xtrue)
1129 if test x$has_threads = xtrue; then
1130   CFLAGS="$CFLAGS -D_REENTRANT"
1131
1132   # XXX possibly incomplete
1133   case "${target}" in
1134     *-*-aix*)
1135       CFLAGS="$CFLAGS -D_THREAD_SAFE"
1136       if test x"$GCC" = xyes; then
1137         CFLAGS="$CFLAGS -mthreads"
1138       fi
1139       ;;
1140     *-*-freebsd*)
1141       CFLAGS="$CFLAGS -D_THREAD_SAFE"
1142       ;;
1143     *-*-sysv5uw7*)  # UnixWare 7
1144       if test "$GCC" != "yes"; then
1145         CFLAGS="$CFLAGS -Kthread"
1146       else
1147         CFLAGS="$CFLAGS -pthread"
1148       fi
1149       ;;
1150     *-dg-dgux*)  # DG/UX
1151       CFLAGS="$CFLAGS -D_POSIX4A_DRAFT10_SOURCE"
1152       ;;
1153    esac
1154
1155   # Check for threads
1156   AC_CHECK_FUNCS(pthread_create pthread_key_create pthread_once)
1157
1158   # Check for read/write locks
1159   AC_CHECK_FUNC(pthread_rwlock_init,
1160   [
1161     AC_RUN_IFELSE(
1162       [
1163         #include <pthread.h>
1164         int main()
1165         {
1166           pthread_rwlock_t rwlock;
1167           pthread_rwlock_init(&rwlock, NULL);
1168           pthread_rwlock_destroy(&rwlock);
1169           return 0;
1170         }
1171       ],
1172       [],
1173       [
1174         # Rwlock not defined
1175         CFLAGS="$CFLAGS -D_XOPEN_SOURCE=600"
1176       ]
1177     )
1178   ],
1179   [
1180     # Rwlock not defined
1181     CFLAGS="$CFLAGS -D_XOPEN_SOURCE=600"
1182   ])
1183
1184   AC_DEFINE([SILC_HAVE_PTHREAD], [], [HAVE_PTHREAD])
1185   AC_DEFINE([SILC_THREADS], [], [HAVE_THREAD])
1186   __SILC_HAVE_PTHREAD="#define __SILC_HAVE_PTHREAD 1"
1187 fi
1188
1189
1190 ##
1191 ## Native WIN32 compilation under cygwin
1192 ##
1193 AC_MSG_CHECKING(whether to compile native WIN32 code)
1194 AC_ARG_WITH(win32,
1195   [  --with-win32            compile native WIN32 (MinGW) code (-mno-cygwin)],
1196   [
1197     AC_MSG_RESULT(yes)
1198     AC_DEFINE([SILC_WIN32], [], [SILC_WIN32])
1199     win32_support=true
1200     CFLAGS="-mno-cygwin $CFLAGS"
1201     LIBS="$LIBS -lwsock32"
1202   ],
1203   [
1204     AC_MSG_RESULT(no)
1205     win32_support=false
1206   ])
1207 AM_CONDITIONAL(SILC_WIN32, test x$win32_support = xtrue)
1208
1209
1210 ##
1211 ## Outputs and substitutions
1212 ##
1213
1214 AC_SUBST(LIBSUBDIR)
1215 AC_SUBST(SILC_TOP_SRCDIR)
1216 AC_SUBST(LDFLAGS)
1217 AC_SUBST(LIBS)
1218 AC_SUBST(SILC_LIB_INCLUDES)
1219 AC_SUBST(__SILC_ENABLE_DEBUG)
1220 AC_SUBST(__SILC_HAVE_PTHREAD)
1221 AC_SUBST(__RUNTIME_PACKAGE_VERSION)
1222
1223 # Native Symbian OS support (disabled by default)
1224 AM_CONDITIONAL(SILC_SYMBIAN, test xfalse = xtrue)
1225
1226 # Make enable-shared aware
1227 AM_CONDITIONAL(SILC_ENABLE_SHARED, test "$enable_shared" = yes)
1228
1229 ETCDIR=`eval echo $sysconfdir`;ETCDIR=`eval echo $ETCDIR`
1230 AC_SUBST(ETCDIR)
1231 AC_DEFINE_UNQUOTED([SILC_ETCDIR], "$ETCDIR", [SILC_ETCDIR])
1232
1233 DOCDIR=`eval echo $docdir`;DOCDIR=`eval echo $DOCDIR`
1234 AC_SUBST(DOCDIR)
1235 AC_DEFINE_UNQUOTED([SILC_DOCDIR], "$DOCDIR", [SILC_DOCDIR])
1236
1237 INCLUDE_DEFINES_INT="include \$(top_srcdir)/Makefile.defines_int"
1238 AC_SUBST(INCLUDE_DEFINES_INT)
1239
1240 DATE=`date`
1241 AC_SUBST(DATE)
1242
1243
1244 #
1245 # Makefile outputs
1246 #
1247 AC_CONFIG_FILES(
1248 Makefile
1249 doc/Makefile
1250 doc/runtime.in/index.html
1251 Makefile.defines
1252 Makefile.defines_int
1253 includes/Makefile
1254 apps/Makefile
1255 win32/Makefile
1256 )
1257
1258 AC_CONFIG_FILES(
1259 lib/Makefile
1260 lib/contrib/Makefile
1261 lib/silcutil/silcruntime.h
1262 lib/silcutil/Makefile
1263 lib/silcutil/tests/Makefile
1264 lib/silcutil/unix/Makefile
1265 lib/silcutil/win32/Makefile
1266 lib/silcutil/symbian/Makefile
1267 lib/srt.pc
1268 )
1269
1270 AC_OUTPUT
1271
1272
1273 ##
1274 ## Summary output
1275 ##
1276
1277 s_bindir=`eval echo $bindir`;s_bindir=`eval echo $s_bindir`
1278 s_sbindir=`eval echo $sbindir`;s_sbindir=`eval echo $s_sbindir`
1279 s_mandir=`eval echo $mandir`;s_mandir=`eval echo $s_mandir`
1280 s_includedir=`eval echo $includedir`;s_includedir=`eval echo $s_includedir`
1281
1282 echo ""
1283 echo "SILC Runtime Toolkit configuration summary:"
1284 echo "------------------------------------------"
1285 echo " Target host ...................: $target"
1286 echo " Compiler ......................: $CC"
1287 echo " CFLAGS ........................: $CFLAGS"
1288 echo " LDFLAGS .......................: $LDFLAGS"
1289 echo " LIBS ..........................: $LIBS"
1290 echo ""
1291 echo " Installation prefix ...........: $prefix"
1292 echo " bin directory .................: $s_bindir"
1293 echo " sbin directory ................: $s_sbindir"
1294 echo " etc directory .................: $ETCDIR"
1295 echo " man directory .................: $s_mandir"
1296 echo " doc directory .................: $DOCDIR"
1297 echo " include directory .............: $s_includedir"
1298 echo ""
1299 echo " IPv6 support ..................: $summary_ipv6"
1300
1301 if test x$has_iconv = xfalse; then
1302   iconv_support="no"
1303 else
1304   iconv_support="yes"
1305 fi
1306 echo " Iconv support .................: $iconv_support"
1307
1308 if test x$want_asm = xfalse; then
1309   summary_asm="no"
1310 else
1311   summary_asm="yes"
1312 fi
1313 echo " Assembler optimizations .......: $summary_asm"
1314
1315 if test x$want_cc_optimizations = xfalse; then
1316   summary_cc_opt="no"
1317 else
1318   summary_cc_opt="yes"
1319 fi
1320 echo " Compiler optimizations ........: $summary_cc_opt"
1321
1322 if test x$want_cpu_optimizations = xfalse; then
1323   summary_cpu_opt="no"
1324 else
1325   summary_cpu_opt="yes"
1326 fi
1327 echo " CPU feature optimizations .....: $summary_cpu_opt"
1328
1329 threads="no"
1330 if test x$has_threads = xtrue; then
1331   threads="yes"
1332 fi
1333 echo " Multi-threads support .........: $threads"
1334 echo " Debugging enabled .............: $summary_debug"
1335 echo ""
1336 echo "Compile the sources with 'make' or 'gmake' command."