Skip to content

Commit 5019482

Browse files
committed
acinclude: Improve detection of not-understood compiler options with clang.
By default, clang warns about but does not fail on unknown -W options. This made configure add the option to WARNING_FLAGS, which caused the warning about not-understood warnings to be emitted for every file compiled. In combination with -Werror, clang does fail on unknown -W options. This commit adds -Werror during configure's warning tests, which should cause the not-understood warnings to be detected that way. Reported-by: Ed Maste <emaste@freebsd.org> Tested-by: Ed Maste <emaste@freebsd.org> Signed-off-by: Ben Pfaff <blp@nicira.com>
1 parent eca39bc commit 5019482

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

acinclude.m4

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,15 @@ dnl This file is free software; the Free Software Foundation
362362
dnl gives unlimited permission to copy and/or distribute it,
363363
dnl with or without modifications, as long as this notice is preserved.
364364

365-
dnl OVS_CHECK_CC_OPTION([OPTION], [ACTION-IF-ACCEPTED], [ACTION-IF-REJECTED])
366-
dnl Check whether the given C compiler OPTION is accepted.
367-
dnl If so, execute ACTION-IF-ACCEPTED, otherwise ACTION-IF-REJECTED.
368-
AC_DEFUN([OVS_CHECK_CC_OPTION],
369-
[
365+
AC_DEFUN([_OVS_CHECK_CC_OPTION], [dnl
370366
m4_define([ovs_cv_name], [ovs_cv_[]m4_translit([$1], [-], [_])])dnl
371367
AC_CACHE_CHECK([whether $CC accepts $1], [ovs_cv_name],
372368
[ovs_save_CFLAGS="$CFLAGS"
373-
CFLAGS="$CFLAGS $1"
369+
dnl Include -Werror in the compiler options, because without -Werror
370+
dnl clang's GCC-compatible compiler driver does not return a failure
371+
dnl exit status even though it complains about options it does not
372+
dnl understand.
373+
CFLAGS="$CFLAGS $WERROR $1"
374374
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,)], [ovs_cv_name[]=yes], [ovs_cv_name[]=no])
375375
CFLAGS="$ovs_save_CFLAGS"])
376376
if test $ovs_cv_name = yes; then
@@ -380,6 +380,21 @@ AC_DEFUN([OVS_CHECK_CC_OPTION],
380380
fi
381381
])
382382

383+
dnl OVS_CHECK_WERROR
384+
dnl
385+
dnl Check whether the C compiler accepts -Werror.
386+
dnl Sets $WERROR to "-Werror", if so, and otherwise to the empty string.
387+
AC_DEFUN([OVS_CHECK_WERROR],
388+
[WERROR=
389+
_OVS_CHECK_CC_OPTION([-Werror], [WERROR=-Werror])])
390+
391+
dnl OVS_CHECK_CC_OPTION([OPTION], [ACTION-IF-ACCEPTED], [ACTION-IF-REJECTED])
392+
dnl Check whether the given C compiler OPTION is accepted.
393+
dnl If so, execute ACTION-IF-ACCEPTED, otherwise ACTION-IF-REJECTED.
394+
AC_DEFUN([OVS_CHECK_CC_OPTION],
395+
[AC_REQUIRE([OVS_CHECK_WERROR])
396+
_OVS_CHECK_CC_OPTION([$1], [$2], [$3])])
397+
383398
dnl OVS_ENABLE_OPTION([OPTION])
384399
dnl Check whether the given C compiler OPTION is accepted.
385400
dnl If so, add it to WARNING_FLAGS.

0 commit comments

Comments
 (0)