This repository has been archived by the owner on Nov 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
112 lines (90 loc) · 2.53 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
BINARY=$(shell pwd | sed -e "s/.*\///")
GOARCH=amd64
UNAME=$(shell uname -s)
VERSION?=?
COMMIT=$(shell git rev-parse HEAD)
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
# Symlink into GOPATH
BUILD_DIR=${GOPATH}/src/${BINARY}
CURRENT_DIR=$(shell pwd)
BUILD_DIR_LINK=$(shell readlink ${BUILD_DIR})
BIN_DIR=${BUILD_DIR}/bin
SOURCEDIR=${BUILD_DIR}/src
VET_REPORT = ${BUILD_DIR}/vet.report
TEST_REPORT = ${BUILD_DIR}/tests.xml
# 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: deps clean test vet fmt linux darwin windows
build: deps clean vet
build:
ifeq ($(OS),Windows_NT)
make windows
else ifeq ($(UNAME),Darwin)
make darwin
else ifeq ($(UNAME),Linux)
make linux
endif
install-windows:
@echo 'Not implemented'
install-darwin:
@echo 'Not implemented'
install-linux:
sudo cp ${BIN_DIR}/${BINARY}-linux-${GOARCH} /usr/local/bin/${BINARY}
install:
ifeq ($(OS),Windows_NT)
make install-windows
else ifeq ($(UNAME),Darwin)
make install-darwin
else ifeq ($(UNAME),Linux)
make install-linux
endif
run: deps
cd ${BUILD_DIR}; \
go run -race -x ${SOURCEDIR} -u $(shell whoami)
deps: vendor
vendor: link
cd ${BUILD_DIR}; \
dep ensure
touch $@
link:
if [ "${BUILD_DIR_LINK}" != "${CURRENT_DIR}" ] && [ "${BUILD_DIR}" != "${CURRENT_DIR}" ]; then \
echo "Fixing symlinks for build"; \
rm -f ${BUILD_DIR}; \
ln -s ${CURRENT_DIR} ${BUILD_DIR}; \
fi
linux:
cd ${SOURCEDIR}; \
GOOS=linux GOARCH=${GOARCH} go build ${LDFLAGS} -o ${BIN_DIR}/${BINARY}-linux-${GOARCH} .
darwin:
cd ${SOURCEDIR}; \
GOOS=darwin GOARCH=${GOARCH} go build ${LDFLAGS} -o ${BIN_DIR}/${BINARY}-darwin-${GOARCH} .
windows:
cd ${SOURCEDIR}; \
GOOS=windows GOARCH=${GOARCH} go build ${LDFLAGS} -o ${BIN_DIR}/${BINARY}-windows-${GOARCH}.exe .
# test:
# export $$(cat ./.env.test | xargs); \
# cd ${BUILD_DIR}; \
# cd $(shell find . -type d -name "go2xunit"); \
# go build;
#
# export $$(cat ./.env.test | xargs); \
# cd ${SOURCEDIR}; \
# go test -v ./... 2>&1 | ${BUILD_DIR}/$(shell find . -type f -name "go2xunit") -output ${TEST_REPORT} ; \
# cd - >/dev/null
test:
export $$(cat ./.env.test | xargs); \
cd ${SOURCEDIR}; \
go test -race -v ./...
vet:
cd ${SOURCEDIR}; \
go vet ./... > ${VET_REPORT} 2>&1
fmt:
cd ${SOURCEDIR}; \
go fmt $$(go list ./... | grep -v /vendor/)
clean:
go clean
-rm -f ${TEST_REPORT}
-rm -f ${VET_REPORT}
-rm -f ${BIN_DIR}/${BINARY}-*
.PHONY: link linux darwin windows test vet fmt clean