Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tools/compat tools/compat: detect supported host compiler flags
details: https://anonhg.NetBSD.org/src/rev/25a4808bcb15
branches: trunk
changeset: 376073:25a4808bcb15
user: lukem <lukem%NetBSD.org@localhost>
date: Tue May 30 18:39:19 2023 +0000
description:
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:
tools/compat/configure.ac | 41 ++++++++++++++++++++++++++++++++++++++---
tools/compat/defs.mk.in | 7 ++-----
2 files changed, 40 insertions(+), 8 deletions(-)
diffs (82 lines):
diff -r 92c64a563439 -r 25a4808bcb15 tools/compat/configure.ac
--- a/tools/compat/configure.ac Tue May 30 18:35:16 2023 +0000
+++ b/tools/compat/configure.ac Tue May 30 18:39:19 2023 +0000
@@ -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@localhost])
-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 -r 92c64a563439 -r 25a4808bcb15 tools/compat/defs.mk.in
--- a/tools/compat/defs.mk.in Tue May 30 18:35:16 2023 +0000
+++ b/tools/compat/defs.mk.in Tue May 30 18:39:19 2023 +0000
@@ -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
Home |
Main Index |
Thread Index |
Old Index