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