-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
92 lines (78 loc) · 3.18 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
# Borrowed from:
# https://github.com/silven/go-example/blob/master/Makefile
# https://vic.demuzere.be/articles/golang-makefile-crosscompile/
BINARY = petrockutil
VET_REPORT = vet.report
TEST_REPORT = tests.xml
GOARCH_1 = amd64
GOARCH_2 = 386
GOARCH_3 = arm
VERSION=$(shell sed -n 4p version.go | cut -d' ' -f4)
COMMIT=$(shell git rev-parse HEAD)
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
# Symlink into GOPATH
GITHUB_USERNAME=petrockblog
BUILD_DIR=${GOPATH}/src/github.com/${GITHUB_USERNAME}/${BINARY}
CURRENT_DIR=$(shell pwd)
BUILD_DIR_LINK=$(shell readlink ${BUILD_DIR})
# 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}"
# Build the project
all: clean linux darwin windows
link:
BUILD_DIR=${BUILD_DIR}; \
BUILD_DIR_LINK=${BUILD_DIR_LINK}; \
CURRENT_DIR=${CURRENT_DIR}; \
if [ "$${BUILD_DIR_LINK}" != "$${CURRENT_DIR}" ]; then \
echo "Fixing symlinks for build"; \
rm -f $${BUILD_DIR}; \
ln -s $${CURRENT_DIR} $${BUILD_DIR}; \
fi
linux:
cd ${BUILD_DIR}; \
GOOS=linux GOARCH=${GOARCH_1} go build ${LDFLAGS} -o ${BINARY}-linux-${GOARCH_1} . ; \
zip ${BINARY}-linux-${GOARCH_1}.zip ${BINARY}-linux-${GOARCH_1} README.md LICENSE; \
rm ${BINARY}-linux-${GOARCH_1}; \
GOOS=linux GOARCH=${GOARCH_2} go build ${LDFLAGS} -o ${BINARY}-linux-${GOARCH_2} . ; \
zip ${BINARY}-linux-${GOARCH_2}.zip ${BINARY}-linux-${GOARCH_2} README.md LICENSE; \
rm ${BINARY}-linux-${GOARCH_2}; \
GOOS=linux GOARCH=${GOARCH_3} GOARM=5 go build ${LDFLAGS} -o ${BINARY}-linux-${GOARCH_3} . ; \
zip ${BINARY}-linux-${GOARCH_3}.zip ${BINARY}-linux-${GOARCH_3} README.md LICENSE; \
rm ${BINARY}-linux-${GOARCH_3}; \
cd - >/dev/null
darwin:
cd ${BUILD_DIR}; \
GOOS=darwin GOARCH=${GOARCH_1} go build ${LDFLAGS} -o ${BINARY}-darwin-${GOARCH_1} . ; \
zip ${BINARY}-darwin-${GOARCH_1}.zip ${BINARY}-darwin-${GOARCH_1} README.md LICENSE; \
rm ${BINARY}-darwin-${GOARCH_1}; \
GOOS=darwin GOARCH=${GOARCH_2} go build ${LDFLAGS} -o ${BINARY}-darwin-${GOARCH_2} . ; \
zip ${BINARY}-darwin-${GOARCH_2}.zip ${BINARY}-darwin-${GOARCH_2} README.md LICENSE; \
rm ${BINARY}-darwin-${GOARCH_2}; \
cd - >/dev/null
windows:
cd ${BUILD_DIR}; \
GOOS=windows GOARCH=${GOARCH_1} go build ${LDFLAGS} -o ${BINARY}-windows-${GOARCH_1}.exe . ; \
zip ${BINARY}-windows-${GOARCH_1}.zip ${BINARY}-windows-${GOARCH_1}.exe README.md LICENSE; \
rm ${BINARY}-windows-${GOARCH_1}.exe; \
GOOS=windows GOARCH=${GOARCH_2} go build ${LDFLAGS} -o ${BINARY}-windows-${GOARCH_2}.exe . ; \
zip ${BINARY}-windows-${GOARCH_2}.zip ${BINARY}-windows-${GOARCH_2}.exe README.md LICENSE; \
rm ${BINARY}-windows-${GOARCH_2}.exe; \
cd - >/dev/null
test:
if ! hash go2xunit 2>/dev/null; then go install github.com/tebeka/go2xunit; fi
cd ${BUILD_DIR}; \
godep go test -v ./... 2>&1 | go2xunit -output ${TEST_REPORT} ; \
cd - >/dev/null
vet:
-cd ${BUILD_DIR}; \
godep go vet ./... > ${VET_REPORT} 2>&1 ; \
cd - >/dev/null
fmt:
cd ${BUILD_DIR}; \
go fmt $$(go list ./... | grep -v /vendor/) ; \
cd - >/dev/null
clean:
-rm -f ${TEST_REPORT}
-rm -f ${VET_REPORT}
-rm -f ${BINARY}-*
.PHONY: link linux darwin windows test vet fmt clean