Added ernno setting.
[silc.git] / configure.ad
index 8ee9d61b87f5e4e494e6f19de149346b9fd56ebb..a162625abcec1e1d736b10ac98c1d637e88310d4 100644 (file)
@@ -3,7 +3,7 @@
 #
 #  Author: Pekka Riikonen <priikone@silcnet.org>
 #
-#  Copyright (C) 2000 - 2007 Pekka Riikonen
+#  Copyright (C) 2000 - 2008 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
@@ -30,6 +30,7 @@ AC_SUBST(LN_S)
 AC_PATH_PROG(sedpath, sed)
 
 #ifdef SILC_DIST_COMPILER
+
 # Put here any platform specific stuff
 #
 case "$target" in
@@ -52,37 +53,91 @@ case "$target" in
 esac
 
 # Get CPU
+SILC_SYSTEM_IS_SMP(AC_DEFINE([SILC_SMP], [], [SILC_SMP]), [],
+                   AC_DEFINE([SILC_SMP], [], [SILC_SMP]))
 cpu_i386=false
-cpu_ix86=false
+cpu_i486=false
+cpu_i586=false
+cpu_i686=false
+cpu_i786=false
 cpu_x86_64=false
 cpu_ppc=false
 cpu_ia64=false
 case "$host_cpu" in
-  i386)
+  # All following Intels are considered 32-bit CPUs.
+  i?86)
+    # All CPUs of today are considered i386 and i486 compatible */
     AC_DEFINE([SILC_I386], [], [SILC_I386])
     AC_DEFINE([SILC_I486], [], [SILC_I486])
     cpu_i386=true
-    cpu_ix86=true
+    cpu_i486=true
+
+    if test "x$host_cpu" = "xi586"; then
+      AC_DEFINE([SILC_I586], [], [SILC_I586])
+      cpu_i586=true
+    fi
+
+    if test "x$host_cpu" = "xi686"; then
+      AC_DEFINE([SILC_I586], [], [SILC_I586])
+      AC_DEFINE([SILC_I686], [], [SILC_I686])
+      cpu_i586=true
+      cpu_i686=true
+    fi
+
+    if test "x$host_cpu" = "xi786"; then
+      AC_DEFINE([SILC_I586], [], [SILC_I586])
+      AC_DEFINE([SILC_I686], [], [SILC_I686])
+      AC_DEFINE([SILC_I786], [], [SILC_I786])
+      cpu_i586=true
+      cpu_i686=true
+      cpu_i786=true
+    fi
+
+    # Check for specific CPU features
+    SILC_CPU_FLAG(mmx, AC_DEFINE([SILC_CPU_MMX], [], [SILC_CPU_MMX]), [])
+    SILC_CPU_FLAG(sse2, AC_DEFINE([SILC_CPU_SSE2], [], [SILC_CPU_SSE2]), [])
+    SILC_CPU_FLAG(pni, AC_DEFINE([SILC_CPU_SSE3], [], [SILC_CPU_SSE3]), [])
+    SILC_CPU_FLAG(ssse3, AC_DEFINE([SILC_CPU_SSSE3], [], [SILC_CPU_SSSE3]), [])
+    SILC_CPU_FLAG(sse4, AC_DEFINE([SILC_CPU_SSE4], [], [SILC_CPU_SSE4]), [])
     ;;
-  i?86)
-    AC_DEFINE([SILC_I486], [], [SILC_I486])
-    cpu_ix86=true
+
+  # Intel IA-64, 64-bit CPU (not x86_64 compatible)
+  ia64)
+    AC_DEFINE([SILC_IA64], [], [SILC_IA64])
+    cpu_ia64=true
+
+    # Check for specific CPU features
+    SILC_CPU_FLAG(mmx, AC_DEFINE([SILC_CPU_MMX], [], [SILC_CPU_MMX]), [])
+    SILC_CPU_FLAG(sse2, AC_DEFINE([SILC_CPU_SSE2], [], [SILC_CPU_SSE2]), [])
+    SILC_CPU_FLAG(pni, AC_DEFINE([SILC_CPU_SSE3], [], [SILC_CPU_SSE3]), [])
+    SILC_CPU_FLAG(ssse3, AC_DEFINE([SILC_CPU_SSSE3], [], [SILC_CPU_SSSE3]), [])
+    SILC_CPU_FLAG(sse4, AC_DEFINE([SILC_CPU_SSE4], [], [SILC_CPU_SSE4]), [])
     ;;
+
+  # AMD/Intel x86_64, 64-bit CPU
   x86_64)
     AC_DEFINE([SILC_X86_64], [], [SILC_X86_64])
     cpu_x86_64=true
+
+    # Check for specific CPU features
+    SILC_CPU_FLAG(mmx, AC_DEFINE([SILC_CPU_MMX], [], [SILC_CPU_MMX]), [])
+    SILC_CPU_FLAG(sse2, AC_DEFINE([SILC_CPU_SSE2], [], [SILC_CPU_SSE2]), [])
+    SILC_CPU_FLAG(pni, AC_DEFINE([SILC_CPU_SSE3], [], [SILC_CPU_SSE3]), [])
+    SILC_CPU_FLAG(ssse3, AC_DEFINE([SILC_CPU_SSSE3], [], [SILC_CPU_SSSE3]), [])
+    SILC_CPU_FLAG(sse4, AC_DEFINE([SILC_CPU_SSE4], [], [SILC_CPU_SSE4]), [])
     ;;
+
+  # PowerPC, 32-bit and 64-bit CPUs
   powerpc*)
     AC_DEFINE([SILC_POWERPC], [], [SILC_POWERPC])
     cpu_ppc=true
     ;;
-  ia64)
-    AC_DEFINE([SILC_IA64], [], [SILC_IA64])
-    cpu_ia64=true
-    ;;
 esac
 AM_CONDITIONAL(SILC_I386, test x$cpu_i386 = xtrue)
-AM_CONDITIONAL(SILC_I486, test x$cpu_ix86 = xtrue)
+AM_CONDITIONAL(SILC_I486, test x$cpu_i486 = xtrue)
+AM_CONDITIONAL(SILC_I586, test x$cpu_i586 = xtrue)
+AM_CONDITIONAL(SILC_I686, test x$cpu_i686 = xtrue)
+AM_CONDITIONAL(SILC_7686, test x$cpu_i786 = xtrue)
 AM_CONDITIONAL(SILC_X86_64, test x$cpu_x86_64 = xtrue)
 AM_CONDITIONAL(SILC_POWERPC, test x$cpu_ppc = xtrue)
 AM_CONDITIONAL(SILC_IA64, test x$cpu_ia64 = xtrue)
@@ -94,6 +149,37 @@ AC_PROG_CC
 AC_C_INLINE
 AC_C_CONST
 
+# Set some compiler options based on CPU
+if test "x$CC" = "xicc"; then
+  # ICC flags
+  if test x$x_have_cpu_sse2 = xtrue; then
+    SILC_ADD_CFLAGS(-axW)
+  fi
+  if test x$x_have_cpu_sse3 = xtrue; then
+    SILC_ADD_CFLAGS(-axP)
+  fi
+  if test x$x_have_cpu_ssse3 = xtrue; then
+    SILC_ADD_CFLAGS(-axT)
+  fi
+  if test x$x_have_cpu_sse4 = xtrue; then
+    SILC_ADD_CFLAGS(-axS)
+  fi
+else
+  # Other compilers
+  if test x$x_have_cpu_sse2 = xtrue; then
+    SILC_ADD_CFLAGS(-msse2)
+  fi
+  if test x$x_have_cpu_pni = xtrue; then
+    SILC_ADD_CFLAGS(-msse3)
+  fi
+  if test x$x_have_cpu_ssse3 = xtrue; then
+    SILC_ADD_CFLAGS(-mssse3)
+  fi
+  if test x$x_have_cpu_sse4 = xtrue; then
+    SILC_ADD_CFLAGS(-msse3)
+  fi
+fi
+
 __SILC_HAVE_PTHREAD=""
 __SILC_HAVE_SIM=""
 __SILC_ENABLE_DEBUG=""
@@ -138,11 +224,11 @@ AC_HEADER_STAT
 
 # More header checking
 #
-AC_CHECK_HEADERS(unistd.h string.h getopt.h errno.h fcntl.h assert.h)
+AC_CHECK_HEADERS(unistd.h string.h errno.h fcntl.h assert.h)
 AC_CHECK_HEADERS(sys/types.h sys/stat.h sys/time.h stddef.h)
 AC_CHECK_HEADERS(netinet/in.h netinet/tcp.h xti.h netdb.h sys/resource.h)
 AC_CHECK_HEADERS(pwd.h grp.h termcap.h paths.h)
-AC_CHECK_HEADERS(ncurses.h signal.h ctype.h utime.h)
+AC_CHECK_HEADERS(ncurses.h signal.h ctype.h utime.h dirent.h)
 AC_CHECK_HEADERS(arpa/inet.h sys/mman.h limits.h termios.h locale.h langinfo.h)
 
 # Data type checking
@@ -168,30 +254,6 @@ AC_SUBST(SILC_SIZEOF_VOID_P, $ac_cv_sizeof_void_p)
 AC_CHECK_TYPES(long long)
 AC_CHECK_TYPES(long double)
 
-# Function to check if compiler flag works
-# Usage: SILC_ADD_CFLAGS(FLAGS, [ACTION-IF-FAILED])
-AC_DEFUN([SILC_ADD_CFLAGS],
-[ tmp_CFLAGS="$CFLAGS"
-  CFLAGS="$CFLAGS $1"
-  AC_MSG_CHECKING(whether $CC accepts $1 flag)
-  AC_TRY_LINK([], [], [AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)
-                                      CFLAGS="$tmp_CFLAGS"
-                                      $2])
-  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
-])
-
 # Function and library checking
 #
 AC_CHECK_FUNC(gethostbyname, [],
@@ -204,6 +266,12 @@ AC_CHECK_FUNC(gethostbyname, [],
 AC_CHECK_FUNC(socket, [],
   AC_CHECK_LIB(socket, socket, LIBS="$LIBS -lsocket")
 )
+AC_CHECK_FUNC(clock_gettime, [],
+  [
+    AC_CHECK_LIB(rt, clock_gettime,
+                 [ LIBS="$LIBS -lrt"
+                   AC_DEFINE([HAVE_CLOCK_GETTIME], [], [HAVE_CLOCK_GETTIME])])
+  ])
 AC_CHECK_FUNCS(gethostname gethostbyaddr getservbyname getservbyport)
 AC_CHECK_FUNCS(poll select listen bind shutdown close connect setsockopt)
 AC_CHECK_FUNCS(setrlimit time ctime utime gettimeofday getrusage)
@@ -211,17 +279,10 @@ AC_CHECK_FUNCS(chmod fcntl stat fstat getenv putenv strerror)
 AC_CHECK_FUNCS(getpid getgid getsid getpgid getpgrp getuid sched_yield)
 AC_CHECK_FUNCS(setgroups initgroups nl_langinfo nanosleep)
 AC_CHECK_FUNCS(strchr snprintf strstr strcpy strncpy memcpy memset memmove)
+AC_CHECK_FUNCS(setenv getenv putenv unsetenv clearenv)
 
 # lib/contrib conditionals
 #
-AC_CHECK_HEADER(regex.h,
-  [
-    AC_DEFINE([HAVE_REGEX_H], [], [HAVE_REGEX_H])
-    have_regex=1
-  ], have_regex=0
-)
-AM_CONDITIONAL(HAVE_REGEX, test x$have_regex = x1)
-
 AC_CHECK_FUNC(getopt_long,
   [
     AC_DEFINE([HAVE_GETOPT_LONG], [], [HAVE_GETOPT_LONG])
@@ -229,13 +290,6 @@ AC_CHECK_FUNC(getopt_long,
   ], have_getopt_long=0
 )
 
-AC_CHECK_FUNC(getopt,
-  [
-    AC_DEFINE([HAVE_GETOPT], [], [HAVE_GETOPT])
-    have_getopt=1
-  ], have_getopt=0
-)
-
 ##
 ##  Enable/disable checking
 ##
@@ -361,13 +415,21 @@ have_assembler=false
 if test x$want_asm = xtrue; then
   AC_PATH_PROG([NASM], [nasm], [no])
   if test "x$NASM" != "xno"; then
-    SILC_ASSEMBLER="$NASM -O2 -felf"
+    if test x$cpu_x86_64 = xtrue; then
+      SILC_ASSEMBLER="$NASM -O2 -felf64"
+    else
+      SILC_ASSEMBLER="$NASM -O2 -felf"
+    fi
     have_assembler=true
   fi
 
   AC_PATH_PROG([YASM], [yasm], [no])
   if test "x$YASM" != "xno"; then
-    SILC_ASSEMBLER="$YASM -Xgnu -felf"
+    if test x$cpu_x86_64 = xtrue; then
+      SILC_ASSEMBLER="$YASM -Xgnu -felf64"
+    else
+      SILC_ASSEMBLER="$YASM -Xgnu -felf"
+    fi
     have_assembler=true
   fi
 fi
@@ -503,9 +565,13 @@ else
       ;;
   esac
 
-  # Intel C++ Compiler needs -restrict
+  # Intel C++ Compiler flags
   if test "x$CC" = "xicc"; then
     SILC_ADD_CFLAGS(-restrict)
+    SILC_ADD_CFLAGS(-finline-functions)
+
+    # Don't define __GNUC__ except for system includes
+    SILC_ADD_CFLAGS(-gcc-sys)
   fi
 fi
 
@@ -654,6 +720,7 @@ else
     LDFLAGS="-L\$(silc_top_srcdir)/lib $LDFLAGS"
   fi
 fi
+
 #else SILC_DIST_TOOLKIT
 LDFLAGS="-L\$(silc_top_srcdir)/lib $LDFLAGS"
 #endif SILC_DIST_TOOLKIT
@@ -671,6 +738,7 @@ AC_CHECK_HEADERS(dlfcn.h,
     AC_CHECK_LIB(dl, dlopen,
       [
         AC_DEFINE([SILC_SIM], [], [HAVE_SIM])
+        AC_DEFINE([HAVE_DLOPEN], [], [HAVE_DLOPEN])
         sim_support=true
         LIBS="$LIBS -ldl"
       ],
@@ -678,6 +746,7 @@ AC_CHECK_HEADERS(dlfcn.h,
         AC_CHECK_LIB(c, dlopen,
           [
             AC_DEFINE([SILC_SIM], [], [HAVE_SIM])
+            AC_DEFINE([HAVE_DLOPEN], [], [HAVE_DLOPEN])
             sim_support=true
           ])
       ])
@@ -1162,7 +1231,7 @@ if test x$has_threads = xtrue; then
    esac
 
   # Check for threads
-  AC_CHECK_FUNC(pthread_create)
+  AC_CHECK_FUNCS(pthread_create pthread_key_create pthread_once)
 
   # Check for read/write locks
   AC_CHECK_FUNC(pthread_rwlock_init,