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