va_copy checks.
[silc.git] / configure.ad
index 410d19f23c4205d405c4eba874ac7a3c1693220e..3244e3786b8962bd6746ab7decd1bf3cb4f40f36 100644 (file)
@@ -3,7 +3,7 @@
 #
 #  Author: Pekka Riikonen <priikone@silcnet.org>
 #
-#  Copyright (C) 2000 - 2005 Pekka Riikonen
+#  Copyright (C) 2000 - 2006 Pekka Riikonen
 #
 #  This program is free software; you can redistribute it and/or modify
 #  it under the terms of the GNU General Public License as published by
@@ -25,6 +25,7 @@ AC_PROG_INSTALL
 AC_PROG_MAKE_SET
 
 AC_PROG_LN_S
+AC_PROG_EGREP
 AC_SUBST(LN_S)
 AC_PATH_PROG(sedpath, sed)
 
@@ -43,7 +44,28 @@ case "$target" in
     ;;
 esac
 
-CFLAGS=
+# Get CPU
+case "$host_cpu" in
+  i386)
+    AC_DEFINE([SILC_I386], [], [SILC_I386])
+    ;;
+  i?86)
+    AC_DEFINE([SILC_I486], [], [SILC_I486])
+    ;;
+  x86_64)
+    AC_DEFINE([SILC_X86_64], [], [SILC_X86_64])
+    ;;
+  powerpc*)
+    AC_DEFINE([SILC_POWERPC], [], [SILC_POWERPC])
+    ;;
+  ia64)
+    AC_DEFINE([SILC_IA64], [], [SILC_IA64])
+    ;;
+esac
+
+# Control compiler optimizations
+CFLAGS=`echo $CFLAGS | sed 's/-O[ 0123456789s]*//g'`
+
 AC_PROG_CC
 AC_C_INLINE
 AC_C_CONST
@@ -53,7 +75,12 @@ __SILC_HAVE_SIM=""
 __SILC_ENABLE_DEBUG=""
 
 AC_PROG_RANLIB
+#ifndef SILC_DIST_TOOLKIT
+AC_DISABLE_SHARED
+#endif SILC_DIST_TOOLKIT
+#ifdef SILC_DIST_INPLACE
 AC_DISABLE_SHARED
+#endif SILC_DIST_INPLACE
 AC_PROG_LIBTOOL
 
 # Header checking
@@ -105,8 +132,8 @@ AC_CHECK_FUNC(socket, [],
   AC_CHECK_LIB(socket, socket, LIBS="$LIBS -lsocket")
 )
 AC_CHECK_FUNCS(gethostname gethostbyaddr getservbyname getservbyport)
-AC_CHECK_FUNCS(select listen bind shutdown close connect setsockopt)
-AC_CHECK_FUNCS(time ctime utime gettimeofday getrusage)
+AC_CHECK_FUNCS(poll select listen bind shutdown close connect setsockopt)
+AC_CHECK_FUNCS(setrlimit time ctime utime gettimeofday getrusage)
 AC_CHECK_FUNCS(chmod fcntl stat fstat getenv putenv strerror)
 AC_CHECK_FUNCS(getpid getgid getsid getpgid getpgrp getuid)
 AC_CHECK_FUNCS(setgroups initgroups nl_langinfo)
@@ -150,7 +177,7 @@ fi
 #
 AC_CHECK_HEADER(regex.h,
   [
-    AC_DEFINE([HAVE_REGEX], [], [HAVE_REGEX])
+    AC_DEFINE([HAVE_REGEX_H], [], [HAVE_REGEX_H])
     have_regex=1
   ], have_regex=0
 )
@@ -162,7 +189,13 @@ AC_CHECK_FUNC(getopt_long,
     have_getopt_long=1
   ], have_getopt_long=0
 )
-AM_CONDITIONAL(HAVE_GETOPT_LONG, test x$have_getopt_long = x1)
+
+AC_CHECK_FUNC(getopt,
+  [
+    AC_DEFINE([HAVE_GETOPT], [], [HAVE_GETOPT])
+    have_getopt=1
+  ], have_getopt=0
+)
 
 ##
 ##  Enable/disable checking
@@ -263,6 +296,109 @@ AC_ARG_ENABLE(asm,
     want_asm=true
   ])
 
+##
+## va_copy checks
+##
+va_copy=false
+AC_MSG_CHECKING(for va_copy)
+AC_TRY_COMPILE(
+  [
+    #include <stdarg.h>
+    #include <stdlib.h>
+  ],
+  [
+    int t(int x, ...)
+    {
+      va_list va, cp;
+      va_start(va, x);
+      va_copy(cp, va);
+      if (va_arg(cp, int) != 0xff11)
+        return 1;
+      va_end(va);
+      va_end(cp);
+      return 0;
+    }
+    int main()
+    {
+      return t(0, 0xff11);
+    }
+  ],
+  [
+    AC_DEFINE([HAVE_VA_COPY], [], [HAVE_VA_COPY])
+    AC_MSG_RESULT(yes)
+    va_copy=true
+  ],
+  [
+    AC_MSG_RESULT(no)
+    va_copy=false
+  ]
+)
+
+if test x$va_copy = xfalse; then
+  AC_MSG_CHECKING(for __va_copy)
+  AC_TRY_COMPILE(
+  [
+    #include <stdarg.h>
+    #include <stdlib.h>
+  ],
+  [
+    int t(int x, ...)
+    {
+      va_list va, cp;
+      va_start(va, x);
+      __va_copy(cp, va);
+      if (va_arg(cp, int) != 0xff11)
+        return 1;
+      va_end(va);
+      va_end(cp);
+      return 0;
+    }
+    int main()
+    {
+      return t(0, 0xff11);
+    }
+  ],
+  [
+    AC_DEFINE([HAVE___VA_COPY], [], [HAVE___VA_COPY])
+    AC_MSG_RESULT(yes)
+    va_copy=true
+  ],
+  [
+    AC_MSG_RESULT(no)
+    va_copy=false
+  ]
+  )
+fi
+
+if test x$va_copy = xfalse; then
+  AC_RUN_IFELSE(
+    [
+      #include <stdarg.h>
+      #include <stdlib.h>
+      int t(int x, ...)
+      {
+        va_list va, cp;
+        va_start(va, x);
+        cp = va;
+        if (va_arg(cp, int) != 0xff11)
+          return 1;
+        va_end(va);
+        va_end(cp);
+        return 0;
+      }
+      int main()
+      {
+        return t(0, 0xff11);
+      }
+    ],
+    [va_copy=false],
+    [
+      AC_DEFINE([SILC_VA_COPY_ARRAY], [], [SILC_VA_COPY_ARRAY])
+    ],
+    [va=copy=false]
+  )
+fi
+
 ##
 ## Compiler and compiler flag checks
 ##
@@ -279,6 +415,18 @@ AC_DEFUN([SILC_ADD_CFLAGS],
   unset tmp_CFLAGS
 ])
 
+# Function to check if compiler flag works, destination specifiable
+# Usage: SILC_ADD_CC_FLAGS(VAR, FLAGS, [ACTION-IF-FAILED])
+AC_DEFUN([SILC_ADD_CC_FLAGS],
+[ tmp_CFLAGS="$1_CFLAGS"
+  $1_CFLAGS="${$1_CFLAGS} $2"
+  AC_MSG_CHECKING(whether $CC accepts $2 flag)
+  AC_TRY_LINK([], [], [AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)
+                                      $1_CFLAGS="$tmp_CFLAGS"
+                                      $3])
+  unset tmp_CFLAGS
+])
+
 if test "$GCC"; then
   # GCC specific options
   if test "x$summary_debug" = "xyes"; then
@@ -287,12 +435,16 @@ if test "$GCC"; then
     SILC_ADD_CFLAGS(-g -O2)
   fi
   SILC_ADD_CFLAGS(-Wall -finline-functions)
+  SILC_ADD_CFLAGS(-Wno-pointer-sign)
 else
   # Other compilers
   case "$target" in
     alpha*-dec-osf*)
       SILC_ADD_CFLAGS(-g3 -O2, SILC_ADD_CFLAGS(-g3 -O, SILC_ADD_CFLAGS(-O)))
       ;;
+    mips*-sgi-irix*)
+      SILC_ADD_CFLAGS(-g3 -O2, SILC_ADD_CFLAGS(-g3 -O, SILC_ADD_CFLAGS(-O)))
+      ;;
     *)
       SILC_ADD_CFLAGS(-g)
       SILC_ADD_CFLAGS(-O2, SILC_ADD_CFLAGS(-O))
@@ -388,95 +540,6 @@ AC_SUBST(DOCDIR)
 AC_DEFINE_UNQUOTED([SILC_DOCDIR], "$DOCDIR", [SILC_DOCDIR])
 #endif SILC_DIST_AUTODIST
 
-#ifdef SILC_DIST_CLIENT
-# help directory
-#
-HELPDIR="$silc_prefix/help"
-AC_ARG_WITH(helpdir,
-  [[  --with-helpdir=DIR      directory for SILC help files [PREFIX/help]]],
-  [
-    case "$withval" in
-      no|yes)
-        ;;
-      *)
-       HELPDIR="$withval"
-       ;;
-    esac
-  ])
-AC_SUBST(HELPDIR)
-AC_DEFINE_UNQUOTED([SILC_HELPDIR], "$HELPDIR", [SILC_HELPDIR])
-#endif SILC_DIST_CLIENT
-
-#ifdef SILC_DIST_SIM
-# SIM modules directory
-#
-MODULESDIR="$silc_prefix/modules"
-AC_ARG_WITH(simdir,
-  [[  --with-simdir=DIR       directory for SIM modules [PREFIX/modules]]],
-  [
-    case "$withval" in
-      no|yes)
-        ;;
-      *)
-        MODULESDIR="$withval"
-        ;;
-    esac
-  ])
-AC_SUBST(MODULESDIR)
-AC_DEFINE_UNQUOTED([SILC_MODULESDIR], "$MODULESDIR", [SILC_MODULESDIR])
-#endif SILC_DIST_SIM
-
-#ifdef SILC_DIST_SERVER
-# Logs directory
-#
-LOGSDIR="$silc_prefix/logs"
-AC_ARG_WITH(logsdir,
-  [[  --with-logsdir=DIR      directory for SILC Server logs [PREFIX/logs]]],
-  [
-    case "$withval" in
-      no|yes)
-        ;;
-      *)
-        LOGSDIR="$withval"
-        ;;
-    esac
-  ])
-AC_SUBST(LOGSDIR)
-AC_DEFINE_UNQUOTED([SILC_LOGSDIR], "$LOGSDIR", [SILC_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", [SILC_SERVER_CONFIG_FILE])
-    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)
-#endif SILC_DIST_SERVER
-
 #ifdef SILC_DIST_COMPILER
 ##
 ##  With/without checkings
@@ -485,34 +548,69 @@ AC_SUBST(PIDFILE)
 #
 # SILC library checking
 compile_libs=true
+LIBSUBDIR=lib
 
 #ifndef SILC_DIST_TOOLKIT
-
-AC_ARG_WITH(silc-includes, 
+AC_ARG_WITH(silc-includes,
   [  --with-silc-includes=DIR SILC Toolkit includes [search in DIR]],
   [ac_silc_includes="$withval"], [ac_silc_includes="no"])
 AC_ARG_WITH(silc-libs,
   [  --with-silc-libs=DIR     SILC Toolkit libraries [search in DIR]],
   [ac_silc_libs="$withval"], [ac_silc_libs="no"])
 
-#
-# XXX missing checking the __SILC_WITH_XXX defines from the provided libs
-# in order to determine correct libs to link.
+if test -n "$with_silc_includes" || test -n "$with_silc_libs"; then
 
-#
-# XXX missing pkg-config check.
+  # Manually provided libs
+  if test "$ac_silc_includes" != "no"; then
+    compile_libs=false
+    SILC_LIB_INCLUDES="-I$ac_silc_includes"
+    LIBSUBDIR=
+  fi
+  if test "$ac_silc_libs" != "no"; then
+    compile_libs=false
+    LIBSUBDIR=
+    LIBS="$LIBS -L$ac_silc_libs"
+  fi
 
-if test "$ac_silc_includes" != "no"; then
-  compile_libs=false
-  SILC_LIB_INCLUDES="-I$ac_silc_includes"
-fi
-if test "$ac_silc_libs" != "no"; then
-  compile_libs=false
-  LIBS="$LIBS -L$ac_silc_libs"
-fi
+  # Check libs to link against
+  f=`$EGREP __SILC_HAVE_PTHREAD $ac_silc_includes/silc.h`
+  if test -n "$f"; then
+    LIBS="$LIBS -lpthread"
+    check_threads=false
+    has_threads=true
+  fi
+  f=`$EGREP __SILC_HAVE_SIM $ac_silc_includes/silc.h`
+  if test -n "$f"; then
+    LIBS="$LIBS -ldl"
+  fi
 
+else
+  # pkg-config check
+  PKG_CHECK_MODULES(SILC, silc, compile_libs=false, compile_libs=true)
+#ifdef SILC_DIST_CLIENTLIB
+  PKG_CHECK_MODULES(SILCCLIENT, silcclient, compile_libs=false, compile_libs=true)
+#endif SILC_DIST_CLIENTLIB
+#ifdef SILC_DIST_SERVERLIB
+  PKG_CHECK_MODULES(SILCSERVER, silcserver, compile_libs=false, compile_libs=true)
+#endif SILC_DIST_SERVERLIB
+
+  if test x$compile_libs = xfalse; then
+    LIBSUBDIR=
+    LIBS="$LIBS $SILC_LIBS"
+    CFLAGS="$CFLAGS $SILC_CFLAGS"
+#ifdef SILC_DIST_CLIENTLIB
+    LIBS="$LIBS $SILCCLIENT_LIBS"
+    CFLAGS="$CFLAGS $SILCCLIENT_CFLAGS"
+#endif SILC_DIST_CLIENTLIB
+#ifdef SILC_DIST_SERVERLIB
+    LIBS="$LIBS $SILCSERVER_LIBS"
+    CFLAGS="$CFLAGS $SILCSERVER_CFLAGS"
+#endif SILC_DIST_SERVERLIB
+  fi
+fi
 #endif SILC_DIST_TOOLKIT
 
+AC_SUBST(LIBSUBDIR)
 
 # SOCKS4 support checking
 #
@@ -631,7 +729,7 @@ fi
 
 #ifdef SILC_DIST_MATH
 # MP library checking. First check whether user wants to use GMP and use
-# it if found. If not or not defined then compile the MPI library in the
+# it if found. If not or not defined then compile the default library in the
 # source tree.
 #
 mp_gmp=false
@@ -640,7 +738,7 @@ SAVE_CFLAGS="$CFLAGS"
 SAVE_LDFLAGS="$LDFLAGS"
 AC_MSG_CHECKING(whether to search for GMP)
 AC_ARG_WITH(gmp,
-  [[  --with-gmp[=DIR]        use GMP instead of MPI [search in DIR/lib and DIR/include]]],
+  [[  --with-gmp[=DIR]        use GMP instead of SILC Math [search in DIR/lib and DIR/include]]],
   [
     case "$withval" in
       no)
@@ -676,10 +774,10 @@ AC_ARG_WITH(gmp,
   )
 
 AM_CONDITIONAL(SILC_MP_GMP, test x$mp_gmp = xtrue)
-AM_CONDITIONAL(SILC_MP_NSS_MPI, test x$mp_gmp = xfalse)
+AM_CONDITIONAL(SILC_MP_SILCMATH, test x$mp_gmp = xfalse)
 if test x$mp_gmp = xfalse; then
-  AC_DEFINE([SILC_MP_NSS_MPI], [], [MPI])
-  AC_MSG_RESULT(Using NSS MPI as a MP library.)
+  AC_DEFINE([SILC_MP_SILCMATH], [], [SILCMATH])
+  AC_MSG_RESULT(Using SILC Math as a MP library.)
 fi
 #endif SILC_DIST_MATH
 
@@ -865,7 +963,6 @@ fi
 
 # POSIX threads support
 #
-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]]],
@@ -889,6 +986,7 @@ AC_ARG_WITH(pthreads,
   ])
 
 if test x$check_threads = xtrue; then
+  has_threads=false
   SAVE_LIBS="$LIBS"
   SAVE_CFLAGS="$CFLAGS"
   SAVE_LDFLAGS="$LDFLAGS"
@@ -1019,45 +1117,41 @@ AM_CONDITIONAL(SILC_BEOS, test xfalse = xtrue)
 AM_CONDITIONAL(SILC_OS2, test xfalse = xtrue)
 
 #ifdef SILC_DIST_TOOLKIT
-
-# --without-irssi
+# --with-irssi
 #
-without_irssi=false
+without_irssi=true
 AC_MSG_CHECKING(whether to compile Irssi SILC Client)
 AC_ARG_WITH(irssi,
-  [  --without-irssi         compile without Irssi SILC Client],
+  [  --with-irssi            compile with Irssi SILC Client],
   [
-    AC_MSG_RESULT(no)
-    without_irssi=true
+    AC_MSG_RESULT(yes)
+    without_irssi=false
   ],
   [
-    AC_MSG_RESULT(yes)
+    AC_MSG_RESULT(no)
+    without_irssi=true
   ])
+AM_CONDITIONAL(with_irssi, test xwithout_irssi = xfalse)
 
-# --without-silcd
+# --with-silcd
 #
-without_silcd=false
+without_silcd=true
 AC_MSG_CHECKING(whether to compile SILC Server)
 AC_ARG_WITH(silcd,
-  [  --without-silcd         compile without SILC Server],
+  [  --with-silcd            compile with SILC Server],
   [
-    AC_MSG_RESULT(no)
-    without_silcd=true
+    AC_MSG_RESULT(yes)
+    without_silcd=false
   ],
   [
-    AC_MSG_RESULT(yes)
+    AC_MSG_RESULT(no)
+    without_silcd=true
   ])
-
 #endif SILC_DIST_TOOLKIT
-
-#ifdef SILC_DIST_CLIENT
-# Irssi perl support
-#
-AC_ARG_WITH(perl,
-  [[  --with-perl[=yes|no|module]  Build with Perl support - also specifies
-                               if it should be built into main silc binary
-                               (static, default) or as a module]])
-#endif SILC_DIST_CLIENT
+#ifdef SILC_DIST_INPLACE
+without_irssi=false
+without_silcd=false
+#endif SILC_DIST_INPLACE
 
 libtoolfix=true
 AC_MSG_CHECKING(whether to do libtoolfix)
@@ -1073,26 +1167,14 @@ AC_ARG_WITH(libtoolfix,
 
 AC_SUBST(ETCDIR)
 AC_DEFINE_UNQUOTED([SILC_ETCDIR], "$ETCDIR", [SILC_ETCDIR])
-
 #endif SILC_DIST_COMPILER
 
 ##
 ##  Misc
 ##
 
-# Other configure scripts
-#
-
-#ifdef SILC_DIST_TOOLKIT
-if test x$without_irssi = xfalse; then
-#endif SILC_DIST_TOOLKIT
-#ifdef SILC_DIST_CLIENT
-  AC_CONFIG_SUBDIRS(irssi)
-  irssi="yes"
-#endif SILC_DIST_CLIENT
-#ifdef SILC_DIST_TOOLKIT
-fi
-#endif SILC_DIST_TOOLKIT
+# Make enable-shared aware
+AM_CONDITIONAL(SILC_ENABLE_SHARED, test "$enable_shared" = yes)
 
 SILC_TOP_SRCDIR=`pwd`
 
@@ -1138,42 +1220,15 @@ Makefile.defines
 Makefile.defines_int
 includes/Makefile
 includes/silcversion.h
-includes/silcincludes.h
+includes/silc.h
 #endif SILC_DIST_COMPILER
 #ifdef SILC_DIST_APPS
 apps/Makefile
 #endif SILC_DIST_APPS
 )
 
-#ifdef SILC_DIST_TOOLKIT
-if test x$without_irssi = xfalse ; then
-#endif SILC_DIST_TOOLKIT
-#ifdef SILC_DIST_CLIENT
-  AC_CONFIG_FILES(
-irssi/Makefile.defines
-irssi/Makefile.defines_int
-)
-#endif SILC_DIST_CLIENT
-#ifdef SILC_DIST_TOOLKIT
-fi
-#endif SILC_DIST_TOOLKIT
-
-#ifdef SILC_DIST_TOOLKIT
-if test x$without_silcd = xfalse ; then
-#endif SILC_DIST_TOOLKIT
-#ifdef SILC_DIST_SERVER
-  AC_CONFIG_FILES(
-silcd/Makefile
-doc/example_silcd.conf
-)
-#endif SILC_DIST_SERVER
-#ifdef SILC_DIST_TOOLKIT
-fi
-#endif SILC_DIST_TOOLKIT
-
 #ifdef SILC_DIST_TOOLKIT
 AC_CONFIG_FILES(
-silc/Makefile
 win32/Makefile
 win32/libsilc/Makefile
 win32/libsilcclient/Makefile
@@ -1197,7 +1252,6 @@ echo "---------------------------"
 echo " Target host ...................: $target"
 echo " Compiler ......................: $CC"
 echo " CFLAGS ........................: $CFLAGS"
-echo " CPPFLAGS ......................: $CPPFLAGS"
 echo " LDFLAGS .......................: $LDFLAGS"
 echo " LIBS ..........................: $LIBS"
 echo ""
@@ -1207,12 +1261,6 @@ echo " sbin directory ................: $s_sbindir"
 echo " etc directory .................: $ETCDIR"
 echo " man directory .................: $s_mandir"
 echo " doc directory .................: $DOCDIR"
-#ifdef SILC_DIST_CLIENT
-echo " help directory ................: $HELPDIR"
-#endif SILC_DIST_CLIENT
-#ifdef SILC_DIST_SERVER
-echo " logs directory ................: $LOGSDIR"
-#endif SILC_DIST_SERVER
 #ifdef SILC_DIST_SIM
 echo " SIM directory .................: $MODULESDIR"
 #endif SILC_DIST_SIM
@@ -1221,10 +1269,6 @@ echo " include directory .............: $s_includedir"
 #endif SILC_DIST_INCLUDES
 echo ""
 
-#ifdef SILC_DIST_SERVER
-silcd="yes"
-#endif SILC_DIST_SERVER
-
 #ifdef SILC_DIST_TOOLKIT
 if test x$without_irssi = xtrue; then
   irssi="no"
@@ -1240,8 +1284,6 @@ echo " Compile SILC Client ...........: $irssi"
 
 #ifdef SILC_DIST_SERVER
 echo " Compile SILC Server ...........: $silcd"
-echo " Server configuration file .....: $summary_silcd_configfile"
-echo " Server PID file ...............: $PIDFILE"
 #endif SILC_DIST_SERVER
 
 #ifdef SILC_DIST_SIM
@@ -1270,11 +1312,9 @@ fi
 echo " Assembler optimizations .......: $summary_asm"
 
 #ifdef SILC_DIST_MATH
-mp="MPI"
 if test x$mp_gmp = xtrue; then
-  mp="GMP"
+  echo " Arithmetic library ............: GMP"
 fi
-echo " Arithmetic library ............: $mp"
 #endif SILC_DIST_MATH
 
 threads="no"
@@ -1286,4 +1326,3 @@ echo " Debugging enabled .............: $summary_debug"
 echo ""
 echo "Compile the sources with 'make' or 'gmake' command."
 #endif SILC_DIST_COMPILER
-