Skip to content

Commit 5b3f2fd

Browse files
committed
Makefile: add support for cross-compilation
Also add a target `common-platforms` to cross-compile binaries for the most common platforms.
1 parent 9e54877 commit 5b3f2fd

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Makefile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,38 @@ bin/git-sizer:
2424
mkdir -p bin
2525
$(GO) build $(GOFLAGS) -o $@ $(PACKAGE)
2626

27+
# Cross-compile for a bunch of common platforms. Note that this
28+
# doesn't work with USE_ISATTY:
29+
.PHONY: common-platforms
30+
common-platforms: \
31+
bin/git-sizer-linux-amd64 \
32+
bin/git-sizer-linux-386 \
33+
bin/git-sizer-darwin-amd64 \
34+
bin/git-sizer-darwin-386 \
35+
bin/git-sizer-windows-amd64.exe \
36+
bin/git-sizer-windows-386.exe
37+
38+
# Define rules for a bunch of common platforms that are supported by go; see
39+
# https://golang.org/doc/install/source#environment
40+
# You can compile for any other platform in that list by running
41+
# make GOOS=foo GOARCH=bar
42+
43+
define PLATFORM_template =
44+
.PHONY: bin/git-sizer-$(1)-$(2)$(3)
45+
bin/git-sizer-$(1)-$(2)$(3):
46+
mkdir -p bin
47+
GOOS=$(1) GOARCH=$(2) $$(GO) build $$(GOFLAGS) -o $$@ $$(PACKAGE)
48+
endef
49+
50+
$(eval $(call PLATFORM_template,linux,amd64))
51+
$(eval $(call PLATFORM_template,linux,386))
52+
53+
$(eval $(call PLATFORM_template,darwin,386))
54+
$(eval $(call PLATFORM_template,darwin,amd64))
55+
56+
$(eval $(call PLATFORM_template,windows,amd64,.exe))
57+
$(eval $(call PLATFORM_template,windows,386,.exe))
58+
2759
.PHONY: test
2860
test: bin/git-sizer gotest
2961

0 commit comments

Comments
 (0)