Merged from silc_1_0_branch.
[silc.git] / configure.in.pre
index 9c87858b39db025942c892cf4301e9ceaca0cf5e..671dac894b0f2fabe6e7c1f8ce2c30b203f3873e 100644 (file)
@@ -22,6 +22,9 @@ AC_INIT(includes/silcversion.h)
 #
 AC_CANONICAL_SYSTEM
 case "$target" in
+  *-*-freebsd*)
+    check_threads=true
+    ;;
   *-*-*bsd*)
     check_threads=false
     ;;
@@ -34,7 +37,7 @@ esac
 #
 AM_INIT_AUTOMAKE(SILC_PACKAGE, SILC_VERSION)
 AC_PREREQ(2.52)
-AM_CONFIG_HEADER(includes/silcdefs.h)
+AC_CONFIG_HEADERS(includes/silcdefs.h)
 
 AC_PROG_CC
 AC_C_INLINE
@@ -57,11 +60,54 @@ if test "$GCC"; then
   CFLAGS="-Wall -finline-functions $CFLAGS"
 fi
 
+#
+# Library versioning.
+#
+# Do the releases and library versioning according to following rules:
+#
+#  - If any code has changed in library, increment [LIB]_REVISION
+#  - If functions were added, set [LIB]_REVISION to 0
+#  - If functions were added, removed or changed, increment [LIB]_CURRENT
+#  - If functions were added, increment [LIB]_AGE
+#  - If functions were removed, set [LIB]_AGE to 0
+#
+# where [LIB] is LIBSILC and LIBSILCCLIENT, and where "functions" means
+# functions public interfaces.
+#
+# The LIB_BASE_VERSION defines the SILC software major.minor version and 
+# it is increment only when these version numbers actually change.
+#
+
+# Base version for libraries.  Do not change this unless SILC version
+# changes too.
+LIB_BASE_VERSION=1.0
+
+# libsilc versions
+LIBSILC_CURRENT=1
+LIBSILC_REVISION=0
+LIBSILC_AGE=1
+
+# libsilcclient versions
+LIBSILCCLIENT_CURRENT=1
+LIBSILCCLIENT_REVISION=1
+LIBSILCCLIENT_AGE=0
+
+# Substitute the version numbers
+AC_SUBST(LIB_BASE_VERSION)
+AC_SUBST(LIBSILC_CURRENT)
+AC_SUBST(LIBSILC_REVISION)
+AC_SUBST(LIBSILC_AGE)
+AC_SUBST(LIBSILCCLIENT_CURRENT)
+AC_SUBST(LIBSILCCLIENT_REVISION)
+AC_SUBST(LIBSILCCLIENT_AGE)
+
+#
 # Program checking
 #
 AC_PROG_INSTALL
 AC_PROG_RANLIB
 AC_PROG_MAKE_SET
+AC_DISABLE_SHARED
 AC_PROG_LIBTOOL
 AC_PATH_PROG(sedpath, sed)
 
@@ -89,17 +135,17 @@ AC_TYPE_UID_T
 AC_TYPE_PID_T
 
 AC_CHECK_SIZEOF(long long, 0)
-AC_DEFINE_UNQUOTED(SILC_SIZEOF_LONG_LONG, $ac_cv_sizeof_long_long)
+AC_SUBST(SILC_SIZEOF_LONG_LONG, $ac_cv_sizeof_long_long)
 AC_CHECK_SIZEOF(long, 0)
-AC_DEFINE_UNQUOTED(SILC_SIZEOF_LONG, $ac_cv_sizeof_long)
+AC_SUBST(SILC_SIZEOF_LONG, $ac_cv_sizeof_long)
 AC_CHECK_SIZEOF(int, 0)
-AC_DEFINE_UNQUOTED(SILC_SIZEOF_INT, $ac_cv_sizeof_int)
+AC_SUBST(SILC_SIZEOF_INT, $ac_cv_sizeof_int)
 AC_CHECK_SIZEOF(short, 0)
-AC_DEFINE_UNQUOTED(SILC_SIZEOF_SHORT, $ac_cv_sizeof_short)
+AC_SUBST(SILC_SIZEOF_SHORT, $ac_cv_sizeof_short)
 AC_CHECK_SIZEOF(char, 0)
-AC_DEFINE_UNQUOTED(SILC_SIZEOF_CHAR, $ac_cv_sizeof_char)
+AC_SUBST(SILC_SIZEOF_CHAR, $ac_cv_sizeof_char)
 AC_CHECK_SIZEOF(void *, 0)
-AC_DEFINE_UNQUOTED(SILC_SIZEOF_VOID_P, $ac_cv_sizeof_void_p)
+AC_SUBST(SILC_SIZEOF_VOID_P, $ac_cv_sizeof_void_p)
 
 # Function and library checking
 #
@@ -118,7 +164,7 @@ AC_CHECK_FUNCS(select listen bind shutdown close connect setsockopt)
 AC_CHECK_FUNCS(time ctime utime gettimeofday)
 AC_CHECK_FUNCS(chmod fcntl stat fstat getenv putenv strerror)
 AC_CHECK_FUNCS(getpid getgid getsid getpgid getpgrp getuid)
-AC_CHECK_FUNCS(setgroups initgroups pthread_create nl_langinfo)
+AC_CHECK_FUNCS(setgroups initgroups nl_langinfo)
 AC_CHECK_FUNCS(strchr strstr strcpy strncpy memcpy memset memmove)
 
 # SIM support checking
@@ -126,22 +172,24 @@ AC_CHECK_FUNCS(strchr strstr strcpy strncpy memcpy memset memmove)
 # XXX This probably needs to be made platform dependant check.
 #
 sim_support=false
-AC_CHECKING(for SIM support)
+AC_MSG_CHECKING(for SIM support)
+AC_MSG_RESULT()
 AC_CHECK_HEADERS(dlfcn.h,
-  AC_CHECK_LIB(dl, dlopen,
-    [
-      AC_DEFINE(SILC_SIM)
-      sim_support=true
-      LIBS="$LIBS -ldl"
-    ],
-    [
-      AC_CHECK_LIB(c, dlopen,
-        [
-          AC_DEFINE(SILC_SIM)
-          sim_support=true
-        ])
-    ])
-  )
+  [
+    AC_CHECK_LIB(dl, dlopen,
+      [
+        AC_DEFINE(SILC_SIM)
+        sim_support=true
+        LIBS="$LIBS -ldl"
+      ],
+      [
+        AC_CHECK_LIB(c, dlopen,
+          [
+            AC_DEFINE(SILC_SIM)
+            sim_support=true
+          ])
+      ])
+   ])
 
 AM_CONDITIONAL(SILC_SIM, test x$sim_support = xtrue)
 if test x$sim_support = xtrue; then
@@ -157,8 +205,131 @@ AM_CONDITIONAL(HAVE_REGEX, test x$have_regex = x1)
 AC_CHECK_FUNC(getopt_long, have_getopt_long=1, have_getopt_long=0)
 AM_CONDITIONAL(HAVE_GETOPT_LONG, test x$have_getopt_long = x1)
 
-# Installation
+
+##
+##  Enable/disable checking
+##
+
+# IPv6 support
+#
+AC_MSG_CHECKING(whether to enable IPv6 support)
+AC_ARG_ENABLE(ipv6,
+  [  --enable-ipv6           enable IPv6 support],
+  [
+    case "${enableval}" in
+      yes)
+        want_ipv6=true
+        check_ipv6=false
+       summary_ipv6="yes"
+        AC_DEFINE(HAVE_IPV6)
+        AC_MSG_RESULT(yes)
+        ;;
+      *)
+        want_ipv6=false
+        check_ipv6=false
+       summary_ipv6="no"
+        AC_MSG_RESULT(no)
+        ;;
+    esac
+  ],
+    check_ipv6=true
+  )
+
+if test x$check_ipv6 = xtrue; then
+  summary_ipv6="no"
+  AC_TRY_COMPILE(
+    [
+      #ifdef HAVE_SYS_TYPES_H
+      #include <sys/types.h>
+      #endif
+      #ifdef HAVE_NETINET_TCP_H
+      #include <netinet/tcp.h>
+      #endif
+      #ifdef HAVE_NETDB_H
+      #include <netdb.h>
+      #endif
+      #include <sys/socket.h>
+      #ifdef HAVE_NETINET_IN_H
+      #include <netinet/in.h>
+      #endif
+    ],
+    [
+      struct sockaddr_in6 sin6;
+      int family = AF_INET6;
+    ],
+    [
+      AC_DEFINE(HAVE_IPV6)
+      AC_MSG_RESULT(yes)
+      summary_ipv6="yes"
+    ],
+      AC_MSG_RESULT(no)
+    )
+fi
+
+# Debug checking
 #
+AC_MSG_CHECKING(whether to enable debugging)
+summary_debug="no"
+AC_ARG_ENABLE(debug,
+  [  --enable-debug          enable debugging],
+  [
+    case "${enableval}" in
+      yes)
+        AC_MSG_RESULT(yes)
+        AC_DEFINE(SILC_DEBUG)
+        CFLAGS="-O -g $CFLAGS"
+       summary_debug="yes"
+        ;;
+      *)
+        AC_MSG_RESULT(no)
+        CFLAGS="-O2 -g $CFLAGS"
+        ;;
+    esac
+  ],
+  [
+    CFLAGS="-O2 -g $CFLAGS"
+    AC_MSG_RESULT(no)
+  ])
+
+# Stack trace checking
+#
+AC_MSG_CHECKING(whether to enable stack tracing)
+summary_stacktrace="no"
+AC_ARG_ENABLE(stack-trace,
+  [  --enable-stack-trace    enable memory stack trace],
+  [
+    case "${enableval}" in
+    yes)
+      AC_MSG_RESULT(yes)
+      AC_DEFINE(SILC_STACKTRACE)
+      summary_stacktrace="yes"
+      ;;
+    *)
+      AC_MSG_RESULT(no)
+      ;;
+    esac
+  ],
+    AC_MSG_RESULT(no)
+  )
+
+# Disable all assembler optimizations
+#
+AC_MSG_CHECKING(whether to enable assembler optimizations)
+summary_asm="no"
+AC_ARG_ENABLE(asm,
+  [  --disable-asm           do not use assembler optimizations],
+  [
+    AC_MSG_RESULT(no)
+  ],
+  [
+    AC_MSG_RESULT(yes)
+    summary_asm="yes"
+  ])
+
+
+##
+##  Installation
+##
 
 # Default installation destination
 #
@@ -178,13 +349,10 @@ else
 fi
 
 AC_ARG_WITH(etcdir,
-  [  --with-etcdir[=PATH]      Directory for system files [/etc/silc]],
+  [[  --with-etcdir=DIR       directory for system files [/etc/silc]]],
   [
     case "$withval" in
-      no)
-        ;;
-      yes)
-        ETCDIR="$withval"
+      no|yes)
         ;;
       *)
         ETCDIR="$withval"
@@ -198,13 +366,10 @@ AC_DEFINE_UNQUOTED(SILC_ETCDIR, "$ETCDIR")
 #
 HELPDIR="$silc_prefix/help"
 AC_ARG_WITH(helpdir,
-  [  --with-helpdir[=PATH]     Directory for SILC help files [PREFIX/help]],
+  [[  --with-helpdir=DIR      directory for SILC help files [PREFIX/help]]],
   [
     case "$withval" in
-      no)
-        ;;
-      yes)
-        HELPDIR="$withval"
+      no|yes)
         ;;
       *)
        HELPDIR="$withval"
@@ -218,13 +383,10 @@ AC_DEFINE_UNQUOTED(SILC_HELPDIR, "$HELPDIR")
 #
 DOCDIR="$silc_prefix/doc"
 AC_ARG_WITH(docdir,
-  [  --with-docdir[=PATH]      Directory for SILC documentation [PREFIX/doc]],
+  [[  --with-docdir=DIR       directory for SILC documentation [PREFIX/doc]]],
   [
     case "$withval" in
-      no)
-        ;;
-      yes)
-        DOCDIR="$withval"
+      no|yes)
         ;;
       *)
         DOCDIR="$withval"
@@ -238,13 +400,10 @@ AC_DEFINE_UNQUOTED(SILC_DOCDIR, "$DOCDIR")
 #
 MODULESDIR="$silc_prefix/modules"
 AC_ARG_WITH(simdir,
-  [  --with-simdir[=PATH]      Directory for SIM modules [PREFIX/modules]],
+  [[  --with-simdir=DIR       directory for SIM modules [PREFIX/modules]]],
   [
     case "$withval" in
-      no)
-        ;;
-      yes)
-        MODULESDIR="$withval"
+      no|yes)
         ;;
       *)
         MODULESDIR="$withval"
@@ -258,13 +417,10 @@ AC_DEFINE_UNQUOTED(SILC_MODULESDIR, "$MODULESDIR")
 #
 LOGSDIR="$silc_prefix/logs"
 AC_ARG_WITH(logsdir,
-  [  --with-logsdir[=PATH]     Directory for Server logs [PREFIX/logs]],
+  [[  --with-logsdir=DIR      directory for SILC Server logs [PREFIX/logs]]],
   [
     case "$withval" in
-      no)
-        ;;
-      yes)
-        LOGSDIR="$withval"
+      no|yes)
         ;;
       *)
         LOGSDIR="$withval"
@@ -274,11 +430,51 @@ AC_ARG_WITH(logsdir,
 AC_SUBST(LOGSDIR)
 AC_DEFINE_UNQUOTED(SILC_LOGSDIR, "$LOGSDIR")
 
+# silcd config file checking
+#
+summary_silcd_configfile="/etc/silc/silcd.conf"
+AC_ARG_WITH(silcd-config-file,
+  [[  --with-silcd-config-file=FILE  use FILE as default configuration file
+                                 for SILC Server [/etc/silc/silcd.conf]]],
+    AC_DEFINE_UNQUOTED(SILC_SERVER_CONFIG_FILE, "$withval")
+    summary_silcd_configfile="$withval"
+  )
+
+# silcd pid file checking
+#
+if test "x$localstatedir" != 'x${prefix}/var'; then
+  PIDFILE="$localstatedir/silcd.pid"
+else
+  PIDFILE="$silc_prefix/var/silcd.pid"
+fi
+
+AC_ARG_WITH(silcd-pid-file,
+  [[  --with-silcd-pid-file=FILE     use FILE as default pid file for SILC
+                                 Server [/var/run/silcd.pid]]],
+  [
+    case "$withval" in
+      no|yes)
+        ;;
+      *)
+        PIDFILE="$withval"
+        ;;
+    esac
+  ])
+AC_SUBST(PIDFILE)
+
+
+##
+##  With/without checkings
+##
+
 # SOCKS4 support checking
 #
+SAVE_LIBS="$LIBS"
+SAVE_CFLAGS="$CFLAGS"
+SAVE_LDFLAGS="$LDFLAGS"
 AC_MSG_CHECKING(whether to support SOCKS4)
 AC_ARG_WITH(socks4,
-  [  --with-socks4[=PATH]      Compile with SOCKS4 support],
+  [[  --with-socks4[=DIR]     with SOCKS4 support [search in DIR/lib and DIR/include]]],
   [
     case "$withval" in
       no)
@@ -290,34 +486,37 @@ AC_ARG_WITH(socks4,
     
         if test -d "$withval/include"; then
           CFLAGS="$CFLAGS -I$withval/include"
-        else
-          CFLAGS="$CFLAGS -I$withval"
         fi
         if test -d "$withval/lib"; then
-          withval="-L$withval/lib -lsocks"
-        else
-          withval="-L$withval -lsocks"
+          LDFLAGS="$LDFLAGS -L$withval/lib"
         fi
     
-        LIBS="$withval $LIBS"
-        AC_TRY_LINK([],
-          [
-            Rconnect();
-          ], [],
-          [
-            AC_MSG_ERROR(Could not find SOCKS4 library.)
-          ])
+        LIBS="-lsocks $LIBS"
         ;;
     esac
+
+    AC_TRY_LINK([],
+      [
+        Rconnect();
+      ], [],
+      [
+        AC_MSG_ERROR(Could not find SOCKS4 library.)
+        LIBS="$SAVE_LIBS"
+        CFLAGS="$SAVE_CFLAGS"
+        LDFLAGS="$SAVE_LDFLAGS"
+      ])
   ],
     AC_MSG_RESULT(no)
   )
 
 # SOCKS5 support checking
 #
+SAVE_LIBS="$LIBS"
+SAVE_CFLAGS="$CFLAGS"
+SAVE_LDFLAGS="$LDFLAGS"
 AC_MSG_CHECKING(whether to support SOCKS5)
 AC_ARG_WITH(socks5,
-  [  --with-socks5[=PATH]      Compile with SOCKS5 support],
+  [[  --with-socks5[=DIR]     with SOCKS5 support [search in DIR/lib and DIR/include]]],
   [
     case "$withval" in
       no)
@@ -329,25 +528,25 @@ AC_ARG_WITH(socks5,
 
         if test -d "$withval/include"; then
           CFLAGS="$CFLAGS -I$withval/include"
-        else
-          CFLAGS="$CFLAGS -I$withval"
         fi
         if test -d "$withval/lib"; then
-          withval="-L$withval/lib -lsocks5"
-        else
-          withval="-L$withval -lsocks5"
+          LDFLAGS="$LDFLAGS -L$withval/lib"
         fi
 
-        LIBS="$withval $LIBS"
-        AC_TRY_LINK([],
-          [
-            SOCKSconnect();
-          ], [],
-          [
-            AC_MSG_ERROR(Could not find SOCKS5 library.)
-          ])
+        LIBS="-lsocks5 $LIBS"
         ;;
     esac
+
+    AC_TRY_LINK([],
+      [
+        SOCKSconnect();
+      ], [],
+      [
+        AC_MSG_ERROR(Could not find SOCKS5 library.)
+        LIBS="$SAVE_LIBS"
+        CFLAGS="$SAVE_CFLAGS"
+        LDFLAGS="$SAVE_LDFLAGS"
+      ])
   ],
     AC_MSG_RESULT(no)
   )
@@ -388,9 +587,12 @@ fi
 # source tree.
 #
 mp_gmp=false
-AC_MSG_CHECKING(whether to support GMP)
+SAVE_LIBS="$LIBS"
+SAVE_CFLAGS="$CFLAGS"
+SAVE_LDFLAGS="$LDFLAGS"
+AC_MSG_CHECKING(whether to search for GMP)
 AC_ARG_WITH(gmp,
-  [  --with-gmp[=PATH]         Compile with GMP support instead of MPI],
+  [[  --with-gmp[=DIR]        use GMP instead of MPI [search in DIR/lib and DIR/include]]],
   [
     case "$withval" in
       no)
@@ -401,24 +603,26 @@ AC_ARG_WITH(gmp,
     
         if test -d "$withval/include"; then
           CFLAGS="$CFLAGS -I$withval/include"
-        else
-          CFLAGS="$CFLAGS -I$withval"
         fi
         if test -d "$withval/lib"; then
-          withval="-L$withval/lib -lgmp"
-        else
-          withval="-L$withval -lgmp"
+          LDFLAGS="$LDFLAGS -L$withval/lib"
         fi
     
-        LIBS="$withval $LIBS"
-        AC_CHECK_LIB(gmp, __gmpz_init,
-          [
-            mp_gmp=true
-            AC_DEFINE(SILC_MP_GMP)
-            AC_MSG_RESULT(Using GMP as MP library.)
-          ])
+        LIBS="-lgmp $LIBS"
         ;;
     esac
+
+    AC_CHECK_LIB(gmp, __gmpz_init,
+      [
+        mp_gmp=true
+        AC_DEFINE(SILC_MP_GMP)
+        AC_MSG_RESULT(Using GMP as a MP library.)
+      ],
+      [
+        LIBS="$SAVE_LIBS"
+        CFLAGS="$SAVE_CFLAGS"
+        LDFLAGS="$SAVE_LDFLAGS"
+      ])
   ],
     AC_MSG_RESULT(no)
   )
@@ -427,15 +631,101 @@ AM_CONDITIONAL(SILC_MP_GMP, test x$mp_gmp = xtrue)
 AM_CONDITIONAL(SILC_MP_NSS_MPI, test x$mp_gmp = xfalse)
 if test x$mp_gmp = xfalse; then
   AC_DEFINE(SILC_MP_NSS_MPI)
-  AC_MSG_RESULT(Using NSS MPI as MP library.)
+  AC_MSG_RESULT(Using NSS MPI as MP library.)
 fi
 
 # iconv support
 #
+check_iconv=true
+has_iconv=false
+SAVE_LIBS="$LIBS"
+SAVE_CFLAGS="$CFLAGS"
+SAVE_LDFLAGS="$LDFLAGS"
+SAVE_CPPFLAGS="$CPPFLAGS"
+AC_MSG_CHECKING(whether to implicit search for libiconv)
 AC_ARG_WITH(iconv,
-  [  --with-iconv[=PATH]       Search for libiconv in DIR/include and DIR/lib],
+  [[  --with-iconv[=DIR]      use libiconv [search in DIR/include and DIR/lib]]],
+  [
+    case "${withval}" in
+      no)
+        AC_MSG_RESULT(no)
+        AC_CHECK_HEADERS(iconv.h,
+          [
+            AC_CHECK_FUNC(iconv, has_iconv=true)
+          ])
+        check_iconv=false
+        ;;
+      *)
+        AC_MSG_RESULT(yes)
+        if test -d $withval/include; then
+          CPPFLAGS="$CPPFLAGS -I$withval/include"
+          CFLAGS="$CFLAGS -I$withval/include"
+        fi
+        if test -d $withval/lib; then
+          LDFLAGS="$LDFLAGS -L$withval/lib"
+        fi
+        ;;
+    esac
+  ],
   [
-    for dir in `echo "$withval" | tr : ' '`; do
+    AC_MSG_RESULT(no)
+    AC_CHECK_HEADERS(iconv.h,
+      [
+        AC_CHECK_FUNCS(iconv,
+          [
+            has_iconv=true
+            check_iconv=false
+          ])
+      ])
+  ])
+
+if test x$check_iconv = xtrue; then
+  AC_MSG_RESULT(starting search...)
+
+  # XXX
+  unset ac_cv_header__iconv_h_ ac_cv_header_iconv_h || true
+
+  AC_CHECK_HEADERS(iconv.h,
+    [
+      LIBS="$LIBS -liconv"
+      AC_MSG_CHECKING(for iconv in -liconv)
+      AC_TRY_LINK(
+        [
+          #include <stdlib.h>
+          #include <iconv.h>
+        ],
+        [
+          iconv_t cd = iconv_open("", "");
+          iconv(cd, NULL, NULL, NULL, NULL);
+          iconv_close(cd);
+        ],
+        [
+          echo "yes"
+          AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
+          has_iconv=true
+          check_iconv=false
+        ],
+        [
+          echo "no"
+          LIBS="$SAVE_LIBS"
+          CFLAGS="$SAVE_CFLAGS"
+          LDFLAGS="$SAVE_LDFLAGS"
+          CPPFLAGS="$SAVE_CPPFLAGS"
+        ])
+     ])
+fi
+
+if test x$check_iconv = xtrue; then
+  # search for iconv library..
+  SAVE_LIBS="$LIBS"
+  SAVE_CFLAGS="$CFLAGS"
+  SAVE_LDFLAGS="$LDFLAGS"
+  SAVE_CPPFLAGS="$CPPFLAGS"
+    
+  for dir in `echo "/usr/local /usr/pkg /usr/contrib"`; do
+    if test x$has_iconv = xfalse; then
+      AC_MSG_RESULT(searching in $dir...)
+     
       if test -d $dir/include; then
         CPPFLAGS="$CPPFLAGS -I$dir/include"
         CFLAGS="$CFLAGS -I$dir/include"
@@ -443,35 +733,49 @@ AC_ARG_WITH(iconv,
       if test -d $dir/lib; then
         LDFLAGS="$LDFLAGS -L$dir/lib"
       fi
+    
+      # XXX
+      unset ac_cv_header__iconv_h_ ac_cv_header_iconv_h || true
+      
+      AC_CHECK_HEADERS(iconv.h,
+        [
+          LIBS="$LIBS -liconv"
+          AC_MSG_CHECKING(for iconv in -liconv)
+          AC_TRY_LINK(
+            [
+              #include <stdlib.h>
+              #include <iconv.h>
+            ],
+            [
+              iconv_t cd = iconv_open("", "");
+              iconv(cd, NULL, NULL, NULL, NULL);
+              iconv_close(cd);
+            ],
+            [
+              echo "yes"
+              has_iconv=true 
+              AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
+            ],
+            [
+              echo "no"
+              has_iconv=false
+              LIBS="$SAVE_LIBS"    
+              CFLAGS="$SAVE_CFLAGS"
+              LDFLAGS="$SAVE_LDFLAGS"
+              CPPFLAGS="$SAVE_CPPFLAGS"
+            ])
+         ],
+         [
+           CFLAGS="$SAVE_CFLAGS"
+           LDFLAGS="$SAVE_LDFLAGS"
+           CPPFLAGS="$SAVE_CPPFLAGS"
+         ])
+      fi
     done
-  ])
-
-AC_CHECK_HEADER(iconv.h,
-  [
-    AC_DEFINE(HAVE_ICONV_H, 1, [Define if you have the iconv.h header.])
-    AC_CHECK_FUNC(iconv, ac_iconv_found=1,
-      [
-        LIBS="$LIBS -liconv"
-        AC_MSG_CHECKING(for iconv in -liconv)
-        AC_TRY_LINK(
-          [
-            #include <stdlib.h>
-            #include <iconv.h>
-          ],
-          [
-            iconv_t cd = iconv_open("", "");
-            iconv(cd, NULL, NULL, NULL, NULL);
-            iconv_close(cd);
-          ],
-          [
-            echo "yes"
-            AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
-          ])
-      ])
-   ])
-
-if test x$ac_iconv_found = x1; then
+fi
 
+if test x$has_iconv = xtrue; then
   # (1) Some implementations of iconv won't convert from UTF-8 to UTF-8.
   # (2) In glibc-2.1.2 and earlier there is a bug that messes up ob and
   #     obl when args 2 and 3 are 0 (fixed in glibc-2.1.3).
@@ -506,54 +810,148 @@ if test x$ac_iconv_found = x1; then
     )
 
   if test x$ac_iconv_good = xno; then
-    AC_MSG_ERROR(Try using libiconv instead.)
+    AC_MSG_RESULT(Try using libiconv instead.)
   fi
 fi
 
-# silcd config file checking
-#
-AC_ARG_WITH(silcd-config-file,
-  [  --with-silcd-config-file[=PATH]
-                          Use PATH as default configuration file in SILC
-                          server [/etc/silc/silcd.conf]],
-    AC_DEFINE_UNQUOTED(SILC_SERVER_CONFIG_FILE, "$withval")
-  )
-
-# silcd pid file checking
+# POSIX threads support
 #
-if test "x$localstatedir" != 'x${prefix}/var'; then
-  PIDFILE="$localstatedir/silcd.pid"
-else
-  PIDFILE="$silc_prefix/var/silcd.pid"
-fi
-
-AC_ARG_WITH(silcd-pid-file,
-  [  --with-silcd-pid-file[=PATH]
-                          Use PATH as default pid file in SILC
-                          server [/var/run/silcd.pid]],
-  [
-    case "$withval" in
+has_threads=false
+AC_MSG_CHECKING(whether to search for POSIX threads)
+AC_ARG_WITH(pthreads,
+  [[  --with-pthreads[=DIR]   use POSIX threads [search in DIR/include and DIR/lib]]],
+  [ 
+    case "${withval}" in
       no)
+        check_threads=false
         ;;
-      yes)
-        PIDFILE="$withval"
-       ;;
       *)
-        PIDFILE="$withval"
+        if test -d $withval/include; then
+          CPPFLAGS="$CPPFLAGS -I$withval/include"
+          CFLAGS="$CFLAGS -I$withval/include"
+        fi
+        if test -d $withval/lib; then
+          LDFLAGS="$LDFLAGS -L$withval/lib"
+        fi
+
+        check_threads=true
         ;;
     esac
   ])
-AC_SUBST(PIDFILE)
+
+if test x$check_threads = xtrue; then
+  SAVE_LIBS="$LIBS"
+  SAVE_CFLAGS="$CFLAGS"
+  SAVE_LDFLAGS="$LDFLAGS"
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  
+  AC_MSG_RESULT(yes)
+  AC_CHECK_HEADERS(pthread.h,
+    [
+      LIBS="$LIBS -lpthread"
+      AC_CHECK_LIB(pthread, pthread_attr_init, has_threads=true,
+        [
+          # FreeBSD
+          case "${target}" in
+            *-*-freebsd*)
+              LIBS="$SAVE_LIBS -pthread"
+              AC_CHECK_LIB(c_r, pthread_attr_init, has_threads=true, LIBS="$SAVE_LIBS")
+              ;;
+            *)
+              LIBS="$SAVE_LIBS"
+              ;;
+          esac
+        ])
+    ],
+    [
+      # search for pthread library..
+      for dir in `echo "/usr/local /usr/pkg /usr/contrib /usr/pkg/pthreads /usr/local/pthreads"`; do
+        if test x$has_threads = xfalse; then
+          AC_MSG_RESULT(searching in $dir...)
+  
+          if test -d $dir/include; then
+            CPPFLAGS="$CPPFLAGS -I$dir/include"
+            CFLAGS="$CFLAGS -I$dir/include"
+          fi
+          if test -d $dir/lib; then
+            LDFLAGS="$LDFLAGS -L$dir/lib"
+          fi
+
+          # XXX
+          unset ac_cv_header__pthread_h_ ac_cv_header_pthread_h || true
+
+          AC_CHECK_HEADERS(pthread.h,
+            [ 
+              LIBS="$LIBS -lpthread"
+              AC_CHECK_LIB(pthread, pthread_attr_init, has_threads=true,
+                [
+                  has_threads=false
+
+                  LIBS="$SAVE_LIBS"
+                  CFLAGS="$SAVE_CFLAGS"
+                  LDFLAGS="$SAVE_LDFLAGS"
+                  CPPFLAGS="$SAVE_CPPFLAGS"
+                ])
+            ],
+            [
+              CFLAGS="$SAVE_CFLAGS"
+              LDFLAGS="$SAVE_LDFLAGS"
+              CPPFLAGS="$SAVE_CPPFLAGS"
+            ])
+        fi
+      done
+    ])
+else
+  AC_MSG_RESULT(no)
+  has_threads=false
+fi
+
+AM_CONDITIONAL(SILC_THREADS, test x$has_threads = xtrue)
+if test x$has_threads = xtrue; then
+  CFLAGS="$CFLAGS -D_REENTRANT"
+
+  # XXX possibly incomplete
+  case "${target}" in
+    *-*-aix*)
+      CFLAGS="$CFLAGS -D_THREAD_SAFE"
+      if test x"$GCC" = xyes; then
+        CFLAGS="$CFLAGS -mthreads"
+      fi
+      ;;
+    *-*-freebsd*)
+      CFLAGS="$CFLAGS -D_THREAD_SAFE"
+      ;;
+    *-*-sysv5uw7*)  # UnixWare 7
+      if test "$GCC" != "yes"; then
+        CFLAGS="$CFLAGS -Kthread"
+      else
+        CFLAGS="$CFLAGS -pthread"
+      fi
+      ;;
+    *-dg-dgux*)  # DG/UX
+      CFLAGS="$CFLAGS -D_POSIX4A_DRAFT10_SOURCE"
+      ;;
+   esac
+
+  AC_CHECK_FUNC(pthread_create)
+  AC_DEFINE(SILC_HAVE_PTHREAD)
+  AC_DEFINE(SILC_THREADS)
+fi
 
 # Native WIN32 compilation under cygwin
 #
+AC_MSG_CHECKING(whether to compile native WIN32 code)
 AC_ARG_WITH(win32,
-  [  --with-win32            Compile native WIN32 code (-mno-cygwin)],
+  [  --with-win32            compile native WIN32 code (-mno-cygwin)],
   [
+    AC_MSG_RESULT(yes)
     AC_DEFINE(SILC_WIN32)
     win32_support=true
     CFLAGS="-mno-cygwin $CFLAGS"
     LIBS="$LIBS -lwsock32"
+  ],
+  [
+    AC_MSG_RESULT(no)
   ])
 AM_CONDITIONAL(SILC_WIN32, test x$win32_support = xtrue)
 
@@ -572,227 +970,53 @@ AM_CONDITIONAL(SILC_OS2, test xfalse = xtrue)
 # --without-irssi
 #
 without_irssi=false
+AC_MSG_CHECKING(whether to compile Irssi SILC Client)
 AC_ARG_WITH(irssi,
-  [  --without-irssi         Compile without Irssi SILC Client],
+  [  --without-irssi         compile without Irssi SILC Client],
   [
+    AC_MSG_RESULT(no)
     without_irssi=true
     SILC_DIST_SUBDIRS=`echo $SILC_DIST_SUBDIRS | $sedpath -e 's/irssi//'`
+  ],
+  [
+    AC_MSG_RESULT(yes)
   ])
 
 # --without-silcd
 #
 without_silcd=false
+AC_MSG_CHECKING(whether to compile SILC Server)
 AC_ARG_WITH(silcd,
-  [  --without-silcd         Compile without SILC Server],
+  [  --without-silcd         compile without SILC Server],
   [
+    AC_MSG_RESULT(no)
     without_silcd=true
     SILC_DIST_SUBDIRS=`echo $SILC_DIST_SUBDIRS | $sedpath -e 's/silcd//'`
-  ])
-
-# Disable all assembler optimizations
-#
-AC_ARG_ENABLE(asm,
-  [  --disable-asm           Do not use assembler optimizations ])
-
-# Threads support
-#
-want_threads=false
-AC_ARG_ENABLE(threads,
-  [  --disable-threads       Do not compile with multi-thread support ],
+  ],
   [
-    case "${enableval}" in
-      yes)
-        want_threads=true
-        check_threads=true
-        ;;
-      *)
-        check_threads=false
-        ;;
-    esac
+    AC_MSG_RESULT(yes)
   ])
 
-if test x$check_threads = xtrue; then
-AC_CHECK_HEADERS(pthread.h,
+libtoolfix=true
+AC_MSG_CHECKING(whether to do libtoolfix)
+AC_ARG_WITH(libtoolfix,
+  [  --without-libtoolfix     Do not fix libtool, for package builders],
   [
-    AC_DEFINE(SILC_HAVE_PTHREAD)
-    want_threads=true
+    AC_MSG_RESULT(no)
+    libtoolfix=false
   ],
   [
-    if test -f /usr/pkg/include/pthread.h ; then
-      AC_DEFINE(SILC_HAVE_PTHREAD)
-      want_threads=true
-      AC_MSG_RESULT(Found pthread.h in /usr/pkg/include/)
-      CFLAGS="$CFLAGS -I/usr/pkg/include"
-    elif test -f /usr/contrib/include/pthread.h ; then
-      AC_DEFINE(SILC_HAVE_PTHREAD)
-      want_threads=true
-      AC_MSG_RESULT(Found pthread.h in /usr/contrib/include/)
-      CFLAGS="$CFLAGS -I/usr/contrib/include"
-    fi
+    AC_MSG_RESULT(yes)
   ])
-fi
 
-AM_CONDITIONAL(SILC_THREADS, test x$want_threads = xtrue)
-if test x$want_threads = xtrue; then
-  TMP_LIBS="$LIBS"
-  LIBS="-lpthread"
-  AC_TRY_LINK(
-    [
-      #include <pthread.h>
-    ],
-    [
-      pthread_attr_t attr;
-      pthread_attr_init(&attr);
-    ],
-    [
-      AC_DEFINE(SILC_THREADS)
-    ],
-    [
-      LIBS="-L/usr/pkg/lib -lpthread"
-      AC_TRY_LINK(
-        [
-          #include <pthread.h>
-        ],
-       [
-          pthread_attr_t attr;
-          pthread_attr_init(&attr);
-        ],
-        [
-          AC_DEFINE(SILC_THREADS)
-        ],
-        [
-          LIBS="-L/usr/contrib/lib -lpthread"
-          AC_TRY_LINK(
-            [
-              #include <pthread.h>
-            ],
-            [
-              pthread_attr_t attr;
-              pthread_attr_init(&attr);
-            ],
-            [
-              AC_DEFINE(SILC_THREADS)
-            ],
-              LIBS=""
-            )
-         ])
-    ])
-
-  CFLAGS="$CFLAGS -D_REENTRANT"
-  case $host in
-    *-aix*)
-      CFLAGS="$CFLAGS -D_THREAD_SAFE"
-      if test x"$GCC" = xyes; then
-        CFLAGS="$CFLAGS -mthreads"
-      fi
-      ;;
-    *-freebsd2.2*)
-      CFLAGS="$CFLAGS -D_THREAD_SAFE"
-      ;;
-    *-sysv5uw7*)  # UnixWare 7
-      if test "$GCC" != "yes"; then
-        CFLAGS="$CFLAGS -Kthread"
-      else
-        CFLAGS="$CFLAGS -pthread"
-      fi
-      ;;
-    *-dg-dgux*)  # DG/UX
-      CFLAGS="$CFLAGS -D_POSIX4A_DRAFT10_SOURCE"
-      ;;
-  esac
-  LIBS="$TMP_LIBS $LIBS"
-fi
+AC_SUBST(ETCDIR)
+AC_DEFINE_UNQUOTED(SILC_ETCDIR, "$ETCDIR")
 
-# IPv6 support
-#
-AC_MSG_CHECKING(for IPv6 support)
-AC_ARG_ENABLE(ipv6,
-  [  --enable-ipv6           Enable IPv6 support],
-  [
-    case "${enableval}" in
-      yes)
-        want_ipv6=true
-        check_ipv6=false
-        AC_DEFINE(HAVE_IPV6)
-        AC_MSG_RESULT(yes)
-        ;;
-      *)
-        want_ipv6=false
-        check_ipv6=false
-        AC_MSG_RESULT(no)
-        ;;
-    esac
-  ],
-    check_ipv6=true
-  )
 
-if test x$check_ipv6 = xtrue; then
-  AC_TRY_COMPILE(
-    [
-      #ifdef HAVE_NETINET_TCP_H
-      #include <netinet/tcp.h>
-      #endif
-      #ifdef HAVE_NETDB_H
-      #include <netdb.h>
-      #endif
-      #include <sys/socket.h>
-      #ifdef HAVE_NETDB_IN_H
-      #include <netinet/in.h>
-      #endif
-    ],
-    [
-      struct sockaddr_in6 sin6;
-      int family = AF_INET6;
-    ],
-    [
-      AC_DEFINE(HAVE_IPV6)
-      AC_MSG_RESULT(yes)
-    ],
-      AC_MSG_RESULT(no)
-    )
-fi
 
-# Debug checking
-#
-AC_MSG_CHECKING(for enabled debugging)
-AC_ARG_ENABLE(debug,
-  [  --enable-debug          Enable debugging],
-  [
-    case "${enableval}" in
-      yes)
-        AC_MSG_RESULT(yes)
-        AC_DEFINE(SILC_DEBUG)
-        CFLAGS="-O -g $CFLAGS"
-      ;;
-    *)
-      AC_MSG_RESULT(no)
-      CFLAGS="-O2 -g $CFLAGS"
-      ;;
-    esac
-  ],
-  [
-    CFLAGS="-O2 -g $CFLAGS"
-    AC_MSG_RESULT(no)
-  ])
-
-# Stack trace checking
-#
-AC_MSG_CHECKING(for enabled stack tracing)
-AC_ARG_ENABLE(stack-trace,
-  [  --enable-stack-trace    Enable memory stack trace],
-  [
-    case "${enableval}" in
-    yes)
-      AC_MSG_RESULT(yes)
-      AC_DEFINE(SILC_STACKTRACE)
-      ;;
-    *)
-      AC_MSG_RESULT(no)
-      ;;
-    esac
-  ],
-    AC_MSG_RESULT(no)
-  )
+##
+##  Misc
+##
 
 # Other configure scripts
 #
@@ -803,7 +1027,10 @@ if test x$without_irssi = xfalse; then
   fi
 fi
 
-AC_CONFIG_SUBDIRS(lib/silcmath/mpi)
+if test x$mp_gmp = xfalse; then
+  AC_CONFIG_SUBDIRS(lib/silcmath/mpi)
+fi
+
 #AC_CONFIG_SUBDIRS(lib/zlib)
 
 SILC_TOP_SRCDIR=`pwd`
@@ -815,6 +1042,18 @@ INCLUDE_DEFINES_INT="include \$(top_srcdir)/Makefile.defines_int"
 AC_SUBST(INCLUDE_DEFINES_INT)
 AC_SUBST(SILC_DIST_SUBDIRS)
 
+#
+# Fix the libtool to support run-time configuration.  This allows us
+# to in run-time specify when to compile shared/static libraries without
+# need to reconfigure the entire libtool.
+#
+if test x$libtoolfix = xtrue; then
+  ./libtoolfix $SILC_TOP_SRCDIR/ltmain.sh
+fi
+AM_CONDITIONAL(SILC_LIBTOOLFIX, test x$libtoolfix = xtrue)
+
+
+#
 # Makefile outputs
 #
 AC_CONFIG_FILES(
@@ -826,7 +1065,9 @@ includes/Makefile
 lib/Makefile
 lib/contrib/Makefile
 lib/silccore/Makefile
+lib/silccore/tests/Makefile
 lib/silccrypt/Makefile
+lib/silccrypt/tests/Makefile
 lib/silcmath/Makefile
 lib/silcmath/mpi/Makefile.defines
 lib/silcmath/mpi/Makefile.defines_int
@@ -841,6 +1082,7 @@ lib/silcutil/epoc/Makefile
 lib/silcsftp/Makefile
 lib/silcsftp/tests/Makefile
 doc/example_silcd.conf
+includes/silcincludes.h
 )
 
 if test "x$silc_dist" = "xsilc-client" ||
@@ -873,7 +1115,85 @@ silc/Makefile
 win32/Makefile
 win32/libsilc/Makefile
 win32/libsilcclient/Makefile
+tutorial/Makefile
+tutorial/Makefile.defines
+tutorial/Makefile.defines_int
 )
 fi
 
 AC_OUTPUT
+
+s_bindir=`eval echo $bindir`;s_bindir=`eval echo $s_bindir`
+s_sbindir=`eval echo $sbindir`;s_sbindir=`eval echo $s_sbindir`
+s_mandir=`eval echo $mandir`;s_mandir=`eval echo $s_mandir`
+s_includedir=`eval echo $includedir`;s_includedir=`eval echo $s_includedir`
+
+echo ""
+echo "SILC Configuration Summary:"
+echo "---------------------------"
+echo " Target host ...................: $target"
+echo " Compiler ......................: $CC"
+echo " CFLAGS ........................: $CFLAGS"
+echo " CPPFLAGS ......................: $CPPFLAGS"
+echo " LDFLAGS .......................: $LDFLAGS"
+echo " LIBS ..........................: $LIBS"
+echo ""
+echo " Installation prefix ...........: $prefix"
+echo " bin directory .................: $s_bindir"
+echo " sbin directory ................: $s_sbindir"
+echo " man directory .................: $s_mandir"
+echo " help directory ................: $HELPDIR"
+echo " doc directory .................: $DOCDIR"
+echo " logs directory ................: $LOGSDIR"
+echo " SIM directory .................: $MODULESDIR"
+echo " include directory .............: $s_includedir"
+echo ""
+
+if test "x$silc_dist" = "xsilc-client" ||
+   test "x$silc_dist" = "xsilc-toolkit"; then
+  irssi="yes"
+  if test x$without_irssi = xtrue; then
+    irssi="no"
+  fi
+echo " Compile SILC Client ...........: $irssi"
+fi
+
+if test "x$silc_dist" = "xsilc-server" ||
+   test "x$silc_dist" = "xsilc-toolkit"; then
+  silcd="yes"
+  if test x$without_silcd = xtrue; then
+    silcd="no"
+  fi
+echo " Compile SILC Server ...........: $silcd"
+echo " Server configuration file .....: $summary_silcd_configfile"
+echo " Server PID file ...............: $PIDFILE"
+fi
+
+if test x$sim_support = xfalse; then
+  sim_support="no"
+else
+  sim_support="yes"
+fi
+echo " SIM support ...................: $sim_support"
+echo " IPv6 support ..................: $summary_ipv6"
+echo " Assembler optimizations .......: $summary_asm"
+
+mp="MPI"
+if test x$mp_gmp = xtrue; then
+  mp="GMP"
+fi
+echo " Arithmetic library ............: $mp"
+
+threads="no"
+if test x$has_threads = xtrue; then
+  threads="yes"
+fi
+echo " Multi-threads support .........: $threads"
+echo " Debugging enabled .............: $summary_debug"
+echo " Stack-trace enabled ...........: $summary_stacktrace"
+echo ""
+if test "x$silc_dist" = "xsilc-client"; then
+  echo "Compile the sources with 'make' or 'gmake' command (GNU make is required)."
+else
+  echo "Compile the sources with 'make' or 'gmake' command."
+fi