From 0ea513cbb8f8064d6bf18fc26724f43e8d23eb73 Mon Sep 17 00:00:00 2001 From: ardnew Date: Wed, 13 Nov 2024 15:31:48 -0600 Subject: [PATCH] fix(Makefile): use native GOOS/GOARCH by default (#488) Co-authored-by: danielpaulus --- Makefile | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index a29cecdf..58377eb3 100644 --- a/Makefile +++ b/Makefile @@ -9,30 +9,19 @@ GO_IOS_BINARY_NAME=ios NCM_BINARY_NAME=go-ncm +# Define only if compiling for system different than our own +OS= +ARCH= -# Detect the system architecture -UNAME_S := $(shell uname -s) -UNAME_M := $(shell uname -m) - -# Default GOARCH value -GOARCH := amd64 - -# Set GOARCH based on the detected architecture -ifeq ($(UNAME_M),x86_64) - GOARCH := amd64 -else ifeq ($(UNAME_M),armv7l) - GOARCH := arm -else ifeq ($(UNAME_M),aarch64) - GOARCH := arm64 -# Add more architecture mappings as needed -endif +# Prepend each non-empty OS/ARCH definition to "go" command +GOEXEC=$(strip $(foreach v,OS ARCH,$(and $($v),GO$v=$($v) )) go) # Build the Go program build: - @go work use . - @GOARCH=$(GOARCH) go build -o $(GO_IOS_BINARY_NAME) ./main.go - @go work use ./ncm - @CGO_ENABLED=1 GOARCH=$(GOARCH) go build -o $(NCM_BINARY_NAME) ./cmd/cdc-ncm/main.go + @$(GOEXEC) work use . + @$(GOEXEC) build -o $(GO_IOS_BINARY_NAME) ./main.go + @$(GOEXEC) work use ./ncm + @CGO_ENABLED=1 $(GOEXEC) build -o $(NCM_BINARY_NAME) ./cmd/cdc-ncm/main.go # Run the Go program with sudo run: build