From 0c7b06f9cafafa1f17cb9eeef3bd3fcd8908283b Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Thu, 13 Jan 2022 00:14:41 -0600 Subject: [PATCH] cf: Check cc support of -Werror=enum-conversion --- cf/check-compile-flag.m4 | 53 ++++++++++++++++++++++++++++++++++++++++ configure.ac | 10 ++++++-- kdc/Makefile.am | 2 +- lib/asn1/Makefile.am | 2 +- lib/gssapi/Makefile.am | 2 +- lib/hcrypto/Makefile.am | 2 +- lib/hdb/Makefile.am | 2 +- lib/kafs/Makefile.am | 2 +- lib/krb5/Makefile.am | 2 +- 9 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 cf/check-compile-flag.m4 diff --git a/cf/check-compile-flag.m4 b/cf/check-compile-flag.m4 new file mode 100644 index 000000000..bd753b34d --- /dev/null +++ b/cf/check-compile-flag.m4 @@ -0,0 +1,53 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT]) +# +# DESCRIPTION +# +# Check whether the given FLAG works with the current language's compiler +# or gives an error. (Warnings, however, are ignored) +# +# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on +# success/failure. +# +# If EXTRA-FLAGS is defined, it is added to the current language's default +# flags (e.g. CFLAGS) when the check is done. The check is thus made with +# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to +# force the compiler to issue an error when a bad flag is given. +# +# INPUT gives an alternative input source to AC_COMPILE_IFELSE. +# +# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this +# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG. +# +# LICENSE +# +# Copyright (c) 2008 Guido U. Draheim +# Copyright (c) 2011 Maarten Bosmans +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 6 + +AC_DEFUN([AX_CHECK_COMPILE_FLAG], +[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF +AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl +AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [ + ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS + _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1" + AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])], + [AS_VAR_SET(CACHEVAR,[yes])], + [AS_VAR_SET(CACHEVAR,[no])]) + _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags]) +AS_VAR_IF(CACHEVAR,yes, + [m4_default([$2], :)], + [m4_default([$3], :)]) +AS_VAR_POPDEF([CACHEVAR])dnl +])dnl AX_CHECK_COMPILE_FLAGS diff --git a/configure.ac b/configure.ac index 1d5f84fd2..663c77039 100644 --- a/configure.ac +++ b/configure.ac @@ -87,8 +87,6 @@ dnl dnl Helper bits for cross compiling dnl - - AM_CONDITIONAL(CROSS_COMPILE, test "${cross_compiling}" = yes) AC_ARG_WITH(cross-tools, @@ -117,6 +115,14 @@ else fi +AX_CHECK_COMPILE_FLAG([-Werror=enum-conversion], + [WFLAGS_ENUM_CONV=-Werror=enum-conversion], + [WFLAGS_ENUM_CONV=], [-Werror]) +AX_CHECK_COMPILE_FLAG([-Wno-unused-but-set-variable], + [WFLAGS_UNUSED_BUT_SET_VAR=-Wno-unused-but-set-variable], + [WFLAGS_UNUSED_BUT_SET_VAR=], [-Werror]) + +AC_SUBST([WFLAGS_ENUM_CONV]) AC_SUBST([ASN1_COMPILE]) AC_SUBST([ASN1_COMPILE_DEP]) AC_SUBST([SLC]) diff --git a/kdc/Makefile.am b/kdc/Makefile.am index 58daa4c74..1f1e516bd 100644 --- a/kdc/Makefile.am +++ b/kdc/Makefile.am @@ -2,7 +2,7 @@ include $(top_srcdir)/Makefile.am.common -WFLAGS += -Wno-error=enum-conversion +WFLAGS += $(WFLAGS_ENUM_CONV) AM_CPPFLAGS += $(INCLUDE_libintl) $(INCLUDE_openssl_crypto) -I$(srcdir)/../lib/krb5 diff --git a/lib/asn1/Makefile.am b/lib/asn1/Makefile.am index b9f7679d7..2d86bdd36 100644 --- a/lib/asn1/Makefile.am +++ b/lib/asn1/Makefile.am @@ -2,7 +2,7 @@ include $(top_srcdir)/Makefile.am.common -WFLAGS += -Wno-error=enum-conversion +WFLAGS += $(WFLAGS_ENUM_CONV) YFLAGS = -d -t diff --git a/lib/gssapi/Makefile.am b/lib/gssapi/Makefile.am index cb525d05d..b060c58b9 100644 --- a/lib/gssapi/Makefile.am +++ b/lib/gssapi/Makefile.am @@ -2,7 +2,7 @@ include $(top_srcdir)/Makefile.am.common -WFLAGS += -Wno-error=enum-conversion +WFLAGS += $(WFLAGS_ENUM_CONV) AUTOMAKE_OPTIONS = subdir-objects diff --git a/lib/hcrypto/Makefile.am b/lib/hcrypto/Makefile.am index f36325a18..fd2966116 100644 --- a/lib/hcrypto/Makefile.am +++ b/lib/hcrypto/Makefile.am @@ -16,7 +16,7 @@ AM_CPPFLAGS += -I$(top_srcdir)/lib/hx509 \ WFLAGS += $(WFLAGS_LITE) -Wno-error=unused-function # XXX: Make these not necessary: WFLAGS += -Wno-error=unused-result -Wno-error=deprecated-declarations -WFLAGS += -Wno-unused-but-set-variable +WFLAGS += $(WFLAGS_UNUSED_BUT_SET_VAR) lib_LTLIBRARIES = libhcrypto.la check_LTLIBRARIES = libhctest.la diff --git a/lib/hdb/Makefile.am b/lib/hdb/Makefile.am index 5dfc28e6e..d528276ec 100644 --- a/lib/hdb/Makefile.am +++ b/lib/hdb/Makefile.am @@ -2,7 +2,7 @@ include $(top_srcdir)/Makefile.am.common -WFLAGS += -Wno-error=enum-conversion +WFLAGS += $(WFLAGS_ENUM_CONV) AM_CPPFLAGS += -I../asn1 -I$(srcdir)/../asn1 AM_CPPFLAGS += $(INCLUDE_openldap) -DHDB_DB_DIR=\"$(DIR_hdbdir)\" diff --git a/lib/kafs/Makefile.am b/lib/kafs/Makefile.am index 22c53ff8e..50d4878ae 100644 --- a/lib/kafs/Makefile.am +++ b/lib/kafs/Makefile.am @@ -2,7 +2,7 @@ include $(top_srcdir)/Makefile.am.common -WFLAGS += -Wno-error=enum-conversion +WFLAGS += $(WFLAGS_ENUM_CONV) AM_CPPFLAGS += $(AFS_EXTRA_DEFS) $(ROKEN_RENAME) diff --git a/lib/krb5/Makefile.am b/lib/krb5/Makefile.am index a13c855a4..2981e3e2a 100644 --- a/lib/krb5/Makefile.am +++ b/lib/krb5/Makefile.am @@ -2,7 +2,7 @@ include $(top_srcdir)/Makefile.am.common -WFLAGS += -Wno-error=enum-conversion +WFLAGS += $(WFLAGS_ENUM_CONV) AM_CPPFLAGS += -I../com_err -I$(srcdir)/../com_err $(INCLUDE_sqlite3) $(INCLUDE_libintl) $(INCLUDE_openssl_crypto)