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