From 0b360f0c7de63ddb9bb20d2fead9e077d9fef735 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Fri, 24 Feb 2023 08:52:32 -0500 Subject: build: Use ASAN and GCC warnings from Gnulib --- diff --git a/Makefile.am b/Makefile.am index 2465627..e78fe46 100644 --- a/Makefile.am +++ b/Makefile.am @@ -34,7 +34,8 @@ boukengine_CPPFLAGS = \ -DTILESETSDIR=\"$(tilesetsdir)\" boukengine_CFLAGS = \ - $(GCC_CFLAGS) + $(WARN_CFLAGS) \ + $(ASAN_CFLAGS) boukengine_LDADD = \ -lm \ diff --git a/boukengine.sh b/boukengine.sh new file mode 100755 index 0000000..f439efd --- /dev/null +++ b/boukengine.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +LSAN_OPTIONS=suppressions=suppr.txt exec "$(dirname "${0}")/boukengine" "${@}" diff --git a/configure.ac b/configure.ac index 8767989..15f9e57 100644 --- a/configure.ac +++ b/configure.ac @@ -19,6 +19,7 @@ dnl Process this file with autoconf to produce a configure script. AC_INIT([boukengine], [0.1.0], [mailto:pj@pehjota.net], [boukengine], [http://www.pehjota.net/projects/overworld-rpg/]) AC_CONFIG_AUX_DIR([build-aux]) +AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_SRCDIR([src/main.c]) AM_INIT_AUTOMAKE([gnu dist-bzip2 dist-xz subdir-objects]) @@ -83,23 +84,6 @@ fi AM_CONDITIONAL([EMBEDDED_XCF2PNG], [${embedded_xcf2png}]) AC_SUBST([XCF2PNG]) -if test "x$GCC" = "xyes"; then - GCC_CFLAGS="-pedantic -Wall -Wextra -Werror" - GCC_CFLAGS="${GCC_CFLAGS} -Wformat=2 -Wswitch -Wswitch-enum" - GCC_CFLAGS="${GCC_CFLAGS} -Wdeclaration-after-statement -Wundef -Wshadow" - GCC_CFLAGS="${GCC_CFLAGS} -Wpointer-arith -Wbad-function-cast" - GCC_CFLAGS="${GCC_CFLAGS} -Wcast-qual -Wcast-align -Wwrite-strings" - #GCC_CFLAGS="${GCC_CFLAGS} -Wconversion" - GCC_CFLAGS="${GCC_CFLAGS} -Wlogical-op -Waggregate-return" - GCC_CFLAGS="${GCC_CFLAGS} -Wstrict-prototypes -Wold-style-definition" - GCC_CFLAGS="${GCC_CFLAGS} -Wmissing-prototypes -Wmissing-declarations" - GCC_CFLAGS="${GCC_CFLAGS} -Wredundant-decls -Wnested-externs" - GCC_CFLAGS="${GCC_CFLAGS} -Wunreachable-code -Winline" - GCC_CFLAGS="${GCC_CFLAGS} -Wdisabled-optimization" - GCC_CFLAGS="${GCC_CFLAGS} -fstack-protector -Wstack-protector" -fi -AC_SUBST(GCC_CFLAGS) - AC_ARG_ENABLE([debug-tmx], [AC_HELP_STRING([--enable-debug-tmx], [enable debug output from TMX parser])], @@ -142,6 +126,67 @@ if test "x$enable_debug_palettes" = "xyes"; then listings.]) fi +AX_CFLAGS_WARN_ALL() dnl Adds -Wall or equivalent +AX_CHECK_COMPILE_FLAG([-Wpedantic], [AX_APPEND_FLAG([-Wpedantic])]) +AX_CHECK_COMPILE_FLAG([-Wextra], [AX_APPEND_FLAG([-Wextra])]) + +AC_ARG_ENABLE([gcc-warnings], + [AS_HELP_STRING([--enable-gcc-warnings], [turn on many GCC warnings])], + [case "${enableval}" in yes|no) gcc_warnings=${enableval};; + *) AC_MSG_ERROR( + [bad value ${enableval} for gcc-warnings option]);; + esac], + [ + gcc_warnings=no + test -d "${srcdir}/.git" && gcc_warnings=yes + ] +) +if test "x${gcc_warnings}" = 'xyes'; then + nowarns='' + nowarns="${nowarns} -Wsystem-headers" + gl_MANYWARN_ALL_GCC([warns]) + gl_MANYWARN_COMPLEMENT([warns], [${warns}], [${nowarns}]) + for warn in ${warns}; do + gl_WARN_ADD([${warn}]) + done + AC_SUBST([WARN_CFLAGS]) +fi + +AX_CHECK_COMPILE_FLAG([-fdiagnostics-color=auto], + [AX_APPEND_FLAG([-fdiagnostics-color=auto])]) + +AC_ARG_ENABLE([address-sanitization], + [AS_HELP_STRING([--enable-address-sanitization], + [turn on AddressSanitizer (if available)])], + [case "${enableval}" in yes|no) address_sanitization=${enableval};; + *) AC_MSG_ERROR( + [bad value ${enableval} for address-sanitization option] + );; + esac], + [ + address_sanitization=no + gl_GCC_VERSION_IFELSE([4], [8], + [test -d "${srcdir}/.git" && address_sanitization=yes]) + ] +) +if test "x${address_sanitization}" = 'xyes'; then + AX_CHECK_COMPILE_FLAG([-fsanitize=address], + [AX_APPEND_FLAG([-fsanitize=address], [ASAN_CFLAGS])]) + AX_CHECK_COMPILE_FLAG([-fno-omit-frame-pointer], + [AX_APPEND_FLAG([-fno-omit-frame-pointer], [ASAN_CFLAGS])]) + AC_SUBST([ASAN_CFLAGS]) +fi + +if ! test -d "${srcdir}/.git"; then + AX_CHECK_COMPILE_FLAG([-s], [AX_APPEND_FLAG([-s])]) +fi +for flag in -Os -fno-unwind-tables -fno-asynchronous-unwind-tables \ + -ffunction-sections -fdata-sections -Wl,--gc-sections \ + -fstack-protector-strong -flto \ + -Wl,-z,now -Wl,--hash-style=sysv -Wl,--build-id=none; do + AX_CHECK_COMPILE_FLAG([${flag}], [AX_APPEND_FLAG([${flag}])]) +done + AC_CONFIG_FILES([Makefile]) AC_CONFIG_HEADERS([config.h]) AC_OUTPUT() diff --git a/m4/ax_append_flag.m4 b/m4/ax_append_flag.m4 new file mode 100644 index 0000000..dd6d8b6 --- /dev/null +++ b/m4/ax_append_flag.m4 @@ -0,0 +1,50 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_append_flag.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_APPEND_FLAG(FLAG, [FLAGS-VARIABLE]) +# +# DESCRIPTION +# +# FLAG is appended to the FLAGS-VARIABLE shell variable, with a space +# added in between. +# +# If FLAGS-VARIABLE is not specified, the current language's flags (e.g. +# CFLAGS) is used. FLAGS-VARIABLE is not changed if it already contains +# FLAG. If FLAGS-VARIABLE is unset in the shell, it is set to exactly +# FLAG. +# +# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. +# +# LICENSE +# +# Copyright (c) 2008 Guido U. Draheim +# Copyright (c) 2011 Maarten Bosmans +# +# 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 8 + +AC_DEFUN([AX_APPEND_FLAG], +[dnl +AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_SET_IF +AS_VAR_PUSHDEF([FLAGS], [m4_default($2,_AC_LANG_PREFIX[FLAGS])]) +AS_VAR_SET_IF(FLAGS,[ + AS_CASE([" AS_VAR_GET(FLAGS) "], + [*" $1 "*], [AC_RUN_LOG([: FLAGS already contains $1])], + [ + AS_VAR_APPEND(FLAGS,[" $1"]) + AC_RUN_LOG([: FLAGS="$FLAGS"]) + ]) + ], + [ + AS_VAR_SET(FLAGS,[$1]) + AC_RUN_LOG([: FLAGS="$FLAGS"]) + ]) +AS_VAR_POPDEF([FLAGS])dnl +])dnl AX_APPEND_FLAG diff --git a/m4/ax_cflags_warn_all.m4 b/m4/ax_cflags_warn_all.m4 new file mode 100644 index 0000000..9235a18 --- /dev/null +++ b/m4/ax_cflags_warn_all.m4 @@ -0,0 +1,158 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_cflags_warn_all.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_CFLAGS_WARN_ALL [(shellvar[, default[, action-if-found[, action-if-not-found]]])] +# AX_CXXFLAGS_WARN_ALL [(shellvar[, default[, action-if-found[, action-if-not-found]]])] +# AX_FCFLAGS_WARN_ALL [(shellvar[, default[, action-if-found[, action-if-not-found]]])] +# +# DESCRIPTION +# +# Specify compiler options that enable most reasonable warnings. For the +# GNU Compiler Collection (GCC), for example, it will be "-Wall". The +# result is added to shellvar, one of CFLAGS, CXXFLAGS or FCFLAGS if the +# first parameter is not specified. +# +# Each of these macros accepts the following optional arguments: +# +# - $1 - shellvar +# shell variable to use (CFLAGS, CXXFLAGS or FCFLAGS if not +# specified, depending on macro) +# +# - $2 - default +# value to use for flags if compiler vendor cannot be determined (by +# default, "") +# +# - $3 - action-if-found +# action to take if the compiler vendor has been successfully +# determined (by default, add the appropriate compiler flags to +# shellvar) +# +# - $4 - action-if-not-found +# action to take if the compiler vendor has not been determined or +# is unknown (by default, add the default flags, or "" if not +# specified, to shellvar) +# +# These macros use AX_COMPILER_VENDOR to determine which flags should be +# returned for a given compiler. Not all compilers currently have flags +# defined for them; patches are welcome. If need be, compiler flags may +# be made language-dependent: use a construct like the following: +# +# [vendor_name], [m4_if(_AC_LANG_PREFIX,[C], VAR="--relevant-c-flags",dnl +# m4_if(_AC_LANG_PREFIX,[CXX], VAR="--relevant-c++-flags",dnl +# m4_if(_AC_LANG_PREFIX,[FC], VAR="--relevant-fortran-flags",dnl +# VAR="$2"; FOUND="no")))], +# +# Note: These macros also depend on AX_PREPEND_FLAG. +# +# LICENSE +# +# Copyright (c) 2008 Guido U. Draheim +# Copyright (c) 2010 Rhys Ulerich +# Copyright (c) 2018 John Zaitseff +# +# 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. + +#serial 25 + +AC_DEFUN([AX_FLAGS_WARN_ALL], [ + AX_REQUIRE_DEFINED([AX_PREPEND_FLAG])dnl + AC_REQUIRE([AX_COMPILER_VENDOR])dnl + + AS_VAR_PUSHDEF([FLAGS], [m4_default($1,_AC_LANG_PREFIX[]FLAGS)])dnl + AS_VAR_PUSHDEF([VAR], [ac_cv_[]_AC_LANG_ABBREV[]flags_warn_all])dnl + AS_VAR_PUSHDEF([FOUND], [ac_save_[]_AC_LANG_ABBREV[]flags_warn_all_found])dnl + + AC_CACHE_CHECK([FLAGS for most reasonable warnings], VAR, [ + VAR="" + FOUND="yes" + dnl Cases are listed in the order found in ax_compiler_vendor.m4 + AS_CASE("$ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor", + [intel], [VAR="-w2"], + [ibm], [VAR="-qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd"], + [pathscale], [], + [clang], [VAR="-Wall"], + [cray], [VAR="-h msglevel 2"], + [fujitsu], [], + [sdcc], [], + [sx], [VAR="-pvctl[,]fullmsg"], + [portland], [], + [gnu], [VAR="-Wall"], + [sun], [VAR="-v"], + [hp], [VAR="+w1"], + [dec], [VAR="-verbose -w0 -warnprotos"], + [borland], [], + [comeau], [], + [kai], [], + [lcc], [], + [sgi], [VAR="-fullwarn"], + [microsoft], [], + [metrowerks], [], + [watcom], [], + [tcc], [], + [unknown], [ + VAR="$2" + FOUND="no" + ], + [ + AC_MSG_WARN([Unknown compiler vendor returned by [AX_COMPILER_VENDOR]]) + VAR="$2" + FOUND="no" + ] + ) + + AS_IF([test "x$FOUND" = "xyes"], [dnl + m4_default($3, [AS_IF([test "x$VAR" != "x"], [AX_PREPEND_FLAG([$VAR], [FLAGS])])]) + ], [dnl + m4_default($4, [m4_ifval($2, [AX_PREPEND_FLAG([$VAR], [FLAGS])], [true])]) + ])dnl + ])dnl + + AS_VAR_POPDEF([FOUND])dnl + AS_VAR_POPDEF([VAR])dnl + AS_VAR_POPDEF([FLAGS])dnl +])dnl AX_FLAGS_WARN_ALL + +AC_DEFUN([AX_CFLAGS_WARN_ALL], [dnl + AC_LANG_PUSH([C]) + AX_FLAGS_WARN_ALL([$1], [$2], [$3], [$4]) + AC_LANG_POP([C]) +])dnl + +AC_DEFUN([AX_CXXFLAGS_WARN_ALL], [dnl + AC_LANG_PUSH([C++]) + AX_FLAGS_WARN_ALL([$1], [$2], [$3], [$4]) + AC_LANG_POP([C++]) +])dnl + +AC_DEFUN([AX_FCFLAGS_WARN_ALL], [dnl + AC_LANG_PUSH([Fortran]) + AX_FLAGS_WARN_ALL([$1], [$2], [$3], [$4]) + AC_LANG_POP([Fortran]) +])dnl diff --git a/m4/ax_check_compile_flag.m4 b/m4/ax_check_compile_flag.m4 new file mode 100644 index 0000000..bd753b3 --- /dev/null +++ b/m4/ax_check_compile_flag.m4 @@ -0,0 +1,53 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT]) +# +# DESCRIPTION +# +# Check whether the given FLAG works with the current language's compiler +# or gives an error. (Warnings, however, are ignored) +# +# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on +# success/failure. +# +# If EXTRA-FLAGS is defined, it is added to the current language's default +# flags (e.g. CFLAGS) when the check is done. The check is thus made with +# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to +# force the compiler to issue an error when a bad flag is given. +# +# INPUT gives an alternative input source to AC_COMPILE_IFELSE. +# +# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this +# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG. +# +# LICENSE +# +# Copyright (c) 2008 Guido U. Draheim +# Copyright (c) 2011 Maarten Bosmans +# +# 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 6 + +AC_DEFUN([AX_CHECK_COMPILE_FLAG], +[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF +AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl +AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [ + ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS + _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1" + AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])], + [AS_VAR_SET(CACHEVAR,[yes])], + [AS_VAR_SET(CACHEVAR,[no])]) + _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags]) +AS_VAR_IF(CACHEVAR,yes, + [m4_default([$2], :)], + [m4_default([$3], :)]) +AS_VAR_POPDEF([CACHEVAR])dnl +])dnl AX_CHECK_COMPILE_FLAGS diff --git a/m4/ax_compiler_vendor.m4 b/m4/ax_compiler_vendor.m4 new file mode 100644 index 0000000..f06e865 --- /dev/null +++ b/m4/ax_compiler_vendor.m4 @@ -0,0 +1,117 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_compiler_vendor.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_COMPILER_VENDOR +# +# DESCRIPTION +# +# Determine the vendor of the C, C++ or Fortran compiler. The vendor is +# returned in the cache variable $ax_cv_c_compiler_vendor for C, +# $ax_cv_cxx_compiler_vendor for C++ or $ax_cv_fc_compiler_vendor for +# (modern) Fortran. The value is one of "intel", "ibm", "pathscale", +# "clang" (LLVM), "cray", "fujitsu", "sdcc", "sx", "portland" (PGI), "gnu" +# (GCC), "sun" (Oracle Developer Studio), "hp", "dec", "borland", +# "comeau", "kai", "lcc", "sgi", "microsoft", "metrowerks", "watcom", +# "tcc" (Tiny CC) or "unknown" (if the compiler cannot be determined). +# +# To check for a Fortran compiler, you must first call AC_FC_PP_SRCEXT +# with an appropriate preprocessor-enabled extension. For example: +# +# AC_LANG_PUSH([Fortran]) +# AC_PROG_FC +# AC_FC_PP_SRCEXT([F]) +# AX_COMPILER_VENDOR +# AC_LANG_POP([Fortran]) +# +# LICENSE +# +# Copyright (c) 2008 Steven G. Johnson +# Copyright (c) 2008 Matteo Frigo +# Copyright (c) 2018-19 John Zaitseff +# +# 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. + +#serial 30 + +AC_DEFUN([AX_COMPILER_VENDOR], [dnl + AC_CACHE_CHECK([for _AC_LANG compiler vendor], ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor, [dnl + dnl If you modify this list of vendors, please add similar support + dnl to ax_compiler_version.m4 if at all possible. + dnl + dnl Note: Do NOT check for GCC first since some other compilers + dnl define __GNUC__ to remain compatible with it. Compilers that + dnl are very slow to start (such as Intel) are listed first. + + vendors=" + intel: __ICC,__ECC,__INTEL_COMPILER + ibm: __xlc__,__xlC__,__IBMC__,__IBMCPP__,__ibmxl__ + pathscale: __PATHCC__,__PATHSCALE__ + clang: __clang__ + cray: _CRAYC + fujitsu: __FUJITSU + sdcc: SDCC,__SDCC + sx: _SX + portland: __PGI + gnu: __GNUC__ + sun: __SUNPRO_C,__SUNPRO_CC,__SUNPRO_F90,__SUNPRO_F95 + hp: __HP_cc,__HP_aCC + dec: __DECC,__DECCXX,__DECC_VER,__DECCXX_VER + borland: __BORLANDC__,__CODEGEARC__,__TURBOC__ + comeau: __COMO__ + kai: __KCC + lcc: __LCC__ + sgi: __sgi,sgi + microsoft: _MSC_VER + metrowerks: __MWERKS__ + watcom: __WATCOMC__ + tcc: __TINYC__ + unknown: UNKNOWN + " + for ventest in $vendors; do + case $ventest in + *:) + vendor=$ventest + continue + ;; + *) + vencpp="defined("`echo $ventest | sed 's/,/) || defined(/g'`")" + ;; + esac + + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[ +#if !($vencpp) + thisisanerror; +#endif + ]])], [break]) + done + + ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor=`echo $vendor | cut -d: -f1` + ]) +])dnl diff --git a/m4/ax_prepend_flag.m4 b/m4/ax_prepend_flag.m4 new file mode 100644 index 0000000..adac8c5 --- /dev/null +++ b/m4/ax_prepend_flag.m4 @@ -0,0 +1,51 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_prepend_flag.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_PREPEND_FLAG(FLAG, [FLAGS-VARIABLE]) +# +# DESCRIPTION +# +# FLAG is added to the front of the FLAGS-VARIABLE shell variable, with a +# space added in between. +# +# If FLAGS-VARIABLE is not specified, the current language's flags (e.g. +# CFLAGS) is used. FLAGS-VARIABLE is not changed if it already contains +# FLAG. If FLAGS-VARIABLE is unset in the shell, it is set to exactly +# FLAG. +# +# NOTE: Implementation based on AX_APPEND_FLAG. +# +# LICENSE +# +# Copyright (c) 2008 Guido U. Draheim +# Copyright (c) 2011 Maarten Bosmans +# Copyright (c) 2018 John Zaitseff +# +# 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 2 + +AC_DEFUN([AX_PREPEND_FLAG], +[dnl +AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_SET_IF +AS_VAR_PUSHDEF([FLAGS], [m4_default($2,_AC_LANG_PREFIX[FLAGS])]) +AS_VAR_SET_IF(FLAGS,[ + AS_CASE([" AS_VAR_GET(FLAGS) "], + [*" $1 "*], [AC_RUN_LOG([: FLAGS already contains $1])], + [ + FLAGS="$1 $FLAGS" + AC_RUN_LOG([: FLAGS="$FLAGS"]) + ]) + ], + [ + AS_VAR_SET(FLAGS,[$1]) + AC_RUN_LOG([: FLAGS="$FLAGS"]) + ]) +AS_VAR_POPDEF([FLAGS])dnl +])dnl AX_PREPEND_FLAG diff --git a/m4/ax_require_defined.m4 b/m4/ax_require_defined.m4 new file mode 100644 index 0000000..17c3eab --- /dev/null +++ b/m4/ax_require_defined.m4 @@ -0,0 +1,37 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_require_defined.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_REQUIRE_DEFINED(MACRO) +# +# DESCRIPTION +# +# AX_REQUIRE_DEFINED is a simple helper for making sure other macros have +# been defined and thus are available for use. This avoids random issues +# where a macro isn't expanded. Instead the configure script emits a +# non-fatal: +# +# ./configure: line 1673: AX_CFLAGS_WARN_ALL: command not found +# +# It's like AC_REQUIRE except it doesn't expand the required macro. +# +# Here's an example: +# +# AX_REQUIRE_DEFINED([AX_CHECK_LINK_FLAG]) +# +# LICENSE +# +# Copyright (c) 2014 Mike Frysinger +# +# 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 2 + +AC_DEFUN([AX_REQUIRE_DEFINED], [dnl + m4_ifndef([$1], [m4_fatal([macro ]$1[ is not defined; is a m4 file missing?])]) +])dnl AX_REQUIRE_DEFINED diff --git a/m4/gcc_version.m4 b/m4/gcc_version.m4 new file mode 100644 index 0000000..9e16450 --- /dev/null +++ b/m4/gcc_version.m4 @@ -0,0 +1,38 @@ +dnl Copied from GNU Coreutils configure.ac +dnl +dnl The 17 lines are probably too trivial to be copyrightable, but just in case: +dnl +dnl Copyright (C) 1991-2017 Free Software Foundation, Inc. +dnl +dnl This program is free software: you can redistribute it and/or modify +dnl it under the terms of the GNU General Public License as published by +dnl the Free Software Foundation, either version 3 of the License, or +dnl (at your option) any later version. +dnl +dnl This program is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +dnl GNU General Public License for more details. +dnl +dnl You should have received a copy of the GNU General Public License +dnl along with this program. If not, see . +dnl +dnl Written by Jim Meyering. + +# gl_GCC_VERSION_IFELSE([major], [minor], [run-if-found], [run-if-not-found]) +# ------------------------------------------------ +# If $CPP is gcc-MAJOR.MINOR or newer, then run RUN-IF-FOUND. +# Otherwise, run RUN-IF-NOT-FOUND. +AC_DEFUN([gl_GCC_VERSION_IFELSE], + [AC_PREPROC_IFELSE( + [AC_LANG_PROGRAM( + [[ +#if ($1) < __GNUC__ || (($1) == __GNUC__ && ($2) <= __GNUC_MINOR__) +/* ok */ +#else +# error "your version of gcc is older than $1.$2" +#endif + ]]), + ], [$3], [$4]) + ] +) diff --git a/m4/gl_manywarnings.m4 b/m4/gl_manywarnings.m4 new file mode 100644 index 0000000..872ea58 --- /dev/null +++ b/m4/gl_manywarnings.m4 @@ -0,0 +1,209 @@ +# manywarnings.m4 serial 23 +dnl Copyright (C) 2008-2021 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Simon Josefsson + +# gl_MANYWARN_COMPLEMENT(OUTVAR, LISTVAR, REMOVEVAR) +# -------------------------------------------------- +# Copy LISTVAR to OUTVAR except for the entries in REMOVEVAR. +# Elements separated by whitespace. In set logic terms, the function +# does OUTVAR = LISTVAR \ REMOVEVAR. +AC_DEFUN([gl_MANYWARN_COMPLEMENT], +[ + gl_warn_set= + set x $2; shift + for gl_warn_item + do + case " $3 " in + *" $gl_warn_item "*) + ;; + *) + gl_AS_VAR_APPEND([gl_warn_set], [" $gl_warn_item"]) + ;; + esac + done + $1=$gl_warn_set +]) + +# gl_MANYWARN_ALL_GCC(VARIABLE) +# ----------------------------- +# Add all documented GCC warning parameters to variable VARIABLE. +# Note that you need to test them using gl_WARN_ADD if you want to +# make sure your gcc understands it. +# +# The effects of this macro depend on the current language (_AC_LANG). +AC_DEFUN([gl_MANYWARN_ALL_GCC], +[_AC_LANG_DISPATCH([$0], _AC_LANG, $@)]) + +# Specialization for _AC_LANG = C. +AC_DEFUN([gl_MANYWARN_ALL_GCC(C)], +[ + AC_LANG_PUSH([C]) + + dnl First, check for some issues that only occur when combining multiple + dnl gcc warning categories. + AC_REQUIRE([AC_PROG_CC]) + if test -n "$GCC"; then + + dnl Check if -Wextra -Werror -Wno-missing-field-initializers is supported + dnl with the current $CC $CFLAGS $CPPFLAGS. + AC_CACHE_CHECK([whether -Wno-missing-field-initializers is supported], + [gl_cv_cc_nomfi_supported], + [gl_save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -Wextra -Werror -Wno-missing-field-initializers" + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[]], [[]])], + [gl_cv_cc_nomfi_supported=yes], + [gl_cv_cc_nomfi_supported=no]) + CFLAGS="$gl_save_CFLAGS" + ]) + + if test "$gl_cv_cc_nomfi_supported" = yes; then + dnl Now check whether -Wno-missing-field-initializers is needed + dnl for the { 0, } construct. + AC_CACHE_CHECK([whether -Wno-missing-field-initializers is needed], + [gl_cv_cc_nomfi_needed], + [gl_save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -Wextra -Werror" + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[int f (void) + { + typedef struct { int a; int b; } s_t; + s_t s1 = { 0, }; + return s1.b; + } + ]], + [[]])], + [gl_cv_cc_nomfi_needed=no], + [gl_cv_cc_nomfi_needed=yes]) + CFLAGS="$gl_save_CFLAGS" + ]) + fi + + dnl Next, check if -Werror -Wuninitialized is useful with the + dnl user's choice of $CFLAGS; some versions of gcc warn that it + dnl has no effect if -O is not also used + AC_CACHE_CHECK([whether -Wuninitialized is supported], + [gl_cv_cc_uninitialized_supported], + [gl_save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -Werror -Wuninitialized" + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[]], [[]])], + [gl_cv_cc_uninitialized_supported=yes], + [gl_cv_cc_uninitialized_supported=no]) + CFLAGS="$gl_save_CFLAGS" + ]) + + fi + + # List all gcc warning categories. + # To compare this list to your installed GCC's, run this Bash command: + # + # comm -3 \ + # <((sed -n 's/^ *\(-[^ 0-9][^ ]*\).*/\1/p' manywarnings.m4; \ + # awk '/^[^#]/ {print $1}' ../build-aux/gcc-warning.spec) | sort) \ + # <(LC_ALL=C gcc --help=warnings | sed -n 's/^ \(-[^ ]*\) .*/\1/p' | sort) + + $1= + for gl_manywarn_item in -fanalyzer -fno-common \ + -Wall \ + -Warith-conversion \ + -Wbad-function-cast \ + -Wcast-align=strict \ + -Wdate-time \ + -Wdisabled-optimization \ + -Wdouble-promotion \ + -Wduplicated-branches \ + -Wduplicated-cond \ + -Wextra \ + -Wformat-signedness \ + -Winit-self \ + -Winline \ + -Winvalid-pch \ + -Wlogical-op \ + -Wmissing-declarations \ + -Wmissing-include-dirs \ + -Wmissing-prototypes \ + -Wnested-externs \ + -Wnull-dereference \ + -Wold-style-definition \ + -Wopenmp-simd \ + -Woverlength-strings \ + -Wpacked \ + -Wpointer-arith \ + -Wshadow \ + -Wstack-protector \ + -Wstrict-overflow \ + -Wstrict-prototypes \ + -Wsuggest-attribute=cold \ + -Wsuggest-attribute=const \ + -Wsuggest-attribute=format \ + -Wsuggest-attribute=malloc \ + -Wsuggest-attribute=noreturn \ + -Wsuggest-attribute=pure \ + -Wsuggest-final-methods \ + -Wsuggest-final-types \ + -Wsync-nand \ + -Wsystem-headers \ + -Wtrampolines \ + -Wuninitialized \ + -Wunknown-pragmas \ + -Wunsafe-loop-optimizations \ + -Wunused-macros \ + -Wvariadic-macros \ + -Wvector-operation-performance \ + -Wvla \ + -Wwrite-strings \ + \ + ; do + gl_AS_VAR_APPEND([$1], [" $gl_manywarn_item"]) + done + + # gcc --help=warnings outputs an unusual form for these options; list + # them here so that the above 'comm' command doesn't report a false match. + gl_AS_VAR_APPEND([$1], [' -Warray-bounds=2']) + gl_AS_VAR_APPEND([$1], [' -Wattribute-alias=2']) + gl_AS_VAR_APPEND([$1], [' -Wformat-overflow=2']) + gl_AS_VAR_APPEND([$1], [' -Wformat=2']) + gl_AS_VAR_APPEND([$1], [' -Wformat-truncation=2']) + gl_AS_VAR_APPEND([$1], [' -Wimplicit-fallthrough=5']) + gl_AS_VAR_APPEND([$1], [' -Wshift-overflow=2']) + gl_AS_VAR_APPEND([$1], [' -Wunused-const-variable=2']) + gl_AS_VAR_APPEND([$1], [' -Wvla-larger-than=4031']) + + # These are needed for older GCC versions. + if test -n "$GCC"; then + case `($CC --version) 2>/dev/null` in + 'gcc (GCC) '[[0-3]].* | \ + 'gcc (GCC) '4.[[0-7]].*) + gl_AS_VAR_APPEND([$1], [' -fdiagnostics-show-option']) + gl_AS_VAR_APPEND([$1], [' -funit-at-a-time']) + ;; + esac + fi + + # Disable specific options as needed. + if test "$gl_cv_cc_nomfi_needed" = yes; then + gl_AS_VAR_APPEND([$1], [' -Wno-missing-field-initializers']) + fi + + if test "$gl_cv_cc_uninitialized_supported" = no; then + gl_AS_VAR_APPEND([$1], [' -Wno-uninitialized']) + fi + + # This warning have too many false alarms in GCC 11.2.1. + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101713 + gl_AS_VAR_APPEND([$1], [' -Wno-analyzer-malloc-leak']) + + AC_LANG_POP([C]) +]) + +# Specialization for _AC_LANG = C++. +AC_DEFUN([gl_MANYWARN_ALL_GCC(C++)], +[ + gl_MANYWARN_ALL_GCC_CXX_IMPL([$1]) +]) diff --git a/m4/gl_warnings.m4 b/m4/gl_warnings.m4 new file mode 100644 index 0000000..9e24d89 --- /dev/null +++ b/m4/gl_warnings.m4 @@ -0,0 +1,110 @@ +# warnings.m4 serial 16 +dnl Copyright (C) 2008-2021 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Simon Josefsson + +# gl_AS_VAR_APPEND(VAR, VALUE) +# ---------------------------- +# Provide the functionality of AS_VAR_APPEND if Autoconf does not have it. +m4_ifdef([AS_VAR_APPEND], +[m4_copy([AS_VAR_APPEND], [gl_AS_VAR_APPEND])], +[m4_define([gl_AS_VAR_APPEND], +[AS_VAR_SET([$1], [AS_VAR_GET([$1])$2])])]) + + +# gl_COMPILER_OPTION_IF(OPTION, [IF-SUPPORTED], [IF-NOT-SUPPORTED], +# [PROGRAM = AC_LANG_PROGRAM()]) +# ----------------------------------------------------------------- +# Check if the compiler supports OPTION when compiling PROGRAM. +# +# The effects of this macro depend on the current language (_AC_LANG). +AC_DEFUN([gl_COMPILER_OPTION_IF], +[ +AS_VAR_PUSHDEF([gl_Warn], [gl_cv_warn_[]_AC_LANG_ABBREV[]_$1])dnl +AS_VAR_PUSHDEF([gl_Flags], [_AC_LANG_PREFIX[]FLAGS])dnl +AS_LITERAL_IF([$1], + [m4_pushdef([gl_Positive], m4_bpatsubst([$1], [^-Wno-], [-W]))], + [gl_positive="$1" +case $gl_positive in + -Wno-*) gl_positive=-W`expr "X$gl_positive" : 'X-Wno-\(.*\)'` ;; +esac +m4_pushdef([gl_Positive], [$gl_positive])])dnl +AC_CACHE_CHECK([whether _AC_LANG compiler handles $1], [gl_Warn], [ + gl_save_compiler_FLAGS="$gl_Flags" + gl_AS_VAR_APPEND(m4_defn([gl_Flags]), + [" $gl_unknown_warnings_are_errors ]m4_defn([gl_Positive])["]) + AC_LINK_IFELSE([m4_default([$4], [AC_LANG_PROGRAM([[]])])], + [AS_VAR_SET([gl_Warn], [yes])], + [AS_VAR_SET([gl_Warn], [no])]) + gl_Flags="$gl_save_compiler_FLAGS" +]) +AS_VAR_IF(gl_Warn, [yes], [$2], [$3]) +m4_popdef([gl_Positive])dnl +AS_VAR_POPDEF([gl_Flags])dnl +AS_VAR_POPDEF([gl_Warn])dnl +]) + +# gl_UNKNOWN_WARNINGS_ARE_ERRORS +# ------------------------------ +# Clang doesn't complain about unknown warning options unless one also +# specifies -Wunknown-warning-option -Werror. Detect this. +# +# The effects of this macro depend on the current language (_AC_LANG). +AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS], +[_AC_LANG_DISPATCH([$0], _AC_LANG, $@)]) + +# Specialization for _AC_LANG = C. This macro can be AC_REQUIREd. +AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS(C)], +[ + AC_LANG_PUSH([C]) + gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL + AC_LANG_POP([C]) +]) + +# Specialization for _AC_LANG = C++. This macro can be AC_REQUIREd. +AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS(C++)], +[ + AC_LANG_PUSH([C++]) + gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL + AC_LANG_POP([C++]) +]) + +# Specialization for _AC_LANG = Objective C. This macro can be AC_REQUIREd. +AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS(Objective C)], +[ + AC_LANG_PUSH([Objective C]) + gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL + AC_LANG_POP([Objective C]) +]) + +AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL], +[gl_COMPILER_OPTION_IF([-Werror -Wunknown-warning-option], + [gl_unknown_warnings_are_errors='-Wunknown-warning-option -Werror'], + [gl_unknown_warnings_are_errors=])]) + +# gl_WARN_ADD(OPTION, [VARIABLE = WARN_CFLAGS/WARN_CXXFLAGS], +# [PROGRAM = AC_LANG_PROGRAM()]) +# ----------------------------------------------------------- +# Adds parameter to WARN_CFLAGS/WARN_CXXFLAGS if the compiler supports it +# when compiling PROGRAM. For example, gl_WARN_ADD([-Wparentheses]). +# +# If VARIABLE is a variable name, AC_SUBST it. +# +# The effects of this macro depend on the current language (_AC_LANG). +AC_DEFUN([gl_WARN_ADD], +[AC_REQUIRE([gl_UNKNOWN_WARNINGS_ARE_ERRORS(]_AC_LANG[)]) +gl_COMPILER_OPTION_IF([$1], + [gl_AS_VAR_APPEND(m4_if([$2], [], [[WARN_]_AC_LANG_PREFIX[FLAGS]], [[$2]]), [" $1"])], + [], + [$3]) +m4_ifval([$2], + [AS_LITERAL_IF([$2], [AC_SUBST([$2])])], + [AC_SUBST([WARN_]_AC_LANG_PREFIX[FLAGS])])dnl +]) + +# Local Variables: +# mode: autoconf +# End: diff --git a/suppr.txt b/suppr.txt new file mode 100644 index 0000000..ca7d479 --- /dev/null +++ b/suppr.txt @@ -0,0 +1 @@ +leak:/lib/ -- cgit v0.9.1