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