From 109787d8ad9d655c7f0af146d7607dbcdce43be7 Mon Sep 17 00:00:00 2001 From: "Peter W. Draper" <p.w.draper@durham.ac.uk> Date: Thu, 4 Jun 2015 17:55:10 +0100 Subject: [PATCH] Update autotools support removes compiler hard coding, adds configure option for controlling optimisation, debugging and sanitizer --- .gitignore | 2 + configure.ac | 124 +++++++++++++++++++++++++++++++++++-------- examples/Makefile.am | 12 ++--- src/Makefile.am | 23 ++++++-- src/version.h.in | 35 ++++++++++++ 5 files changed, 161 insertions(+), 35 deletions(-) create mode 100644 src/version.h.in diff --git a/.gitignore b/.gitignore index 07956c0..9ea508a 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,8 @@ doc/latex/ doc/man/ doc/Doxyfile +src/version.h + examples/test examples/test_bh examples/test_bh_sorted diff --git a/configure.ac b/configure.ac index 9511f8d..3928803 100644 --- a/configure.ac +++ b/configure.ac @@ -18,49 +18,111 @@ # init the project AC_INIT([QUICKSCHED],[0.1.0]) AC_CONFIG_SRCDIR([src/qsched.c]) -AM_INIT_AUTOMAKE([gnu]) +AC_CONFIG_AUX_DIR([.]) +AM_INIT_AUTOMAKE -AC_GNU_SOURCE -AC_PROG_LIBTOOL - -# my own macro collection +# Add local macro collection AC_CONFIG_MACRO_DIR([m4]) +# Stop default CFLAGS from anyone except the environment. +: ${CFLAGS=""} + # generate header file AM_CONFIG_HEADER(config.h) -# compiler settings -#CFLAGS="-Wall $(CFLAGS)" - -# find and test the compiler +# Find and test the compiler. +AX_CHECK_ENABLE_DEBUG +AC_PROG_CC AM_PROG_CC_C_O + +# Enable POSIX and platform extension preprocessor macros. +AC_USE_SYSTEM_EXTENSIONS + +# Add libtool support. +LT_INIT + +# Check for compiler version and vendor. +AX_COMPILER_VENDOR +AX_COMPILER_VERSION + +# Need C99 and inline support. AC_PROG_CC_C99 -AC_LANG_C -# AX_CC_MAXOPT -AX_FUNC_POSIX_MEMALIGN -AX_GCC_ARCHFLAG([no]) -AX_EXT +AC_C_INLINE + +# Only optimize if allowed, otherwise assume user will set CFLAGS as +# appropriate. +AC_ARG_ENABLE([optimization], + [AS_HELP_STRING([--enable-optimization], + [Enable compile time optimization flags for host @<:@default=yes@:>@] + )], + [enable_opt="$enableval"], + [enable_opt="yes"] +) + +if test "$enable_opt" = "yes" ; then -# autoconf stuff + # Add code optimisation flags and tuning to host. This is a funny macro + # that does not like CFLAGS being already set. Work around that as we have + # at least set it to "", so it is set. + ac_test_CFLAGS="no" + old_CFLAGS="$CFLAGS" + AX_CC_MAXOPT + ac_test_CFLAGS="yes" + CFLAGS="$old_CFLAGS $CFLAGS" + + # Check SSE & AVX support (some overlap with AX_CC_MAXOPT). + AX_EXT + if test "$SIMD_FLAGS" != ""; then + CFLAGS="$CFLAGS $SIMD_FLAGS" + fi +fi + +# Add address sanitizer options to flags, if requested. Only useful for GCC +# version 4.8 and later. +AC_ARG_ENABLE([sanitizer], + [AS_HELP_STRING([--enable-sanitizer], + [Enable memory error detection using address sanitizer @<:@default=no@:>@] + )], + [enable_san="$enableval"], + [enable_san="no"] +) + +if test "$enable_san" = "yes"; then + if test "$ax_cv_c_compiler_vendor" = "gnu"; then + AX_COMPARE_VERSION( $ax_cv_c_compiler_version, [ge], [4.8.0], + [enable_san="yes"], [enable_san="no"] ) + if test "$enable_san" = "yes"; then + CFLAGS="$CFLAGS -fsanitize=address -fno-omit-frame-pointer" + fi + else + AC_MSG_WARN([Compiler does not support address sanitizer option]) + fi +fi + +# Autoconf stuff AC_PROG_INSTALL AC_PROG_MAKE_SET AC_HEADER_STDC -# Check for pthreads -ACX_PTHREAD([LIBS="$PTHREAD_LIBS $LIBS" CFLAGS="$CFLAGS $PTHREAD_CFLAGS" - CC="$PTHREAD_CC" LDFLAGS="$PTHREAD_LIBS $LIBS" - AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.])], +# Check for pthreads. +AX_PTHREAD([LIBS="$PTHREAD_LIBS $LIBS" CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + CC="$PTHREAD_CC" LDFLAGS="$LDFLAGS $PTHREAD_LIBS $LIBS"] + AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]), AC_MSG_ERROR([Could not find a working version of the pthread library. Make sure you have the library and header files installed or use CPPFLAGS and LDFLAGS if the library is installed in a non-standard location.])) -# Check for OpenMP -AX_OPENMP +# Check for OpenMP, is required. +AC_OPENMP AC_SUBST(OPENMP_CFLAGS) -if test -z "${OPENMP_CFLAGS}"; then - echo $OPENMP_CFLAGS +enable_openmp="no" +if test -z "$OPENMP_CFLAGS"; then AC_MSG_ERROR(Compiler does not support OpenMP, 1) +else + CFLAGS="$CFLAGS $OPENMP_CFLAGS" + enable_openmp="yes" + AC_DEFINE(HAVE_OPENMP,1,[Define if OpenMP is enabled]) fi # Check for timing functions needed by cycle.h @@ -78,11 +140,27 @@ AC_TRY_LINK([#ifdef HAVE_INTRINSICS_H #endif], [_rtc()], [AC_DEFINE(HAVE__RTC,1,[Define if you have the UNICOS _rtc() intrinsic.])], [rtc_ok=no]) AC_MSG_RESULT($rtc_ok) +# Check for feenableexcept, should be present in C99, also checks for -lm. +AC_CHECK_LIB([m],[feenableexcept]) + +# Check for git, needed for revision stamps. +AC_PATH_PROG([GIT_CMD], [git]) +AC_SUBST([GIT_CMD]) + # make the documentation DX_INIT_DOXYGEN(libquicksched,doc/Doxyfile,doc/) # .in files. AC_CONFIG_FILES([Makefile src/Makefile examples/Makefile doc/Makefile doc/Doxyfile]) +# Report general configuration. +AC_MSG_RESULT([ + Compiler: $CC + vendor: $ax_cv_c_compiler_vendor + version: $ax_cv_c_compiler_version + flags: $CFLAGS + OpenMP enabled: $enable_openmp +]) + # generate output. AC_OUTPUT diff --git a/examples/Makefile.am b/examples/Makefile.am index 4cacb43..61c0267 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -17,15 +17,9 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # Add the source directory and debug to CFLAGS -AM_CFLAGS = -g -O3 -Wall -Werror -I../src -ffast-math -fstrict-aliasing \ - -ftree-vectorize -funroll-loops $(SIMD_FLAGS) $(OPENMP_CFLAGS) \ - -DCPU_TPS=2.67e9 -DTIMERS \ - # -fsanitize=address -fno-omit-frame-pointer -# AM_CFLAGS = -g -O0 -Wall -Werror -I../src \ -# -DCPU_TPS=2.67e9 -DTIMERS $(OPENMP_CFLAGS) \ -# -fsanitize=address -fno-omit-frame-pointer - -AM_LDFLAGS = -lm # -fsanitize=address +AM_CFLAGS = -I../src -DCPU_TPS=2.67e9 -DTIMERS + +AM_LDFLAGS = # Set-up the library bin_PROGRAMS = test test_qr test_bh test_bh_sorted test_fmm_sorted diff --git a/src/Makefile.am b/src/Makefile.am index c953a49..aded797 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -16,13 +16,14 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # Add the debug flag to the whole thing -AM_CFLAGS = -g -O3 -Wall -Werror -ffast-math -fstrict-aliasing -ftree-vectorize \ - -funroll-loops $(SIMD_FLAGS) $(OPENMP_CFLAGS) -DTIMERS \ - # -fsanitize=address -fno-omit-frame-pointer +AM_CFLAGS = -DTIMERS # Assign a "safe" version number AM_LDFLAGS = -version-info 0:0:0 +# The git command, if available. +GIT_CMD = @GIT_CMD@ + # Build the libquicksched library lib_LTLIBRARIES = libquicksched.la libquicksched_la_SOURCES = qsched.c queue.c @@ -32,3 +33,19 @@ include_HEADERS = atomic.h lock.h queue.h qsched.h task.h res.h error.h # Private headers. noinst_HEADERS = cycle.h quicksched.h + +# Versioning. If any sources change then update the version.h file with +# the current git revision and package version. +version.h: version.h.in $(AM_SOURCES) $(include_HEADERS) $(noinst_HEADERS) + if test "X$(GIT_CMD)" != "X"; then \ + GIT_REVISION=`git describe --abbrev=8 --always --tags --dirty`; \ + sed -e "s,@PACKAGE_VERSION\@,$(PACKAGE_VERSION)," \ + -e "s,@GIT_REVISION\@,$${GIT_REVISION}," version.h.in > version.h; \ + fi + +# Make sure version.h is built first. +BUILT_SOURCES = version.h + +# And distribute the built files. +EXTRA_DIST = version.h version.h.in + diff --git a/src/version.h.in b/src/version.h.in new file mode 100644 index 0000000..81e9597 --- /dev/null +++ b/src/version.h.in @@ -0,0 +1,35 @@ +/******************************************************************************* + * This file is part of SWIFT. + * Copyright (c) 2012 Matthieu Schaller (matthieu.schaller@durham.ac.uk). + * Copyright (c) 2015 Peter W. Draper (p.w.draper@durham.ac.uk). + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + ******************************************************************************/ +#ifndef SWIFT_VERSION_H +#define SWIFT_VERSION_H + +/** + * @file version.h + * @brief Package version and git revision sha. + */ + +#define PACKAGE_VERSION "@PACKAGE_VERSION@" +#define GIT_REVISION "@GIT_REVISION@" + +const char* package_description( void ); +const char* package_version(void); +const char* git_revision(void); + +#endif /* SWIFT_VERSION_H */ -- GitLab