-AC_CHECK_FUNCS([bzero gettimeofday munmap strtoul])
-
-# Find arch type
-case $target_cpu in
- i386) ARCHTYPE="x86"; SUBARCHTYPE="x86compat" ;;
- i486) ARCHTYPE="x86"; SUBARCHTYPE="x86compat" ;;
- i586) ARCHTYPE="x86"; SUBARCHTYPE="x86compat" ;;
- i686) ARCHTYPE="x86"; SUBARCHTYPE="x86compat" ;;
- x86_64) ARCHTYPE="x86";;
- powerpc) ARCHTYPE="ppc" ;;
- ppc64) ARCHTYPE="ppc" ;;
- powerpc64) ARCHTYPE="ppc" ;;
- ppc) ARCHTYPE="ppc" ;;
- s390) ARCHTYPE="s390" ;;
- s390x) ARCHTYPE="s390" ;;
- *) ARCHTYPE="unknown";;
-esac
-
-if test "$ARCHTYPE" = "unknown"; then
- AC_MSG_ERROR([Unable to detect the architecture.])
-fi
-AC_SUBST(ARCHTYPE)
-AC_SUBST(SUBARCHTYPE)
-
-[
-if test "x$ARCHTYPE" = "xx86" -a "x$target_cpu" != "xi386" -a "x$target_cpu" != "xi486" -a "x$target_cpu" != "xi586"; then
-]
- AC_DEFINE([CONFIG_HAVE_FENCE], [1])
-[
-fi
-]
-
-AM_CONDITIONAL([GCC_API], [test "x$ARCHTYPE" != xx86 -a "x$ARCHTYPE" != xppc])
-
-AM_CONDITIONAL([COMPAT_ARCH], [test "x$SUBARCHTYPE" == xx86compat ])
-
-AC_ARG_ENABLE([smp-support], [ --disable-smp-support Disable SMP support. Warning: only use this
- on uniprocessor systems. [[default=enabled]]], [def_smp_support=$enableval], [def_smp_support="yes"])
-
-[
-if test "$def_smp_support" = "no"; then
- echo "SMP support disabled."
-else
-]
- AC_DEFINE([CONFIG_SMP], [1])
-[
- echo "SMP support enabled."
-fi
-]
+AC_FUNC_FORK
+AC_CHECK_FUNCS([ \
+ atexit \
+ getcpuid \
+ gettid \
+ gettimeofday \
+ memeset \
+ memset \
+ munmap \
+ rand_r \
+ sched_getcpu \
+ strerror \
+ strtoul \
+ sysconf \
+])
+
+# AC_FUNC_MALLOC causes problems when cross-compiling.
+#AC_FUNC_MALLOC
+
+# Check for headers
+AC_HEADER_STDBOOL
+AC_CHECK_HEADERS([ \
+ limits.h \
+ stddef.h \
+ sys/param.h \
+ sys/time.h \
+])
+
+AS_CASE([$host],[*-cygwin*],
+ [AM_CONDITIONAL(USE_CYGWIN, true)],
+ [AM_CONDITIONAL(USE_CYGWIN, false)]
+)
+
+AS_IF([test "$host_cpu" = "armv7l"],[
+ AM_CFLAGS="$AM_CFLAGS -mcpu=cortex-a9 -mtune=cortex-a9 -O1"
+])
+
+# ARM-specific checks
+AS_CASE([$host_cpu], [arm*], [
+ AC_MSG_CHECKING([for dmb instruction])
+ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
+ int main()
+ {
+ asm volatile("dmb":::"memory");
+ return 0;
+ }
+ ]])
+ ],[
+ AC_MSG_RESULT([yes])
+ AC_DEFINE([CONFIG_RCU_ARM_HAVE_DMB], [1])
+ ],[
+ AC_MSG_RESULT([no])
+ ])
+])
+
+# Check if sys_futex() is available
+AC_MSG_CHECKING([for sys_futex()])
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
+ #include <sys/syscall.h>
+ #ifndef __NR_futex
+ #error "futexes not available"
+ #endif
+ ]])
+],[
+ AC_MSG_RESULT([yes])
+ AC_DEFINE([CONFIG_RCU_HAVE_FUTEX], [1])
+ compat_futex_test=0
+],[
+ AC_MSG_RESULT([no])
+ compat_futex_test=1
+])
+
+# Search for clock_gettime
+AC_SEARCH_LIBS([clock_gettime], [rt], [
+ AC_DEFINE([CONFIG_RCU_HAVE_CLOCK_GETTIME], [1])
+ config_rcu_have_clock_gettime=yes
+], [])
+
+AM_CONDITIONAL([COMPAT_FUTEX], [test "x$compat_futex_test" = "x1"])
+AM_CONDITIONAL([NO_SHARED], [test "x$enable_shared" = "xno"])
+
+# smp-support configure option
+AC_ARG_ENABLE([smp-support],
+ AS_HELP_STRING([--disable-smp-support], [Disable SMP support. Warning: only use this on uniprocessor systems. [default=enabled]]),
+ [def_smp_support=$enableval],
+ [def_smp_support="yes"])
+AS_IF([test "x$def_smp_support" = "xyes"], [AC_DEFINE([CONFIG_RCU_SMP], [1])])
+
+# RCU debugging option
+AC_ARG_ENABLE([rcu-debug],
+ AS_HELP_STRING([--enable-rcu-debug], [Enable internal debugging
+ self-checks. Introduces a performance penalty.]))
+AS_IF([test "x$enable_rcu_debug" = "xyes"], [
+ AC_DEFINE([CONFIG_RCU_DEBUG], [1])
+])
+
+# rculfhash iterator debugging
+AC_ARG_ENABLE([cds-lfht-iter-debug],
+ AS_HELP_STRING([--enable-cds-lfht-iter-debug], [Enable extra debugging checks for lock-free hash table iterator traversal. Alters the rculfhash ABI. Make sure to compile both library and application with matching configuration.]))
+AS_IF([test "x$enable_cds_lfht_iter_debug" = "xyes"], [
+ AC_DEFINE([CONFIG_CDS_LFHT_ITER_DEBUG], [1])
+])
+
+# From the sched_setaffinity(2)'s man page:
+# ~~~~
+# The CPU affinity system calls were introduced in Linux kernel 2.5.8.
+# The library interfaces were introduced in glibc 2.3. Initially, the
+# glibc interfaces included a cpusetsize argument. In glibc 2.3.3,
+# the cpuset size argument was removed, but this argument was
+# restored in glibc 2.3.4.
+# ~~~~
+
+# In addition to that, some vendors ported the system call to 2.4
+# kernels.
+
+# Furthermore, when the function first appeared, the MASK argument was
+# an unsigned long pointer, while later it was made into a cpu_set_t
+# pointer. Systems that have the cpu_set_t version also should have
+# the CPU_ZERO, CPU_SET, etc. macros.
+
+# All this mess means we have to cater for at least 3 different
+# sched_setaffinity prototypes:
+
+# ~~~~
+# int sched_setaffinity (pid_t pid, unsigned int len, unsigned long *mask);
+# int sched_setaffinity (pid_t __pid, size_t __cpusetsize, const cpu_set_t *__cpuset);
+# int sched_setaffinity (pid_t __pid, const cpu_set_t *__mask);
+# ~~~~
+
+AC_CHECK_TYPES([cpu_set_t],
+ [have_cpu_set_t="yes"],
+ [have_cpu_set_t="no"],
+ [#include <sched.h>])
+
+# Confirm that we have CPU_ZERO, and it actually works.
+AC_MSG_CHECKING([whether CPU_ZERO works])
+AH_TEMPLATE([HAVE_CPU_ZERO], [Defined to 1 if we have CPU_ZERO and it works])
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
+ #include <sched.h>
+ int main()
+ {
+ cpu_set_t foo; CPU_ZERO(&foo);
+ return 0;
+ }
+ ]])
+],[
+ AC_DEFINE(HAVE_CPU_ZERO, 1)
+ AC_MSG_RESULT([yes])
+],[
+ AC_MSG_RESULT([no])
+])
+
+# Confirm that we have CPU_SET, and it actually works.
+AC_MSG_CHECKING([whether CPU_SET works])
+AH_TEMPLATE([HAVE_CPU_SET], [Defined to 1 if we have CPU_SET and it works])
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
+ #include <sched.h>
+ int main()
+ {
+ cpu_set_t foo; CPU_SET(0, &foo);
+ return 0;
+ }
+ ]])
+],[
+ AC_DEFINE(HAVE_CPU_SET, 1)
+ AC_MSG_RESULT([yes])
+],[
+ AC_MSG_RESULT([no])
+])
+
+# First check if the function is available at all.
+AC_CHECK_FUNCS([sched_setaffinity],[
+ # Okay, we have it. Check if also have cpu_set_t. If we don't,
+ # then we have the first version using unsigned long, and no
+ # CPU_ZERO, etc. macros. If we do have cpu_set_t, we may have the
+ # version with 2 or 3 arguments. In that case, CPU_ZERO, etc.,
+ # should also be present, but we confirm nonetheless.
+
+ AS_IF([test "x$have_cpu_set_t" = "xyes"], [
+ # We do have it.
+ # Check how many arguments does sched_setaffinity take.
+ # Should be 3 or 2.
+ AC_MSG_CHECKING([how many arguments sched_setaffinity takes])
+ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
+ #include <sched.h>
+ int main()
+ {
+ cpu_set_t foo;
+ sched_setaffinity(0, sizeof (foo), &foo);
+ return 0;
+ }
+ ]])
+ ],
+ [sched_set_affinity_args=3],
+ [sched_set_affinity_args=2])
+ AC_DEFINE_UNQUOTED(SCHED_SETAFFINITY_ARGS,
+ $sched_set_affinity_args,
+ [Defined to sched_setaffinity's number of arguments.])
+ AC_MSG_RESULT([$sched_set_affinity_args])
+ ],[
+ # No cpu_set_t, always 3 args.
+ AC_DEFINE(SCHED_SETAFFINITY_ARGS, 3)
+ ])
+])
+
+AM_CPPFLAGS="-include config.h"
+AC_SUBST(AM_CPPFLAGS)
+
+AM_CFLAGS="-Wall -Wextra -Wno-unused-parameter $AM_CFLAGS"
+AC_SUBST(AM_CFLAGS)