/
default.mk
64 lines (51 loc) · 1.61 KB
/
default.mk
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
SHELL := /usr/bin/env bash
GOPATH := $(shell go env GOPATH)
GO_SOURCE_FILES = $(shell find . -name "*.go")
SUBREPO := $(shell cat .subrepo)
LIBNAME := $(shell cat .subrepo | cut -d'/' -f2)
GOX_LDFLAGS := "-X main.version=${TRAVIS_TAG}"
EXES := $(shell find dist -name '$(LIBNAME)-*')
UPX_EXES = $(patsubst dist/$(LIBNAME)-%,dist_compressed/$(LIBNAME)-%,$(EXES))
IN_GOPATH := $(shell [[ "$$(pwd)" == ${GOPATH}/* ]] && echo 1 || echo 0)
ifeq ($(IN_GOPATH), 0)
.deps: .linked
endif
ifneq (,$(wildcard ./cli))
default: .dist
endif
default: .tested
.PHONY: default
.dist: .deps
mkdir -p dist
gox -ldflags $(GOX_LDFLAGS) -output "dist/$(LIBNAME)-{{.OS}}-{{.Arch}}" -rebuild ./cli
touch $@
dist/$(LIBNAME)-%: .dist
.dist-compressed: $(UPX_EXES)
touch $@
dist_compressed/$(LIBNAME)-%: dist/$(LIBNAME)-%
mkdir -p dist_compressed
# requires upx in PATH to compress supported binaries
# may produce an error ARCH not supported
-upx $< -o $@
# Test the integrity
if [ -f "$@" ]; then upx -t $@ || rm $@; fi
# Symlink this dir to GOPATH
.linked:
mkdir -p $$(dirname ${GOPATH}/src/github.com/${SUBREPO})
rm -rf ${GOPATH}/src/github.com/${SUBREPO}
ln -fs ${CURDIR} ${GOPATH}/src/github.com/${SUBREPO}
touch $@
# Remove symlink
unlink:
rm -rf .linked ${GOPATH}/src/github.com/${SUBREPO}
# Use env variable ARGS to pass arguments to 'go test'
# (for running only a specific test or using verbose mode)
# Example: ARGS='-v -run TestCucumberExpression' make test
.tested: .deps $(GO_SOURCE_FILES)
go test ${ARGS}
touch $@
clean: clean-go
.PHONY: clean
clean-go:
rm -rf .deps .linked .tested dist/* dist_compressed
.PHONY: clean-go