Module Name: src Committed By: lukem Date: Tue May 30 18:39:19 UTC 2023
Modified Files: src/tools/compat: configure.ac defs.mk.in Log Message: tools/compat: detect supported host compiler flags Define NB_CC_FLAG(FLAG) to use AX_CHECK_COMPILE_FLAG to determine if the host compiler supports FLAG and define and AC_SUBST CC_FLAG if so. Use workarounds to force clang to hard-fail on unknown -Wwarning, and gcc to use -WWARN to check unknown -Wno-WARN because the latter doesn't cause an error in gcc. In the future we could use NB_CC_FLAG([-fcommon]) for older NetBSD release branches compiled with host gcc 10+. Rework Darwin -no-cpp-precomp check to use NB_CC_FLAG(). Note: this flag probably hasn't been required on macOS (Darwin) for a long time, but serves as a good example on how to use this. Display varaibles at the end of configure to show what was detected. To generate a diff of this commit: cvs rdiff -u -r1.102 -r1.103 src/tools/compat/configure.ac cvs rdiff -u -r1.13 -r1.14 src/tools/compat/defs.mk.in Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tools/compat/configure.ac diff -u src/tools/compat/configure.ac:1.102 src/tools/compat/configure.ac:1.103 --- src/tools/compat/configure.ac:1.102 Tue May 30 18:31:55 2023 +++ src/tools/compat/configure.ac Tue May 30 18:39:19 2023 @@ -1,4 +1,4 @@ -# $NetBSD: configure.ac,v 1.102 2023/05/30 18:31:55 lukem Exp $ +# $NetBSD: configure.ac,v 1.103 2023/05/30 18:39:19 lukem Exp $ # # Autoconf definition file for libnbcompat. # @@ -20,9 +20,11 @@ # AC_INIT([libnbcompat], [noversion], [lib-bug-peo...@netbsd.org]) -AC_CONFIG_HEADERS(nbtool_config.h) -AC_CONFIG_FILES(defs.mk) +AC_CONFIG_HEADERS([nbtool_config.h]) +AC_CONFIG_FILES([defs.mk]) +AC_CONFIG_MACRO_DIR([buildaux]) +m4_pattern_forbid([^AX_]) m4_pattern_forbid([^NB_]) # Autoheader header and footer @@ -321,4 +323,37 @@ main(void) ) ]) +dnl +dnl Set per-warning CC_* variables if supported by HOST_CC. +dnl + +dnl clang needs to fail if given an unknown -WWARN. +cc_fail_unknown= +AX_CHECK_COMPILE_FLAG([-Werror=unknown-warning-option], + [AS_VAR_APPEND([cc_fail_unknown], [-Werror=unknown-warning-option])]) + +AC_DEFUN([NB_CC_FLAG], [dnl +m4_pushdef([NB_FLAG], [$1]) +dnl gcc ignores unknown -Wno-WARN but will fail unknown equivalent -WWARN. +m4_pushdef([NB_WFLAG], m4_bpatsubst(NB_FLAG, [^-Wno-], [-W])) +m4_pushdef([NB_VAR], [CC]m4_translit(NB_FLAG, [-a-z], [_A-Z])) +AX_CHECK_COMPILE_FLAG(NB_WFLAG, [AS_VAR_SET(NB_VAR,NB_FLAG)], [], [$cc_fail_unknown]) +AC_SUBST(NB_VAR) +m4_popdef([NB_FLAG]) +m4_popdef([NB_WFLAG]) +m4_popdef([NB_VAR]) +]) dnl NB_CC_FLAG + +dnl Disable use of pre-compiled headers on Darwin. +NB_CC_FLAG([-no-cpp-precomp]) + + AC_OUTPUT() + +# Display results +# +AC_MSG_NOTICE([========= Configuration results =========]) +AC_MSG_NOTICE([CC $CC]) +AC_MSG_NOTICE([CC_NO_CPP_PRECOMP $CC_NO_CPP_PRECOMP]) +AC_MSG_NOTICE([LIBS $LIBS]) +AC_MSG_NOTICE([=========================================]) Index: src/tools/compat/defs.mk.in diff -u src/tools/compat/defs.mk.in:1.13 src/tools/compat/defs.mk.in:1.14 --- src/tools/compat/defs.mk.in:1.13 Tue May 30 18:31:55 2023 +++ src/tools/compat/defs.mk.in Tue May 30 18:39:19 2023 @@ -1,4 +1,4 @@ -# $NetBSD: defs.mk.in,v 1.13 2023/05/30 18:31:55 lukem Exp $ +# $NetBSD: defs.mk.in,v 1.14 2023/05/30 18:39:19 lukem Exp $ # # Makefile fragment for building with libnbcompat and associated # include files. It can also be used for building just with @@ -71,10 +71,7 @@ HOST_BSHELL= @BSHELL@ BUILD_OSTYPE!= uname -s -# Disable use of pre-compiled headers on Darwin. -.if ${BUILD_OSTYPE} == "Darwin" -HOST_CPPFLAGS+= -no-cpp-precomp -.endif +HOST_CFLAGS+= @CC_NO_CPP_PRECOMP@ HOST_CPPFLAGS+= ${COMPATINCFLAGS} -I${NETBSDSRCDIR}/tools/compat \ -DHAVE_NBTOOL_CONFIG_H=1 -D_FILE_OFFSET_BITS=64