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