This repository has been archived by the owner on Dec 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathMakefile
91 lines (62 loc) · 2.23 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
SHELL = bash
# Environment
GIT_BRANCH = $(or $(CI_BUILD_REF_NAME) ,`git rev-parse --abbrev-ref HEAD 2>/dev/null`)
GIT_COMMIT = $(or $(CI_BUILD_REF), `git rev-parse HEAD 2>/dev/null`)
GIT_TAG = $(shell git describe --abbrev=0 --tags 2>/dev/null)
BUILD_DATE = $(or $(CI_BUILD_DATE), `date -u +%Y-%m-%dT%H:%M:%SZ`)
ifeq ($(GIT_BRANCH), $(GIT_TAG))
TTN_VERSION = $(GIT_TAG)
TAGS += prod
else
TTN_VERSION = $(GIT_TAG)-dev
TAGS += dev
endif
# All
.PHONY: all deps dev-deps test cover-clean cover-deps cover coveralls fmt vet build dev link docs clean docker
all: deps build
# Deps
deps:
go mod download
dev-deps: deps
@command -v forego > /dev/null || go get github.com/ddollar/forego
# Go Test
GO_FILES = $(shell find . -name "*.go" | grep -vE ".git|.env|vendor")
test: $(GO_FILES)
go test -v ./...
GO_COVER_FILE ?= coverage.out
cover-clean:
rm -f $(GO_COVER_FILE)
cover-deps:
@command -v goveralls > /dev/null || go get github.com/mattn/goveralls
cover:
go test -cover -coverprofile=$(GO_COVER_FILE) ./...
coveralls: cover-deps $(GO_COVER_FILE)
goveralls -coverprofile=$(GO_COVER_FILE) -service=travis-ci -repotoken $$COVERALLS_TOKEN
fmt:
go fmt ./...
vet:
go vet ./...
# Go Build
RELEASE_DIR ?= release
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
GOEXE = $(shell GOOS=$(GOOS) GOARCH=$(GOARCH) go env GOEXE)
CGO_ENABLED ?= 0
splitfilename = $(subst ., ,$(subst -, ,$(subst $(RELEASE_DIR)/,,$1)))
GOOSfromfilename = $(word 4, $(call splitfilename, $1))
GOARCHfromfilename = $(word 5, $(call splitfilename, $1))
LDFLAGS = -ldflags "-w -X main.gitBranch=${GIT_BRANCH} -X main.gitCommit=${GIT_COMMIT} -X main.buildDate=${BUILD_DATE}"
GOBUILD = CGO_ENABLED=$(CGO_ENABLED) GOOS=$(call GOOSfromfilename, $@) GOARCH=$(call GOARCHfromfilename, $@) go build ${LDFLAGS} -tags "${TAGS}" -o "$@"
build: $(RELEASE_DIR)/gateway-connector-bridge-$(GOOS)-$(GOARCH)$(GOEXE)
$(RELEASE_DIR)/gateway-connector-bridge-%: $(GO_FILES)
$(GOBUILD) .
install:
go install -v
# Clean
clean:
[ -d $(RELEASE_DIR) ] && rm -rf $(RELEASE_DIR) || [ ! -d $(RELEASE_DIR) ]
# Docker
docker: GOOS=linux
docker: GOARCH=amd64
docker: $(RELEASE_DIR)/gateway-connector-bridge-linux-amd64
docker build -t thethingsnetwork/gateway-connector-bridge -f Dockerfile .