-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
99 lines (78 loc) · 2.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
OS=
ARCH=
NAME=ncp
BINDIR=bin
PROFIX=
COMMIT=$(shell git rev-parse HEAD)
VERSION=$(shell git describe --tags || echo "unknown version")
BUILDTIME=$(shell date +%FT%T%z)
LD_FLAGS='\
-X "sb.im/ncp/constant.Commit=$(COMMIT)" \
-X "sb.im/ncp/constant.Version=$(VERSION)" \
-X "sb.im/ncp/constant.BuildTime=$(BUILDTIME)" \
'
GOBUILD=CGO_ENABLED=0 go build -trimpath -ldflags $(LD_FLAGS)
PLATFORM_LIST = \
darwin-amd64 \
linux-386 \
linux-amd64 \
linux-armv7 \
linux-armv8 \
freebsd-amd64
WINDOWS_ARCH_LIST = \
windows-386 \
windows-amd64
all: build
build:
GOOS=$(OS) GOARCH=$(ARCH) $(GOBUILD)
run:
go run main.go -debug
install:
install -Dm755 ncp -t ${PROFIX}/usr/bin/
install -Dm644 conf/ncp.service -t ${PROFIX}/lib/systemd/system/
install -Dm644 conf/ncp@.service -t ${PROFIX}/lib/systemd/system/
install -Dm644 conf/config-dist.yml -t ${PROFIX}/etc/ncp/
# Need Container Network Interface
# Linux tc (Traffic Control)
#
# Manual test
# docker run --cap-add "NET_ADMIN" -it -v $(pwd):/ncp golang:1.13.1-buster /bin/bash
# apt-get update -y && apt-get install -y mosquitto-clients
# cd /ncp
#
# docker run eclipse-mosquitto:1.6
#
# # YOU Broker IP
# MQTT=172.17.0.3:1883 ./test.network
test-detach:
CGO_ENABLED=0 go test ./tests/network -c -o test.network -v
# Need mosquitto && mosquitto_pub
test-integration:
go test ./tests/integration
test:
go test ./ncpio ./util ./history ./cache -cover
# \(statements\)(?:\s+)?(\d+(?:\.\d+)?%)
# https://stackoverflow.com/questions/61246686/go-coverage-over-multiple-package-and-gitlab-coverage-badge
cover:
go test ./ncpio ./util ./history ./cache -coverprofile=coverage.txt -covermode=atomic
go tool cover -func coverage.txt
darwin-amd64:
GOARCH=amd64 GOOS=darwin $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
linux-386:
GOARCH=386 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
linux-amd64:
GOARCH=amd64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
linux-armv7:
GOARCH=arm GOOS=linux GOARM=7 $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
linux-armv8:
GOARCH=arm64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
freebsd-amd64:
GOARCH=amd64 GOOS=freebsd $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
windows-386:
GOARCH=386 GOOS=windows $(GOBUILD) -o $(BINDIR)/$(NAME)-$@.exe
windows-amd64:
GOARCH=amd64 GOOS=windows $(GOBUILD) -o $(BINDIR)/$(NAME)-$@.exe
releases: $(PLATFORM_LIST) $(WINDOWS_ARCH_LIST)
clean:
go clean
rm $(BINDIR)/*