From 7b5b400a2628e782f5f3ec791ca41043839648c8 Mon Sep 17 00:00:00 2001
From: Matthias Arno Uebel <matthias.uebel@fn.de>
Date: Sun, 2 Apr 2017 06:37:22 +0200
Subject: [PATCH] Add AX_CFLAGS_WARN_EXTRA.

---
 m4/ax_cflags_warn_extra.m4 | 117 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 117 insertions(+)
 create mode 100644 m4/ax_cflags_warn_extra.m4

diff --git a/m4/ax_cflags_warn_extra.m4 b/m4/ax_cflags_warn_extra.m4
new file mode 100644
index 0000000..d8ffcb5
--- /dev/null
+++ b/m4/ax_cflags_warn_extra.m4
@@ -0,0 +1,117 @@
+# ===========================================================================
+#    http://www.gnu.org/software/autoconf-archive/ax_cflags_warn_extra.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+#   AX_CFLAGS_WARN_EXTRA   [(shellvar [,default, [A/NA]])]
+#   AX_CXXFLAGS_WARN_EXTRA [(shellvar [,default, [A/NA]])]
+#   AX_FCFLAGS_WARN_EXTRA  [(shellvar [,default, [A/NA]])]
+#
+# DESCRIPTION
+#
+#   Try to find a compiler option that enables extra warnings.
+#
+#   For the GNU compiler it will be -Wextra. The result is added to the
+#   shellvar being CFLAGS, CXXFLAGS, or FCFLAGS by default.
+#
+#   Currently this macro knows about the GNU Compiler Collection,
+#   Oracle Solaris Studio C++ and Intel C/C++ compilers.
+#
+#    - $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
+#
+#   This macro is based on the source code of AX_CFLAGS_WARN_ALL.
+#
+#   NOTE: These macros depend on AX_APPEND_FLAG and AX_REQUIRE_DEFINED.
+#
+# LICENSE
+#
+#   Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
+#   Copyright (c) 2010 Rhys Ulerich <rhys.ulerich@gmail.com>
+#   Copyright (c) 2017 Matthias Arno Uebel <matthias.uebel@fn.de>
+#
+#   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 <http://www.gnu.org/licenses/>.
+#
+#   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 1
+
+AC_DEFUN([AX_FLAGS_WARN_EXTRA],[dnl
+AS_VAR_PUSHDEF([FLAGS],[_AC_LANG_PREFIX[]FLAGS])dnl
+AS_VAR_PUSHDEF([VAR],[ac_cv_[]_AC_LANG_ABBREV[]flags_warn_extra])dnl
+AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for additional warnings],
+VAR,[VAR="no, unknown"
+ac_save_[]FLAGS="$[]FLAGS"
+for ac_arg dnl
+in "-strict ansi   % -diag-warning remark"  dnl Intel C/C++ Compiler
+   "-pedantic      % -Wextra"               dnl GNU Compiler Collection
+   "-xstrconst     % +w"                    dnl Oracle Solaris Studio C++
+   #
+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
+])dnl AX_FLAGS_WARN_EXTRA
+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_EXTRA],[dnl
+AC_LANG_PUSH([C])
+AX_FLAGS_WARN_EXTRA([$1], [$2], [$3], [$4])
+AC_LANG_POP([C])
+])
+
+AC_DEFUN([AX_CXXFLAGS_WARN_EXTRA],[dnl
+AC_LANG_PUSH([C++])
+AX_FLAGS_WARN_EXTRA([$1], [$2], [$3], [$4])
+AC_LANG_POP([C++])
+])
+
+AC_DEFUN([AX_FCFLAGS_WARN_EXTRA],[dnl
+AC_LANG_PUSH([Fortran])
+AX_FLAGS_WARN_EXTRA([$1], [$2], [$3], [$4])
+AC_LANG_POP([Fortran])
+])
-- 
1.9.1

