do environment variables saving/restoring for --with-pthreads too
[silc.git] / configure.in.pre
1 #
2 #  configure.in.pre
3 #
4 #  Author: Pekka Riikonen <priikone@silcnet.org>
5 #
6 #  Copyright (C) 2000 - 2002 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 AC_PROG_CC
43 AC_C_INLINE
44 AC_C_CONST
45
46 AC_PROG_LN_S
47 AC_SUBST(LN_S)
48
49 # Distribution definition. ./prepare will automatically add here a correct
50 # value. Do not edit!
51 #
52 silc_dist=SILC_PACKAGE
53 SILC_DIST_SUBDIRS="SILC_DISTRIBUTION_SUBDIRS"
54 AC_DEFINE(SILC_DIST_DEFINE)
55
56 # XXX
57 # Compiler flags
58 #
59 if test "$GCC"; then
60   CFLAGS="-Wall -finline-functions $CFLAGS"
61 fi
62
63 # Program checking
64 #
65 AC_PROG_INSTALL
66 AC_PROG_RANLIB
67 AC_PROG_MAKE_SET
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)
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)
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   AC_CHECK_LIB(dl, dlopen,
136     [
137       AC_DEFINE(SILC_SIM)
138       sim_support=true
139       LIBS="$LIBS -ldl"
140     ],
141     [
142       AC_CHECK_LIB(c, dlopen,
143         [
144           AC_DEFINE(SILC_SIM)
145           sim_support=true
146         ])
147     ])
148   )
149
150 AM_CONDITIONAL(SILC_SIM, test x$sim_support = xtrue)
151 if test x$sim_support = xtrue; then
152   AC_MSG_RESULT(Enabled SIM support.)
153 else
154   AC_MSG_RESULT(No SIM support found.)
155 fi
156
157 # lib/contrib conditionals
158 #
159 AC_CHECK_HEADER(regex.h, have_regex=1, have_regex=0)
160 AM_CONDITIONAL(HAVE_REGEX, test x$have_regex = x1)
161 AC_CHECK_FUNC(getopt_long, have_getopt_long=1, have_getopt_long=0)
162 AM_CONDITIONAL(HAVE_GETOPT_LONG, test x$have_getopt_long = x1)
163
164
165 ##
166 ##  Enable/disable checking
167 ##
168
169 # IPv6 support
170 #
171 AC_MSG_CHECKING(whether to enable IPv6 support)
172 AC_ARG_ENABLE(ipv6,
173   [  --enable-ipv6           enable IPv6 support],
174   [
175     case "${enableval}" in
176       yes)
177         want_ipv6=true
178         check_ipv6=false
179         summary_ipv6="yes"
180         AC_DEFINE(HAVE_IPV6)
181         AC_MSG_RESULT(yes)
182         ;;
183       *)
184         want_ipv6=false
185         check_ipv6=false
186         summary_ipv6="no"
187         AC_MSG_RESULT(no)
188         ;;
189     esac
190   ],
191     check_ipv6=true
192   )
193
194 if test x$check_ipv6 = xtrue; then
195   summary_ipv6="no"
196   AC_TRY_COMPILE(
197     [
198       #ifdef HAVE_SYS_TYPES_H
199       #include <sys/types.h>
200       #endif
201       #ifdef HAVE_NETINET_TCP_H
202       #include <netinet/tcp.h>
203       #endif
204       #ifdef HAVE_NETDB_H
205       #include <netdb.h>
206       #endif
207       #include <sys/socket.h>
208       #ifdef HAVE_NETINET_IN_H
209       #include <netinet/in.h>
210       #endif
211     ],
212     [
213       struct sockaddr_in6 sin6;
214       int family = AF_INET6;
215     ],
216     [
217       AC_DEFINE(HAVE_IPV6)
218       AC_MSG_RESULT(yes)
219       summary_ipv6="yes"
220     ],
221       AC_MSG_RESULT(no)
222     )
223 fi
224
225 # Debug checking
226 #
227 AC_MSG_CHECKING(whether to enable debugging)
228 summary_debug="no"
229 AC_ARG_ENABLE(debug,
230   [  --enable-debug          enable debugging],
231   [
232     case "${enableval}" in
233       yes)
234         AC_MSG_RESULT(yes)
235         AC_DEFINE(SILC_DEBUG)
236         CFLAGS="-O -g $CFLAGS"
237         summary_debug="yes"
238         ;;
239       *)
240         AC_MSG_RESULT(no)
241         CFLAGS="-O2 -g $CFLAGS"
242         ;;
243     esac
244   ],
245   [
246     CFLAGS="-O2 -g $CFLAGS"
247     AC_MSG_RESULT(no)
248   ])
249
250 # Stack trace checking
251 #
252 AC_MSG_CHECKING(whether to enable stack tracing)
253 summary_stacktrace="no"
254 AC_ARG_ENABLE(stack-trace,
255   [  --enable-stack-trace    enable memory stack trace],
256   [
257     case "${enableval}" in
258     yes)
259       AC_MSG_RESULT(yes)
260       AC_DEFINE(SILC_STACKTRACE)
261       summary_stacktrace="yes"
262       ;;
263     *)
264       AC_MSG_RESULT(no)
265       ;;
266     esac
267   ],
268     AC_MSG_RESULT(no)
269   )
270
271 # Disable all assembler optimizations
272 #
273 AC_MSG_CHECKING(whether to enable assembler optimizations)
274 summary_asm="no"
275 AC_ARG_ENABLE(asm,
276   [  --disable-asm           do not use assembler optimizations],
277   [
278     AC_MSG_RESULT(no)
279   ],
280   [
281     AC_MSG_RESULT(yes)
282     summary_asm="yes"
283   ])
284
285
286 ##
287 ##  Installation
288 ##
289
290 # Default installation destination
291 #
292 AC_PREFIX_DEFAULT(/usr/local/silc)
293 if test "x$prefix" != xNONE; then
294   silc_prefix="$prefix"
295 else
296   silc_prefix="$ac_default_prefix"
297 fi
298
299 # etc directory
300 #
301 if test "x$sysconfdir" != 'x${prefix}/etc'; then
302   ETCDIR="$sysconfdir"
303 else
304   ETCDIR="$silc_prefix/etc"
305 fi
306
307 AC_ARG_WITH(etcdir,
308   [[  --with-etcdir=DIR       directory for system files [/etc/silc]]],
309   [
310     case "$withval" in
311       no|yes)
312         ;;
313       *)
314         ETCDIR="$withval"
315         ;;
316     esac
317   ])
318 AC_SUBST(ETCDIR)
319 AC_DEFINE_UNQUOTED(SILC_ETCDIR, "$ETCDIR")
320
321 # help directory
322 #
323 HELPDIR="$silc_prefix/help"
324 AC_ARG_WITH(helpdir,
325   [[  --with-helpdir=DIR      directory for SILC help files [PREFIX/help]]],
326   [
327     case "$withval" in
328       no|yes)
329         ;;
330       *)
331        HELPDIR="$withval"
332        ;;
333     esac
334   ])
335 AC_SUBST(HELPDIR)
336 AC_DEFINE_UNQUOTED(SILC_HELPDIR, "$HELPDIR")
337
338 # doc directory
339 #
340 DOCDIR="$silc_prefix/doc"
341 AC_ARG_WITH(docdir,
342   [[  --with-docdir=DIR       directory for SILC documentation [PREFIX/doc]]],
343   [
344     case "$withval" in
345       no|yes)
346         ;;
347       *)
348         DOCDIR="$withval"
349         ;;
350     esac
351   ])
352 AC_SUBST(DOCDIR)
353 AC_DEFINE_UNQUOTED(SILC_DOCDIR, "$DOCDIR")
354
355 # SIM modules directory
356 #
357 MODULESDIR="$silc_prefix/modules"
358 AC_ARG_WITH(simdir,
359   [[  --with-simdir=DIR       directory for SIM modules [PREFIX/modules]]],
360   [
361     case "$withval" in
362       no|yes)
363         ;;
364       *)
365         MODULESDIR="$withval"
366         ;;
367     esac
368   ])
369 AC_SUBST(MODULESDIR)
370 AC_DEFINE_UNQUOTED(SILC_MODULESDIR, "$MODULESDIR")
371
372 # Logs directory
373 #
374 LOGSDIR="$silc_prefix/logs"
375 AC_ARG_WITH(logsdir,
376   [[  --with-logsdir=DIR      directory for SILC Server logs [PREFIX/logs]]],
377   [
378     case "$withval" in
379       no|yes)
380         ;;
381       *)
382         LOGSDIR="$withval"
383         ;;
384     esac
385   ])
386 AC_SUBST(LOGSDIR)
387 AC_DEFINE_UNQUOTED(SILC_LOGSDIR, "$LOGSDIR")
388
389 # Manual directory
390 #
391 MANDIR="$silc_prefix/man"
392 AC_ARG_WITH(mandir,
393   [[  --with-mandir=DIR       directory for SILC manual pages [PREFIX/man]]],
394   [
395     case "$withval" in
396       no|yes)
397         ;;
398       *)
399         MANDIR="$withval"
400         ;;
401     esac
402   ])
403 AC_SUBST(MANDIR)
404 AC_DEFINE_UNQUOTED(SILC_MANDIR, "$MANDIR")
405
406 # silcd config file checking
407 #
408 summary_silcd_configfile="/etc/silc/silcd.conf"
409 AC_ARG_WITH(silcd-config-file,
410   [[  --with-silcd-config-file=FILE  use FILE as default configuration file
411                                  for SILC Server [/etc/silc/silcd.conf]]],
412     AC_DEFINE_UNQUOTED(SILC_SERVER_CONFIG_FILE, "$withval")
413     summary_silcd_configfile="$withval"
414   )
415
416 # silcd pid file checking
417 #
418 if test "x$localstatedir" != 'x${prefix}/var'; then
419   PIDFILE="$localstatedir/silcd.pid"
420 else
421   PIDFILE="$silc_prefix/var/silcd.pid"
422 fi
423
424 AC_ARG_WITH(silcd-pid-file,
425   [[  --with-silcd-pid-file=FILE     use FILE as default pid file for SILC
426                                  Server [/var/run/silcd.pid]]],
427   [
428     case "$withval" in
429       no|yes)
430         ;;
431       *)
432         PIDFILE="$withval"
433         ;;
434     esac
435   ])
436 AC_SUBST(PIDFILE)
437
438
439 ##
440 ##  With/without checkings
441 ##
442
443 # SOCKS4 support checking
444 #
445 SAVE_LIBS="$LIBS"
446 SAVE_CFLAGS="$CFLAGS"
447 SAVE_LDFLAGS="$LDFLAGS"
448 AC_MSG_CHECKING(whether to support SOCKS4)
449 AC_ARG_WITH(socks4,
450   [[  --with-socks4[=DIR]     with SOCKS4 support [search in DIR/lib and DIR/include]]],
451   [
452     case "$withval" in
453       no)
454         AC_MSG_RESULT(no)
455         ;;
456       *)
457         AC_MSG_RESULT(yes)
458         socks=4
459     
460         if test -d "$withval/include"; then
461           CFLAGS="$CFLAGS -I$withval/include"
462         fi
463         if test -d "$withval/lib"; then
464           LDFLAGS="$LDFLAGS -L$withval/lib"
465         fi
466     
467         LIBS="-lsocks $LIBS"
468         ;;
469     esac
470
471     AC_TRY_LINK([],
472       [
473         Rconnect();
474       ], [],
475       [
476         AC_MSG_ERROR(Could not find SOCKS4 library.)
477         LIBS="$SAVE_LIBS"
478         CFLAGS="$SAVE_CFLAGS"
479         LDFLAGS="$SAVE_LDFLAGS"
480       ])
481   ],
482     AC_MSG_RESULT(no)
483   )
484
485 # SOCKS5 support checking
486 #
487 SAVE_LIBS="$LIBS"
488 SAVE_CFLAGS="$CFLAGS"
489 SAVE_LDFLAGS="$LDFLAGS"
490 AC_MSG_CHECKING(whether to support SOCKS5)
491 AC_ARG_WITH(socks5,
492   [[  --with-socks5[=DIR]     with SOCKS5 support [search in DIR/lib and DIR/include]]],
493   [
494     case "$withval" in
495       no)
496         AC_MSG_RESULT(no)
497         ;;
498       *)
499         AC_MSG_RESULT(yes)
500         socks=5
501
502         if test -d "$withval/include"; then
503           CFLAGS="$CFLAGS -I$withval/include"
504         fi
505         if test -d "$withval/lib"; then
506           LDFLAGS="$LDFLAGS -L$withval/lib"
507         fi
508
509         LIBS="-lsocks5 $LIBS"
510         ;;
511     esac
512
513     AC_TRY_LINK([],
514       [
515         SOCKSconnect();
516       ], [],
517       [
518         AC_MSG_ERROR(Could not find SOCKS5 library.)
519         LIBS="$SAVE_LIBS"
520         CFLAGS="$SAVE_CFLAGS"
521         LDFLAGS="$SAVE_LDFLAGS"
522       ])
523   ],
524     AC_MSG_RESULT(no)
525   )
526
527 if test "x$socks" = "x4"; then
528   AC_DEFINE(SOCKS)
529   CFLAGS="$CFLAGS -Dconnect=Rconnect -Dgetsockname=Rgetsockname -Dbind=Rbind -Daccept=Raccept -Dlisten=Rlisten -Dselect=Rselect"
530 fi
531
532 if test "x$socks" = "x5"; then
533   AC_DEFINE(SOCKS)
534   AC_DEFINE(SOCKS5)
535   AC_DEFINE(Rconnect, SOCKSconnect)
536   AC_DEFINE(Rgetsockname, SOCKSgetsockname)
537   AC_DEFINE(Rgetpeername, SOCKSgetpeername)
538   AC_DEFINE(Rbind, SOCKSbind)
539   AC_DEFINE(Raccept, SOCKSaccept)
540   AC_DEFINE(Rlisten, SOCKSlisten)
541   AC_DEFINE(Rselect, SOCKSselect)
542   AC_DEFINE(Rrecvfrom, SOCKSrecvfrom)
543   AC_DEFINE(Rsendto, SOCKSsendto)
544   AC_DEFINE(Rrecv, SOCKSrecv)
545   AC_DEFINE(Rsend, SOCKSsend)
546   AC_DEFINE(Rread, SOCKSread)
547   AC_DEFINE(Rwrite, SOCKSwrite)
548   AC_DEFINE(Rrresvport, SOCKSrresvport)
549   AC_DEFINE(Rshutdown, SOCKSshutdown)
550   AC_DEFINE(Rlisten, SOCKSlisten)
551   AC_DEFINE(Rclose, SOCKSclose)
552   AC_DEFINE(Rdup, SOCKSdup)
553   AC_DEFINE(Rdup2, SOCKSdup2)
554   AC_DEFINE(Rfclose, SOCKSfclose)
555   AC_DEFINE(Rgethostbyname, SOCKSgethostbyname)
556 fi
557
558 # MP library checking. First check whether user wants to use GMP and use
559 # it if found. If not or not defined then compile the MPI library in the
560 # source tree.
561 #
562 mp_gmp=false
563 SAVE_LIBS="$LIBS"
564 SAVE_CFLAGS="$CFLAGS"
565 SAVE_LDFLAGS="$LDFLAGS"
566 AC_MSG_CHECKING(whether to search for GMP)
567 AC_ARG_WITH(gmp,
568   [[  --with-gmp[=DIR]        use GMP instead of MPI [search in DIR/lib and DIR/include]]],
569   [
570     case "$withval" in
571       no)
572         AC_MSG_RESULT(no)
573         ;;
574       *)
575         AC_MSG_RESULT(yes)
576     
577         if test -d "$withval/include"; then
578           CFLAGS="$CFLAGS -I$withval/include"
579         fi
580         if test -d "$withval/lib"; then
581           LDFLAGS="$LDFLAGS -L$withval/lib"
582         fi
583     
584         LIBS="-lgmp $LIBS"
585         ;;
586     esac
587
588     AC_CHECK_LIB(gmp, __gmpz_init,
589       [
590         mp_gmp=true
591         AC_DEFINE(SILC_MP_GMP)
592         AC_MSG_RESULT(Using GMP as a MP library.)
593       ],
594       [
595         LIBS="$SAVE_LIBS"
596         CFLAGS="$SAVE_CFLAGS"
597         LDFLAGS="$SAVE_LDFLAGS"
598       ])
599   ],
600     AC_MSG_RESULT(no)
601   )
602
603 AM_CONDITIONAL(SILC_MP_GMP, test x$mp_gmp = xtrue)
604 AM_CONDITIONAL(SILC_MP_NSS_MPI, test x$mp_gmp = xfalse)
605 if test x$mp_gmp = xfalse; then
606   AC_DEFINE(SILC_MP_NSS_MPI)
607   AC_MSG_RESULT(Using NSS MPI as a MP library.)
608 fi
609
610 # iconv support
611 #
612 check_iconv=true
613 has_iconv=false
614 SAVE_LIBS="$LIBS"
615 SAVE_CFLAGS="$CFLAGS"
616 SAVE_LDFLAGS="$LDFLAGS"
617 SAVE_CPPFLAGS="$CPPFLAGS"
618 AC_MSG_CHECKING(whether to implicit search for libiconv)
619 AC_ARG_WITH(iconv,
620   [[  --with-iconv[=DIR]      use libiconv [search in DIR/include and DIR/lib]]],
621   [
622     case "${withval}" in
623       no)
624         AC_MSG_RESULT(no)
625
626         AC_CHECK_HEADERS(iconv.h, AC_CHECK_FUNC(iconv, has_iconv=true))
627         check_iconv=false
628         ;;
629       *)
630         AC_MSG_RESULT(yes)
631
632         if test -d $withval/include; then
633           CPPFLAGS="$CPPFLAGS -I$withval/include"
634           CFLAGS="$CFLAGS -I$withval/include"
635         fi
636         if test -d $withval/lib; then
637           LDFLAGS="$LDFLAGS -L$withval/lib"
638         fi
639     esac
640   ],
641   [
642     AC_MSG_RESULT(no)
643
644     AC_CHECK_HEADERS(iconv.h, AC_CHECK_FUNCS(iconv,
645                                 [
646                                   has_iconv=true
647                                   check_iconv=false
648                                  ]))
649   ])
650
651 if test x$check_iconv = xtrue; then
652   AC_MSG_RESULT(starting search...)
653
654   # XXX
655   unset ac_cv_header__iconv_h_ ac_cv_header_iconv_h || true
656
657   AC_CHECK_HEADERS(iconv.h,
658     [
659       LIBS="$LIBS -liconv"
660       AC_MSG_CHECKING(for iconv in -liconv)
661       AC_TRY_LINK(
662         [
663           #include <stdlib.h>
664           #include <iconv.h>
665         ],
666         [
667           iconv_t cd = iconv_open("", "");
668           iconv(cd, NULL, NULL, NULL, NULL);
669           iconv_close(cd);
670         ],
671         [
672           echo "yes"
673           AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
674           has_iconv=true
675           check_iconv=false
676         ],
677         [
678           echo "no"
679           LIBS="$SAVE_LIBS"
680           CFLAGS="$SAVE_CFLAGS"
681           LDFLAGS="$SAVE_LDFLAGS"
682           CPPFLAGS="$SAVE_CPPFLAGS"
683         ])
684      ])
685 fi
686
687 if test x$check_iconv = xtrue; then
688   # search for iconv library..
689   SAVE_LIBS="$LIBS"
690   SAVE_CFLAGS="$CFLAGS"
691   SAVE_LDFLAGS="$LDFLAGS"
692   SAVE_CPPFLAGS="$CPPFLAGS"
693     
694   for dir in `echo "/usr/local /usr/pkg /usr/contrib"`; do
695     if test x$has_iconv = xfalse; then
696       AC_MSG_RESULT(searching in $dir...)
697      
698       if test -d $dir/include; then
699         CPPFLAGS="$CPPFLAGS -I$dir/include"
700         CFLAGS="$CFLAGS -I$dir/include"
701       fi
702       if test -d $dir/lib; then
703         LDFLAGS="$LDFLAGS -L$dir/lib"
704       fi
705     
706       # XXX
707       unset ac_cv_header__iconv_h_ ac_cv_header_iconv_h || true
708       
709       AC_CHECK_HEADERS(iconv.h,
710         [
711           LIBS="$LIBS -liconv"
712           AC_MSG_CHECKING(for iconv in -liconv)
713           AC_TRY_LINK(
714             [
715               #include <stdlib.h>
716               #include <iconv.h>
717             ],
718             [
719               iconv_t cd = iconv_open("", "");
720               iconv(cd, NULL, NULL, NULL, NULL);
721               iconv_close(cd);
722             ],
723             [
724               echo "yes"
725               has_iconv=true 
726               AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
727             ],
728             [
729               echo "no"
730               has_iconv=false
731  
732               LIBS="$SAVE_LIBS"    
733               CFLAGS="$SAVE_CFLAGS"
734               LDFLAGS="$SAVE_LDFLAGS"
735               CPPFLAGS="$SAVE_CPPFLAGS"
736             ])
737          ],
738          [
739            CFLAGS="$SAVE_CFLAGS"
740            LDFLAGS="$SAVE_LDFLAGS"
741            CPPFLAGS="$SAVE_CPPFLAGS"
742          ])
743       fi
744     done
745 fi
746
747 if test x$has_iconv = xtrue; then
748   # (1) Some implementations of iconv won't convert from UTF-8 to UTF-8.
749   # (2) In glibc-2.1.2 and earlier there is a bug that messes up ob and
750   #     obl when args 2 and 3 are 0 (fixed in glibc-2.1.3).
751   #
752   AC_CACHE_CHECK([whether this iconv is good enough], ac_iconv_good,
753     AC_TRY_RUN(
754       [
755         #include <iconv.h>
756         int main() {
757           iconv_t cd;
758         changequote(, )dnl
759           char buf[4];
760         changequote([, ])dnl
761           char *ob;
762           size_t obl;
763           ob = buf, obl = sizeof(buf);
764           return ((cd = iconv_open("UTF-8", "UTF-8")) != (iconv_t)(-1) &&
765                  (iconv(cd, 0, 0, &ob, &obl) ||
766                  !(ob == buf && obl == sizeof(buf)) ||
767                  iconv_close(cd)));
768         }
769       ],
770       [
771         ac_iconv_good=yes
772       ],
773       [
774         ac_iconv_good=no
775       ],
776       [
777         ac_iconv_good=yes
778       ])
779     )
780
781   if test x$ac_iconv_good = xno; then
782     AC_MSG_RESULT(Try using libiconv instead.)
783   fi
784 fi
785
786 # POSIX threads support
787 #
788 has_threads=false
789 AC_MSG_CHECKING(whether to search for POSIX threads)
790 AC_ARG_WITH(pthreads,
791   [[  --with-pthreads[=DIR]   use POSIX threads [search in DIR/include and DIR/lib]]],
792   [ 
793     case "${withval}" in
794       no)
795         check_threads=false
796         ;;
797       *)
798         if test -d $withval/include; then
799           CPPFLAGS="$CPPFLAGS -I$withval/include"
800           CFLAGS="$CFLAGS -I$withval/include"
801         fi
802         if test -d $withval/lib; then
803           LDFLAGS="$LDFLAGS -L$withval/lib"
804         fi
805
806         check_threads=true
807         ;;
808     esac
809   ])
810
811 if test x$check_threads = xtrue; then
812   SAVE_LIBS="$LIBS"
813   SAVE_CFLAGS="$CFLAGS"
814   SAVE_LDFLAGS="$LDFLAGS"
815   SAVE_CPPFLAGS="$CPPFLAGS"
816   
817   AC_MSG_RESULT(yes)
818   AC_CHECK_HEADERS(pthread.h,
819     [
820       LIBS="$LIBS -lpthread"
821       AC_CHECK_LIB(pthread, pthread_attr_init, has_threads=true,
822         [
823           # FreeBSD
824           case "${target}" in
825             *-*-freebsd*)
826               LIBS="$SAVE_LIBS -pthread"
827               AC_CHECK_LIB(c_r, pthread_attr_init, has_threads=true, LIBS="$SAVE_LIBS")
828               ;;
829             *)
830               LIBS="$SAVE_LIBS"
831               ;;
832           esac
833         ])
834     ],
835     [
836       # search for pthread library..
837       for dir in `echo "/usr/local /usr/pkg /usr/contrib /usr/pkg/pthreads /usr/local/pthreads"`; do
838         if test x$has_threads = xfalse; then
839           AC_MSG_RESULT(searching in $dir...)
840   
841           if test -d $dir/include; then
842             CPPFLAGS="$CPPFLAGS -I$dir/include"
843             CFLAGS="$CFLAGS -I$dir/include"
844           fi
845           if test -d $dir/lib; then
846             LDFLAGS="$LDFLAGS -L$dir/lib"
847           fi
848
849           # XXX
850           unset ac_cv_header__pthread_h_ ac_cv_header_pthread_h || true
851
852           AC_CHECK_HEADERS(pthread.h,
853             [ 
854               LIBS="$LIBS -lpthread"
855               AC_CHECK_LIB(pthread, pthread_attr_init, has_threads=true,
856                 [
857                   has_threads=false
858
859                   LIBS="$SAVE_LIBS"
860                   CFLAGS="$SAVE_CFLAGS"
861                   LDFLAGS="$SAVE_LDFLAGS"
862                   CPPFLAGS="$SAVE_CPPFLAGS"
863                 ])
864             ],
865             [
866               CFLAGS="$SAVE_CFLAGS"
867               LDFLAGS="$SAVE_LDFLAGS"
868               CPPFLAGS="$SAVE_CPPFLAGS"
869             ])
870         fi
871       done
872     ])
873 else
874   AC_MSG_RESULT(no)
875   has_threads=false
876 fi
877
878 AM_CONDITIONAL(SILC_THREADS, test x$has_threads = xtrue)
879 if test x$has_threads = xtrue; then
880   CFLAGS="$CFLAGS -D_REENTRANT"
881
882   # XXX possibly incomplete
883   case "${target}" in
884     *-*-aix*)
885       CFLAGS="$CFLAGS -D_THREAD_SAFE"
886       if test x"$GCC" = xyes; then
887         CFLAGS="$CFLAGS -mthreads"
888       fi
889       ;;
890     *-*-freebsd*)
891       CFLAGS="$CFLAGS -D_THREAD_SAFE"
892       ;;
893     *-*-sysv5uw7*)  # UnixWare 7
894       if test "$GCC" != "yes"; then
895         CFLAGS="$CFLAGS -Kthread"
896       else
897         CFLAGS="$CFLAGS -pthread"
898       fi
899       ;;
900     *-dg-dgux*)  # DG/UX
901       CFLAGS="$CFLAGS -D_POSIX4A_DRAFT10_SOURCE"
902       ;;
903    esac
904
905   AC_CHECK_FUNC(pthread_create)
906   AC_DEFINE(SILC_HAVE_PTHREAD)
907   AC_DEFINE(SILC_THREADS)
908 fi
909
910 # Native WIN32 compilation under cygwin
911 #
912 AC_MSG_CHECKING(whether to compile native WIN32 code)
913 AC_ARG_WITH(win32,
914   [  --with-win32            compile native WIN32 code (-mno-cygwin)],
915   [
916     AC_MSG_RESULT(yes)
917     AC_DEFINE(SILC_WIN32)
918     win32_support=true
919     CFLAGS="-mno-cygwin $CFLAGS"
920     LIBS="$LIBS -lwsock32"
921   ],
922   [
923     AC_MSG_RESULT(no)
924   ])
925 AM_CONDITIONAL(SILC_WIN32, test x$win32_support = xtrue)
926
927 # Native EPOC support (disabled by default)
928 #
929 AM_CONDITIONAL(SILC_EPOC, test xfalse = xtrue)
930
931 # Native BeOS support (disabled by default)
932 #
933 AM_CONDITIONAL(SILC_BEOS, test xfalse = xtrue)
934
935 # Native OS2 support (disabled by default)
936 #
937 AM_CONDITIONAL(SILC_OS2, test xfalse = xtrue)
938
939 # --without-irssi
940 #
941 without_irssi=false
942 AC_MSG_CHECKING(whether to compile Irssi SILC Client)
943 AC_ARG_WITH(irssi,
944   [  --without-irssi         compile without Irssi SILC Client],
945   [
946     AC_MSG_RESULT(no)
947     without_irssi=true
948     SILC_DIST_SUBDIRS=`echo $SILC_DIST_SUBDIRS | $sedpath -e 's/irssi//'`
949   ],
950   [
951     AC_MSG_RESULT(yes)
952   ])
953
954 # --without-silcd
955 #
956 without_silcd=false
957 AC_MSG_CHECKING(whether to compile SILC Server)
958 AC_ARG_WITH(silcd,
959   [  --without-silcd         compile without SILC Server],
960   [
961     AC_MSG_RESULT(no)
962     without_silcd=true
963     SILC_DIST_SUBDIRS=`echo $SILC_DIST_SUBDIRS | $sedpath -e 's/silcd//'`
964   ],
965   [
966     AC_MSG_RESULT(yes)
967   ])
968
969
970 ##
971 ##  Misc
972 ##
973
974 # Other configure scripts
975 #
976 if test x$without_irssi = xfalse; then
977   if test "x$silc_dist" = "xsilc-client" ||
978      test "x$silc_dist" = "xsilc-toolkit"; then
979     AC_CONFIG_SUBDIRS(irssi)
980   fi
981 fi
982
983 if test x$mp_gmp = xfalse; then
984   AC_CONFIG_SUBDIRS(lib/silcmath/mpi)
985 fi
986
987 #AC_CONFIG_SUBDIRS(lib/zlib)
988
989 SILC_TOP_SRCDIR=`pwd`
990 AC_SUBST(SILC_TOP_SRCDIR)
991 #SILC_INSTALL_PREFIX=$ac_default_prefix
992 #AC_SUBST(SILC_INSTALL_PREFIX)
993 AC_SUBST(LIBS)
994 INCLUDE_DEFINES_INT="include \$(top_srcdir)/Makefile.defines_int"
995 AC_SUBST(INCLUDE_DEFINES_INT)
996 AC_SUBST(SILC_DIST_SUBDIRS)
997
998 # Makefile outputs
999 #
1000 AC_CONFIG_FILES(
1001 Makefile
1002 Makefile.defines
1003 Makefile.defines_int
1004 doc/Makefile
1005 includes/Makefile
1006 lib/Makefile
1007 lib/contrib/Makefile
1008 lib/silccore/Makefile
1009 lib/silccrypt/Makefile
1010 lib/silcmath/Makefile
1011 lib/silcmath/mpi/Makefile.defines
1012 lib/silcmath/mpi/Makefile.defines_int
1013 lib/silcsim/Makefile
1014 lib/silcske/Makefile
1015 lib/silcutil/Makefile
1016 lib/silcutil/unix/Makefile
1017 lib/silcutil/win32/Makefile
1018 lib/silcutil/beos/Makefile
1019 lib/silcutil/os2/Makefile
1020 lib/silcutil/epoc/Makefile
1021 lib/silcsftp/Makefile
1022 lib/silcsftp/tests/Makefile
1023 doc/example_silcd.conf
1024 includes/silcincludes.h
1025 )
1026
1027 if test "x$silc_dist" = "xsilc-client" ||
1028    test "x$silc_dist" = "xsilc-toolkit"; then
1029   AC_CONFIG_FILES(lib/silcclient/Makefile)
1030 fi
1031
1032 if test x$without_irssi = xfalse ; then
1033   if test "x$silc_dist" = "xsilc-client" ||
1034      test "x$silc_dist" = "xsilc-toolkit"; then
1035     AC_CONFIG_FILES(
1036 irssi/Makefile.defines
1037 irssi/Makefile.defines_int
1038 )
1039   fi
1040 fi
1041
1042 if test x$without_silcd = xfalse ; then
1043   if test "x$silc_dist" = "xsilc-server" ||
1044      test "x$silc_dist" = "xsilc-toolkit"; then
1045     AC_CONFIG_FILES(
1046 silcd/Makefile
1047 )
1048   fi
1049 fi
1050
1051 if test "x$silc_dist" = "xsilc-toolkit"; then
1052   AC_CONFIG_FILES(
1053 silc/Makefile
1054 win32/Makefile
1055 win32/libsilc/Makefile
1056 win32/libsilcclient/Makefile
1057 tutorial/Makefile
1058 tutorial/Makefile.defines
1059 tutorial/Makefile.defines_int
1060 )
1061 fi
1062
1063 AC_OUTPUT
1064
1065 s_bindir=`eval echo $bindir`;s_bindir=`eval echo $s_bindir`
1066 s_sbindir=`eval echo $sbindir`;s_sbindir=`eval echo $s_sbindir`
1067 s_includedir=`eval echo $includedir`;s_includedir=`eval echo $s_includedir`
1068
1069 echo ""
1070 echo "SILC Configuration Summary:"
1071 echo "---------------------------"
1072 echo " Target host ...................: $target"
1073 echo " Compiler ......................: $CC"
1074 echo " CFLAGS ........................: $CFLAGS"
1075 echo " CPPFLAGS ......................: $CPPFLAGS"
1076 echo " LDFLAGS .......................: $LDFLAGS"
1077 echo " LIBS ..........................: $LIBS"
1078 echo ""
1079 echo " Installation prefix ...........: $prefix"
1080 echo " bin directory .................: $s_bindir"
1081 echo " sbin directory ................: $s_sbindir"
1082 echo " man directory .................: $MANDIR"
1083 echo " help directory ................: $HELPDIR"
1084 echo " doc directory .................: $DOCDIR"
1085 echo " logs directory ................: $LOGSDIR"
1086 echo " SIM directory .................: $MODULESDIR"
1087 echo " include directory .............: $s_includedir"
1088 echo ""
1089
1090 if test "x$silc_dist" = "xsilc-client" ||
1091    test "x$silc_dist" = "xsilc-toolkit"; then
1092   irssi="yes"
1093   if test x$without_irssi = xtrue; then
1094     irssi="no"
1095   fi
1096 echo " Compile SILC Client ...........: $irssi"
1097 fi
1098
1099 if test "x$silc_dist" = "xsilc-server" ||
1100    test "x$silc_dist" = "xsilc-toolkit"; then
1101   silcd="yes"
1102   if test x$without_silcd = xtrue; then
1103     without_silcd="no"
1104   fi
1105 echo " Compile SILC Server ...........: $silcd"
1106 echo " Server configuration file .....: $summary_silcd_configfile"
1107 echo " Server PID file ...............: $PIDFILE"
1108 fi
1109
1110 if test x$sim_support = xfalse; then
1111   sim_support="no"
1112 else
1113   sim_support="yes"
1114 fi
1115 echo " SIM support ...................: $sim_support"
1116 echo " IPv6 support ..................: $summary_ipv6"
1117 echo " Assmebler optimizations .......: $summary_asm"
1118
1119 mp="MPI"
1120 if test x$mp_gmp = xtrue; then
1121   mp="GMP"
1122 fi
1123 echo " Arithmetic library ............: $mp"
1124
1125 threads="no"
1126 if test x$has_threads = xtrue; then
1127   threads="yes"
1128 fi
1129 echo " Multi-threads support .........: $threads"
1130 echo " Debugging enabled .............: $summary_debug"
1131 echo " Stack-trace enabled ...........: $summary_stacktrace"
1132 echo ""
1133 if test "x$silc_dist" = "xsilc-client"; then
1134   echo "Compile the sources with 'make' or 'gmake' command (GNU make is required)."
1135 else
1136   echo "Compile the sources with 'make' or 'gmake' command."
1137 fi