summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorlukem <lukem@NetBSD.org>2023-05-30 18:39:19 +0000
committerlukem <lukem@NetBSD.org>2023-05-30 18:39:19 +0000
commita226cb0efc621a678526e83312786b47a4786197 (patch)
treee643a979abd2ec1bd433c21517830ac5c6df7b6f /tools
parentc08f864ef2b338270174f90ede0c50f7589d7534 (diff)
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.
Diffstat (limited to 'tools')
-rw-r--r--tools/compat/configure.ac41
-rw-r--r--tools/compat/defs.mk.in7
2 files changed, 40 insertions, 8 deletions
diff --git a/tools/compat/configure.ac b/tools/compat/configure.ac
index 315ab4ae1b5..2bedaeb185a 100644
--- a/tools/compat/configure.ac
+++ b/tools/compat/configure.ac
@@ -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-people@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([=========================================])
diff --git a/tools/compat/defs.mk.in b/tools/compat/defs.mk.in
index 25f705fba78..31e565fd7c1 100644
--- a/tools/compat/defs.mk.in
+++ b/tools/compat/defs.mk.in
@@ -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