forked from github/git-sizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
81 lines (65 loc) · 2.47 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
PACKAGE := github.com/github/git-sizer
GO111MODULES := 1
export GO111MODULES
GO := $(CURDIR)/script/go
GO_LDFLAGS := -X main.BuildVersion=$(shell git describe --tags --always --dirty || echo unknown)
GOFLAGS := -mod=readonly -ldflags "$(GO_LDFLAGS)"
ifdef USE_ISATTY
GOFLAGS := $(GOFLAGS) --tags isatty
endif
.PHONY: all
all: bin/git-sizer
.PHONY: bin/git-sizer
bin/git-sizer:
mkdir -p bin
$(GO) build $(GOFLAGS) -o $@ .
# Cross-compile for a bunch of common platforms. Note that this
# doesn't work with USE_ISATTY:
.PHONY: common-platforms
common-platforms:
# Create releases for a bunch of common platforms. Note that this
# doesn't work with USE_ISATTY, and VERSION must be set on the command
# line; e.g.,
#
# make releases VERSION=1.2.3
.PHONY: releases
releases:
# Define rules for a bunch of common platforms that are supported by go; see
# https://golang.org/doc/install/source#environment
# You can compile for any other platform in that list by running
# make GOOS=foo GOARCH=bar
define PLATFORM_template =
.PHONY: bin/git-sizer-$(1)-$(2)$(3)
bin/git-sizer-$(1)-$(2)$(3):
mkdir -p bin
GOOS=$(1) GOARCH=$(2) $$(GO) build $$(GOFLAGS) -ldflags "-X main.ReleaseVersion=$$(VERSION)" -o $$@ .
common-platforms: bin/git-sizer-$(1)-$(2)$(3)
# Note that releases don't include code from vendor (they're only used
# for testing), so no license info is needed from those projects.
.PHONY: releases/git-sizer-$$(VERSION)-$(1)-$(2).zip
releases/git-sizer-$$(VERSION)-$(1)-$(2).zip: bin/git-sizer-$(1)-$(2)$(3)
if test -z "$$(VERSION)"; then echo "Please set VERSION to make releases"; exit 1; fi
mkdir -p releases/tmp-$$(VERSION)-$(1)-$(2)
cp README.md LICENSE.md releases/tmp-$$(VERSION)-$(1)-$(2)
cp bin/git-sizer-$(1)-$(2)$(3) releases/tmp-$$(VERSION)-$(1)-$(2)/git-sizer$(3)
cp $$$$($$(GO) list -f '{{.Dir}}' github.com/spf13/pflag)/LICENSE \
releases/tmp-$$(VERSION)-$(1)-$(2)/LICENSE-spf13-pflag
rm -f $$@
zip -j $$@ releases/tmp-$$(VERSION)-$(1)-$(2)/*
rm -rf releases/tmp-$$(VERSION)-$(1)-$(2)
releases: releases/git-sizer-$$(VERSION)-$(1)-$(2).zip
endef
$(eval $(call PLATFORM_template,linux,amd64))
$(eval $(call PLATFORM_template,linux,386))
$(eval $(call PLATFORM_template,darwin,amd64))
$(eval $(call PLATFORM_template,darwin,arm64))
$(eval $(call PLATFORM_template,windows,amd64,.exe))
$(eval $(call PLATFORM_template,windows,386,.exe))
.PHONY: test
test: bin/git-sizer gotest
.PHONY: gotest
gotest:
$(GO) test -timeout 60s $(GOFLAGS) ./...
.PHONY: clean
clean:
rm -rf bin