forked from open-horizon/anax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
160 lines (135 loc) · 5.41 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
ifeq ($(TMPDIR),)
TMPDIR := /tmp/
endif
ifneq ("$(wildcard ./rules.env)","")
include rules.env
export $(shell sed 's/=.*//' rules.env)
endif
SHELL := /bin/bash
EXECUTABLE := $(shell basename $$PWD)
CLI_EXECUTABLE := cli/hzn
DEFAULT_UI = api/static/index.html
export TMPGOPATH ?= $(TMPDIR)$(EXECUTABLE)-gopath
export PKGPATH := $(TMPGOPATH)/src/github.com/open-horizon/$(EXECUTABLE)
export PATH := $(TMPGOPATH)/bin:$(PATH)
# we use a script that will give us the debian arch version since that's what the packaging system inputs
arch ?= $(shell tools/arch-tag)
COMPILE_ARGS := CGO_ENABLED=0
# TODO: handle other ARM architectures on build boxes too
ifeq ($(arch),armhf)
COMPILE_ARGS += GOARCH=arm GOARM=7
else ifeq ($(arch),arm64)
COMPILE_ARGS += GOARCH=arm64
else ifeq ($(arch),amd64)
COMPILE_ARGS += GOARCH=amd64
else ifeq ($(arch),ppc64el)
COMPILE_ARGS += GOARCH=ppc64le
endif
ifeq ($(shell uname -s),Linux)
COMPILE_ARGS += GOOS=linux
else ifeq ($(shell uname -s),Darwin)
COMPILE_ARGS += GOOS=darwin
endif
ifndef verbose
.SILENT:
endif
all: deps all-nodeps
all-nodeps: gopathlinks $(EXECUTABLE) $(CLI_EXECUTABLE)
$(EXECUTABLE): $(shell find . -name '*.go' -not -path './vendor/*') $(CLI_EXECUTABLE) gopathlinks
@echo "Producing $(EXECUTABLE) given arch: $(arch)"
cd $(PKGPATH) && \
export GOPATH=$(TMPGOPATH); \
$(COMPILE_ARGS) go build -o $(EXECUTABLE);
exch_ver=$(shell grep "REQUIRED_EXCHANGE_VERSION =" $(PKGPATH)/version/version.go | awk -F '"' '{print $$2}') && \
echo "The required minimum exchange version is $$exch_ver"
$(CLI_EXECUTABLE): $(shell find . -name '*.go' -not -path './vendor/*') gopathlinks
@echo "Producing $(CLI_EXECUTABLE) given arch: $(arch)"
cd $(PKGPATH) && \
export GOPATH=$(TMPGOPATH); \
$(COMPILE_ARGS) go build -o $(CLI_EXECUTABLE) $(CLI_EXECUTABLE).go
clean: mostlyclean
@echo "Clean"
find ./vendor -maxdepth 1 -not -path ./vendor -and -not -iname "vendor.json" -print0 | xargs -0 rm -Rf
ifneq ($(TMPGOPATH),$(GOPATH))
rm -rf $(TMPGOPATH)
endif
rm -rf ./contracts
mostlyclean:
@echo "Mostlyclean"
rm -f $(EXECUTABLE) $(CLI_EXECUTABLE)
deps: $(TMPGOPATH)/bin/govendor
@echo "Fetching dependencies"
cd $(PKGPATH) && \
export GOPATH=$(TMPGOPATH); export PATH=$(TMPGOPATH)/bin:$$PATH; \
govendor sync
$(TMPGOPATH)/bin/govendor: gopathlinks
if [ ! -e "$(TMPGOPATH)/bin/govendor" ]; then \
echo "Fetching govendor"; \
export GOPATH=$(TMPGOPATH); export PATH=$(TMPGOPATH)/bin:$$PATH; \
go get -u github.com/kardianos/govendor; \
fi
gopathlinks:
# unfortunately the .cache directory has to be copied b/c of https://github.com/kardianos/govendor/issues/274
ifneq ($(GOPATH),$(TMPGOPATH))
if [ -d "$(PKGPATH)" ] && [ "$(readlink -- "$(PKGPATH)")" != "$(CURDIR)" ]; then \
rm $(PKGPATH); \
fi
if [ ! -L "$(PKGPATH)" ]; then \
mkdir -p $(shell dirname "$(PKGPATH)"); \
ln -s "$(CURDIR)" "$(PKGPATH)"; \
fi
for d in bin pkg; do \
if [ ! -L "$(TMPGOPATH)/$$d" ]; then \
ln -s $(GOPATH)/$$d $(TMPGOPATH)/$$d; \
fi; \
done
if [ ! -L "$(TMPGOPATH)/.cache" ] && [ -d "$(GOPATH)/.cache" ]; then \
cp -Rfpa $(GOPATH)/.cache $(TMPGOPATH)/.cache; \
fi
endif
PKGS=$(shell cd $(PKGPATH); GOPATH=$(TMPGOPATH) go list ./... | gawk '$$1 !~ /vendor\// {print $$1}')
CDIR=$(DESTDIR)/go/src/github.com/open-horizon/go-solidity/contracts
install:
@echo "Installing $(EXECUTABLE) and $(CLI_EXECUTABLE) in $(DESTDIR)/bin"
mkdir -p $(DESTDIR)/bin && \
cp $(EXECUTABLE) $(DESTDIR)/bin && \
cp $(CLI_EXECUTABLE) $(DESTDIR)/bin
# mkdir -p $(DESTDIR)/web && \
# cp $(DEFAULT_UI) $(DESTDIR)/web
cp -Rapv cli/samples $(DESTDIR)
mkdir -p $(CDIR) && \
cp -apv ./vendor/github.com/open-horizon/go-solidity/contracts/. $(CDIR)/
find $(CDIR)/ \( -name "Makefile" -or -iname ".git*" \) -exec rm {} \;
format:
@echo "Formatting all Golang source code with gofmt"
find . -name '*.go' -not -path './vendor/*' -exec gofmt -l -w {} \;
lint: gopathlinks
@echo "Checking source code for style issues and statically-determinable errors"
-golint ./... | grep -v "vendor/"
-cd $(PKGPATH) && \
GOPATH=$(TMPGOPATH) go vet $(shell find . -not -path './vendor/*' -iname '*.go' -print | xargs dirname | sort | uniq | xargs) 2>&1 | grep -vP "^exit.*"
pull: deps
# only unit tests
test: gopathlinks
@echo "Executing unit tests"
-@cd $(PKGPATH) && \
GOPATH=$(TMPGOPATH) go test -cover -tags=unit $(PKGS)
test-integration: gopathlinks
@echo "Executing integration tests"
-@cd $(PKGPATH) && \
GOPATH=$(TMPGOPATH) go test -cover -tags=integration $(PKGS)
test-ci: gopathlinks
@echo "Executing integration tests intended for CI systems with special configuration"
-@cd $(PKGPATH) && \
GOPATH=$(TMPGOPATH) go test -cover -tags=ci $(PKGS)
# N.B. this doesn't run ci tests, the ones that require CI system setup
check: deps lint test test-integration
# build sequence diagrams
diagrams:
java -jar $(plantuml_path)/plantuml.jar ./citizenscientist/diagrams/horizonSequenceDiagram.txt
java -jar $(plantuml_path)/plantuml.jar ./citizenscientist/diagrams/protocolSequenceDiagram.txt
java -jar $(plantuml_path)/plantuml.jar ./messaging/diagrams/senderEncryption.txt
java -jar $(plantuml_path)/plantuml.jar ./messaging/diagrams/receiverEncryption.txt
java -jar $(plantuml_path)/plantuml.jar ./basicprotocol/diagrams/protocolSequenceDiagram.txt
java -jar $(plantuml_path)/plantuml.jar ./basicprotocol/diagrams/horizonSequenceDiagram.txt
.PHONY: check clean deps format gopathlinks install lint mostlyclean pull test test-integration