git: fba998a3d897 - main - tools/build: Unbreak bmake bootstrap on Linux

From: Jessica Clarke <jrtc27_at_FreeBSD.org>
Date: Mon, 22 Aug 2022 21:03:15 UTC
The branch main has been updated by jrtc27:

URL: https://cgit.FreeBSD.org/src/commit/?id=fba998a3d897e6297baca74068e4ec1db7adaeec

commit fba998a3d897e6297baca74068e4ec1db7adaeec
Author:     Jessica Clarke <jrtc27@FreeBSD.org>
AuthorDate: 2022-08-22 21:02:53 +0000
Commit:     Jessica Clarke <jrtc27@FreeBSD.org>
CommitDate: 2022-08-22 21:02:53 +0000

    tools/build: Unbreak bmake bootstrap on Linux
    
    Currently make.py has a hack to add the cross-build headers to the
    include search path when bootstrapping bmake on Linux (but not macOS).
    This is a bit of an abuse of these headers, and e9ba1fd5eda2 was not
    prepared for this, since sys/bitcount.h won't exist in that instance (it
    gets copied into WORLDTMP during the legacy build). Work around this
    until we can wean the bmake bootstrap off using these headers by not
    including sys/bitcount.h when it doesn't exist.
    
    Fixes:  e9ba1fd5eda2 ("tools/build: Provide FreeBSD's bitstring API when cross-building")
---
 tools/build/cross-build/include/common/sys/types.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/tools/build/cross-build/include/common/sys/types.h b/tools/build/cross-build/include/common/sys/types.h
index 82436e7e9224..0bfe2bac2aea 100644
--- a/tools/build/cross-build/include/common/sys/types.h
+++ b/tools/build/cross-build/include/common/sys/types.h
@@ -69,7 +69,15 @@ struct cap_rights;
 
 typedef struct cap_rights cap_rights_t;
 
+/*
+ * make.py uses these headers during the bmake bootstrap on Linux only, at
+ * which point sys/bitcount.h won't yet exist, so don't include it there.
+ *
+ * TODO: Untangle this mess.
+ */
+#if __has_include(<sys/bitcount.h>)
 /* Needed for bitstring */
 #include <sys/bitcount.h>
+#endif
 
 #endif