Skip to content

Commit

Permalink
configure: detect compiler flag
Browse files Browse the repository at this point in the history
Use m4 macro AC_TRY_CCFLAG to detect presence of some compiler
option.
Use it to detect -Wjump-misses-init.
  • Loading branch information
Zdenek Kabelac committed Oct 24, 2013
1 parent 772fa46 commit d95751c
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 1 deletion.
39 changes: 39 additions & 0 deletions acinclude.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
dnl AC_GCC_VERSION
dnl check for compiler version
dnl sets COMPILER_VERSION and GCC_VERSION

AC_DEFUN([AC_CC_VERSION],
[
AC_MSG_CHECKING([C compiler version])
COMPILER_VERSION=`$CC -v 2>&1 | grep version`
case "$COMPILER_VERSION" in
*gcc*)
dnl Ok, how to turn $3 into the real $3
GCC_VERSION=`echo $COMPILER_VERSION | \
sed -e 's/[[^ ]]*\ [[^ ]]*\ \([[^ ]]*\)\ .*/\1/'` ;;
*) GCC_VERSION=unknown ;;
esac
AC_MSG_RESULT($GCC_VERSION)
])

dnl AC_TRY_CCFLAG([CCFLAG], [VAR], [ACTION-IF-WORKS], [ACTION-IF-FAILS])
dnl check if $CC supports a given flag

AC_DEFUN([AC_TRY_CCFLAG],
[
AC_REQUIRE([AC_PROG_CC])
ac_save_CFLAGS=$CFLAGS
CFLAGS=$1
AC_MSG_RESULT([KOUKEJ $name])
AC_CACHE_CHECK([whether $CC accepts $1 flag], [ac_cv_flag_$2],
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
[AS_VAR_SET([ac_cv_flag_$2], [yes])],
[AS_VAR_SET([ac_cv_flag_$2], [no])])])
CFLAGS=$ac_save_CFLAGS
$2=AS_VAR_GET([ac_cv_flag_$2])
if test "$2" = yes; then
ifelse([$3], [], [:], [$3])
else
ifelse([$4], [], [:], [$4])
fi
])
1 change: 1 addition & 0 deletions aclocal.m4
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,4 @@ else
fi[]dnl
])# PKG_CHECK_MODULES

m4_include([acinclude.m4])
42 changes: 42 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ CUNIT_CFLAGS
GENPNG
GENHTML
LCOV
HAVE_WJUMP
SACKPT_LIBS
SACKPT_CFLAGS
DLM_LIBS
Expand Down Expand Up @@ -8677,6 +8678,47 @@ else
CSCOPE_CMD=
fi



ac_save_CFLAGS=$CFLAGS
CFLAGS=-Wjump-misses-init
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: KOUKEJ $name" >&5
$as_echo "KOUKEJ $name" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -Wjump-misses-init flag" >&5
$as_echo_n "checking whether $CC accepts -Wjump-misses-init flag... " >&6; }
if test "${ac_cv_flag_HAVE_WJUMP+set}" = set; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
ac_cv_flag_HAVE_WJUMP=yes
else
ac_cv_flag_HAVE_WJUMP=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_flag_HAVE_WJUMP" >&5
$as_echo "$ac_cv_flag_HAVE_WJUMP" >&6; }
CFLAGS=$ac_save_CFLAGS
HAVE_WJUMP=$ac_cv_flag_HAVE_WJUMP
if test "HAVE_WJUMP" = yes; then
:
else
:
fi



################################################################################
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C optimisation flag" >&5
$as_echo_n "checking for C optimisation flag... " >&6; }
Expand Down
4 changes: 4 additions & 0 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,10 @@ else
CSCOPE_CMD=
fi

dnl -- Check if compiler supports -Wjump-misses-init
AC_TRY_CCFLAG([-Wjump-misses-init], [HAVE_WJUMP], [], [])
AC_SUBST(HAVE_WJUMP)

################################################################################
dnl -- Override optimisation
AC_MSG_CHECKING(for C optimisation flag)
Expand Down
6 changes: 5 additions & 1 deletion make.tmpl.in
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,13 @@ WFLAGS += -Wall -Wundef -Wshadow -Wcast-align -Wwrite-strings \
-Wpointer-arith -Wclobbered -Wempty-body -Wignored-qualifiers \
-Wmissing-parameter-type -Wold-style-declaration -Woverride-init \
-Wtype-limits -Wuninitialized -Wmissing-include-dirs -Wsync-nand \
-Wfloat-equal -Wjump-misses-init -Wlogical-op -Wstrict-prototypes \
-Wfloat-equal -Wlogical-op -Wstrict-prototypes \
-Wold-style-definition -Wmissing-format-attribute

ifeq ("@HAVE_WJUMP@", "yes")
WFLAGS += -Wjump-misses-init
endif

#WFLAGS += -W -Wno-sign-compare -Wno-unused-parameter -Wno-missing-field-initializers
#WFLAGS += -Wsign-compare -Wunused-parameter -Wmissing-field-initializers
#WFLAGS += -Wconversion -Wbad-function-cast -Wcast-qual -Waggregate-return -Wpacked
Expand Down

0 comments on commit d95751c

Please sign in to comment.