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