[PATCH] add configure script

From: Luiz Capitulino
Date: Tue Feb 23 2016 - 15:53:43 EST


Signed-off-by: Luiz Capitulino <lcapitulino@xxxxxxxxxx>
---
.gitignore | 1 +
Makefile | 22 ++----------
configure | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 120 insertions(+), 19 deletions(-)
create mode 100755 configure

diff --git a/.gitignore b/.gitignore
index ceee8bf..5b3e4cc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -34,3 +34,4 @@ SRPMS
rt-tests.spec
tags
TAGS
+config.mk
diff --git a/Makefile b/Makefile
index 280fd3b..dad0175 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,5 @@
+include config.mk
+
VERSION = 0.97
CC?=$(CROSS_COMPILE)gcc
AR?=$(CROSS_COMPILE)ar
@@ -17,7 +19,6 @@ sources = cyclictest.c \
svsematest.c

TARGETS = $(sources:.c=)
-LIBS = -lrt -lpthread
RTTESTLIB = -lrttest -L$(OBJDIR)
EXTRA_LIBS ?= -ldl # for get_cpu
DESTDIR ?=
@@ -48,26 +49,9 @@ ostype := $(lastword $(subst -, ,$(dumpmachine)))
machinetype := $(shell echo $(dumpmachine)| \
sed -e 's/-.*//' -e 's/i.86/i386/' -e 's/mips.*/mips/' -e 's/ppc.*/powerpc/')

-# The default is to assume you have libnuma installed, which is fine to do
-# even on non-numa machines. If you don't want to install the numa libs, for
-# example, they might not be available in an embedded environment, then
-# compile with
-# make NUMA=0
-ifneq ($(filter x86_64 i386 ia64 mips powerpc,$(machinetype)),)
-NUMA := 1
-endif
-
-# The default is to assume that you only have numa_parse_cpustring
-# If you are sure you have a version of libnuma with numa_parse_cpustring_all
-# then compile with
-# make HAVE_PARSE_CPUSTRING_ALL=1
-ifeq ($(NUMA),1)
- CFLAGS += -DNUMA
- NUMA_LIBS = -lnuma
ifdef HAVE_PARSE_CPUSTRING_ALL
CFLAGS += -DHAVE_PARSE_CPUSTRING_ALL
endif
-endif

include src/arch/android/Makefile

@@ -100,7 +84,7 @@ $(OBJDIR):
-include $(addprefix $(OBJDIR)/,$(sources:.c=.d))

cyclictest: $(OBJDIR)/cyclictest.o $(OBJDIR)/librttest.a
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(RTTESTLIB) $(NUMA_LIBS)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(RTTESTLIB)

signaltest: $(OBJDIR)/signaltest.o $(OBJDIR)/librttest.a
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(RTTESTLIB)
diff --git a/configure b/configure
new file mode 100755
index 0000000..1d17ef9
--- /dev/null
+++ b/configure
@@ -0,0 +1,116 @@
+#!/bin/sh
+
+build_config=config.mk
+temp_dir=$(mktemp -d)
+temp_file=$temp_dir/file.c
+
+LIBS=
+NUMA_LIBS=
+EXTRA_CFLAGS=
+has_numa=n
+has_numa_cpustring_all=n
+
+build_test()
+{
+ local libs=$*
+ local ret=
+
+ cd $temp_dir
+ cc -o prog $temp_file $libs 2> /dev/null
+ ret=$?
+ cd - > /dev/null
+ return $ret
+}
+
+#
+# -lpthread
+#
+pthread_lib=-lpthread
+
+cat > $temp_file << EOF
+#include <pthread.h>
+static void *func(void *p) { return NULL; }
+int main(void) {
+ pthread_t thread;
+ pthread_create(&thread, 0, func, 0);
+ return 0;
+}
+EOF
+
+if ! build_test $pthread_lib; then
+ echo ERROR: missing pthread library
+ exit 1
+else
+ LIBS="$LIBS $pthread_lib"
+fi
+
+#
+# -lrt
+#
+rt_lib=-lrt
+
+cat > $temp_file << EOF
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+int main(void) {
+ shm_open("", 0, 0);
+ return 0;
+}
+EOF
+
+if ! build_test $rt_lib; then
+ echo ERROR: missing rt library
+ exit 1
+else
+ LIBS="$LIBS $rt_lib"
+fi
+
+#
+# -lnuma
+#
+numa_lib=-lnuma
+
+cat > $temp_file << EOF
+#include <numa.h>
+int main(void) {
+ numa_available();
+ return 0;
+}
+EOF
+
+if build_test $numa_lib; then
+ LIBS="$LIBS $numa_lib"
+ EXTRA_CFLAGS="$EXTRA_CFLAGS -DNUMA"
+ has_numa=y
+fi
+
+#
+# numa_parse_cpustring_all
+#
+if [ $has_numa = "y" ]; then
+
+ cat > $temp_file << EOF
+#include <numa.h>
+int main(void) {
+ numa_parse_cpustring_all("");
+ return 0;
+}
+EOF
+
+ if build_test $numa_lib; then
+ has_numa_cpustring_all=y;
+ fi
+fi
+
+#
+# Write $build_config
+#
+echo "LIBS = $LIBS" > $build_config
+echo "EXTRA_CFLAGS = $EXTRA_CFLAGS" >> $build_config
+
+if [ "$has_numa_cpustring_all" = "y" ]; then
+ echo "HAVE_PARSE_CPUSTRING_ALL := 1" >> $build_config
+fi
+
+rm -rf $temp_dir
--
2.5.5