From 3b83bc7e3a9f0fb73641f41e2399bbfbf7491b2b Mon Sep 17 00:00:00 2001 From: Daniel Uptain Date: Thu, 24 Sep 2026 22:42:16 -0700 Subject: [PATCH] fix(make): detect cmd.exe shell for native Windows ABE builds (#642) * fix(make): detect cmd.exe shell for native Windows ABE builds * Fix build command syntax in Makefile for Windows --- Makefile | 9 ++++++--- crypto/windows/abe_native/Makefile.frag | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 12f2849..6b307c4 100644 --- a/Makefile +++ b/Makefile @@ -8,10 +8,13 @@ include crypto/windows/abe_native/Makefile.frag build: $(GO) build -o $(GOEXE) ./cmd/hack-browser-data +# Make sets these in the recipe environment on both POSIX and native Windows +# GNU Make, so we do not need a cmd.exe vs sh branch for build-windows. +build-windows: export GOOS := windows +build-windows: export GOARCH := amd64 +build-windows: export CGO_ENABLED := 0 build-windows: $(ABE_BIN) - GOOS=windows GOARCH=amd64 CGO_ENABLED=0 \ - $(GO) build -tags abe_embed -trimpath -ldflags="-s -w" \ - -o $(GOEXE).exe ./cmd/hack-browser-data + $(GO) build -tags abe_embed -trimpath -ldflags="-s -w" -o $(GOEXE).exe ./cmd/hack-browser-data clean: payload-clean rm -f $(GOEXE) $(GOEXE).exe diff --git a/crypto/windows/abe_native/Makefile.frag b/crypto/windows/abe_native/Makefile.frag index 34ea921..da5377a 100644 --- a/crypto/windows/abe_native/Makefile.frag +++ b/crypto/windows/abe_native/Makefile.frag @@ -20,11 +20,24 @@ ABE_HDRS = $(ABE_SRC_DIR)/com_iid.h \ $(ABE_SRC_DIR)/bootstrap.h \ $(ABE_SRC_DIR)/bootstrap_layout.h +# Detect cmd.exe vs POSIX sh. OS=Windows_NT is set under MSYS2/Git Bash too, +# but those use sh — so shell detection is what matters for recipe syntax. +# cmd echoes the quotes back; POSIX sh strips them. +ifeq ($(shell echo "x"),"x") +WIN_CMD_SHELL := 1 +endif + +ifdef WIN_CMD_SHELL +ABE_REPORT_CMD = for %%I in ("$@") do @echo built $@ (%%~zI bytes) +else +ABE_REPORT_CMD = printf "built %s (%s bytes)\n" "$@" "$$(wc -c < $@ | tr -d ' ')" +endif + +# crypto/windows/payload/ is tracked in git, so no mkdir is required. $(ABE_BIN): $(ABE_C_SRCS) $(ABE_HDRS) - @mkdir -p $(ABE_BIN_DIR) $(ZIG) cc -target $(ABE_TARGET) $(ABE_CFLAGS) $(ABE_LDFLAGS) \ $(ABE_C_SRCS) -o $@ $(ABE_LDLIBS) - @printf "built %s (%s bytes)\n" "$@" "$$(wc -c < $@ | tr -d ' ')" + @$(ABE_REPORT_CMD) .PHONY: payload payload-verify payload-clean