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