1
0
mirror of https://git.zap.org.au/git/trader.git synced 2024-12-04 14:46:45 -05:00

Update to an unreleased version of ax_cflags_warn_all.m4

This version of the AX_CFLAGS_WARN_ALL macro uses a far more robust
method of detecting compilers to select appropriate warning flags.  It
also uses the AX_PREPEND_FLAG macro instead of AX_APPEND_FLAG.

This version of ax_cflags_warn_all.m4 (and ax_prepend_flag.m4) has been
submitted upstream; see https://savannah.gnu.org/patch/?9673 for details.
This commit is contained in:
John Zaitseff 2018-08-06 15:21:05 +10:00
parent 5caf1ef165
commit 265ed12de8
2 changed files with 117 additions and 81 deletions

View File

@ -4,33 +4,54 @@
#
# SYNOPSIS
#
# AX_CFLAGS_WARN_ALL [(shellvar [,default, [A/NA]])]
# AX_CXXFLAGS_WARN_ALL [(shellvar [,default, [A/NA]])]
# AX_FCFLAGS_WARN_ALL [(shellvar [,default, [A/NA]])]
# 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
#
# Try to find a compiler option that enables most reasonable warnings.
# 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.
#
# For the GNU compiler it will be -Wall (and -ansi -pedantic) The result
# is added to the shellvar being CFLAGS, CXXFLAGS, or FCFLAGS by default.
# Each of these macros accepts the following optional arguments:
#
# Currently this macro knows about the GCC, Solaris, Digital Unix, AIX,
# HP-UX, IRIX, NEC SX-5 (Super-UX 10), Cray J90 (Unicos 10.0.0.8), and
# Intel compilers. For a given compiler, the Fortran flags are much more
# experimental than their C equivalents.
# - $1 - shellvar
# shell variable to use (CFLAGS, CXXFLAGS or FCFLAGS if not
# specified, depending on macro)
#
# - $1 shell-variable-to-add-to : CFLAGS, CXXFLAGS, or FCFLAGS
# - $2 add-value-if-not-found : nothing
# - $3 action-if-found : add value to shellvariable
# - $4 action-if-not-found : nothing
# - $2 - default
# value to use for flags if compiler vendor cannot be determined (by
# default, "")
#
# NOTE: These macros depend on AX_APPEND_FLAG.
# - $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 <guidod@gmx.de>
# Copyright (c) 2010 Rhys Ulerich <rhys.ulerich@gmail.com>
# Copyright (c) 2018 John Zaitseff <J.Zaitseff@zap.org.au>
#
# 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
@ -58,65 +79,79 @@
# modified version of the Autoconf Macro, you may extend this special
# exception to the GPL to apply to your modified version as well.
#serial 16
#serial 17
AC_DEFUN([AX_FLAGS_WARN_ALL],[dnl
AS_VAR_PUSHDEF([FLAGS],[_AC_LANG_PREFIX[]FLAGS])dnl
AS_VAR_PUSHDEF([VAR],[ac_cv_[]_AC_LANG_ABBREV[]flags_warn_all])dnl
AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for maximum warnings],
VAR,[VAR="no, unknown"
ac_save_[]FLAGS="$[]FLAGS"
for ac_arg dnl
in "-warn all % -warn all" dnl Intel
"-pedantic % -Wall" dnl GCC
"-xstrconst % -v" dnl Solaris C
"-std1 % -verbose -w0 -warnprotos" dnl Digital Unix
"-qlanglvl=ansi % -qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd" dnl AIX
"-ansi -ansiE % -fullwarn" dnl IRIX
"+ESlit % +w1" dnl HP-UX C
"-Xc % -pvctl[,]fullmsg" dnl NEC SX-5 (Super-UX 10)
"-h conform % -h msglevel 2" dnl Cray C (Unicos)
#
do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
AC_COMPILE_IFELSE([AC_LANG_PROGRAM],
[VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
done
FLAGS="$ac_save_[]FLAGS"
])
AS_VAR_POPDEF([FLAGS])dnl
AX_REQUIRE_DEFINED([AX_APPEND_FLAG])
case ".$VAR" in
.ok|.ok,*) m4_ifvaln($3,$3) ;;
.|.no|.no,*) m4_default($4,[m4_ifval($2,[AX_APPEND_FLAG([$2], [$1])])]) ;;
*) m4_default($3,[AX_APPEND_FLAG([$VAR], [$1])]) ;;
esac
AS_VAR_POPDEF([VAR])dnl
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, [
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], [VAR=""],
[clang], [VAR="-Wall"],
[cray], [VAR="-h msglevel 2"],
[fujitsu], [VAR=""],
[sdcc], [VAR=""],
[sx], [VAR="-pvctl[,]fullmsg"],
[portland], [VAR=""],
[gnu], [VAR="-Wall"],
[sun], [VAR="-v"],
[hp], [VAR="+w1"],
[dec], [VAR="-verbose -w0 -warnprotos"],
[borland], [VAR=""],
[comeau], [VAR=""],
[kai], [VAR=""],
[lcc], [VAR=""],
[sgi], [VAR="-fullwarn"],
[microsoft], [VAR=""],
[metrowerks], [VAR=""],
[watcom], [VAR=""],
[tcc], [VAR=""],
[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, [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
dnl implementation tactics:
dnl the for-argument contains a list of options. The first part of
dnl these does only exist to detect the compiler - usually it is
dnl a global option to enable -ansi or -extrawarnings. All other
dnl compilers will fail about it. That was needed since a lot of
dnl compilers will give false positives for some option-syntax
dnl like -Woption or -Xoption as they think of it is a pass-through
dnl to later compile stages or something. The "%" is used as a
dnl delimiter. A non-option comment can be given after "%%" marks
dnl which will be shown but not added to the respective C/CXXFLAGS.
AC_DEFUN([AX_CFLAGS_WARN_ALL],[dnl
AC_LANG_PUSH([C])
AX_FLAGS_WARN_ALL([$1], [$2], [$3], [$4])
AC_LANG_POP([C])
])
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++])
])
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])
])
AC_DEFUN([AX_FCFLAGS_WARN_ALL], [dnl
AC_LANG_PUSH([Fortran])
AX_FLAGS_WARN_ALL([$1], [$2], [$3], [$4])
AC_LANG_POP([Fortran])
])dnl

View File

@ -1,36 +1,37 @@
# ===========================================================================
# https://www.gnu.org/software/autoconf-archive/ax_append_flag.html
# https://www.gnu.org/software/autoconf-archive/ax_prepend_flag.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_APPEND_FLAG(FLAG, [FLAGS-VARIABLE])
# AX_PREPEND_FLAG(FLAG, [FLAGS-VARIABLE])
#
# DESCRIPTION
#
# FLAG is appended to the FLAGS-VARIABLE shell variable, with a space
# added in between.
# 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_CFLAGS_GCC_OPTION.
# NOTE: Implementation based on AX_APPEND_FLAG.
#
# LICENSE
#
# Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
# Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>
# Copyright (c) 2018 John Zaitseff <J.Zaitseff@zap.org.au>
#
# 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
#serial 1
AC_DEFUN([AX_APPEND_FLAG],
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])])
@ -38,7 +39,7 @@ AS_VAR_SET_IF(FLAGS,[
AS_CASE([" AS_VAR_GET(FLAGS) "],
[*" $1 "*], [AC_RUN_LOG([: FLAGS already contains $1])],
[
AS_VAR_APPEND(FLAGS,[" $1"])
FLAGS="$1 $FLAGS"
AC_RUN_LOG([: FLAGS="$FLAGS"])
])
],
@ -47,4 +48,4 @@ AS_VAR_SET_IF(FLAGS,[
AC_RUN_LOG([: FLAGS="$FLAGS"])
])
AS_VAR_POPDEF([FLAGS])dnl
])dnl AX_APPEND_FLAG
])dnl AX_PREPEND_FLAG