-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
110 lines (97 loc) · 2.76 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
ifeq ($(OS),Windows_NT)
HOSTOS=windows
ifeq ($(PROCESSOR_ARCHITEW6432),AMD64)
HOSTARCH=amd64
else
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
HOSTARCH=amd64
else ifeq ($(PROCESSOR_ARCHITECTURE),x86)
HOSTARCH=amd32
endif
endif
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
HOSTOS=linux
else ifeq ($(UNAME_S),Darwin)
HOSTOS=darwin
else
$(info Unknown OS: $(UNAME_S))
exit
endif
UNAME_M := $(shell uname -m)
ifeq ($(UNAME_M),x86_64)
HOSTARCH=amd64
else ifneq ($(filter %86,$(UNAME_M)),)
HOSTARCH=amd32
else ifeq ($(UNAME_M),arm64)
HOSTARCH=arm64
else ifneq ($(filter arm%,$(UNAME_M)),)
HOSTARCH=arm
endif
endif
TARGETOS=$(HOSTOS)
ifdef MAKECMDGOALS
ifeq ($(MAKECMDGOALS), $(filter $(MAKECMDGOALS), windows linux darwin))
TARGETOS=$(MAKECMDGOALS)
endif
endif
#GITTAG=$(shell git describe --tags $(shell git rev-list --tags --max-count=1))
GITCOMMIT=$(shell git log -1 --pretty=format:"%h")
BUILD_FLAGS=-a -ldflags "-w -s -X 'github.com/beatoz/beatoz-go/cmd/version.GitCommit=$(GITCOMMIT)'"
LOCAL_GOPATH = $(shell go env GOPATH)
BUILDDIR=./build/$(HOSTOS)
OUTPUT=$(BUILDDIR)/beatoz
ifeq ($(HOSTOS), windows)
OUTPUT=$(BUILDDIR)/beatoz.exe
endif
BUILD_YN="N"
# if there is no `beatoz` binary.
ifeq ($(wildcard $(OUTPUT)),)
BUILD_YN="Y"
$(info [info] not found $(OUTPUT))
else
# if source files are updated.
status=$(shell git status -s | grep ".go")
ifneq ($(status), )
BUILD_YN="Y"
$(info [info] modified files: $(status))
else
# if commit hashes are different
ver_commit=$(word 2, $(subst -, ,$(subst @, ,$(shell $(OUTPUT) version))))
ifneq ($(ver_commit),$(GITCOMMIT))
BUILD_YN="Y"
$(info [info] commit hash is different: $(GITCOMMIT) <> $(ver_commit))
endif
endif
endif
.PHONY: all pbm $(TARGETOS) deploy
all: pbm $(TARGETOS)
$(TARGETOS):
ifeq ($(BUILD_YN),"Y")
@echo "[$(@)] Build beatoz($(GITCOMMIT)) for $(@) on $(UNAME_S)-$(UNAME_M)"
ifeq ($(HOSTOS),windows)
@set GOOS=$@& set GOARCH=$(HOSTARCH)& go build -o $(OUTPUT) $(BUILD_FLAGS) ./cmd/
else
@GOOS=$@ GOARCH=$(HOSTARCH) go build -o $(OUTPUT) $(BUILD_FLAGS) ./cmd/
endif
else
@echo "[$(@)] The last version ($(shell $(OUTPUT) version)) has already been built."
endif
pbm:
@echo "[$(@)] Compile protocol messages"
@protoc --go_out=$(LOCAL_GOPATH)/src -I./protos/ account.proto
@protoc --go_out=$(LOCAL_GOPATH)/src -I./protos/ gov_params.proto
@protoc --go_out=$(LOCAL_GOPATH)/src -I./protos/ trx.proto
@protoc --go_out=$(LOCAL_GOPATH)/src -I./protos/ reward.proto
install: $(TARGETOS)
@echo "[$(@)] Install binaries to $(LOCAL_GOPATH)/bin"
@cp $(BUILDDIR)/* $(LOCAL_GOPATH)/bin
clean:
@echo "[$(@)] Clean build..."
@rm -rf $(BUILDDIR)
check:
@echo "GOPATH": $(LOCAL_GOPATH)
@echo "HOSTOS: $(HOSTOS)"
@echo "HOSTARCH: $(HOSTARCH)"
@echo "MAKECMDGOALS $(MAKECMDGOALS)"