Skip to content

Commit f12a461

Browse files
authored
Merge pull request #3 from SgtCoDFish/multiarch
Add build of binaries for different platforms
2 parents 52eb5f5 + 8b137e4 commit f12a461

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

Makefile

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ GOLANGCI_LINT_VERSION := v1.52.2
2828

2929
GOFLAGS := -trimpath
3030

31+
GO_OS := $(shell go env GOOS)
32+
GO_ARCH := $(shell go env GOARCH)
33+
3134
RELEASE_VERSION := $(shell git describe --tags --match='v*' --abbrev=14)
3235
GITCOMMIT := $(shell git rev-parse HEAD)
3336

@@ -38,8 +41,22 @@ GOLDFLAGS := -w -s \
3841
.PHONY: build
3942
build: $(BINDIR)/boilersuite
4043

41-
$(BINDIR)/boilersuite: $(GO_FILES) $(TEMPLATE_FILES) | $(BINDIR)
42-
CGO_ENABLED=0 go build $(GOFLAGS) -ldflags "$(GOLDFLAGS)" -o $@ main.go
44+
$(BINDIR)/boilersuite: $(BINDIR)/boilersuite-$(GO_OS)-$(GO_ARCH)
45+
ln -fs $< $@
46+
47+
.PHONY: build-release
48+
build-release: $(BINDIR)/SHA256SUMS
49+
50+
$(BINDIR)/SHA256SUMS: $(BINDIR)/boilersuite-linux-amd64 $(BINDIR)/boilersuite-darwin-amd64 $(BINDIR)/boilersuite-darwin-arm64
51+
cd $(BINDIR) && sha256sum $(notdir $^) > $(notdir $@)
52+
53+
# Expects to be called with a golang OS / Arch combination separated by a dash
54+
$(BINDIR)/boilersuite-%: $(GO_FILES) $(TEMPLATE_FILES) | $(BINDIR)
55+
# the OS is the part before the dash
56+
$(eval OS := $(word 1,$(subst -, ,$*)))
57+
# the arch is the part after the dash
58+
$(eval ARCH := $(word 2,$(subst -, ,$*)))
59+
GOOS=$(OS) GOARCH=$(ARCH) CGO_ENABLED=0 go build $(GOFLAGS) -ldflags "$(GOLDFLAGS)" -o $@ main.go
4360

4461
.PHONY: test
4562
test:

0 commit comments

Comments
 (0)