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