-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
68 lines (51 loc) · 2.24 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
## the publicly-visible name of your binary; defaults to name of directory
NAME = $(notdir $(CURRENT_DIR))
## version, taken from Git tag (like v1.0.0) or hash
VER := $(shell (git describe --always --dirty 2>/dev/null || echo '<unknown>') | sed -e 's/^v//g' )
## fully-qualified path to this Makefile
MKFILE_PATH := $(realpath $(lastword $(MAKEFILE_LIST)))
## fully-qualified path to the current directory
CURRENT_DIR := $(patsubst %/,%,$(dir $(MKFILE_PATH)))
BIN = .godeps/bin
GO_MOD_SOURCES := go.mod go.sum
SOURCES := $(shell go list -f '{{range .GoFiles}}{{ $$.Dir }}/{{.}} {{end}}' ./... | sed -e 's@$(CURRENT_DIR)/@@g' )
TEST_SOURCES := $(shell go list -f '{{range .TestGoFiles}}{{ $$.Dir }}/{{.}} {{end}} {{range .XTestGoFiles}}{{ $$.Dir }}/{{.}} {{end}} ' ./... | sed -e 's@$(CURRENT_DIR)/@@g')
## targets after a | are order-only; the presence of the target is sufficient
## http://stackoverflow.com/questions/4248300/in-a-makefile-is-a-directory-name-a-phony-target-or-real-target
.PHONY: all
all: build
.PHONY: clean
clean:
git clean -f -Xd
$(BIN) stage:
@mkdir -p $@
$(BIN)/ginkgo: $(GO_MOD_SOURCES) | $(BIN)
go build -o $@ github.com/onsi/ginkgo/ginkgo
@touch $@
$(BIN)/mockery: $(GO_MOD_SOURCES) | $(BIN)
go build -o $@ github.com/vektra/mockery
@touch $@
## installs dev tools
.PHONY: devtools
devtools: $(BIN)/ginkgo $(BIN)/mockery
## run tests
stage/.tests_ran: $(GO_MOD_SOURCES) $(TEST_SOURCES) $(SOURCES) $(BIN)/ginkgo | stage
$(BIN)/ginkgo -r
@touch $@
.PHONY: test
test: stage/.tests_ran
.PHONY: watch-tests
watch-tests: $(GINKGO)
@$(GINKGO) watch -r
.PHONY: build
build: stage/nomad-watcher stage/nomad-tail
stage/nomad-watcher stage/nomad-tail: $(SOURCES) | test
go build -o $@ -ldflags '-X main.version=$(VER)' ./cmd/$(notdir $@)
.PHONY: linux
linux: stage/nomad-watcher-linux stage/nomad-tail-linux
stage/nomad-watcher-linux stage/nomad-tail-linux: $(SOURCES) | test
GOOS=linux GOARCH=amd64 go build -o $@ -ldflags '-X main.version=$(VER)' ./cmd/$(patsubst %-linux,%,$(notdir $@))
.PHONY: darwin
darwin: stage/nomad-watcher-darwin stage/nomad-tail-darwin
stage/nomad-watcher-darwin stage/nomad-tail-darwin: $(SOURCES) | test
GOOS=darwin GOARCH=amd64 go build -o $@ -ldflags '-X main.version=$(VER)' ./cmd/$(patsubst %-darwin,%,$(notdir $@))