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