From 9683141c86e3d76c6bbae232a9e12bf4c59da10d Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Fri, 8 Sep 2023 21:57:51 +0200 Subject: [PATCH] Update m4 scripts Update ax_check_define.m4 Update ax_check_gnu_make.m4 Update ax_pthread.m4 Update ax_valgrind_check.m4 Update ax_add_fortify_source.m4 --- m4/ax_add_fortify_source.m4 | 79 +++++++++++++++++++++++++++++-------- m4/ax_check_define.m4 | 33 ++++------------ m4/ax_check_gnu_make.m4 | 15 ++++++- m4/ax_pthread.m4 | 12 +++--- m4/ax_valgrind_check.m4 | 48 +++++++++++----------- 5 files changed, 112 insertions(+), 75 deletions(-) diff --git a/m4/ax_add_fortify_source.m4 b/m4/ax_add_fortify_source.m4 index b88d496f..c0b089c0 100644 --- a/m4/ax_add_fortify_source.m4 +++ b/m4/ax_add_fortify_source.m4 @@ -9,9 +9,9 @@ # DESCRIPTION # # Check whether -D_FORTIFY_SOURCE=2 can be added to CPPFLAGS without macro -# redefinition warnings or linker errors. Some distributions (such as -# Gentoo Linux) enable _FORTIFY_SOURCE globally in their compilers, -# leading to unnecessary warnings in the form of +# redefinition warnings, other cpp warnings or linker. Some distributions +# (such as Ubuntu or Gentoo Linux) enable _FORTIFY_SOURCE globally in +# their compilers, leading to unnecessary warnings in the form of # # :0:0: error: "_FORTIFY_SOURCE" redefined [-Werror] # : note: this is the location of the previous definition @@ -21,41 +21,45 @@ # to CPPFLAGS. # # Newer mingw-w64 msys2 package comes with a bug in -# headers-git-7.0.0.5546.d200317d-1. It broke -D_FORTIFY_SOURCE -# support, and would need -lssp or -fstack-protector. See -# https://github.com/msys2/MINGW-packages/issues/5803. Try to -# actually link it. +# headers-git-7.0.0.5546.d200317d-1. It broke -D_FORTIFY_SOURCE support, +# and would need -lssp or -fstack-protector. See +# https://github.com/msys2/MINGW-packages/issues/5803. Try to actually +# link it. # # LICENSE # # Copyright (c) 2017 David Seifert -# Copyright (c) 2019 Reini Urban +# Copyright (c) 2019, 2023 Reini Urban # # Copying and distribution of this file, with or without modification, are # permitted in any medium without royalty provided the copyright notice # and this notice are preserved. This file is offered as-is, without any # warranty. -#serial 3 +#serial 8 AC_DEFUN([AX_ADD_FORTIFY_SOURCE],[ - AC_MSG_CHECKING([whether to add -D_FORTIFY_SOURCE=2 to CPPFLAGS]) + ac_save_cflags=$CFLAGS + ac_cwerror_flag=yes + AX_CHECK_COMPILE_FLAG([-Werror],[CFLAGS="$CFLAGS -Werror"]) + ax_add_fortify_3_failed= + AC_MSG_CHECKING([whether to add -D_FORTIFY_SOURCE=3 to CPPFLAGS]) AC_LINK_IFELSE([ AC_LANG_PROGRAM([], [[ #ifndef _FORTIFY_SOURCE return 0; #else - this_is_an_error; + _FORTIFY_SOURCE_already_defined; #endif ]] )], AC_LINK_IFELSE([ AC_LANG_SOURCE([[ - #define _FORTIFY_SOURCE 2 + #define _FORTIFY_SOURCE 3 #include int main() { - const char *s = " "; + char *s = " "; strcpy(s, "x"); return strlen(s)-1; } @@ -63,12 +67,55 @@ AC_DEFUN([AX_ADD_FORTIFY_SOURCE],[ )], [ AC_MSG_RESULT([yes]) - CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2" + CFLAGS=$ac_save_cflags + CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=3" ], [ AC_MSG_RESULT([no]) + CFLAGS=$ac_save_cflags + ax_add_fortify_3_failed=1 ], ), [ - AC_MSG_RESULT([no]) - ]) + AC_MSG_RESULT([no]) + CFLAGS=$ac_save_cflags + ax_add_fortify_3_failed=1 + ]) + if test -n "$ax_add_fortify_3_failed" + then + AC_MSG_CHECKING([whether to add -D_FORTIFY_SOURCE=2 to CPPFLAGS]) + AC_LINK_IFELSE([ + AC_LANG_PROGRAM([], + [[ + #ifndef _FORTIFY_SOURCE + return 0; + #else + _FORTIFY_SOURCE_already_defined; + #endif + ]] + )], + AC_LINK_IFELSE([ + AC_LANG_SOURCE([[ + #define _FORTIFY_SOURCE 2 + #include + int main(void) { + char *s = " "; + strcpy(s, "x"); + return strlen(s)-1; + } + ]] + )], + [ + AC_MSG_RESULT([yes]) + CFLAGS=$ac_save_cflags + CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2" + ], [ + AC_MSG_RESULT([no]) + CFLAGS=$ac_save_cflags + ], + ), + [ + AC_MSG_RESULT([no]) + CFLAGS=$ac_save_cflags + ]) + fi ]) diff --git a/m4/ax_check_define.m4 b/m4/ax_check_define.m4 index 20ba8086..c10d1137 100644 --- a/m4/ax_check_define.m4 +++ b/m4/ax_check_define.m4 @@ -18,33 +18,12 @@ # # Copyright (c) 2008 Guido U. Draheim # -# 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; 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 General Public License along -# with this program. If not, see . -# -# As a special exception, the respective Autoconf Macro's copyright owner -# gives unlimited permission to copy, distribute and modify the configure -# scripts that are the output of Autoconf when processing the Macro. You -# need not follow the terms of the GNU General Public License when using -# or distributing such scripts, even though portions of the text of the -# Macro appear in them. The GNU General Public License (GPL) does govern -# all other use of the material that constitutes the Autoconf Macro. -# -# This special exception to the GPL applies to versions of the Autoconf -# Macro released by the Autoconf Archive. When you make and distribute a -# modified version of the Autoconf Macro, you may extend this special -# exception to the GPL to apply to your modified version as well. +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. -#serial 9 +#serial 11 AU_ALIAS([AC_CHECK_DEFINED], [AC_CHECK_DEFINE]) AC_DEFUN([AC_CHECK_DEFINE],[ @@ -53,6 +32,7 @@ AC_CACHE_CHECK([for $1 defined], ac_var, AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[ #ifdef $1 int ok; + (void)ok; #else choke me #endif @@ -68,6 +48,7 @@ AC_CACHE_CHECK([for $2 defined in $1], ac_var, AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <$1>]], [[ #ifdef $2 int ok; + (void)ok; #else choke me #endif diff --git a/m4/ax_check_gnu_make.m4 b/m4/ax_check_gnu_make.m4 index 4c761ea0..785dc96d 100644 --- a/m4/ax_check_gnu_make.m4 +++ b/m4/ax_check_gnu_make.m4 @@ -4,7 +4,7 @@ # # SYNOPSIS # -# AX_CHECK_GNU_MAKE() +# AX_CHECK_GNU_MAKE([run-if-true],[run-if-false]) # # DESCRIPTION # @@ -13,6 +13,10 @@ # * The makefile variable `ifGNUmake' is set to the empty string, otherwise # it is set to "#". This is useful for including a special features in a # Makefile, which cannot be handled by other versions of make. +# * The makefile variable `ifnGNUmake' is set to #, otherwise +# it is set to the empty string. This is useful for including a special +# features in a Makefile, which can be handled +# by other versions of make or to specify else like clause. # * The variable `_cv_gnu_make_command` is set to the command to invoke # GNU make if it exists, the empty string otherwise. # * The variable `ax_cv_gnu_make_command` is set to the command to invoke @@ -20,6 +24,8 @@ # * If GNU Make is found, its version is extracted from the output of # `make --version` as the last field of a record of space-separated # columns and saved into the variable `ax_check_gnu_make_version`. +# * Additionally if GNU Make is found, run shell code run-if-true +# else run shell code run-if-false. # # Here is an example of its use: # @@ -31,6 +37,8 @@ # # @ifGNUmake@ ifeq ($(DEPEND),$(wildcard $(DEPEND))) # @ifGNUmake@ include $(DEPEND) +# @ifGNUmake@ else +# fallback code # @ifGNUmake@ endif # # Then configure.in would normally contain: @@ -61,7 +69,7 @@ # and this notice are preserved. This file is offered as-is, without any # warranty. -#serial 9 +#serial 12 AC_DEFUN([AX_CHECK_GNU_MAKE],dnl [AC_PROG_AWK @@ -79,6 +87,9 @@ dnl Search all the common names for GNU make done ;]) dnl If there was a GNU version, then set @ifGNUmake@ to the empty string, '#' otherwise AS_VAR_IF([_cv_gnu_make_command], [""], [AS_VAR_SET([ifGNUmake], ["#"])], [AS_VAR_SET([ifGNUmake], [""])]) + AS_VAR_IF([_cv_gnu_make_command], [""], [AS_VAR_SET([ifnGNUmake], [""])], [AS_VAR_SET([ifnGNUmake], ["#"])]) AS_VAR_IF([_cv_gnu_make_command], [""], [AS_UNSET(ax_cv_gnu_make_command)], [AS_VAR_SET([ax_cv_gnu_make_command], [${_cv_gnu_make_command}])]) + AS_VAR_IF([_cv_gnu_make_command], [""],[$2],[$1]) AC_SUBST([ifGNUmake]) + AC_SUBST([ifnGNUmake]) ]) diff --git a/m4/ax_pthread.m4 b/m4/ax_pthread.m4 index e5858e50..9f35d139 100644 --- a/m4/ax_pthread.m4 +++ b/m4/ax_pthread.m4 @@ -87,11 +87,11 @@ # modified version of the Autoconf Macro, you may extend this special # exception to the GPL to apply to your modified version as well. -#serial 30 +#serial 31 AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD]) AC_DEFUN([AX_PTHREAD], [ -AC_REQUIRE([AC_CANONICAL_TARGET]) +AC_REQUIRE([AC_CANONICAL_HOST]) AC_REQUIRE([AC_PROG_CC]) AC_REQUIRE([AC_PROG_SED]) AC_LANG_PUSH([C]) @@ -158,7 +158,7 @@ ax_pthread_flags="pthreads none -Kthread -pthread -pthreads -mthreads pthread -- # --thread-safe: KAI C++ # pthread-config: use pthread-config program (for GNU Pth library) -case $target_os in +case $host_os in freebsd*) @@ -248,7 +248,7 @@ AS_IF([test "x$ax_pthread_clang" = "xyes"], # definitions is, on some systems, a strong hint that pthreads support is # correctly enabled -case $target_os in +case $host_os in darwin* | hpux* | linux* | osf* | solaris*) ax_pthread_check_macro="_REENTRANT" ;; @@ -450,7 +450,7 @@ if test "x$ax_pthread_ok" = "xyes"; then AC_CACHE_CHECK([whether more special flags are required for pthreads], [ax_cv_PTHREAD_SPECIAL_FLAGS], [ax_cv_PTHREAD_SPECIAL_FLAGS=no - case $target_os in + case $host_os in solaris*) ax_cv_PTHREAD_SPECIAL_FLAGS="-D_POSIX_PTHREAD_SEMANTICS" ;; @@ -480,7 +480,7 @@ if test "x$ax_pthread_ok" = "xyes"; then # More AIX lossage: compile with *_r variant if test "x$GCC" != "xyes"; then - case $target_os in + case $host_os in aix*) AS_CASE(["x/$CC"], [x*/c89|x*/c89_128|x*/c99|x*/c99_128|x*/cc|x*/cc128|x*/xlc|x*/xlc_v6|x*/xlc128|x*/xlc128_v6], diff --git a/m4/ax_valgrind_check.m4 b/m4/ax_valgrind_check.m4 index 876f8876..e0d8a2f3 100644 --- a/m4/ax_valgrind_check.m4 +++ b/m4/ax_valgrind_check.m4 @@ -36,21 +36,19 @@ # AX_VALGRIND_DFLT([sgcheck], [off]) # AX_VALGRIND_CHECK # -# Makefile.am: +# in each Makefile.am with tests: # # @VALGRIND_CHECK_RULES@ # VALGRIND_SUPPRESSIONS_FILES = my-project.supp # EXTRA_DIST = my-project.supp # -# This results in a "check-valgrind" rule being added to any Makefile.am -# which includes "@VALGRIND_CHECK_RULES@" (assuming the module has been -# configured with --enable-valgrind). Running `make check-valgrind` in -# that directory will run the module's test suite (`make check`) once for -# each of the available Valgrind tools (out of memcheck, helgrind and drd) -# while the sgcheck will be skipped unless enabled again on the -# commandline with --enable-valgrind-sgcheck. The results for each check -# will be output to test-suite-$toolname.log. The target will succeed if -# there are zero errors and fail otherwise. +# This results in a "check-valgrind" rule being added. Running `make +# check-valgrind` in that directory will recursively run the module's test +# suite (`make check`) once for each of the available Valgrind tools (out +# of memcheck, helgrind and drd) while the sgcheck will be skipped unless +# enabled again on the commandline with --enable-valgrind-sgcheck. The +# results for each check will be output to test-suite-$toolname.log. The +# target will succeed if there are zero errors and fail otherwise. # # Alternatively, a "check-valgrind-$TOOL" rule will be added, for $TOOL in # memcheck, helgrind, drd and sgcheck. These are useful because often only @@ -67,7 +65,7 @@ # and this notice are preserved. This file is offered as-is, without any # warranty. -#serial 15 +#serial 23 dnl Configured tools m4_define([valgrind_tool_list], [[memcheck], [helgrind], [drd], [sgcheck]]) @@ -80,10 +78,14 @@ AC_DEFUN([AX_VALGRIND_DFLT],[ ])dnl AC_DEFUN([AX_VALGRIND_CHECK],[ + AM_EXTRA_RECURSIVE_TARGETS([check-valgrind]) + m4_foreach([vgtool], [valgrind_tool_list], + [AM_EXTRA_RECURSIVE_TARGETS([check-valgrind-]vgtool)]) + dnl Check for --enable-valgrind AC_ARG_ENABLE([valgrind], - [AS_HELP_STRING([--enable-valgrind], [Whether to enable Valgrind on the unit tests (requires GNU make)])], - [enable_valgrind=$enableval],[enable_valgrind=no]) + [AS_HELP_STRING([--enable-valgrind], [Whether to enable Valgrind on the unit tests])], + [enable_valgrind=$enableval],[enable_valgrind=]) AS_IF([test "$enable_valgrind" != "no"],[ # Check for Valgrind. @@ -175,7 +177,7 @@ valgrind_quiet_ = $(valgrind_quiet_$(AM_DEFAULT_VERBOSITY)) valgrind_quiet_0 = --quiet valgrind_v_use = $(valgrind_v_use_$(V)) valgrind_v_use_ = $(valgrind_v_use_$(AM_DEFAULT_VERBOSITY)) -valgrind_v_use_0 = @echo " USE " $(patsubst check-valgrind-%,%,$''@):; +valgrind_v_use_0 = @echo " USE " $(patsubst check-valgrind-%-local,%,$''@):; # Support running with and without libtool. ifneq ($(LIBTOOL),) @@ -185,12 +187,12 @@ valgrind_lt = endif # Use recursive makes in order to ignore errors during check -check-valgrind: +check-valgrind-local: ifeq ($(VALGRIND_ENABLED),yes) $(A''M_V_at)$(MAKE) $(AM_MAKEFLAGS) -k \ $(foreach tool, $(valgrind_enabled_tools), check-valgrind-$(tool)) else - @echo "Need to use GNU make and reconfigure with --enable-valgrind" + @echo "Need to reconfigure with --enable-valgrind" endif # Valgrind running @@ -204,14 +206,16 @@ VALGRIND_LOG_COMPILER = \ $(valgrind_lt) \ $(VALGRIND) $(VALGRIND_SUPPRESSIONS) --error-exitcode=1 $(VALGRIND_FLAGS) -define valgrind_tool_rule = -check-valgrind-$(1): +define valgrind_tool_rule +check-valgrind-$(1)-local: ifeq ($$(VALGRIND_ENABLED)-$$(ENABLE_VALGRIND_$(1)),yes-yes) +ifneq ($$(TESTS),) $$(valgrind_v_use)$$(MAKE) check-TESTS \ TESTS_ENVIRONMENT="$$(VALGRIND_TESTS_ENVIRONMENT)" \ LOG_COMPILER="$$(VALGRIND_LOG_COMPILER)" \ LOG_FLAGS="$$(valgrind_$(1)_flags)" \ TEST_SUITE_LOG=test-suite-$(1).log +endif else ifeq ($$(VALGRIND_ENABLED),yes) @echo "Need to reconfigure with --enable-valgrind-$(1)" else @@ -227,15 +231,9 @@ A''M_DISTCHECK_CONFIGURE_FLAGS += --disable-valgrind MOSTLYCLEANFILES ?= MOSTLYCLEANFILES += $(valgrind_log_files) -.PHONY: check-valgrind $(add-prefix check-valgrind-,$(valgrind_tools)) +.PHONY: check-valgrind $(addprefix check-valgrind-,$(valgrind_tools)) '] - AS_IF([test "$enable_valgrind" != "yes"], [ - VALGRIND_CHECK_RULES=' -check-valgrind: - @echo "Need to use GNU make and reconfigure with --enable-valgrind"' - ]) - AC_SUBST([VALGRIND_CHECK_RULES]) m4_ifdef([_AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE([VALGRIND_CHECK_RULES])]) ])