-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
70 lines (55 loc) · 2.06 KB
/
Makefile
File metadata and controls
70 lines (55 loc) · 2.06 KB
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
Project := Code Push
BuildDist = build
ReleaseDist = release
Platforms = linux darwin windows
CmdTypes = svr cli
GOOS = $(shell go env GOOS)
Svrs := $(foreach n,$(shell go list ./cmd/svr/*),$(notdir $(n)))
#Clis := $(foreach n,$(shell go list ./cmd/cli/*),$(notdir $(n)))
Version := $(shell git describe --tags --dirty --match="v*" 2> /dev/null || echo v0.0.0-dev)
Date := $(shell date -u '+%Y-%m-%d-%H%M UTC')
SvrReleaseDistribution = $(foreach p,$(Platforms),$(foreach c,$(Svrs),$(ReleaseDist)/svr/$(Version)/$(p)-amd64/$(c)))
SvrBuildDistribution = $(foreach c,$(Svrs),$(BuildDist)/svr/$(c))
CliReleaseDistribution = $(foreach p,$(Platforms),$(foreach c,$(Clis),$(ReleaseDist)/cli/$(Version)/$(p)-amd64/$(c)))
CliBuildDistribution = $(foreach c,$(Clis),$(BuildDist)/cli/$(c))
go-clean:
go clean ./cmd/...
.PHONY: go-clean
go-get:
go get
go mod download
.PHONY: go-get
clean: go-clean
rm -rf $(ReleaseDist)/$(Version)
.PHONY: clean
$(SvrReleaseDistribution):
$(call go_build,$@)
.PHONY: $(SvrReleaseDistribution)
$(SvrBuildDistribution):
$(call go_build,$@)
.PHONY: $(SvrBuildDistribution)
$(CliReleaseDistribution):
$(call go_build,$@)
.PHONY: $(CliReleaseDistribution)
$(CliBuildDistribution):
$(call go_build,$@)
.PHONY: $(CliBuildDistribution)
#build: $(CliBuildDistribution)
build: $(SvrBuildDistribution)
.PHONY: build
#release: $(CliReleaseDistribution)
release: $(SvrReleaseDistribution)
.PHONY: release
define go_build
@-rm $1
$(eval buildPlatform = $(shell $(foreach p,$(Platforms),echo $1 | grep -owh $(p);)))
$(eval buildCmdType = $(shell $(foreach p,$(CmdTypes),echo $1 | grep -owh $(p);)))
$(eval buildCmd := $(notdir $1))
$(eval buildGOOS := $(if $(buildPlatform),$(buildPlatform),$(GOOS)))
CGO_ENABLED=0 GOOS=$(buildGOOS) GOARCH=amd64 \
go build \
-gcflags="all=-N -l" \
-ldflags="-X 'github.com/funnyecho/code-push/pkg/svrkit.BuildPlatform=$(buildGOOS)-amd64' -X 'github.com/funnyecho/code-push/pkg/svrkit.Version=$(Version)' -X 'github.com/funnyecho/code-push/pkg/svrkit.BuildTime=$(Date)'" \
-o ./$1 \
./cmd/$(buildCmdType)/$(buildCmd);
endef