mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 04:20:27 +01:00
configure: add macro to check compiler flag '-Wstrict-prototype'
Strict prototype are better for portability and to avoid bugs because it makes sure the compiler has the information to properly validate the arguments given when a function is called. This flag however need special care when checking for it, because the declaration for 'main' generated by autoconf cannot be a strict prototype so the detection would always see the flag as failing. This patch handles this by creating a dedicated macro for this detection which uses a good prototype because we're in a case where it is possible, so the detection will not always fail; it also makes sure to add the flag to CFLAG only at the end, to avoid falsely crashing any further test done in the configure script. Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
committed by
Carlos R. Mafra
parent
11fe8bd860
commit
30e1fad926
@@ -129,6 +129,11 @@ AS_IF([test "x$debug" = "xyes"],
|
|||||||
dnl more difficult, so try to avoid it
|
dnl more difficult, so try to avoid it
|
||||||
AX_CFLAGS_GCC_OPTION([-Wredundant-decls])
|
AX_CFLAGS_GCC_OPTION([-Wredundant-decls])
|
||||||
dnl
|
dnl
|
||||||
|
dnl Prototype of function must be explicit, no deprecated K&R syntax
|
||||||
|
dnl and no empty argument list which prevents compiler from doing
|
||||||
|
dnl type checking when using the function
|
||||||
|
WM_CFLAGS_GCC_OPTION_STRICTPROTO
|
||||||
|
dnl
|
||||||
dnl Proper attributes helps the compiler to produce better code
|
dnl Proper attributes helps the compiler to produce better code
|
||||||
WM_CFLAGS_CHECK_FIRST([format attribute suggest],
|
WM_CFLAGS_CHECK_FIRST([format attribute suggest],
|
||||||
[-Wsuggest-attribute=format dnl new gcc syntax
|
[-Wsuggest-attribute=format dnl new gcc syntax
|
||||||
|
|||||||
@@ -122,6 +122,44 @@ _ACEOF
|
|||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
# WM_CFLAGS_GCC_OPTION_STRICTPROTO
|
||||||
|
# --------------------------------
|
||||||
|
#
|
||||||
|
# Check if the compiler support '-Wstrict-prototypes'. This would be done
|
||||||
|
# traditionally using AX_CFLAGS_GCC_OPTION(...), but in the present case it
|
||||||
|
# always fail because the test program generated by autoconf always use a
|
||||||
|
# non-compliant prototype (this is needed for portability to avoid possible
|
||||||
|
# function declaration mismatch on 'main').
|
||||||
|
#
|
||||||
|
# This macro works around this by providing a strict prototype for 'main'
|
||||||
|
# in this case because we are in a very known case.
|
||||||
|
AC_DEFUN([WM_CFLAGS_GCC_OPTION_STRICTPROTO],
|
||||||
|
[AC_CACHE_CHECK([CFLAGS for gcc -Wstrict-prototypes], [wm_cv_c_checks_compopt_Wstrict_prototypes],
|
||||||
|
[AC_LANG_COMPILER_REQUIRE()dnl
|
||||||
|
AC_LANG_PUSH([C])
|
||||||
|
wm_save_CFLAGS="$CFLAGS"
|
||||||
|
CFLAGS="$wm_save_CFLAGS -pedantic -Werror -Wstrict-prototypes"
|
||||||
|
AC_COMPILE_IFELSE(
|
||||||
|
[AC_LANG_SOURCE([dnl
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
/* to avoid failing on -Wunused-parameter */
|
||||||
|
(void) argc;
|
||||||
|
(void) argv;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}])],
|
||||||
|
[wm_cv_c_checks_compopt_Wstrict_prototypes="-Wstrict-prototypes"],
|
||||||
|
[wm_cv_c_checks_compopt_Wstrict_prototypes="no"])
|
||||||
|
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
|
# WM_CFLAGS_GCC_OPTION_POSTPONED
|
||||||
# ------------------------------
|
# ------------------------------
|
||||||
#
|
#
|
||||||
@@ -133,7 +171,7 @@ _ACEOF
|
|||||||
AC_DEFUN_ONCE([WM_CFLAGS_GCC_OPTION_POSTPONED],
|
AC_DEFUN_ONCE([WM_CFLAGS_GCC_OPTION_POSTPONED],
|
||||||
[# WM_CFLAGS_GCC_OPTION_POSTPONED: add compiler flags at the end of the autoconf flow
|
[# WM_CFLAGS_GCC_OPTION_POSTPONED: add compiler flags at the end of the autoconf flow
|
||||||
AS_IF([test "x$debug" = "xyes"],
|
AS_IF([test "x$debug" = "xyes"],
|
||||||
[m4_foreach([arg_name], [[Wunused_macros]],
|
[m4_foreach([arg_name], [[Wstrict_prototypes], [Wunused_macros]],
|
||||||
[AS_CASE([$wm_cv_c_checks_compopt_[]arg_name],
|
[AS_CASE([$wm_cv_c_checks_compopt_[]arg_name],
|
||||||
[no*], [],
|
[no*], [],
|
||||||
[AS_IF([echo " $CFLAGS " | grep " $wm_cv_c_checks_compopt_[]arg_name " 2>&1 > /dev/null],
|
[AS_IF([echo " $CFLAGS " | grep " $wm_cv_c_checks_compopt_[]arg_name " 2>&1 > /dev/null],
|
||||||
|
|||||||
Reference in New Issue
Block a user