Skip to content

Commit

Permalink
Unix configure: add -Wdeclaration-after-statement by default in CFLAG…
Browse files Browse the repository at this point in the history
…S to issue 'warning: ISO C90 forbids mixed declarations and code' with GCC, which means that compilation will fails with MSVC, so something that *MUST* be fixed
  • Loading branch information
rouault authored and tbonfort committed Jul 30, 2012
1 parent 73761fd commit 3128a3c
Show file tree
Hide file tree
Showing 3 changed files with 274 additions and 40 deletions.
164 changes: 143 additions & 21 deletions configure
Expand Up @@ -11210,6 +11210,13 @@ CC="$lt_save_CC"










ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
Expand Down Expand Up @@ -20519,48 +20526,163 @@ if test "${with_warnings+set}" = set; then :
fi


{ $as_echo "$as_me:${as_lineno-$LINENO}: checking C_WFLAGS for maximum warnings" >&5
$as_echo_n "checking C_WFLAGS for maximum warnings... " >&6; }
if test "${ac_cv_cflags_warn_all+set}" = set; then :
$as_echo_n "(cached) " >&6
else
ac_cv_cflags_warn_all="no, unknown"

ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu

ac_save_CFLAGS="$CFLAGS"
for ac_arg in "-pedantic -Wdeclaration-after-statement % -Wall -Wdeclaration-after-statement" "-pedantic % -Wall" "-xstrconst % -v" "-std1 % -verbose -w0 -warnprotos" "-qlanglvl=ansi % -qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd" "-ansi -ansiE % -fullwarn" "+ESlit % +w1" "-Xc % -pvctl,fullmsg" "-h conform % -h msglevel 2" #
do CFLAGS="$ac_save_CFLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */

int
main ()
{
return 0;
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
ac_cv_cflags_warn_all=`echo $ac_arg | sed -e 's,.*% *,,'` ; break
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
done
CFLAGS="$ac_save_CFLAGS"
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu


fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cflags_warn_all" >&5
$as_echo "$ac_cv_cflags_warn_all" >&6; }
case ".$ac_cv_cflags_warn_all" in
.ok|.ok,*) ;;
.|.no|.no,*)
;;
*)
if echo " $C_WFLAGS " | grep " $ac_cv_cflags_warn_all " 2>&1 >/dev/null
then { { $as_echo "$as_me:${as_lineno-$LINENO}: : C_WFLAGS does contain \$ac_cv_cflags_warn_all"; } >&5
(: C_WFLAGS does contain $ac_cv_cflags_warn_all) 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }
else { { $as_echo "$as_me:${as_lineno-$LINENO}: : C_WFLAGS=\"\$C_WFLAGS \$ac_cv_cflags_warn_all\""; } >&5
(: C_WFLAGS="$C_WFLAGS $ac_cv_cflags_warn_all") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }
C_WFLAGS="$C_WFLAGS $ac_cv_cflags_warn_all"
fi
;;
esac

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking CXX_WFLAGS for maximum warnings" >&5
$as_echo_n "checking CXX_WFLAGS for maximum warnings... " >&6; }
if test "${ac_cv_cxxflags_warn_all+set}" = set; then :
$as_echo_n "(cached) " >&6
else
ac_cv_cxxflags_warn_all="no, unknown"

ac_ext=cpp
ac_cpp='$CXXCPP $CPPFLAGS'
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu

ac_save_CXXFLAGS="$CXXFLAGS"
for ac_arg in "-pedantic % -Wall" "-xstrconst % -v" "-std1 % -verbose -w0 -warnprotos" "-qlanglvl=ansi % -qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd" "-ansi -ansiE % -fullwarn" "+ESlit % +w1" "-Xc % -pvctl,fullmsg" "-h conform % -h msglevel 2" #
do CXXFLAGS="$ac_save_CXXFLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */

int
main ()
{
return 0;
;
return 0;
}
_ACEOF
if ac_fn_cxx_try_compile "$LINENO"; then :
ac_cv_cxxflags_warn_all=`echo $ac_arg | sed -e 's,.*% *,,'` ; break
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
done
CXXFLAGS="$ac_save_CXXFLAGS"
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu


fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cxxflags_warn_all" >&5
$as_echo "$ac_cv_cxxflags_warn_all" >&6; }
case ".$ac_cv_cxxflags_warn_all" in
.ok|.ok,*) ;;
.|.no|.no,*)
;;
*)
if echo " $CXX_WFLAGS " | grep " $ac_cv_cxxflags_warn_all " 2>&1 >/dev/null
then { { $as_echo "$as_me:${as_lineno-$LINENO}: : CXX_WFLAGS does contain \$ac_cv_cxxflags_warn_all"; } >&5
(: CXX_WFLAGS does contain $ac_cv_cxxflags_warn_all) 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }
else { { $as_echo "$as_me:${as_lineno-$LINENO}: : CXX_WFLAGS=\"\$CXX_WFLAGS \$ac_cv_cxxflags_warn_all\""; } >&5
(: CXX_WFLAGS="$CXX_WFLAGS $ac_cv_cxxflags_warn_all") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }
CXX_WFLAGS="$CXX_WFLAGS $ac_cv_cxxflags_warn_all"
fi
;;
esac


if test "$with_warnings" = "yes" ; then
if test "$GCC" = "yes" ; then
WFLAGS="-W -Wall -Wcast-align -Wmissing-prototypes -Wstrict-prototypes -Wpointer-arith -Wreturn-type"
C_EXTRA_WFLAGS="-Wmissing-declarations"
WFLAGS="-W -Wcast-align -Wmissing-prototypes -Wstrict-prototypes -Wpointer-arith -Wreturn-type"
C_WFLAGS="$C_WFLAGS -Wmissing-declarations"

{ $as_echo "$as_me:${as_lineno-$LINENO}: result: strict" >&5
$as_echo "strict" >&6; }
else
WFLAGS=""
C_EXTRA_WFLAGS=""
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: disabled" >&5
$as_echo "disabled" >&6; }
fi

elif test "$with_warnings" = "" ; then
if test "$GCC" = "yes" ; then
WFLAGS="-Wall"
C_EXTRA_WFLAGS=""
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: basic" >&5
$as_echo "basic" >&6; }
else
WFLAGS=""
C_EXTRA_WFLAGS=""
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: disabled" >&5
$as_echo "disabled" >&6; }
fi

elif test "$with_warnings" = "no" ; then
WFLAGS=""
C_EXTRA_WFLAGS=""
C_WFLAGS=""
CXX_WFLAGS=""
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: disabled" >&5
$as_echo "disabled" >&6; }

else
elif test "$with_warnings" != "" ; then
WFLAGS="$with_warnings"
C_EXTRA_WFLAGS=""
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: user defined" >&5
$as_echo "user defined" >&6; }
fi

CFLAGS="$CFLAGS $WFLAGS $C_EXTRA_WFLAGS"
CXXFLAGS="$CXXFLAGS $WFLAGS "
CFLAGS="$CFLAGS $WFLAGS $C_WFLAGS"
CXXFLAGS="$CXXFLAGS $WFLAGS $CXX_WFLAGS"


{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we should enable debug features..." >&5
Expand Down
30 changes: 11 additions & 19 deletions configure.in
Expand Up @@ -36,6 +36,7 @@ m4_include([m4/mapserver.m4])
m4_include([m4/apache.m4])
m4_include([m4/ax_jni_include_dir.m4])
m4_include([m4/ax_pkg_swig.m4])
m4_include([m4/ax_cflags_warn_all.m4])

AC_CONFIG_SRCDIR([mapserv.c])
dnl Checks for programs.
Expand Down Expand Up @@ -2163,42 +2164,33 @@ AC_MSG_CHECKING(compiler warnings)
AC_ARG_WITH(warnings,
[ --with-warnings[[=flags]] Enable strict warnings (or user defined warnings)],,)

AX_CFLAGS_WARN_ALL(C_WFLAGS)
AX_CXXFLAGS_WARN_ALL(CXX_WFLAGS)

if test "$with_warnings" = "yes" ; then
if test "$GCC" = "yes" ; then
WFLAGS="-W -Wall -Wcast-align -Wmissing-prototypes -Wstrict-prototypes -Wpointer-arith -Wreturn-type"
C_EXTRA_WFLAGS="-Wmissing-declarations"
WFLAGS="-W -Wcast-align -Wmissing-prototypes -Wstrict-prototypes -Wpointer-arith -Wreturn-type"
C_WFLAGS="$C_WFLAGS -Wmissing-declarations"

AC_MSG_RESULT([strict])
else
WFLAGS=""
C_EXTRA_WFLAGS=""
AC_MSG_RESULT([disabled])
fi

elif test "$with_warnings" = "" ; then
if test "$GCC" = "yes" ; then
WFLAGS="-Wall"
C_EXTRA_WFLAGS=""
AC_MSG_RESULT([basic])
else
WFLAGS=""
C_EXTRA_WFLAGS=""
AC_MSG_RESULT([disabled])
fi

elif test "$with_warnings" = "no" ; then
WFLAGS=""
C_EXTRA_WFLAGS=""
C_WFLAGS=""
CXX_WFLAGS=""
AC_MSG_RESULT([disabled])

else
elif test "$with_warnings" != "" ; then
WFLAGS="$with_warnings"
C_EXTRA_WFLAGS=""
AC_MSG_RESULT([user defined])
fi

CFLAGS="$CFLAGS $WFLAGS $C_EXTRA_WFLAGS"
CXXFLAGS="$CXXFLAGS $WFLAGS "
CFLAGS="$CFLAGS $WFLAGS $C_WFLAGS"
CXXFLAGS="$CXXFLAGS $WFLAGS $CXX_WFLAGS"

dnl ---------------------------------------------------------------------
dnl Check --enable-debug option for "-g" compile flag. (OFF by default)
Expand Down
120 changes: 120 additions & 0 deletions m4/ax_cflags_warn_all.m4
@@ -0,0 +1,120 @@
dnl @synopsis AX_CFLAGS_WARN_ALL [(shellvar [,default, [A/NA]])]
dnl
dnl Try to find a compiler option that enables most reasonable
dnl warnings. This macro is directly derived from VL_PROG_CC_WARNINGS
dnl which is split up into two AX_CFLAGS_WARN_ALL and
dnl AX_CFLAGS_WARN_ALL_ANSI
dnl
dnl For the GNU CC compiler it will be -Wall (and -ansi -pedantic) The
dnl result is added to the shellvar being CFLAGS by default.
dnl
dnl Currently this macro knows about GCC, Solaris C compiler, Digital
dnl Unix C compiler, C for AIX Compiler, HP-UX C compiler, IRIX C
dnl compiler, NEC SX-5 (Super-UX 10) C compiler, and Cray J90 (Unicos
dnl 10.0.0.8) C compiler.
dnl
dnl - $1 shell-variable-to-add-to : CFLAGS
dnl - $2 add-value-if-not-found : nothing
dnl - $3 action-if-found : add value to shellvariable
dnl - $4 action-if-not-found : nothing
dnl
dnl @category C
dnl @author Guido Draheim <guidod@gmx.de>
dnl @version 2003-01-06
dnl @license GPLWithACException

AC_DEFUN([AX_CFLAGS_WARN_ALL],[dnl
AS_VAR_PUSHDEF([FLAGS],[CFLAGS])dnl
AS_VAR_PUSHDEF([VAR],[ac_cv_cflags_warn_all])dnl
AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for maximum warnings],
VAR,[VAR="no, unknown"
AC_LANG_SAVE
AC_LANG(C)
ac_save_[]FLAGS="$[]FLAGS"
for ac_arg dnl
in "-pedantic -Wdeclaration-after-statement % dnl
-Wall -Wdeclaration-after-statement" dnl works since GCC version 3
"-pedantic % -Wall" dnl older 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_TRY_COMPILE([],[return 0;],
[VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
done
FLAGS="$ac_save_[]FLAGS"
AC_LANG_RESTORE
])
case ".$VAR" in
.ok|.ok,*) m4_ifvaln($3,$3) ;;
.|.no|.no,*) m4_ifvaln($4,$4,[m4_ifval($2,[
AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])
m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])]) ;;
*) m4_ifvaln($3,$3,[
if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR])
else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"
fi ]) ;;
esac
AS_VAR_POPDEF([VAR])dnl
AS_VAR_POPDEF([FLAGS])dnl
])

dnl the only difference - the LANG selection... and the default FLAGS

AC_DEFUN([AX_CXXFLAGS_WARN_ALL],[dnl
AS_VAR_PUSHDEF([FLAGS],[CXXFLAGS])dnl
AS_VAR_PUSHDEF([VAR],[ac_cv_cxxflags_warn_all])dnl
AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for maximum warnings],
VAR,[VAR="no, unknown"
AC_LANG_SAVE
AC_LANG(C++)
ac_save_[]FLAGS="$[]FLAGS"
for ac_arg dnl
in "-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_TRY_COMPILE([],[return 0;],
[VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
done
FLAGS="$ac_save_[]FLAGS"
AC_LANG_RESTORE
])
case ".$VAR" in
.ok|.ok,*) m4_ifvaln($3,$3) ;;
.|.no|.no,*) m4_ifvaln($4,$4,[m4_ifval($2,[
AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])
m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])]) ;;
*) m4_ifvaln($3,$3,[
if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR])
else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"
fi ]) ;;
esac
AS_VAR_POPDEF([VAR])dnl
AS_VAR_POPDEF([FLAGS])dnl
])

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 delimimiter. A non-option comment can be given after "%%" marks.

0 comments on commit 3128a3c

Please sign in to comment.