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