-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile.single
More file actions
125 lines (97 loc) · 3.29 KB
/
makefile.single
File metadata and controls
125 lines (97 loc) · 3.29 KB
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
# project name
PROJECT_NAME=xxxx
# main version
VERSION ?= $(shell git describe --tags --always --dirty)
# git commit Hash
COMMIT_HASH ?= $(shell git show -s --format=%H)
# build at
BUILD_TIME ?= $(shell date +"%F %T")
# go source file list
GOFILES := $(shell find . ! -path "./vendor/*" -name "*.go")
# build environment
BUILD_ENV :=
# unit test environment
TEST_ENV :=
# benchmark test environment
BENCHMARK_ENV :=
# operating system
GOOSES := linux windows darwin plan9
# compilation architecture
GOARCHES := 386 amd64
# output folder
BUILD_FOLDER := target/debug
# output folder
RELEASE_FOLDER := target/release
# build options
BUILD_OPTS := -trimpath -ldflags "-s -w -X 'main.Version=${VERSION}' -X 'main.CommitHash=${COMMIT_HASH}' -X 'main.BuildTime=${BUILD_TIME}'"
# release options
RELEASE_OPTS := -trimpath -ldflags "-s -w -X 'main.Version=${VERSION}' -X 'main.CommitHash=${COMMIT_HASH}' -X 'main.BuildTime=${BUILD_TIME}'"
# unit test options
TEST_OPTS := -v
# benchmark test options
BENCHMARK_OPTS := -cpu 1,2,3,4,5,6,7,8
# sonar report output folder
REPORT_FOLDER := sonar
# sonar report file list
TEST_REPORT := ${REPORT_FOLDER}/test.report
COVER_REPORT := ${REPORT_FOLDER}/cover.report
GOLANGCI_LINT_REPORT := ${REPORT_FOLDER}/golangci-lint.xml
GOLINT_REPORT := ${REPORT_FOLDER}/golint.report
GO_VET_REPORT := ${REPORT_FOLDER}/go_vet.report
SONAR_SERVICE=http://xxx.xxx.xxx.xxx:9000
SONAR_TOKEN=
.PHONY: build format test benchmark sonar release clean
.DEFAULT_GOAL := build
build: ${BUILD_FOLDER}/${PROJECT_NAME}
# build target executable program
${BUILD_FOLDER}/${PROJECT_NAME}: ${GOFILES}
${BUILD_ENV} go build ${BUILD_OPTS} -o $@
# format go code
format:
@for f in ${GOFILES} ; do \
gofmt -w $${f}; \
done
# unit test
test:
${TEST_ENV} go test ${TEST_OPTS} ./...
# benchmark test
benchmark:
${BENCHMARK_ENV} go test -bench . -run ^$$ ${BENCHMARK_OPTS} ./...
# sonar
sonar:
mkdir -p ${REPORT_FOLDER}
go test -json ./... > ${TEST_REPORT}
go test -coverprofile=${COVER_REPORT} ./...
golangci-lint run --out-format checkstyle --issues-exit-code 0 ./... > ${GOLANGCI_LINT_REPORT}
# golint ./... > ${GOLINT_REPORT}
go vet ./... > ${GO_VET_REPORT} 2>&1
# sonar-scanner -Dsonar.projectKey=${PROJECT_NAME} \
-Dsonar.sources=. \
-Dsonar.host.url=${SONAR_SERVICE} \
# -Dsonar.login=${SONAR_TOKEN} \
-Dsonar.token=${SONAR_TOKEN} \
-Dproject.settings=target/sonar-project.properties
# cross compiling
release:
@for os in ${GOOSES} ; do \
for arch in ${GOARCHES} ; do \
if [ "$${os}" = "windows" ] ;then \
GOOS=$${os} GOARCH=$${arch} \
${BUILD_ENV} go build ${RELEASE_OPTS} -o ${RELEASE_FOLDER}/$${os}_$${arch}/${PROJECT_NAME}.exe ; \
else \
GOOS=$${os} GOARCH=$${arch} \
${BUILD_ENV} go build ${RELEASE_OPTS} -o ${RELEASE_FOLDER}/$${os}_$${arch}/${PROJECT_NAME} ; \
fi \
done \
done
# clean target executable program and sonar report
clean:
-rm -rf $(BUILD_FOLDER)/*
-rm -rf $(RELEASE_FOLDER)/*
-rm -f ${TEST_REPORT}
-rm -f ${COVER_REPORT}
-rm -f ${GOLANGCI_LINT_REPORT}
-rm -f ${GOLINT_REPORT}
-rm -f ${GO_VET_REPORT}
-go clean
-go clean -cache