6060# ---- SBOM generation ----
6161CC ?= cc
6262WOLFSSL_DIR ?= ../wolfssl
63+ WOLFHSM_CFG_DIR ?= test/config
6364VERSION = $(shell sed -n 's/^. wolfHSM Release v//p' ChangeLog.md | head -1 | cut -d' ' -f1)
6465SRCS := $(sort $(wildcard src/* .c) )
6566SBOM_CDX = wolfhsm-$(VERSION ) .cdx.json
@@ -84,12 +85,41 @@ sbom:
8485 echo " Set WOLFSSL_DIR to such a tree." >&2 ; \
8586 exit 1; \
8687 fi
88+ @if [ ! -f " $( WOLFHSM_CFG_DIR) /wolfhsm_cfg.h" ]; then \
89+ echo " ERROR: $( WOLFHSM_CFG_DIR) /wolfhsm_cfg.h not found." >&2 ; \
90+ echo " Set WOLFHSM_CFG_DIR to the directory holding the" >&2 ; \
91+ echo " wolfhsm_cfg.h (and user_settings.h) your build uses." >&2 ; \
92+ exit 1; \
93+ fi
8794 @echo " wolfHSM version: $( VERSION) "
8895 @echo " Sources: $( words $( SRCS) ) .c files in src/"
96+ @echo " Config: $( WOLFHSM_CFG_DIR) /wolfhsm_cfg.h"
97+ # Effective build config for the SBOM: preprocess wolfhsm/wh_settings.h with
98+ # the same defines and include path the test build compiles under, so the -dM
99+ # dump holds every WOLFHSM_CFG_* option (explicit and defaulted) plus the
100+ # wolfSSL options from user_settings.h — the configuration the library is
101+ # actually built with. Point WOLFHSM_CFG_DIR at the directory holding your
102+ # build's wolfhsm_cfg.h/user_settings.h for an integrator-accurate SBOM.
103+ #
104+ # ponytail: wh_settings.h pulls libc headers (stdint/stdio/strings/stdatomic),
105+ # so ~330 toolchain constants (INT16_MAX, ACCESSPERMS, ...) ride along into
106+ # the SBOM next to the ~175 real config macros. The dump is deliberately NOT
107+ # filtered here: a prefix allowlist would silently drop real options that
108+ # carry no standard prefix (GCM_TABLE_4BIT, FP_MAX_BITS, SINGLE_THREADED).
109+ # The durable fix belongs in gen-sbom's noise filter (wolfSSL PR #10343,
110+ # scripts/gen-sbom _NOISE_MACRO_RE), either of:
111+ # a) provenance filtering: accept a -dD dump and use its #line markers to
112+ # drop macros defined in system headers, or
113+ # b) an --options-baseline flag: subtract a second -dM dump made with the
114+ # same flags minus the -include, plus the libc headers it pulls.
115+ # Once gen-sbom grows that, this recipe needs no change — it already hands
116+ # over the full dump.
89117 @_defines=$$(mktemp "$${TMPDIR:-/tmp}/wolfhsm-defines.XXXXXX") && \
90118 trap 'rm -f "$$_defines"' 0 && \
91- if ! $( CC) -dM -E -I. -I$( WOLFSSL_DIR) -x c /dev/null > " $$ _defines" 2> /dev/null; then \
92- echo " ERROR: $( CC) -dM -E failed." >&2 ; exit 1; \
119+ if ! $(CC) -dM -E -DWOLFHSM_CFG -DWOLFSSL_USER_SETTINGS \
120+ -I. -I$(WOLFHSM_CFG_DIR) -I$(WOLFSSL_DIR) \
121+ -include wolfhsm/wh_settings.h -x c /dev/null >"$$_defines"; then \
122+ echo "ERROR: $(CC) -dM -E on wolfhsm/wh_settings.h failed." >&2; exit 1; \
93123 fi && \
94124 if ! command -v python3 >/dev/null 2>&1; then \
95125 echo "ERROR: python3 not found." >&2; exit 1; \
0 commit comments