Skip to content

Instantly share code, notes, and snippets.

@bryanjhv
Created February 13, 2022 04:43
Show Gist options
  • Save bryanjhv/05762f3d931d839b807535c5b2bca3cf to your computer and use it in GitHub Desktop.
Save bryanjhv/05762f3d931d839b807535c5b2bca3cf to your computer and use it in GitHub Desktop.
Golang multi-arch makefile
PLATFORMS := windows/386 windows/amd64 linux/386 linux/amd64 linux/arm linux/arm64
export CGO_ENABLED = 0
export GO386 = softfloat
parts = $(subst /, ,$@)
export GOOS = $(word 1,$(parts))
export GOARCH = $(word 2,$(parts))
export EXT = $(if $(filter windows,$(GOOS)),exe,bin)
release: clean $(PLATFORMS)
clean:
rm -rf bin
mkdir -p bin
$(PLATFORMS):
go build -ldflags="-s -w" -o "bin/program-$(GOOS)_$(GOARCH).$(EXT)" .
.PHONY: clean release $(PLATFORMS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment