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