diff --git a/configure.ac b/configure.ac index d7ccdaec..05831a88 100644 --- a/configure.ac +++ b/configure.ac @@ -146,7 +146,7 @@ AS_IF([test "x$debug" = "xyes"], dnl dnl GCC provides a couple of checks to detect incorrect macro uses AX_CFLAGS_GCC_OPTION([-Wundef]) - AX_CFLAGS_GCC_OPTION([-Wunused-macros]) + WM_CFLAGS_GCC_OPTION_UNUSEDMACROS ], [dnl dnl When debug not enabled, we try to avoid some non-necessary dnl messages from the compiler @@ -845,6 +845,12 @@ fi gl_LD_VERSION_SCRIPT + +dnl Add the post-poned compilation options +dnl ====================================== +WM_CFLAGS_GCC_OPTION_POSTPONED + + AC_OUTPUT(Makefile po/Makefile util/Makefile util/po/Makefile test/Makefile \ WINGs/Makefile WINGs/WINGs/Makefile WINGs/Documentation/Makefile \ WINGs/Examples/Makefile WINGs/Resources/Makefile WINGs/Tests/Makefile \ diff --git a/m4/wm_cflags_check.m4 b/m4/wm_cflags_check.m4 index d46511a1..26745b69 100644 --- a/m4/wm_cflags_check.m4 +++ b/m4/wm_cflags_check.m4 @@ -75,3 +75,71 @@ wm_fn_c_try_compile_cflag () AS_SET_STATUS([$wm_retval]) } ]) + + +# WM_CFLAGS_GCC_OPTION_UNUSEDMACROS +# --------------------------------- +# +# Check if the compiler support '-Wunused-macros'. This would be done +# traditionally using AX_CFLAGS_GCC_OPTION(...), but in the present case it +# always fail because the test program defines many macro (all the stuff +# detected so far) so the warning always trigger, the compilation then fail, +# and the option is then marked as never supported. +# +# This macro works around this by using a basic program without any #define +AC_DEFUN([WM_CFLAGS_GCC_OPTION_UNUSEDMACROS], +[AC_CACHE_CHECK([CFLAGS for gcc -Wunused-macros], [wm_cv_c_checks_compopt_Wunused_macros], + [AC_LANG_COMPILER_REQUIRE()dnl + AC_LANG_PUSH([C]) + wm_save_CFLAGS="$CFLAGS" + CFLAGS="$wm_save_CFLAGS -pedantic -Werror -Wunused-macros" + dnl Similar to AC_LANG_CONFTEST(C), except we do not include the 'confdefs.h' + dnl directly in the source to avoid an "unused macro" error, but we include + dnl it in the same way we will include the "config.h", so we get in the same + dnl condition as WindowMaker's source + cat <<_ACEOF >conftest.$ac_ext +@%:@include "confdefs.h" + +int +main(int argc, char **argv) +{ + /* to avoid failing on -Wunused-parameter */ + (void) argc; + (void) argv; + + return 0; +} +_ACEOF + AS_IF([ac_fn_[]_AC_LANG_ABBREV[]_try_compile "$LINENO"], + [wm_cv_c_checks_compopt_Wunused_macros="-Wunused-macros"], + [wm_cv_c_checks_compopt_Wunused_macros="no"]) + rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + CFLAGS="$wm_save_CFLAGS" + AC_LANG_POP([C]) ]) +# We cannot add this flag now to CFLAGS because it could break all further +# detections done by configure, the flag will be added at the end by the +# macro WM_CFLAGS_GCC_OPTION_POSTPONED +]) + + +# WM_CFLAGS_GCC_OPTION_POSTPONED +# ------------------------------ +# +# Some options cannot be added to the compilation command as soon as they have +# been detected because they can break the detection done in autoconf, because +# the template are cannot always be perfect. +# This macro takes care of making them effective, so it should be called just +# before AC_OUTPUT. +AC_DEFUN_ONCE([WM_CFLAGS_GCC_OPTION_POSTPONED], +[# WM_CFLAGS_GCC_OPTION_POSTPONED: add compiler flags at the end of the autoconf flow +AS_IF([test "x$debug" = "xyes"], + [m4_foreach([arg_name], [[Wunused_macros]], + [AS_CASE([$wm_cv_c_checks_compopt_[]arg_name], + [no*], [], + [AS_IF([echo " $CFLAGS " | grep " $wm_cv_c_checks_compopt_[]arg_name " 2>&1 > /dev/null], + [AC_MSG_WARN([option $wm_cv_c_checks_compopt_[]arg_name already present in \$CFLAGS, not appended])], + [CFLAGS="$CFLAGS $wm_cv_c_checks_compopt_[]arg_name"])dnl + ]) + ])dnl + ])dnl +])