OSDN Git Service

Merge pull request #467 from Bytom/fix
[bytom/vapor.git] / Makefile
1 ifndef GOOS
2 UNAME_S := $(shell uname -s)
3 ifeq ($(UNAME_S),Darwin)
4         GOOS := darwin
5 else ifeq ($(UNAME_S),Linux)
6         GOOS := linux
7 else
8 $(error "$$GOOS is not defined. If you are using Windows, try to re-make using 'GOOS=windows make ...' ")
9 endif
10 endif
11
12 PACKAGES    := $(shell go list ./... | grep -v '/vendor/' | grep -v '/crypto/ed25519/chainkd' | grep -v '/mining/tensority')
13
14 BUILD_FLAGS := -ldflags "-X github.com/bytom/vapor/version.GitCommit=`git rev-parse HEAD`"
15
16
17 VAPORD_BINARY32 := vapord-$(GOOS)_386
18 VAPORD_BINARY64 := vapord-$(GOOS)_amd64
19
20 VAPORCLI_BINARY32 := vaporcli-$(GOOS)_386
21 VAPORCLI_BINARY64 := vaporcli-$(GOOS)_amd64
22
23 VERSION := $(shell awk -F= '/Version =/ {print $$2}' version/version.go | tr -d "\" ")
24
25
26 VAPORD_RELEASE32 := vapord-$(VERSION)-$(GOOS)_386
27 VAPORD_RELEASE64 := vapord-$(VERSION)-$(GOOS)_amd64
28
29 VAPORCLI_RELEASE32 := vaporcli-$(VERSION)-$(GOOS)_386
30 VAPORCLI_RELEASE64 := vaporcli-$(VERSION)-$(GOOS)_amd64
31
32 VAPOR_RELEASE32 := vapor-$(VERSION)-$(GOOS)_386
33 VAPOR_RELEASE64 := vapor-$(VERSION)-$(GOOS)_amd64
34
35 all: test target release-all install
36
37 fedd:
38         @echo "Building fedd to cmd/fedd/fedd"
39         @go build $(BUILD_FLAGS) -o cmd/fedd/fedd cmd/fedd/main.go
40
41 precognitive:
42         @echo "Building precognitive to cmd/precognitive/precognitive"
43         @go build $(BUILD_FLAGS) -o cmd/precognitive/precognitive cmd/precognitive/main.go
44
45 vapord:
46         @echo "Building vapord to cmd/vapord/vapord"
47         @go build $(BUILD_FLAGS) -o cmd/vapord/vapord cmd/vapord/main.go
48
49 vaporcli:
50         @echo "Building vaporcli to cmd/vaporcli/vaporcli"
51         @go build $(BUILD_FLAGS) -o cmd/vaporcli/vaporcli cmd/vaporcli/main.go
52
53 install:
54         @echo "Installing vapord and vaporcli to $(GOPATH)/bin"
55         @go install ./cmd/vapord
56         @go install ./cmd/vaporcli
57
58 target:
59         mkdir -p $@
60
61 binary: target/$(VAPORD_BINARY32) target/$(VAPORD_BINARY64) target/$(VAPORCLI_BINARY32) target/$(VAPORCLI_BINARY64)
62
63 ifeq ($(GOOS),windows)
64 release: binary
65         cd target && cp -f $(VAPORD_BINARY32) $(VAPORD_BINARY32).exe
66         cd target && cp -f $(VAPORCLI_BINARY32) $(VAPORCLI_BINARY32).exe
67         cd target && md5sum $(VAPORD_BINARY32).exe $(VAPORCLI_BINARY32).exe >$(VAPOR_RELEASE32).md5
68         cd target && zip $(VAPOR_RELEASE32).zip $(VAPORD_BINARY32).exe $(VAPORCLI_BINARY32).exe $(VAPOR_RELEASE32).md5
69         cd target && rm -f $(VAPORD_BINARY32) $(VAPORCLI_BINARY32) $(VAPORD_BINARY32).exe $(VAPORCLI_BINARY32).exe $(VAPOR_RELEASE32).md5
70         cd target && cp -f $(VAPORD_BINARY64) $(VAPORD_BINARY64).exe
71         cd target && cp -f $(VAPORCLI_BINARY64) $(VAPORCLI_BINARY64).exe
72         cd target && md5sum $(VAPORD_BINARY64).exe $(VAPORCLI_BINARY64).exe >$(VAPOR_RELEASE64).md5
73         cd target && zip $(VAPOR_RELEASE64).zip $(VAPORD_BINARY64).exe $(VAPORCLI_BINARY64).exe $(VAPOR_RELEASE64).md5
74         cd target && rm -f $(VAPORD_BINARY64) $(VAPORCLI_BINARY64) $(VAPORD_BINARY64).exe $(VAPORCLI_BINARY64).exe $(VAPOR_RELEASE64).md5
75 else
76 release: binary
77         cd target && md5sum $(VAPORD_BINARY32) $(VAPORCLI_BINARY32) >$(VAPOR_RELEASE32).md5
78         cd target && tar -czf $(VAPOR_RELEASE32).tgz $(VAPORD_BINARY32) $(VAPORCLI_BINARY32) $(VAPOR_RELEASE32).md5
79         cd target && rm -f $(VAPORD_BINARY32) $(VAPORCLI_BINARY32) $(VAPOR_RELEASE32).md5
80         cd target && md5sum $(VAPORD_BINARY64) $(VAPORCLI_BINARY64) >$(VAPOR_RELEASE64).md5
81         cd target && tar -czf $(VAPOR_RELEASE64).tgz $(VAPORD_BINARY64) $(VAPORCLI_BINARY64) $(VAPOR_RELEASE64).md5
82         cd target && rm -f $(VAPORD_BINARY64) $(VAPORCLI_BINARY64) $(VAPOR_RELEASE64).md5
83 endif
84
85 release-all: clean
86         GOOS=darwin  make release
87         GOOS=linux   make release
88         GOOS=windows make release
89
90 clean:
91         @echo "Cleaning binaries built..."
92         @rm -rf cmd/vapord/vapord
93         @rm -rf cmd/vaporcli/vaporcli
94         @rm -rf target
95         @rm -rf $(GOPATH)/bin/vapord
96         @rm -rf $(GOPATH)/bin/vaporcli
97         @echo "Cleaning temp test data..."
98         @rm -rf test/pseudo_hsm*
99         @rm -rf blockchain/pseudohsm/testdata/pseudo/
100         @echo "Cleaning sm2 pem files..."
101         @rm -rf crypto/sm2/*.pem
102         @echo "Done."
103
104 target/$(VAPORD_BINARY32):
105         CGO_ENABLED=0 GOARCH=386 go build $(BUILD_FLAGS) -o $@ cmd/vapord/main.go
106
107 target/$(VAPORD_BINARY64):
108         CGO_ENABLED=0 GOARCH=amd64 go build $(BUILD_FLAGS) -o $@ cmd/vapord/main.go
109
110 target/$(VAPORCLI_BINARY32):
111         CGO_ENABLED=0 GOARCH=386 go build $(BUILD_FLAGS) -o $@ cmd/vaporcli/main.go
112
113 target/$(VAPORCLI_BINARY64):
114         CGO_ENABLED=0 GOARCH=amd64 go build $(BUILD_FLAGS) -o $@ cmd/vaporcli/main.go
115
116
117 test:
118         @echo "====> Running go test"
119         @go test -tags "network" $(PACKAGES)
120
121 benchmark:
122         @go test -bench $(PACKAGES)
123
124 functional-tests:
125         @go test -timeout=5m -tags="functional" ./test 
126
127 ci: test
128
129 .PHONY: all target release-all clean test benchmark