Skip to content

Commit f37ee1a

Browse files
committed
Makefile: auto-detect legacy macOS targets in bundle signing
Pre-Mavericks (< 10.9) codesign predates the '--timestamp' option, so 'make bundle' currently fails on macOS 10.5-10.8 with: codesign: unrecognized option `--timestamp=none' The ad-hoc signing step exists to satisfy dyld / hardened-runtime enforcement on Apple Silicon and recent Intel. That enforcement doesn't exist on legacy targets, so the signing step isn't just broken there but unnecessary. Derive MACOS_LEGACY from BUNDLE_MIN_OS (itself parsed out of MINVERFLAGS), which means: - Detection is automatic; no user-specified flag needed. - Keying off the target OS rather than the build host means cross-compiling for ppc/10.5 on a modern Mac still takes the legacy path. On legacy targets the entire signing block is skipped via a shell conditional (Make directives can't interleave with recipe lines). Modern builds are unchanged.
1 parent ade6cfd commit f37ee1a

1 file changed

Lines changed: 25 additions & 12 deletions

File tree

Makefile

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,13 @@ BUNDLE_BUILD ?= 44
402402
# Extract X.Y from '-mmacosx-version-min=X.Y' inside $(MINVERFLAGS).
403403
# If nothing matches (e.g. building with a custom toolchain), fall back to 10.13.
404404
BUNDLE_MIN_OS ?= $(or $(patsubst -mmacosx-version-min=%,%,$(filter -mmacosx-version-min=%,$(MINVERFLAGS))),10.13)
405+
# Detect legacy macOS targets (< 10.9 Mavericks). Pre-Mavericks codesign
406+
# predates the `--timestamp` option; the dyld/Gatekeeper enforcement that
407+
# makes ad-hoc signing worth doing didn't exist yet either, so on legacy
408+
# targets we skip signing entirely rather than fight an older toolchain.
409+
# We key off BUNDLE_MIN_OS rather than the build host so cross-compiling
410+
# for ppc/10.5 on a modern Mac still picks up the legacy path.
411+
MACOS_LEGACY := $(shell echo $(BUNDLE_MIN_OS) | awk -F. '{ exit !($$1 < 10 || ($$1 == 10 && $$2 < 9)) }' && echo 1)
405412
INFO_PLIST_SRC := pkg/apple/OSX/Info_Metal.plist
406413
# Universal (arm64 + x86_64) MoltenVK.framework shipped in the repo.
407414
# Only copied when HAVE_VULKAN=1; on pre-Metal / non-Vulkan builds
@@ -439,19 +446,25 @@ bundle: $(TARGET) $(METALLIB)
439446
-e 's|$$(CURRENT_PROJECT_VERSION)|$(BUNDLE_BUILD)|g' \
440447
-e 's|$$(MACOSX_DEPLOYMENT_TARGET)|$(BUNDLE_MIN_OS)|g' \
441448
$(INFO_PLIST_SRC) > $(BUNDLE)/Contents/Info.plist
442-
@# Ad-hoc code signing. On Apple Silicon (and increasingly on Intel with
443-
@# hardened runtime enforcement), dyld refuses to load unsigned dylibs
444-
@# even for ad-hoc app-internal use — including the MoltenVK framework
445-
@# copied in above. `codesign --sign -` produces an ad-hoc signature
446-
@# that satisfies the loader without requiring a developer identity.
447-
@# Sign nested content first (frameworks), then the outer .app wrapper,
448-
@# so the app's seal covers all contents.
449-
$(Q)if [ -d $(BUNDLE)/Contents/Frameworks ]; then \
450-
for fw in $(BUNDLE)/Contents/Frameworks/*.framework; do \
451-
[ -d "$$fw" ] && codesign --force --sign - --timestamp=none "$$fw"; \
452-
done; \
449+
@# Ad-hoc code signing. On Apple Silicon (and increasingly on Intel
450+
@# with hardened runtime enforcement), dyld refuses to load unsigned
451+
@# dylibs even for ad-hoc app-internal use — including the MoltenVK
452+
@# framework copied in above. `codesign --sign -` produces an ad-hoc
453+
@# signature that satisfies the loader without needing a developer
454+
@# identity. Sign nested content first (frameworks), then the outer
455+
@# .app wrapper, so the app's seal covers all contents.
456+
@#
457+
@# Skip entirely on pre-Mavericks targets: those toolchains predate
458+
@# `--timestamp`, the dyld enforcement that makes this necessary, and
459+
@# in some cases ad-hoc signing support altogether.
460+
$(Q)if [ "$(MACOS_LEGACY)" != "1" ]; then \
461+
if [ -d $(BUNDLE)/Contents/Frameworks ]; then \
462+
for fw in $(BUNDLE)/Contents/Frameworks/*.framework; do \
463+
[ -d "$$fw" ] && codesign --force --sign - --timestamp=none "$$fw"; \
464+
done; \
465+
fi; \
466+
codesign --force --sign - --timestamp=none $(BUNDLE); \
453467
fi
454-
$(Q)codesign --force --sign - --timestamp=none $(BUNDLE)
455468
@echo "Done. Run with: open $(BUNDLE)"
456469

457470
.PHONY: bundle

0 commit comments

Comments
 (0)