From 486172f0f37b13b3deff8f5aa140f054bfe0599d Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Wed, 8 Aug 2007 15:56:11 +0000 Subject: [PATCH] Added silc.m4. Added SILC_SYSTEM_IS_CPU and SILC_CPU_FLAG m4 functions. --- configure.ad | 41 +++++------- distdir/autodist.conf | 2 +- lib/silcutil/silcatomic.h | 3 - silc.m4 | 129 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 147 insertions(+), 28 deletions(-) create mode 100644 silc.m4 diff --git a/configure.ad b/configure.ad index ca534c97..d98e4db2 100644 --- a/configure.ad +++ b/configure.ad @@ -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,6 +53,7 @@ case "$target" in esac # Get CPU +SILC_SYSTEM_IS_SMP(AC_DEFINE([SILC_SMP], [], [SILC_SMP]), []) cpu_i386=false cpu_i486=false cpu_i586=false @@ -88,18 +90,33 @@ case "$host_cpu" in cpu_i686=true cpu_i786=true fi + + # Check for specific CPU features + SILC_CPU_FLAG(sse2, AC_DEFINE([SILC_CPU_SSE2], [], [SILC_CPU_SSE2]), []) + SILC_CPU_FLAG(sse3, AC_DEFINE([SILC_CPU_SSE3], [], [SILC_CPU_SSE3]), []) + SILC_CPU_FLAG(ssse3, AC_DEFINE([SILC_CPU_SSSE3], [], [SILC_CPU_SSSE3]), []) ;; # 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(sse2, AC_DEFINE([SILC_CPU_SSE2], [], [SILC_CPU_SSE2]), []) + SILC_CPU_FLAG(sse3, AC_DEFINE([SILC_CPU_SSE3], [], [SILC_CPU_SSE3]), []) + SILC_CPU_FLAG(ssse3, AC_DEFINE([SILC_CPU_SSSE3], [], [SILC_CPU_SSSE3]), []) ;; # 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(sse2, AC_DEFINE([SILC_CPU_SSE2], [], [SILC_CPU_SSE2]), []) + SILC_CPU_FLAG(sse3, AC_DEFINE([SILC_CPU_SSE3], [], [SILC_CPU_SSE3]), []) + SILC_CPU_FLAG(ssse3, AC_DEFINE([SILC_CPU_SSSE3], [], [SILC_CPU_SSSE3]), []) ;; # PowerPC, 32-bit and 64-bit CPUs @@ -198,30 +215,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, [], diff --git a/distdir/autodist.conf b/distdir/autodist.conf index 22cc82ba..6c81ff68 100644 --- a/distdir/autodist.conf +++ b/distdir/autodist.conf @@ -21,7 +21,7 @@ DISTDEFS="includes/silcdistdefs.h" # Location of the aclocal tool. If this is omitted the Autodist will not # run aclocal. User need to run it manually then. # -ACLOCAL="aclocal" +ACLOCAL="aclocal -I." # Location of the autoheader tool. If this is omitted the Autodist will not # run autoheader. User need to run it manually then. diff --git a/lib/silcutil/silcatomic.h b/lib/silcutil/silcatomic.h index 3f79dc54..bef237a7 100644 --- a/lib/silcutil/silcatomic.h +++ b/lib/silcutil/silcatomic.h @@ -53,9 +53,6 @@ #ifndef SILCATOMIC_H #define SILCATOMIC_H -/* For now we always assume SMP */ -#define SILC_SMP 1 - /* Use lock prefix only on true SMP systems */ #ifdef SILC_SMP #define SILC_SMP_LOCK "lock; " diff --git a/silc.m4 b/silc.m4 new file mode 100644 index 00000000..e84ea0c0 --- /dev/null +++ b/silc.m4 @@ -0,0 +1,129 @@ +# +# silc.m4 +# +# Author: Pekka Riikonen +# +# Copyright (C) 2007 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 +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# + +# Function to check if system has SMP kernel. +# Usage: SILC_SYSTEM_IS_SMP([ACTION-IF-FOUND] [, ACTION-IF-NOT-FOUND]) +AC_DEFUN([SILC_SYSTEM_IS_SMP], +[ + AC_MSG_CHECKING(whether system has SMP kernel) + + case "$target" in + *-*-linux*) + # Take data from Linux /proc + if test -f /proc/stat; then + cpucount=`grep "^cpu" /proc/stat -c 2> /dev/null` + if test $cpucount -gt 1; then + AC_DEFINE([SILC_SMP], [], [SILC_SMP]) + AC_MSG_RESULT(yes) + ifelse([$1], , :, [$1]) + else + AC_MSG_RESULT(no) + ifelse([$2], , :, [$2]) + fi + else + AC_MSG_RESULT(no) + ifelse([$2], , :, [$2]) + fi + ;; + + *-*-*bsd*) + # BSDs can have SMP info in sysctl 'kern.smp.cpus' variable + cpucount=`/sbin/sysctl kern.smp.cpus 2> /dev/null | \ + cut -d'=' -f2 | cut -d' ' -f2` + if test $cpucount -gt 1; then + AC_DEFINE([SILC_SMP], [], [SILC_SMP]) + AC_MSG_RESULT(yes) + ifelse([$1], , :, [$1]) + else + AC_MSG_RESULT(no) + ifelse([$2], , :, [$2]) + fi + ;; + + *) + AC_MSG_RESULT(no) + ifelse([$2], , :, [$2]) + ;; + esac +]) + +# Function to check for CPU feature flags. +# Usage: SILC_CPU_FLAG(flag [, ACTION-IF-FOUND] [, ACTION-IF-NOT-FOUND]) +AC_DEFUN([SILC_CPU_FLAG], +[ + AC_MSG_CHECKING(whether CPU supports $1) + + case "$target" in + *-*-linux*) + # Take data from Linux /proc + if test -f /proc/cpuinfo; then + cpuflags=`grep "^flags.*$1 " /proc/cpuinfo 2> /dev/null` + if test $? != 0; then + AC_MSG_RESULT(no) + ifelse([$3], , :, [$3]) + else + AC_MSG_RESULT(yes) + ifelse([$2], , :, [$2]) + fi + else + AC_MSG_RESULT(no) + ifelse([$3], , :, [$3]) + fi + ;; + + *-*-*bsd*) + # BSDs have some flags in sysctl 'machdep' variable + cpuflags=`/sbin/sysctl machdep 2> /dev/null | grep "\.$1.*.1"` + if test $? != 0; then + AC_MSG_RESULT(no) + ifelse([$3], , :, [$3]) + else + AC_MSG_RESULT(yes) + ifelse([$2], , :, [$2]) + fi + ;; + + *) + AC_MSG_RESULT(no) + ifelse([$3], , :, [$3]) + ;; + esac +]) + +# 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 +]) -- 2.24.0