<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40056 >
- This adds new file compiler.m4 containing macros for testing if compiler supports some comamndline option or not. Main use for this will probably be setting tighter warning-options when compiler supports it instead of using only those options available in all gcc-versions we support. - Above macros are used for setting debug options (mainly Warning options) instead of just assuming that hardcoded set is supported in gcc, and no options set when using other compilers. - As side effect of the unification, C++ compilers are better supported. Originally this was written as part of #39661. The main principle remains, but otherwise couple of cleanup iterations has caused quite complete rewrite since then. - ML
diff -Nurd -X.diff_ignore freeciv/configure.ac freeciv/configure.ac --- freeciv/configure.ac 2008-01-27 11:28:36.000000000 +0200 +++ freeciv/configure.ac 2008-01-27 19:23:30.000000000 +0200 @@ -327,15 +327,13 @@ AC_SUBST([POFILES]) fi -EXTRA_GCC_DEBUG_CFLAGS="" -EXTRA_GCC_DEBUG_CXXFLAGS="" - -if test -n "$GCC"; then - EXTRA_GCC_DEBUG_CFLAGS="$CFLAGS" - EXTRA_GCC_DEBUG_CXXFLAGS="$CXXFLAGS" - CFLAGS="-Wall -Wpointer-arith -Wcast-align -Wmissing-prototypes -Wmissing-declarations" - CXXFLAGS="-Wall -Wpointer-arith -Wcast-align" -fi +dnl Set debug flags supported by compiler +EXTRA_DEBUG_CFLAGS="" +EXTRA_DEBUG_CXXFLAGS="" +FC_C_FLAGS([-Wall -Wpointer-arith -Wcast-align -Wmissing-prototypes -Wmissing-declarations], + [], [EXTRA_DEBUG_CFLAGS]) +FC_CXX_FLAGS([-Wall -Wpointer-arith -Wcast-align], + [], [EXTRA_DEBUG_CXXFLAGS]) FC_DEBUG AC_C99_VARIADIC_MACROS @@ -742,10 +740,8 @@ fi fi]],[[]]) -if test -n "$GCC"; then - CFLAGS="$EXTRA_GCC_DEBUG_CFLAGS $CFLAGS" - CXXFLAGS="$EXTRA_GCC_DEBUG_CXXFLAGS $CXXFLAGS" -fi +CFLAGS="$EXTRA_DEBUG_CFLAGS $CFLAGS" +CXXFLAGS="$EXTRA_DEBUG_CXXFLAGS $CXXFLAGS" dnl Rebuild 'configure' whenever version.in changes, if maintainer mode enabled. AC_SUBST([CONFIGURE_DEPENDENCIES], ["$CONFIGURE_DEPENDENCIES \$(top_srcdir)/version.in"]) diff -Nurd -X.diff_ignore freeciv/m4/compiler.m4 freeciv/m4/compiler.m4 --- freeciv/m4/compiler.m4 1970-01-01 02:00:00.000000000 +0200 +++ freeciv/m4/compiler.m4 2008-01-27 19:11:41.000000000 +0200 @@ -0,0 +1,68 @@ +# Macros to check compiler options +# + +# Helper function that adds flags (words) to variable listing them. +# Makes sure there is no extra spaces even in any situation +# +# $1 - Name of the target variable +# $2 - Flags to add +# +AC_DEFUN([FC_ADD_WORDS_TO_VAR], +[ +old_value="`eval echo '$'$1`" +if test "x$old_value" = "x" ; then + $1="$2" +elif test "x$2" != "x" ; then + $1="$old_value $2" +fi +]) + +# Check if compiler supports given commandline parameter in language specific +# variable. If it does, it will be concatenated to variable. If several +# parameters are given, they are tested, and added to target variable, +# one at a time. +# +# $1 - Language +# $2 - Language specific variable +# $3 - Parameters to test +# $4 - Additional parameters +# $5 - Variable where to add +# + +AC_DEFUN([FC_COMPILER_FLAGS], +[ +AC_LANG_PUSH([$1]) + +flags_save="`eval echo '$'$2`" +accepted_flags="" + +for flag in $3 +do + $2="$flags_save $accepted_flags $flag $4" + AC_COMPILE_IFELSE([int a;], + [FC_ADD_WORDS_TO_VAR([accepted_flags], [$flag])]) +done +FC_ADD_WORDS_TO_VAR([$5], [$accepted_flags]) + +$2="$flags_save" + +AC_LANG_POP([$1]) +]) + +# Commandling flag tests for C and C++ +# +# +# $1 - Parameters to test +# $2 - Additional parameters +# $3 - Variable where to add + +AC_DEFUN([FC_C_FLAGS], +[ +FC_COMPILER_FLAGS([C], [CFLAGS], [$1], [$2], [$3]) +]) + + +AC_DEFUN([FC_CXX_FLAGS], +[ +FC_COMPILER_FLAGS([C++], [CXXFLAGS], [$1], [$2], [$3]) +]) diff -Nurd -X.diff_ignore freeciv/m4/debug.m4 freeciv/m4/debug.m4 --- freeciv/m4/debug.m4 2007-08-04 18:36:07.000000000 +0300 +++ freeciv/m4/debug.m4 2008-01-27 19:16:02.000000000 +0200 @@ -10,12 +10,14 @@ dnl -g is added by AC_PROG_CC if the compiler understands it if test "x$enable_debug" = "xyes"; then - AC_DEFINE(DEBUG, 1, [Define if you want extra debugging.]) - EXTRA_GCC_DEBUG_CFLAGS="$EXTRA_GCC_DEBUG_CFLAGS -Werror" + AC_DEFINE([DEBUG], [1], [Extra debugging support]) + FC_C_FLAGS([-Werror], [], [EXTRA_DEBUG_C_FLAGS]) + FC_CXX_FLAGS([-Werror], [], [EXTRA_DEBUG_CXX_FLAGS]) else if test "x$enable_debug" = "xno"; then - AC_DEFINE(NDEBUG, 1, [Define if you want no debug support.]) - EXTRA_GCC_DEBUG_CFLAGS="-O3 -fomit-frame-pointer" + AC_DEFINE([NDEBUG], [1], [No debugging support at all]) + FC_C_FLAGS([-O3 -fomit-frame-pointer], [], [EXTRA_DEBUG_C_FLAGS]) + FC_CXX_FLAGS([-O3 -fomit-frame-pointer], [], [EXTRA_DEBUG_CXX_FLAGS]) fi fi ])
_______________________________________________ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev