Skip to content

Commit d5f9d33

Browse files
committed
build: disable some gcc compier warnings
Add --enable-extra-warning option to the configure script. By default, it is disabled to suppress some gcc warnings: * -Wno-misleading-indentation. This is because, for the short term, it seems unfeasible to clearly rewrite FORM source code (by hand) unless we introduce some automatization with formatters, linters or static analyzers. * -Wno-stringop-overflow. It seems to give many false positives (though there may be some true positives). Stop using obsolete macros when autoconf>=2.70 is used. Improve the handling of i486 (Pentium) processors on old 32-bit systems (-march=i486). ax_check_compile_flag.m4 (GPL-3.0-or-later) is taken from: autoconf-archive/autoconf-archive@7f56aaa (v2014.10.15) Resolve #416
1 parent 9a149d4 commit d5f9d33

File tree

2 files changed

+136
-56
lines changed

2 files changed

+136
-56
lines changed

configure.ac

Lines changed: 62 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ m4_define([serial_tests], [m4_esyscmd_s([
6666
awk '{split ($NF,a,"."); if (a[1] >= 2 || (a[1] == 1 && a[2] >= 13)) { print "serial-tests" }}'
6767
])])
6868

69-
AC_PREREQ(2.59)
70-
AC_INIT([FORM], FORM_VERSION, [https://github.com/vermaseren/form/issues])
69+
AC_PREREQ([2.59])
70+
AC_INIT([FORM], [FORM_VERSION], [https://github.com/vermaseren/form/issues])
71+
AC_CONFIG_MACRO_DIR([m4])
7172
AC_CONFIG_SRCDIR([sources/form3.h])
7273
AC_CONFIG_HEADERS([config.h])
7374
AC_CONFIG_AUX_DIR([build-aux])
@@ -96,8 +97,18 @@ AC_PROG_CXX([g++ c++ icpc])
9697
AC_PROG_LN_S
9798

9899
# Checks for header files
99-
AC_HEADER_STDC
100-
AC_HEADER_TIME
100+
# NOTE: autoconf>=2.70 has started to warn obsolete macros.
101+
# We check if AC_CHECK_INCLUDES_DEFAULT (introduced in 2.70) is available
102+
# and switch to the new code if possible.
103+
m4_ifdef([AC_CHECK_INCLUDES_DEFAULT],
104+
[AC_CHECK_INCLUDES_DEFAULT
105+
AC_PROG_EGREP
106+
AC_CHECK_HEADERS_ONCE([sys/time.h])
107+
AC_DEFINE([TIME_WITH_SYS_TIME],
108+
[1],
109+
[Define to 1 if you can safely include both <sys/time.h> and <time.h>. This macro is obsolete.])],
110+
[AC_HEADER_STDC
111+
AC_HEADER_TIME])
101112
AC_CHECK_HEADERS([fcntl.h limits.h sys/file.h])
102113

103114
AC_LANG_PUSH([C++])
@@ -160,17 +171,20 @@ case $host_os in
160171
;;
161172
esac
162173
case $host_cpu in
163-
i?86 )
174+
i586 )
164175
print_cpu="Pentium"
165176
;;
177+
i686 )
178+
print_cpu="Pentium Pro"
179+
;;
166180
x86_64 )
167181
print_cpu="Opteron"
168182
;;
169183
alpha* )
170184
print_cpu="Alpha"
171185
;;
172186
* )
173-
print_cpu="UNKNOWN CPU"
187+
print_cpu="UNKNOWN CPU ($host_cpu)"
174188
;;
175189
esac
176190

@@ -730,6 +744,13 @@ AC_ARG_ENABLE([sanitize],
730744
[enable_sanitize=no])],
731745
[enable_sanitize=no])
732746

747+
# Check for extra compiler warnings
748+
AC_ARG_ENABLE([extra-warning],
749+
[AS_HELP_STRING([--enable-extra-warning],
750+
[enable extra compiler warnings @<:@default=no@:>@])],
751+
[enable_extra_warning=yes],
752+
[enable_extra_warning=no])
753+
733754
# Optimization/debugging flags
734755
AC_ARG_VAR([COMPILEFLAGS], [Compiler flags for release versions])
735756
AC_ARG_VAR([LINKFLAGS], [Linker flags for release versions])
@@ -738,36 +759,45 @@ AC_ARG_VAR([DEBUGLINKFLAGS], [Linker flags for debugging versions])
738759
TOOL_LIBS=
739760
DEBUGTOOL_LIBS=
740761

762+
# AX_HANDLE_EXTRA_WARNING(COMPILEFLAGS)
763+
# -------------------------------------
764+
AC_DEFUN([AX_HANDLE_EXTRA_WARNING],
765+
[if test "x$enable_extra_warning" = xno; then
766+
# Too many misleading indentation in the FORM source code.
767+
AX_CHECK_COMPILE_FLAG([-Wno-misleading-indentation],
768+
[$1="$$1 -Wno-misleading-indentation"])
769+
# Too many false positives.
770+
# See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88443
771+
AX_CHECK_COMPILE_FLAG([-Wno-stringop-overflow],
772+
[$1="$$1 -Wno-stringop-overflow"])
773+
fi[]dnl
774+
])
775+
741776
my_test_COMPILEFLAGS=${COMPILEFLAGS+set}
742777
if test "$my_test_COMPILEFLAGS" != set; then
743778
if test "x$vendor" = xgnu; then
744779
# We don't use -pedantic option because of horrible warnings.
745-
COMPILEFLAGS="-Wall -Wextra -Wpadded -O3"
780+
COMPILEFLAGS="-Wall -Wextra -Wpadded"
781+
AX_HANDLE_EXTRA_WARNING([COMPILEFLAGS])
782+
# Enable optimizations.
783+
COMPILEFLAGS="$COMPILEFLAGS -O3"
746784
if test "x$enable_profile" != xgprof; then
747785
# -pg conflicts with -fomit-frame-pointer.
748786
COMPILEFLAGS="$COMPILEFLAGS -fomit-frame-pointer"
749787
fi
750788
if test "x$enable_native" = xyes; then
751-
# Check for -march=native.
752-
AC_MSG_CHECKING([whether compiler accepts -march=native])
753-
ok=no
754-
save_CFLAGS=$CFLAGS
755-
CFLAGS="$CFLAGS -march=native"
756-
AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [ok=yes])
757-
CFLAGS=$save_CFLAGS
758-
AC_MSG_RESULT($ok)
759-
if test "x$ok" = xyes; then
760-
COMPILEFLAGS="$COMPILEFLAGS -march=native"
761-
else
762-
if test "x$print_data_model" = xILP32; then
789+
# Use -march=native if available.
790+
AX_CHECK_COMPILE_FLAG([-march=native],
791+
[COMPILEFLAGS="$COMPILEFLAGS -march=native"],
792+
[if test "x$print_data_model" = xILP32; then
763793
if test "x$print_cpu" = xPentium; then
764-
# NOTE: In a strict sense, i686 must be used for Pentium Pro or later.
794+
COMPILEFLAGS="$COMPILEFLAGS -march=i586"
795+
elif test "x$print_cpu" = 'xPentium Pro'; then
765796
COMPILEFLAGS="$COMPILEFLAGS -march=i686"
766797
elif test "x$print_cpu" = xOpteron; then
767798
COMPILEFLAGS="$COMPILEFLAGS -march=opteron"
768799
fi
769-
fi
770-
fi
800+
fi])
771801
fi
772802
# Profiling option.
773803
if test "x$enable_profile" = xgprof; then
@@ -809,24 +839,18 @@ fi
809839
my_test_DEBUGCOMPILEFLAGS=${DEBUGCOMPILEFLAGS+set}
810840
if test "$my_test_DEBUGCOMPILEFLAGS" != set && test "x$enable_debug" = xyes; then
811841
if test "x$vendor" = xgnu; then
812-
DEBUGCOMPILEFLAGS='-g3 -Wall -Wextra'
842+
DEBUGCOMPILEFLAGS='-Wall -Wextra'
813843
if test "x$enable_sanitize" = xno; then
814844
# UBSan puts many paddings (at least in gcc 5.3).
815845
DEBUGCOMPILEFLAGS="$DEBUGCOMPILEFLAGS -Wpadded"
816846
fi
817-
# Check for -Og.
818-
AC_MSG_CHECKING([whether compiler accepts -Og])
819-
ok=no
820-
save_CFLAGS=$CFLAGS
821-
CFLAGS="$CFLAGS -Og"
822-
AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [ok=yes])
823-
CFLAGS=$save_CFLAGS
824-
AC_MSG_RESULT($ok)
825-
if test "x$ok" = xyes; then
826-
DEBUGCOMPILEFLAGS="$DEBUGCOMPILEFLAGS -Og"
827-
else
828-
DEBUGCOMPILEFLAGS="$DEBUGCOMPILEFLAGS -O0"
829-
fi
847+
AX_HANDLE_EXTRA_WARNING([DEBUGCOMPILEFLAGS])
848+
# Check for -Og. If it doesn't work then use -O0.
849+
AX_CHECK_COMPILE_FLAG([-Og],
850+
[DEBUGCOMPILEFLAGS="$DEBUGCOMPILEFLAGS -Og"],
851+
[DEBUGCOMPILEFLAGS="$DEBUGCOMPILEFLAGS -O0"])
852+
# Debugging information.
853+
DEBUGCOMPILEFLAGS="$DEBUGCOMPILEFLAGS -g3"
830854
# Coverage option.
831855
if test "x$enable_coverage" = xyes; then
832856
DEBUGCOMPILEFLAGS="$DEBUGCOMPILEFLAGS -coverage"
@@ -840,31 +864,13 @@ if test "$my_test_DEBUGCOMPILEFLAGS" != set && test "x$enable_debug" = xyes; the
840864
else
841865
tmp_sanitize=$enable_sanitize,$san
842866
fi
843-
AC_MSG_CHECKING([whether compiler accepts -fsanitize=$tmp_sanitize])
844-
ok=no
845-
save_CFLAGS=$CFLAGS
846-
CFLAGS="$CFLAGS -fsanitize=$tmp_sanitize"
847-
AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [ok=yes])
848-
CFLAGS=$save_CFLAGS
849-
AC_MSG_RESULT($ok)
850-
if test "x$ok" = xyes; then
851-
enable_sanitize=$tmp_sanitize
852-
fi
867+
AX_CHECK_COMPILE_FLAG([-fsanitize=$tmp_sanitize], [enable_sanitize=$tmp_sanitize])
853868
done
854869
if test "x$enable_sanitize" = x; then
855870
enable_sanitize=failed
856871
fi
857872
elif test "x$enable_sanitize" != xno; then
858-
AC_MSG_CHECKING([whether compiler accepts -fsanitize=$enable_sanitize])
859-
ok=no
860-
save_CFLAGS=$CFLAGS
861-
CFLAGS="$CFLAGS -fsanitize=$enable_sanitize"
862-
AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [ok=yes])
863-
CFLAGS=$save_CFLAGS
864-
AC_MSG_RESULT($ok)
865-
if test "x$ok" != xyes; then
866-
enable_sanitize=failed
867-
fi
873+
AX_CHECK_COMPILE_FLAG([-fsanitize=$enable_sanitize], [], [enable_sanitize=failed])
868874
fi
869875
if test "x$enable_sanitize" = xfailed; then
870876
AC_MSG_FAILURE([test for sanitizer failed. Give --disable-sanitize if you want to compile without sanitizer])

m4/ax_check_compile_flag.m4

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# ===========================================================================
2+
# http://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
3+
# ===========================================================================
4+
#
5+
# SYNOPSIS
6+
#
7+
# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
8+
#
9+
# DESCRIPTION
10+
#
11+
# Check whether the given FLAG works with the current language's compiler
12+
# or gives an error. (Warnings, however, are ignored)
13+
#
14+
# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
15+
# success/failure.
16+
#
17+
# If EXTRA-FLAGS is defined, it is added to the current language's default
18+
# flags (e.g. CFLAGS) when the check is done. The check is thus made with
19+
# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to
20+
# force the compiler to issue an error when a bad flag is given.
21+
#
22+
# INPUT gives an alternative input source to AC_COMPILE_IFELSE.
23+
#
24+
# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
25+
# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG.
26+
#
27+
# LICENSE
28+
#
29+
# Copyright (c) 2008 Guido U. Draheim <[email protected]>
30+
# Copyright (c) 2011 Maarten Bosmans <[email protected]>
31+
#
32+
# This program is free software: you can redistribute it and/or modify it
33+
# under the terms of the GNU General Public License as published by the
34+
# Free Software Foundation, either version 3 of the License, or (at your
35+
# option) any later version.
36+
#
37+
# This program is distributed in the hope that it will be useful, but
38+
# WITHOUT ANY WARRANTY; without even the implied warranty of
39+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
40+
# Public License for more details.
41+
#
42+
# You should have received a copy of the GNU General Public License along
43+
# with this program. If not, see <http://www.gnu.org/licenses/>.
44+
#
45+
# As a special exception, the respective Autoconf Macro's copyright owner
46+
# gives unlimited permission to copy, distribute and modify the configure
47+
# scripts that are the output of Autoconf when processing the Macro. You
48+
# need not follow the terms of the GNU General Public License when using
49+
# or distributing such scripts, even though portions of the text of the
50+
# Macro appear in them. The GNU General Public License (GPL) does govern
51+
# all other use of the material that constitutes the Autoconf Macro.
52+
#
53+
# This special exception to the GPL applies to versions of the Autoconf
54+
# Macro released by the Autoconf Archive. When you make and distribute a
55+
# modified version of the Autoconf Macro, you may extend this special
56+
# exception to the GPL to apply to your modified version as well.
57+
58+
#serial 3
59+
60+
AC_DEFUN([AX_CHECK_COMPILE_FLAG],
61+
[AC_PREREQ(2.59)dnl for _AC_LANG_PREFIX
62+
AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
63+
AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
64+
ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
65+
_AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
66+
AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
67+
[AS_VAR_SET(CACHEVAR,[yes])],
68+
[AS_VAR_SET(CACHEVAR,[no])])
69+
_AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
70+
AS_IF([test x"AS_VAR_GET(CACHEVAR)" = xyes],
71+
[m4_default([$2], :)],
72+
[m4_default([$3], :)])
73+
AS_VAR_POPDEF([CACHEVAR])dnl
74+
])dnl AX_CHECK_COMPILE_FLAGS

0 commit comments

Comments
 (0)