Skip to content

Commit ca03c07

Browse files
authored
Merge pull request #5 from github/cross-compile
Support cross-compiling
2 parents e19b4c7 + ccb76d4 commit ca03c07

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

Makefile

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ GO := $(CURDIR)/script/go
77
GOFMT := $(CURDIR)/script/gofmt
88

99
GOFLAGS := \
10-
--tags "static" \
1110
-ldflags "-X main.BuildVersion=$(shell git rev-parse HEAD) -X main.BuildDescribe=$(shell git describe --tags --always --dirty)"
1211

12+
ifdef USE_ISATTY
13+
GOFLAGS := $(GOFLAGS) --tags isatty
14+
endif
15+
1316
GO_SRCS := $(shell cd $(GOPATH)/src/$(PACKAGE) && $(GO) list -f '{{$$ip := .ImportPath}}{{range .GoFiles}}{{printf ".gopath/src/%s/%s\n" $$ip .}}{{end}}{{range .CgoFiles}}{{printf ".gopath/src/%s/%s\n" $$ip .}}{{end}}{{range .TestGoFiles}}{{printf ".gopath/src/%s/%s\n" $$ip .}}{{end}}{{range .XTestGoFiles}}{{printf ".gopath/src/%s/%s\n" $$ip .}}{{end}}' ./...)
1417

1518
.PHONY: all
@@ -20,6 +23,38 @@ bin/git-sizer:
2023
mkdir -p bin
2124
$(GO) build $(GOFLAGS) -o $@ $(PACKAGE)
2225

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

isatty/isatty_disabled.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// +build !isatty
2+
3+
package isatty
4+
5+
func Isatty(fd uintptr) (bool, error) {
6+
return true, nil
7+
}

isatty/isatty.go renamed to isatty/isatty_enabled.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build isatty
2+
13
package isatty
24

35
/*

0 commit comments

Comments
 (0)