-
Notifications
You must be signed in to change notification settings - Fork 203
/
Makefile
142 lines (111 loc) · 3.81 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Copyright (C) 2017 go-nebulas authors
#
# This file is part of the go-nebulas library.
#
# the go-nebulas library is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# the go-nebulas library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with the go-nebulas library. If not, see <http://www.gnu.org/licenses/>.
#
SHELL := /bin/bash
VERSION?=3.0.0
COMMIT=$(shell git rev-parse HEAD)
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
CURRENT_DIR=$(shell pwd)
BUILD_DIR=${CURRENT_DIR}
BINARY=neb
VET_REPORT=vet.report
LINT_REPORT=lint.report
TEST_REPORT=test.report
TEST_XUNIT_REPORT=test.report.xml
OS := $(shell uname -s)
ifeq ($(OS),Darwin)
DYLIB=.dylib
INSTALL=install
LDCONFIG=
NEBBINARY=$(BINARY)
BUUILDLOG=
DBCHECK=brew list | grep -c rocksdb
else
DYLIB=.so
INSTALL=sudo install
LDCONFIG=sudo /sbin/ldconfig
NEBBINARY=$(BINARY)-$(COMMIT)
BUUILDLOG=-rm -f $(BINARY); ln -s $(BINARY)-$(COMMIT) $(BINARY)
DBCHECK=ldconfig -p | grep -c rocksdb
endif
NATIVELIB := native-lib
ifeq ($(NATIVELIB),$(wildcard $(NATIVELIB)))
CGO_CFLAGS=
CGO_LDFLAGS=CGO_LDFLAGS="-L$(CURRENT_DIR)/native-lib -lrocksdb -lstdc++ -lm -lz -lbz2 -lsnappy -llz4 -lzstd"
else
CGO_CFLAGS=
CGO_LDFLAGS=
endif
# ifeq ($(shell command -v dep 2> /dev/null || echo "uninstalled"),uninstalled)
# DEPINSTALL=mkdir -p $(GOPATH)/bin && curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
# else
# DEPINSTALL=
# endif
ifeq ($(shell command -v go 2> /dev/null || echo "uninstalled"),uninstalled)
GOCHECK=$(error "go not installed. run `source setup.sh` first!")
else
# GOCHECK=$(info "go installed.")
GOCHECK=
endif
ifneq ($(DBCHECK),0)
DBCHECK=
else
DBCHECK=$(error "rocksdb not installed. run `source setup.sh` first!")
endif
ifneq ($(shell ls $(CURRENT_DIR)/nf/nvm/native-lib |grep -c libnebulas),0)
LIBCHECK=
else
LIBCHECK=$(error "nvm not installed. run `source setup.sh` first!")
endif
# $(warning $(CGO_LDFLAGS))
# Setup the -ldflags option for go build here, interpolate the variable values
LDFLAGS = -ldflags "-X main.version=${VERSION} -X main.commit=${COMMIT} -X main.branch=${BRANCH} -X main.compileAt=`date +%s`"
# Build the project
.PHONY: build build-linux clean dep lint run test vet link-libs all
all: clean vet fmt lint build test
#dep:
# $(DEPINSTALL) dep ensure -v
check: check-go check-db check-lib
check-go:
$(GOCHECK)
check-db:
$(DBCHECK)
check-lib:
$(LIBCHECK)
build: check build-neb
build-neb:
cd cmd/neb; GOPROXY=https://goproxy.io $(CGO_CFLAGS) $(CGO_LDFLAGS) go build $(LDFLAGS) -o ../../$(NEBBINARY)
$(BUUILDLOG)
#build-linux:
# cd cmd/neb; GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o ../../$(BINARY)-linux
LIST := ./account/... ./cmd/... ./common/... ./consensus ./core/... ./crypto/... ./metrics/... ./neblet/... ./net/... ./nf/... ./rpc/... ./storage/... ./sync/... ./util/... ./nip/... ./nr/...
# LIST := $(ls -d */|grep -Ev "vendor|logs|nebtestkit|.db")/...
test:
$(CGO_CFLAGS) $(CGO_LDFLAGS) go test $(LIST) 2>&1 | tee $(TEST_REPORT); go2xunit -fail -input $(TEST_REPORT) -output $(TEST_XUNIT_REPORT)
vet:
go vet $$(go list $(LIST)) 2>&1 | tee $(VET_REPORT)
fmt:
goimports -w $$(go list -f "{{.Dir}}" $(LIST) | grep -v /vendor/)
lint:
golint $$(go list $(LIST)) | sed "s:^$(BUILD_DIR)/::" | tee $(LINT_REPORT)
clean:
-rm -f $(VET_REPORT)
-rm -f $(LINT_REPORT)
-rm -f $(TEST_REPORT)
-rm -f $(TEST_XUNIT_REPORT)
-rm -f $(BINARY)
-rm -f $(BINARY)-$(COMMIT)