Do not include silcdefs.h in installed headers anymore. Include
[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_DEFINE_UNQUOTED(SILC_SIZEOF_LONG_LONG, $ac_cv_sizeof_long_long)
96 AC_CHECK_SIZEOF(long, 0)
97 AC_DEFINE_UNQUOTED(SILC_SIZEOF_LONG, $ac_cv_sizeof_long)
98 AC_CHECK_SIZEOF(int, 0)
99 AC_DEFINE_UNQUOTED(SILC_SIZEOF_INT, $ac_cv_sizeof_int)
100 AC_CHECK_SIZEOF(short, 0)
101 AC_DEFINE_UNQUOTED(SILC_SIZEOF_SHORT, $ac_cv_sizeof_short)
102 AC_CHECK_SIZEOF(char, 0)
103 AC_DEFINE_UNQUOTED(SILC_SIZEOF_CHAR, $ac_cv_sizeof_char)
104 AC_CHECK_SIZEOF(void *, 0)
105 AC_DEFINE_UNQUOTED(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)
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)
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)
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)
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)
380         ;;
381       *)
382         LOGSDIR="$withval"
383         ;;
384     esac
385   ])
386 AC_SUBST(LOGSDIR)
387 AC_DEFINE_UNQUOTED(SILC_LOGSDIR, "$LOGSDIR")
388
389 # silcd config file checking
390 #
391 summary_silcd_configfile="/etc/silc/silcd.conf"
392 AC_ARG_WITH(silcd-config-file,
393   [[  --with-silcd-config-file=FILE  use FILE as default configuration file
394                                  for SILC Server [/etc/silc/silcd.conf]]],
395     AC_DEFINE_UNQUOTED(SILC_SERVER_CONFIG_FILE, "$withval")
396     summary_silcd_configfile="$withval"
397   )
398
399 # silcd pid file checking
400 #
401 if test "x$localstatedir" != 'x${prefix}/var'; then
402   PIDFILE="$localstatedir/silcd.pid"
403 else
404   PIDFILE="$silc_prefix/var/silcd.pid"
405 fi
406
407 AC_ARG_WITH(silcd-pid-file,
408   [[  --with-silcd-pid-file=FILE     use FILE as default pid file for SILC
409                                  Server [/var/run/silcd.pid]]],
410   [
411     case "$withval" in
412       no)
413         ;;
414       *)
415         PIDFILE="$withval"
416         ;;
417     esac
418   ])
419 AC_SUBST(PIDFILE)
420
421
422 ##
423 ##  With/without checkings
424 ##
425
426 # SOCKS4 support checking
427 #
428 AC_MSG_CHECKING(whether to support SOCKS4)
429 AC_ARG_WITH(socks4,
430   [[  --with-socks4[=DIR]     with SOCKS4 support [search in DIR/lib and DIR/include]]],
431   [
432     case "$withval" in
433       no)
434         AC_MSG_RESULT(no)
435         ;;
436       *)
437         AC_MSG_RESULT(yes)
438         socks=4
439     
440         if test -d "$withval/include"; then
441           CFLAGS="$CFLAGS -I$withval/include"
442         else
443           CFLAGS="$CFLAGS -I$withval"
444         fi
445         if test -d "$withval/lib"; then
446           withval="-L$withval/lib -lsocks"
447         else
448           withval="-L$withval -lsocks"
449         fi
450     
451         LIBS="$withval $LIBS"
452         AC_TRY_LINK([],
453           [
454             Rconnect();
455           ], [],
456           [
457             AC_MSG_ERROR(Could not find SOCKS4 library.)
458           ])
459         ;;
460     esac
461   ],
462     AC_MSG_RESULT(no)
463   )
464
465 # SOCKS5 support checking
466 #
467 AC_MSG_CHECKING(whether to support SOCKS5)
468 AC_ARG_WITH(socks5,
469   [[  --with-socks5[=DIR]     with SOCKS5 support [search in DIR/lib and DIR/include]]],
470   [
471     case "$withval" in
472       no)
473         AC_MSG_RESULT(no)
474         ;;
475       *)
476         AC_MSG_RESULT(yes)
477         socks=5
478
479         if test -d "$withval/include"; then
480           CFLAGS="$CFLAGS -I$withval/include"
481         else
482           CFLAGS="$CFLAGS -I$withval"
483         fi
484         if test -d "$withval/lib"; then
485           withval="-L$withval/lib -lsocks5"
486         else
487           withval="-L$withval -lsocks5"
488         fi
489
490         LIBS="$withval $LIBS"
491         AC_TRY_LINK([],
492           [
493             SOCKSconnect();
494           ], [],
495           [
496             AC_MSG_ERROR(Could not find SOCKS5 library.)
497           ])
498         ;;
499     esac
500   ],
501     AC_MSG_RESULT(no)
502   )
503
504 if test "x$socks" = "x4"; then
505   AC_DEFINE(SOCKS)
506   CFLAGS="$CFLAGS -Dconnect=Rconnect -Dgetsockname=Rgetsockname -Dbind=Rbind -Daccept=Raccept -Dlisten=Rlisten -Dselect=Rselect"
507 fi
508
509 if test "x$socks" = "x5"; then
510   AC_DEFINE(SOCKS)
511   AC_DEFINE(SOCKS5)
512   AC_DEFINE(Rconnect, SOCKSconnect)
513   AC_DEFINE(Rgetsockname, SOCKSgetsockname)
514   AC_DEFINE(Rgetpeername, SOCKSgetpeername)
515   AC_DEFINE(Rbind, SOCKSbind)
516   AC_DEFINE(Raccept, SOCKSaccept)
517   AC_DEFINE(Rlisten, SOCKSlisten)
518   AC_DEFINE(Rselect, SOCKSselect)
519   AC_DEFINE(Rrecvfrom, SOCKSrecvfrom)
520   AC_DEFINE(Rsendto, SOCKSsendto)
521   AC_DEFINE(Rrecv, SOCKSrecv)
522   AC_DEFINE(Rsend, SOCKSsend)
523   AC_DEFINE(Rread, SOCKSread)
524   AC_DEFINE(Rwrite, SOCKSwrite)
525   AC_DEFINE(Rrresvport, SOCKSrresvport)
526   AC_DEFINE(Rshutdown, SOCKSshutdown)
527   AC_DEFINE(Rlisten, SOCKSlisten)
528   AC_DEFINE(Rclose, SOCKSclose)
529   AC_DEFINE(Rdup, SOCKSdup)
530   AC_DEFINE(Rdup2, SOCKSdup2)
531   AC_DEFINE(Rfclose, SOCKSfclose)
532   AC_DEFINE(Rgethostbyname, SOCKSgethostbyname)
533 fi
534
535 # MP library checking. First check whether user wants to use GMP and use
536 # it if found. If not or not defined then compile the MPI library in the
537 # source tree.
538 #
539 mp_gmp=false
540 AC_MSG_CHECKING(whether to search for GMP)
541 AC_ARG_WITH(gmp,
542   [[  --with-gmp[=DIR]        use GMP instead of MPI [search in DIR/lib and DIR/include]]],
543   [
544     case "$withval" in
545       no)
546         AC_MSG_RESULT(no)
547         ;;
548       *)
549         AC_MSG_RESULT(yes)
550     
551         if test -d "$withval/include"; then
552           CFLAGS="$CFLAGS -I$withval/include"
553         else
554           CFLAGS="$CFLAGS -I$withval"
555         fi
556         if test -d "$withval/lib"; then
557           withval="-L$withval/lib -lgmp"
558         else
559           withval="-L$withval -lgmp"
560         fi
561     
562         LIBS="$withval $LIBS"
563         AC_CHECK_LIB(gmp, __gmpz_init,
564           [
565             mp_gmp=true
566             AC_DEFINE(SILC_MP_GMP)
567             AC_MSG_RESULT(Using GMP as a MP library.)
568           ])
569         ;;
570     esac
571   ],
572     AC_MSG_RESULT(no)
573   )
574
575 AM_CONDITIONAL(SILC_MP_GMP, test x$mp_gmp = xtrue)
576 AM_CONDITIONAL(SILC_MP_NSS_MPI, test x$mp_gmp = xfalse)
577 if test x$mp_gmp = xfalse; then
578   AC_DEFINE(SILC_MP_NSS_MPI)
579   AC_MSG_RESULT(Using NSS MPI as a MP library.)
580 fi
581
582 # iconv support
583 #
584 check_iconv=true
585 has_iconv=false
586 AC_MSG_CHECKING(whether to implicit search for libiconv)
587 AC_ARG_WITH(iconv,
588   [[  --with-iconv[=DIR]      use libiconv [search in DIR/include and DIR/lib]]],
589   [
590     case "${withval}" in
591       no)
592         AC_MSG_RESULT(no)
593
594         AC_CHECK_HEADERS(iconv.h, AC_CHECK_FUNC(iconv, has_iconv=true))
595         check_iconv=false
596         ;;
597       *)
598         AC_MSG_RESULT(yes)
599
600         if test -d $withval/include; then
601           CPPFLAGS="$CPPFLAGS -I$withval/include"
602           CFLAGS="$CFLAGS -I$withval/include"
603         fi
604         if test -d $withval/lib; then
605           LDFLAGS="$LDFLAGS -L$withval/lib"
606         fi
607     esac
608   ],
609   [
610     AC_MSG_RESULT(no)
611
612     AC_CHECK_HEADERS(iconv.h, AC_CHECK_FUNCS(iconv,
613                                 [
614                                   has_iconv=true
615                                   check_iconv=false
616                                  ]))
617   ])
618
619 if test x$check_iconv = xtrue; then
620   AC_MSG_RESULT(starting search...)
621
622   # XXX
623   unset ac_cv_header__iconv_h_ ac_cv_header_iconv_h || true
624
625   AC_CHECK_HEADERS(iconv.h,
626     [
627       LIBS="$LIBS -liconv"
628       AC_MSG_CHECKING(for iconv in -liconv)
629       AC_TRY_LINK(
630         [
631           #include <stdlib.h>
632           #include <iconv.h>
633         ],
634         [
635           iconv_t cd = iconv_open("", "");
636           iconv(cd, NULL, NULL, NULL, NULL);
637           iconv_close(cd);
638         ],
639         [
640           echo "yes"
641           AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
642           has_iconv=true
643           check_iconv=false
644         ],
645         [
646           echo "no"
647         ])
648      ])
649 fi
650
651 if test x$check_iconv = xtrue; then
652   # search for iconv library..
653   SAVE_CPPFLAGS="$CPPFLAGS"
654   SAVE_CFLAGS="$CFLAGS"
655   SAVE_LDFLAGS="$LDFLAGS"
656     
657   for dir in `echo "/usr/local /usr/pkg /usr/contrib"`; do
658     if test x$has_iconv = xfalse; then
659       AC_MSG_RESULT(searching in $dir...)
660     
661       CPPFLAGS="$SAVE_CPPFLAGS"
662       CFLAGS="$SAVE_CFLAGS"
663       LDFLAGS="$SAVE_LDFLAGS"
664       
665       if test -d $dir/include; then
666         CPPFLAGS="$CPPFLAGS -I$dir/include"
667         CFLAGS="$CFLAGS -I$dir/include"
668       fi
669       if test -d $dir/lib; then
670         LDFLAGS="$LDFLAGS -L$dir/lib"
671       fi
672     
673       # XXX
674       unset ac_cv_header__iconv_h_ ac_cv_header_iconv_h || true
675       
676       AC_CHECK_HEADERS(iconv.h,
677         [
678           LIBS="$LIBS -liconv"
679           AC_MSG_CHECKING(for iconv in -liconv)
680           AC_TRY_LINK(
681             [
682               #include <stdlib.h>
683               #include <iconv.h>
684             ],
685             [
686               iconv_t cd = iconv_open("", "");
687               iconv(cd, NULL, NULL, NULL, NULL);
688               iconv_close(cd);
689             ],
690             [
691               echo "yes"
692               has_iconv=true 
693               AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
694             ],
695             [
696               echo "no"
697               has_iconv=false
698             ])
699          ])
700       fi
701     done
702 fi
703
704 if test x$has_iconv = xtrue; then
705   # (1) Some implementations of iconv won't convert from UTF-8 to UTF-8.
706   # (2) In glibc-2.1.2 and earlier there is a bug that messes up ob and
707   #     obl when args 2 and 3 are 0 (fixed in glibc-2.1.3).
708   #
709   AC_CACHE_CHECK([whether this iconv is good enough], ac_iconv_good,
710     AC_TRY_RUN(
711       [
712         #include <iconv.h>
713         int main() {
714           iconv_t cd;
715         changequote(, )dnl
716           char buf[4];
717         changequote([, ])dnl
718           char *ob;
719           size_t obl;
720           ob = buf, obl = sizeof(buf);
721           return ((cd = iconv_open("UTF-8", "UTF-8")) != (iconv_t)(-1) &&
722                  (iconv(cd, 0, 0, &ob, &obl) ||
723                  !(ob == buf && obl == sizeof(buf)) ||
724                  iconv_close(cd)));
725         }
726       ],
727       [
728         ac_iconv_good=yes
729       ],
730       [
731         ac_iconv_good=no
732       ],
733       [
734         ac_iconv_good=yes
735       ])
736     )
737
738   if test x$ac_iconv_good = xno; then
739     AC_MSG_RESULT(Try using libiconv instead.)
740   fi
741 fi
742
743 # POSIX threads support
744 #
745 has_threads=false
746 AC_MSG_CHECKING(whether to search for POSIX threads)
747 AC_ARG_WITH(pthreads,
748   [[  --with-pthreads[=DIR]   use POSIX threads [search in DIR/include and DIR/lib]]],
749   [ 
750     case "${withval}" in
751       no)
752         check_threads=false
753         ;;
754       *)
755         if test -d $withval/include; then
756           CPPFLAGS="$CPPFLAGS -I$withval/include"
757           CFLAGS="$CFLAGS -I$withval/include"
758         fi
759         if test -d $withval/lib; then
760           LDFLAGS="$LDFLAGS -L$withval/lib"
761         fi
762
763         check_threads=true
764         ;;
765     esac
766   ])
767
768 if test x$check_threads = xtrue; then
769   AC_MSG_RESULT(yes)
770   AC_CHECK_HEADERS(pthread.h,
771     [
772       SAVE_LIBS="$LIBS"
773       LIBS="$LIBS -lpthread"
774       AC_CHECK_LIB(pthread, pthread_attr_init, has_threads=true,
775         [
776           # FreeBSD
777           case "${target}" in
778             *-*-freebsd*)
779               LIBS="$SAVE_LIBS -pthread"
780               AC_CHECK_LIB(c_r, pthread_attr_init, has_threads=true)
781               ;;
782           esac
783         ])
784     ],
785     [
786       # search for pthread library..
787       SAVE_CPPFLAGS="$CPPFLAGS"
788       SAVE_CFLAGS="$CFLAGS"
789       SAVE_LDFLAGS="$LDFLAGS"
790
791       for dir in `echo "/usr/local /usr/pkg /usr/contrib /usr/pkg/pthreads /usr/local/pthreads"`; do
792         if test x$has_threads = xfalse; then
793           AC_MSG_RESULT(searching in $dir...)
794   
795           CPPFLAGS="$SAVE_CPPFLAGS"
796           CFLAGS="$SAVE_CFLAGS"
797           LDFLAGS="$SAVE_LDFLAGS"
798   
799           if test -d $dir/include; then
800             CPPFLAGS="$CPPFLAGS -I$dir/include"
801             CFLAGS="$CFLAGS -I$dir/include"
802           fi
803           if test -d $dir/lib; then
804             LDFLAGS="$LDFLAGS -L$dir/lib"
805           fi
806
807           # XXX
808           unset ac_cv_header__pthread_h_ ac_cv_header_pthread_h || true
809
810           AC_CHECK_HEADERS(pthread.h,
811             [ 
812               LIBS="$LIBS -lpthread"
813               AC_CHECK_LIB(pthread, pthread_attr_init, has_threads=true,
814                                                        has_threads=false)
815             ])
816         fi
817       done
818     ])
819 else
820   AC_MSG_RESULT(no)
821   has_threads=false
822 fi
823
824 AM_CONDITIONAL(SILC_THREADS, test x$has_threads = xtrue)
825 if test x$has_threads = xtrue; then
826   CFLAGS="$CFLAGS -D_REENTRANT"
827
828   # XXX possibly incomplete
829   case "${target}" in
830     *-*-aix*)
831       CFLAGS="$CFLAGS -D_THREAD_SAFE"
832       if test x"$GCC" = xyes; then
833         CFLAGS="$CFLAGS -mthreads"
834       fi
835       ;;
836     *-*-freebsd*)
837       CFLAGS="$CFLAGS -D_THREAD_SAFE"
838       ;;
839     *-*-sysv5uw7*)  # UnixWare 7
840       if test "$GCC" != "yes"; then
841         CFLAGS="$CFLAGS -Kthread"
842       else
843         CFLAGS="$CFLAGS -pthread"
844       fi
845       ;;
846     *-dg-dgux*)  # DG/UX
847       CFLAGS="$CFLAGS -D_POSIX4A_DRAFT10_SOURCE"
848       ;;
849    esac
850
851   AC_CHECK_FUNC(pthread_create)
852   AC_DEFINE(SILC_HAVE_PTHREAD)
853   AC_DEFINE(SILC_THREADS)
854 fi
855
856 # Native WIN32 compilation under cygwin
857 #
858 AC_MSG_CHECKING(whether to compile native WIN32 code)
859 AC_ARG_WITH(win32,
860   [  --with-win32            compile native WIN32 code (-mno-cygwin)],
861   [
862     AC_MSG_RESULT(yes)
863     AC_DEFINE(SILC_WIN32)
864     win32_support=true
865     CFLAGS="-mno-cygwin $CFLAGS"
866     LIBS="$LIBS -lwsock32"
867   ],
868   [
869     AC_MSG_RESULT(no)
870   ])
871 AM_CONDITIONAL(SILC_WIN32, test x$win32_support = xtrue)
872
873 # Native EPOC support (disabled by default)
874 #
875 AM_CONDITIONAL(SILC_EPOC, test xfalse = xtrue)
876
877 # Native BeOS support (disabled by default)
878 #
879 AM_CONDITIONAL(SILC_BEOS, test xfalse = xtrue)
880
881 # Native OS2 support (disabled by default)
882 #
883 AM_CONDITIONAL(SILC_OS2, test xfalse = xtrue)
884
885 # --without-irssi
886 #
887 without_irssi=false
888 AC_MSG_CHECKING(whether to compile Irssi SILC Client)
889 AC_ARG_WITH(irssi,
890   [  --without-irssi         compile without Irssi SILC Client],
891   [
892     AC_MSG_RESULT(no)
893     without_irssi=true
894     SILC_DIST_SUBDIRS=`echo $SILC_DIST_SUBDIRS | $sedpath -e 's/irssi//'`
895   ],
896   [
897     AC_MSG_RESULT(yes)
898   ])
899
900 # --without-silcd
901 #
902 without_silcd=false
903 AC_MSG_CHECKING(whether to compile SILC Server)
904 AC_ARG_WITH(silcd,
905   [  --without-silcd         compile without SILC Server],
906   [
907     AC_MSG_RESULT(no)
908     without_silcd=true
909     SILC_DIST_SUBDIRS=`echo $SILC_DIST_SUBDIRS | $sedpath -e 's/silcd//'`
910   ],
911   [
912     AC_MSG_RESULT(yes)
913   ])
914
915
916 ##
917 ##  Misc
918 ##
919
920 # Other configure scripts
921 #
922 if test x$without_irssi = xfalse; then
923   if test "x$silc_dist" = "xsilc-client" ||
924      test "x$silc_dist" = "xsilc-toolkit"; then
925     AC_CONFIG_SUBDIRS(irssi)
926   fi
927 fi
928
929 if test x$mp_gmp = xfalse; then
930   AC_CONFIG_SUBDIRS(lib/silcmath/mpi)
931 fi
932
933 #AC_CONFIG_SUBDIRS(lib/zlib)
934
935 SILC_TOP_SRCDIR=`pwd`
936 AC_SUBST(SILC_TOP_SRCDIR)
937 #SILC_INSTALL_PREFIX=$ac_default_prefix
938 #AC_SUBST(SILC_INSTALL_PREFIX)
939 AC_SUBST(LIBS)
940 INCLUDE_DEFINES_INT="include \$(top_srcdir)/Makefile.defines_int"
941 AC_SUBST(INCLUDE_DEFINES_INT)
942 AC_SUBST(SILC_DIST_SUBDIRS)
943
944 # Makefile outputs
945 #
946 AC_CONFIG_FILES(
947 Makefile
948 Makefile.defines
949 Makefile.defines_int
950 doc/Makefile
951 includes/Makefile
952 lib/Makefile
953 lib/contrib/Makefile
954 lib/silccore/Makefile
955 lib/silccrypt/Makefile
956 lib/silcmath/Makefile
957 lib/silcmath/mpi/Makefile.defines
958 lib/silcmath/mpi/Makefile.defines_int
959 lib/silcsim/Makefile
960 lib/silcske/Makefile
961 lib/silcutil/Makefile
962 lib/silcutil/unix/Makefile
963 lib/silcutil/win32/Makefile
964 lib/silcutil/beos/Makefile
965 lib/silcutil/os2/Makefile
966 lib/silcutil/epoc/Makefile
967 lib/silcsftp/Makefile
968 lib/silcsftp/tests/Makefile
969 doc/example_silcd.conf
970 )
971
972 if test "x$silc_dist" = "xsilc-client" ||
973    test "x$silc_dist" = "xsilc-toolkit"; then
974   AC_CONFIG_FILES(lib/silcclient/Makefile)
975 fi
976
977 if test x$without_irssi = xfalse ; then
978   if test "x$silc_dist" = "xsilc-client" ||
979      test "x$silc_dist" = "xsilc-toolkit"; then
980     AC_CONFIG_FILES(
981 irssi/Makefile.defines
982 irssi/Makefile.defines_int
983 )
984   fi
985 fi
986
987 if test x$without_silcd = xfalse ; then
988   if test "x$silc_dist" = "xsilc-server" ||
989      test "x$silc_dist" = "xsilc-toolkit"; then
990     AC_CONFIG_FILES(
991 silcd/Makefile
992 )
993   fi
994 fi
995
996 if test "x$silc_dist" = "xsilc-toolkit"; then
997   AC_CONFIG_FILES(
998 silc/Makefile
999 win32/Makefile
1000 win32/libsilc/Makefile
1001 win32/libsilcclient/Makefile
1002 )
1003 fi
1004
1005 # Use our configuration in compilation
1006 CFLAGS="-DHAVE_SILCDEFS_H $CFLAGS"
1007
1008 AC_OUTPUT
1009
1010 s_bindir=`eval echo $bindir`;s_bindir=`eval echo $s_bindir`
1011 s_sbindir=`eval echo $sbindir`;s_sbindir=`eval echo $s_sbindir`
1012 s_mandir=`eval echo $mandir`;s_mandir=`eval echo $s_mandir`
1013 s_includedir=`eval echo $includedir`;s_includedir=`eval echo $s_includedir`
1014
1015 echo ""
1016 echo "SILC Configuration Summary:"
1017 echo "---------------------------"
1018 echo " Target host ...................: $target"
1019 echo " Compiler ......................: $CC"
1020 echo " CFLAGS ........................: $CFLAGS"
1021 echo " CPPFLAGS ......................: $CPPFLAGS"
1022 echo " LDFLAGS .......................: $LDFLAGS"
1023 echo " LIBS ..........................: $LIBS"
1024 echo ""
1025 echo " Installation prefix ...........: $prefix"
1026 echo " bin directory .................: $s_bindir"
1027 echo " sbin directory ................: $s_sbindir"
1028 echo " man directory .................: $s_mandir"
1029 echo " help directory ................: $HELPDIR"
1030 echo " doc directory .................: $DOCDIR"
1031 echo " logs directory ................: $LOGSDIR"
1032 echo " SIM directory .................: $MODULESDIR"
1033 echo " include directory .............: $s_includedir"
1034 echo ""
1035
1036 if test "x$silc_dist" = "xsilc-client" ||
1037    test "x$silc_dist" = "xsilc-toolkit"; then
1038   irssi="yes"
1039   if test x$without_irssi = xtrue; then
1040     irssi="no"
1041   fi
1042 echo " Compile SILC Client ...........: $irssi"
1043 fi
1044
1045 if test "x$silc_dist" = "xsilc-server" ||
1046    test "x$silc_dist" = "xsilc-toolkit"; then
1047   silcd="yes"
1048   if test x$without_silcd = xtrue; then
1049     without_silcd="no"
1050   fi
1051 echo " Compile SILC Server ...........: $silcd"
1052 echo " Server configuration file .....: $summary_silcd_configfile"
1053 echo " Server PID file ...............: $PIDFILE"
1054 fi
1055
1056 if test x$sim_support = xfalse; then
1057   sim_support="no"
1058 else
1059   sim_support="yes"
1060 fi
1061 echo " SIM support ...................: $sim_support"
1062 echo " IPv6 support ..................: $summary_ipv6"
1063 echo " Assmebler optimizations .......: $summary_asm"
1064
1065 mp="MPI"
1066 if test x$mp_gmp = xtrue; then
1067   mp="GMP"
1068 fi
1069 echo " Arithmetic library ............: $mp"
1070
1071 threads="no"
1072 if test x$has_threads = xtrue; then
1073   threads="yes"
1074 fi
1075 echo " Multi-threads support .........: $threads"
1076 echo " Debugging enabled .............: $summary_debug"
1077 echo " Stack-trace enabled ...........: $summary_stacktrace"
1078 echo ""
1079 if test "x$silc_dist" = "xsilc-client"; then
1080   echo "Compile the sources with 'make' or 'gmake' command (GNU make is required)."
1081 else
1082   echo "Compile the sources with 'make' or 'gmake' command."
1083 fi