1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-01-04 04:44:16 +01:00

configure: rewrote the detection for -Wunused-macro

This flag is always detected as unsupported because every time autoconf is
generating a test program for any feature, it puts at the beginning of the
test source all the '#define' that have been detected so far, which is what
we expect normally.

But for this option, as we cannot reasonably make a dummy use of every
macro, the warning triggers and falsely gets autoconf into thinking it does
not work.

This patch creates a dedicated macro (WM_CFLAGS_GCC_OPTION_UNUSEDMACROS)
for this flag, which works around the problem by having no '#define' in the
test source. It also adds a new macro WM_CFLAGS_GCC_OPTION_POSTPONED
because if the flag works, we still cannot add it to the compilation
command because it could fail all further tests done, so the macro will add
it to CFLAGS only at the end.

Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
Christophe CURIS
2014-12-08 22:42:22 +01:00
committed by Carlos R. Mafra
parent fa4d50a0ca
commit 11fe8bd860
2 changed files with 75 additions and 1 deletions

View File

@@ -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 \

View File

@@ -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
])