From: Michael Jeanson Date: Fri, 19 Mar 2021 17:45:34 +0000 (-0400) Subject: Modernize autotools setup X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=refs%2Fpull%2F8%2Fhead;p=librseq.git Modernize autotools setup This is part of an effort to standardise our autotools setup across project to simplify maintenance. Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- diff --git a/bootstrap b/bootstrap index ace8016..f6a332b 100755 --- a/bootstrap +++ b/bootstrap @@ -6,4 +6,4 @@ if [ ! -d "config" ]; then mkdir config fi -autoreconf -vi +autoreconf -vif -W all,error diff --git a/configure.ac b/configure.ac index 7da138d..e526976 100644 --- a/configure.ac +++ b/configure.ac @@ -1,14 +1,31 @@ -# SPDX-License-Identifier: MIT -# -# Copyright (C) 2019 Michael Jeanson -# - -AC_PREREQ(2.59) -AC_INIT([librseq],[0.1.0-pre],[mathieu dot desnoyers at efficios dot com], [], [https://github.com/compudj/librseq/]) - +dnl SPDX-License-Identifier: MIT +dnl +dnl Copyright (C) 2021 EfficiOS, Inc. +dnl +dnl Process this file with autoconf to produce a configure script. + +# Project version information +m4_define([rseq_version_major], [0]) +m4_define([rseq_version_minor], [1]) +m4_define([rseq_version_patch], [0]) +m4_define([rseq_version_dev_stage], [-pre]) +m4_define([rseq_version], rseq_version_major[.]rseq_version_minor[.]rseq_version_patch[]rseq_version_dev_stage) + +# Library version information of "librseq" # Following the numbering scheme proposed by libtool for the library version # http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html -AC_SUBST([RSEQ_LIBRARY_VERSION], [0:0:0]) +m4_define([rseq_lib_version_current], [0]) +m4_define([rseq_lib_version_revision], [0]) +m4_define([rseq_lib_version_age], [0]) +m4_define([rseq_lib_version], rseq_lib_version_current[:]rseq_lib_version_revision[:]rseq_lib_version_age) + + +## ## +## Autoconf base setup ## +## ## + +AC_PREREQ([2.69]) +AC_INIT([librseq],[rseq_version],[mathieu dot desnoyers at efficios dot com],[],[https://github.com/compudj/librseq/]) AC_CONFIG_HEADERS([include/config.h]) AC_CONFIG_AUX_DIR([config]) @@ -17,26 +34,45 @@ AC_CONFIG_MACRO_DIR([m4]) AC_CANONICAL_TARGET AC_CANONICAL_HOST -AM_INIT_AUTOMAKE([foreign dist-bzip2 no-dist-gzip nostdinc]) + +## ## +## Automake base setup ## +## ## + +AM_INIT_AUTOMAKE([1.12 foreign dist-bzip2 no-dist-gzip nostdinc -Wall -Werror]) AM_MAINTAINER_MODE([enable]) -# Enable silent rules if available (Introduced in AM 1.11) -m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) +# Enable silent rules by default +AM_SILENT_RULES([yes]) -# Checks for C compiler -AC_USE_SYSTEM_EXTENSIONS + +## ## +## C compiler checks ## +## ## + +# Choose the C compiler AC_PROG_CC -AC_PROG_CC_STDC -AC_PROG_CXX +# AC_PROG_CC_STDC was merged in AC_PROG_CC in autoconf 2.70 +m4_version_prereq([2.70], [], [AC_PROG_CC_STDC]) -# Checks for programs. -AC_PROG_AWK -AC_PROG_MAKE_SET +# Make sure the C compiler supports C99 +AS_IF([test "$ac_cv_prog_cc_c99" = "no"], [AC_MSG_ERROR([The compiler does not support C99])]) -LT_INIT +# Enable available system extensions and LFS support +AC_USE_SYSTEM_EXTENSIONS +AC_SYS_LARGEFILE + +# Make sure the C compiler supports __attribute__ +AX_C___ATTRIBUTE__ +AS_IF([test "x$ax_cv___attribute__" != "xyes"], + [AC_MSG_ERROR([The compiler does not support __attribute__ extensions])]) + +# Make sure we have pthread support +AX_PTHREAD([], [AC_MSG_ERROR([Could not configure pthread support])]) # Checks for typedefs, structures, and compiler characteristics. AC_C_INLINE +AC_C_TYPEOF AC_TYPE_INT32_T AC_TYPE_INT64_T AC_TYPE_OFF_T @@ -44,19 +80,44 @@ AC_TYPE_SIZE_T AC_TYPE_UINT32_T AC_TYPE_UINT64_T -AX_C___ATTRIBUTE__ -AS_IF([test "x$ax_cv___attribute__" = "xyes"], - [:], - [AC_MSG_ERROR([The compiler does not support __attribute__ extensions])]) -AX_PTHREAD(,[AC_MSG_ERROR([Could not configure pthreads support])]) +## ## +## Header checks ## +## ## + +AC_HEADER_STDBOOL +AC_CHECK_HEADERS([ \ + limits.h \ + stddef.h \ + sys/time.h \ +]) + +AC_CHECK_HEADER([linux/rseq.h], [], + [AC_MSG_ERROR([Cannot find 'linux/rseq.h'.]) +]) + + +## ## +## Programs checks ## +## ## + +AM_PROG_AR +AC_PROG_AWK +AC_PROG_MAKE_SET + +# Initialize and configure libtool +LT_INIT -AM_CFLAGS="$AM_CFLAGS $PTHREAD_CFLAGS" + +## ## +## Library checks ## +## ## # Checks for library functions. AC_FUNC_MMAP AC_FUNC_FORK AC_CHECK_FUNCS([ \ + atexit \ memset \ strerror \ ]) @@ -64,24 +125,28 @@ AC_CHECK_FUNCS([ \ # AC_FUNC_MALLOC causes problems when cross-compiling. #AC_FUNC_MALLOC -# Check for headers -AC_HEADER_STDBOOL -AC_CHECK_HEADERS([ \ - limits.h \ - stddef.h \ -]) -AC_CHECK_HEADER([linux/rseq.h]) -AS_IF([test "x${ac_cv_header_linux_rseq_h}" != "xyes"], [ - AC_MSG_ERROR([Cannot find 'linux/rseq.h'.]) -]) +## ## +## Substitute variables for use in Makefile.am ## +## ## + +# Library versions for libtool +AC_SUBST([RSEQ_LIBRARY_VERSION], [rseq_lib_version]) -AM_CPPFLAGS="-include config.h" +# The order in which the include folders are searched is important. +# The top_builddir should always be searched first in the event that a build +# time generated file is included. +AM_CPPFLAGS="-I\$(top_builddir)/include -I\$(top_srcdir)/include -include config.h" AC_SUBST(AM_CPPFLAGS) -AM_CFLAGS="-Wall -Wextra $AM_CFLAGS" +AM_CFLAGS="-Wall -Wextra $PTHREAD_CFLAGS" AC_SUBST(AM_CFLAGS) + +## ## +## Output files generated by configure ## +## ## + AC_CONFIG_FILES([ Makefile doc/Makefile @@ -95,6 +160,7 @@ AC_CONFIG_FILES([ AC_OUTPUT + # # Mini-report on what will be built. # diff --git a/m4/ax_pthread.m4 b/m4/ax_pthread.m4 index 4920e07..507f182 100644 --- a/m4/ax_pthread.m4 +++ b/m4/ax_pthread.m4 @@ -55,6 +55,7 @@ # # Copyright (c) 2008 Steven G. Johnson # Copyright (c) 2011 Daniel Richard G. +# Copyright (c) 2019 Marc Stevens # # 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 @@ -82,7 +83,7 @@ # modified version of the Autoconf Macro, you may extend this special # exception to the GPL to apply to your modified version as well. -#serial 25 +#serial 27 AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD]) AC_DEFUN([AX_PTHREAD], [ @@ -123,10 +124,12 @@ fi # (e.g. DEC) have both -lpthread and -lpthreads, where one of the # libraries is broken (non-POSIX). -# Create a list of thread flags to try. Items starting with a "-" are -# C compiler flags, and other items are library names, except for "none" -# which indicates that we try without any flags at all, and "pthread-config" -# which is a program returning the flags for the Pth emulation library. +# Create a list of thread flags to try. Items with a "," contain both +# C compiler flags (before ",") and linker flags (after ","). Other items +# starting with a "-" are C compiler flags, and remaining items are +# library names, except for "none" which indicates that we try without +# any flags at all, and "pthread-config" which is a program returning +# the flags for the Pth emulation library. ax_pthread_flags="pthreads none -Kthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" @@ -194,14 +197,47 @@ case $host_os in # that too in a future libc.) So we'll check first for the # standard Solaris way of linking pthreads (-mt -lpthread). - ax_pthread_flags="-mt,pthread pthread $ax_pthread_flags" + ax_pthread_flags="-mt,-lpthread pthread $ax_pthread_flags" ;; esac +# Are we compiling with Clang? + +AC_CACHE_CHECK([whether $CC is Clang], + [ax_cv_PTHREAD_CLANG], + [ax_cv_PTHREAD_CLANG=no + # Note that Autoconf sets GCC=yes for Clang as well as GCC + if test "x$GCC" = "xyes"; then + AC_EGREP_CPP([AX_PTHREAD_CC_IS_CLANG], + [/* Note: Clang 2.7 lacks __clang_[a-z]+__ */ +# if defined(__clang__) && defined(__llvm__) + AX_PTHREAD_CC_IS_CLANG +# endif + ], + [ax_cv_PTHREAD_CLANG=yes]) + fi + ]) +ax_pthread_clang="$ax_cv_PTHREAD_CLANG" + + # GCC generally uses -pthread, or -pthreads on some platforms (e.g. SPARC) +# Note that for GCC and Clang -pthread generally implies -lpthread, +# except when -nostdlib is passed. +# This is problematic using libtool to build C++ shared libraries with pthread: +# [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25460 +# [2] https://bugzilla.redhat.com/show_bug.cgi?id=661333 +# [3] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=468555 +# To solve this, first try -pthread together with -lpthread for GCC + AS_IF([test "x$GCC" = "xyes"], - [ax_pthread_flags="-pthread -pthreads $ax_pthread_flags"]) + [ax_pthread_flags="-pthread,-lpthread -pthread -pthreads $ax_pthread_flags"]) + +# Clang takes -pthread (never supported any other flag), but we'll try with -lpthread first + +AS_IF([test "x$ax_pthread_clang" = "xyes"], + [ax_pthread_flags="-pthread,-lpthread -pthread"]) + # The presence of a feature test macro requesting re-entrant function # definitions is, on some systems, a strong hint that pthreads support is @@ -224,25 +260,86 @@ AS_IF([test "x$ax_pthread_check_macro" = "x--"], [ax_pthread_check_cond=0], [ax_pthread_check_cond="!defined($ax_pthread_check_macro)"]) -# Are we compiling with Clang? -AC_CACHE_CHECK([whether $CC is Clang], - [ax_cv_PTHREAD_CLANG], - [ax_cv_PTHREAD_CLANG=no - # Note that Autoconf sets GCC=yes for Clang as well as GCC - if test "x$GCC" = "xyes"; then - AC_EGREP_CPP([AX_PTHREAD_CC_IS_CLANG], - [/* Note: Clang 2.7 lacks __clang_[a-z]+__ */ -# if defined(__clang__) && defined(__llvm__) - AX_PTHREAD_CC_IS_CLANG -# endif - ], - [ax_cv_PTHREAD_CLANG=yes]) - fi - ]) -ax_pthread_clang="$ax_cv_PTHREAD_CLANG" +if test "x$ax_pthread_ok" = "xno"; then +for ax_pthread_try_flag in $ax_pthread_flags; do + + case $ax_pthread_try_flag in + none) + AC_MSG_CHECKING([whether pthreads work without any flags]) + ;; + + *,*) + PTHREAD_CFLAGS=`echo $ax_pthread_try_flag | sed "s/^\(.*\),\(.*\)$/\1/"` + PTHREAD_LIBS=`echo $ax_pthread_try_flag | sed "s/^\(.*\),\(.*\)$/\2/"` + AC_MSG_CHECKING([whether pthreads work with "$PTHREAD_CFLAGS" and "$PTHREAD_LIBS"]) + ;; + + -*) + AC_MSG_CHECKING([whether pthreads work with $ax_pthread_try_flag]) + PTHREAD_CFLAGS="$ax_pthread_try_flag" + ;; + + pthread-config) + AC_CHECK_PROG([ax_pthread_config], [pthread-config], [yes], [no]) + AS_IF([test "x$ax_pthread_config" = "xno"], [continue]) + PTHREAD_CFLAGS="`pthread-config --cflags`" + PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" + ;; + + *) + AC_MSG_CHECKING([for the pthreads library -l$ax_pthread_try_flag]) + PTHREAD_LIBS="-l$ax_pthread_try_flag" + ;; + esac + + ax_pthread_save_CFLAGS="$CFLAGS" + ax_pthread_save_LIBS="$LIBS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + LIBS="$PTHREAD_LIBS $LIBS" + + # Check for various functions. We must include pthread.h, + # since some functions may be macros. (On the Sequent, we + # need a special flag -Kthread to make this header compile.) + # We check for pthread_join because it is in -lpthread on IRIX + # while pthread_create is in libc. We check for pthread_attr_init + # due to DEC craziness with -lpthreads. We check for + # pthread_cleanup_push because it is one of the few pthread + # functions on Solaris that doesn't have a non-functional libc stub. + # We try pthread_create on general principles. + + AC_LINK_IFELSE([AC_LANG_PROGRAM([#include +# if $ax_pthread_check_cond +# error "$ax_pthread_check_macro must be defined" +# endif + static void *some_global = NULL; + static void routine(void *a) + { + /* To avoid any unused-parameter or + unused-but-set-parameter warning. */ + some_global = a; + } + static void *start_routine(void *a) { return a; }], + [pthread_t th; pthread_attr_t attr; + pthread_create(&th, 0, start_routine, 0); + pthread_join(th, 0); + pthread_attr_init(&attr); + pthread_cleanup_push(routine, 0); + pthread_cleanup_pop(0) /* ; */])], + [ax_pthread_ok=yes], + []) + + CFLAGS="$ax_pthread_save_CFLAGS" + LIBS="$ax_pthread_save_LIBS" + + AC_MSG_RESULT([$ax_pthread_ok]) + AS_IF([test "x$ax_pthread_ok" = "xyes"], [break]) + + PTHREAD_LIBS="" + PTHREAD_CFLAGS="" +done +fi -ax_pthread_clang_warning=no # Clang needs special handling, because older versions handle the -pthread # option in a rather... idiosyncratic way @@ -261,11 +358,6 @@ if test "x$ax_pthread_clang" = "xyes"; then # -pthread does define _REENTRANT, and while the Darwin headers # ignore this macro, third-party headers might not.) - PTHREAD_CFLAGS="-pthread" - PTHREAD_LIBS= - - ax_pthread_ok=yes - # However, older versions of Clang make a point of warning the user # that, in an invocation where only linking and no compilation is # taking place, the -pthread option has no effect ("argument unused @@ -294,7 +386,7 @@ if test "x$ax_pthread_clang" = "xyes"; then # step ax_pthread_save_ac_link="$ac_link" ax_pthread_sed='s/conftest\.\$ac_ext/conftest.$ac_objext/g' - ax_pthread_link_step=`$as_echo "$ac_link" | sed "$ax_pthread_sed"` + ax_pthread_link_step=`AS_ECHO(["$ac_link"]) | sed "$ax_pthread_sed"` ax_pthread_2step_ac_link="($ac_compile) && (echo ==== >&5) && ($ax_pthread_link_step)" ax_pthread_save_CFLAGS="$CFLAGS" for ax_pthread_try in '' -Qunused-arguments -Wno-unused-command-line-argument unknown; do @@ -320,78 +412,7 @@ if test "x$ax_pthread_clang" = "xyes"; then fi # $ax_pthread_clang = yes -if test "x$ax_pthread_ok" = "xno"; then -for ax_pthread_try_flag in $ax_pthread_flags; do - - case $ax_pthread_try_flag in - none) - AC_MSG_CHECKING([whether pthreads work without any flags]) - ;; - - -mt,pthread) - AC_MSG_CHECKING([whether pthreads work with -mt -lpthread]) - PTHREAD_CFLAGS="-mt" - PTHREAD_LIBS="-lpthread" - ;; - - -*) - AC_MSG_CHECKING([whether pthreads work with $ax_pthread_try_flag]) - PTHREAD_CFLAGS="$ax_pthread_try_flag" - ;; - - pthread-config) - AC_CHECK_PROG([ax_pthread_config], [pthread-config], [yes], [no]) - AS_IF([test "x$ax_pthread_config" = "xno"], [continue]) - PTHREAD_CFLAGS="`pthread-config --cflags`" - PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" - ;; - *) - AC_MSG_CHECKING([for the pthreads library -l$ax_pthread_try_flag]) - PTHREAD_LIBS="-l$ax_pthread_try_flag" - ;; - esac - - ax_pthread_save_CFLAGS="$CFLAGS" - ax_pthread_save_LIBS="$LIBS" - CFLAGS="$CFLAGS $PTHREAD_CFLAGS" - LIBS="$PTHREAD_LIBS $LIBS" - - # Check for various functions. We must include pthread.h, - # since some functions may be macros. (On the Sequent, we - # need a special flag -Kthread to make this header compile.) - # We check for pthread_join because it is in -lpthread on IRIX - # while pthread_create is in libc. We check for pthread_attr_init - # due to DEC craziness with -lpthreads. We check for - # pthread_cleanup_push because it is one of the few pthread - # functions on Solaris that doesn't have a non-functional libc stub. - # We try pthread_create on general principles. - - AC_LINK_IFELSE([AC_LANG_PROGRAM([#include -# if $ax_pthread_check_cond -# error "$ax_pthread_check_macro must be defined" -# endif - static void routine(void *a) { a = 0; } - static void *start_routine(void *a) { return a; }], - [pthread_t th; pthread_attr_t attr; - pthread_create(&th, 0, start_routine, 0); - pthread_join(th, 0); - pthread_attr_init(&attr); - pthread_cleanup_push(routine, 0); - pthread_cleanup_pop(0) /* ; */])], - [ax_pthread_ok=yes], - []) - - CFLAGS="$ax_pthread_save_CFLAGS" - LIBS="$ax_pthread_save_LIBS" - - AC_MSG_RESULT([$ax_pthread_ok]) - AS_IF([test "x$ax_pthread_ok" = "xyes"], [break]) - - PTHREAD_LIBS="" - PTHREAD_CFLAGS="" -done -fi # Various other checks: if test "x$ax_pthread_ok" = "xyes"; then diff --git a/src/Makefile.am b/src/Makefile.am index 1d2d38c..85b692c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,8 +3,6 @@ # Copyright (C) 2019 Michael Jeanson # -AM_CPPFLAGS += -I$(top_srcdir)/include -I$(top_builddir)/include - lib_LTLIBRARIES = librseq.la librseq_la_SOURCES = \ diff --git a/tests/Makefile.am b/tests/Makefile.am index 6d271dd..60c541b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -3,7 +3,7 @@ # Copyright (C) 2020 Michael Jeanson # -AM_CFLAGS += -I$(top_srcdir)/include -I$(top_builddir)/include -I$(top_srcdir)/tests/utils +AM_CPPFLAGS += -I$(top_srcdir)/tests/utils SUBDIRS = utils @@ -28,11 +28,11 @@ param_test_SOURCES = param_test.c param_test_LDADD = $(top_builddir)/src/librseq.la param_test_benchmark_SOURCES = param_test.c -param_test_benchmark_CPPFLAGS = -DBENCHMARK +param_test_benchmark_CPPFLAGS = $(AM_CPPFLAGS) -DBENCHMARK param_test_benchmark_LDADD = $(top_builddir)/src/librseq.la param_test_compare_twice_SOURCES = param_test.c -param_test_compare_twice_CPPFLAGS = -DRSEQ_COMPARE_TWICE +param_test_compare_twice_CPPFLAGS = $(AM_CPPFLAGS) -DRSEQ_COMPARE_TWICE param_test_compare_twice_LDADD = $(top_builddir)/src/librseq.la TESTS = basic_percpu_ops_test.tap basic_test.tap run_param_test.tap diff --git a/tests/utils/Makefile.am b/tests/utils/Makefile.am index 33083da..c3c372c 100644 --- a/tests/utils/Makefile.am +++ b/tests/utils/Makefile.am @@ -1,7 +1,5 @@ # SPDX-License-Identifier: MIT -AM_CFLAGS += -I$(top_srcdir)/include -I$(top_builddir)/include - noinst_LTLIBRARIES = libtap.la libtap_la_SOURCES = tap.c tap.h