-
Notifications
You must be signed in to change notification settings - Fork 1
/
GNUmakefile
95 lines (80 loc) · 1.98 KB
/
GNUmakefile
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
SHELL = bash
PROJECT_ROOT := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
OS := $(shell uname | cut -d- -f1)
PREFIX := " --"
ifeq (Linux,$(OS))
ALL_TARGETS += linux_amd64 \
linux_386
endif
ifeq (Darwin,$(OS))
ALL_TARGETS += darwin_amd64
endif
GOTEST_CMD = go test
GOTEST_FILES ?= "./..."
##
## Darwin
##
pkg/darwin_amd64/openstate: $(SOURCE_FILES)
@echo "$(PREFIX) Building $@"
@CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 \
go build \
-trimpath \
-o "$@"
##
## Linux
##
pkg/linux_amd64/openstate: $(SOURCE_FILES)
@echo "$(PREFIX) Building $@"
@CGO_ENABLED=1 GOOS=linux GOARCH=amd64 \
go build \
-trimpath \
-o "$@"
pkg/linux_386/openstate: $(SOURCE_FILES)
@echo "$(PREFIX) Building $@"
@CGO_ENABLED=1 GOOS=linux GOARCH=386 \
go build \
-trimpath \
-o "$@"
.PHONY: dev
dev: GOOS=$(shell go env GOOS)
dev: GOARCH=$(shell go env GOARCH)
dev: GOPATH=$(shell go env GOPATH)
dev: DEV_TARGET=pkg/$(GOOS)_$(GOARCH)/openstate
dev:
@echo "$(PREFIX) Removing old development build"
@rm -f $(PROJECT_ROOT)/$(DEV_TARGET)
@rm -f $(PROJECT_ROOT)/bin/openstate
@rm -f $(GOPATH)/bin/openstate
@$(MAKE) --no-print-directory $(DEV_TARGET)
@mkdir -p $(PROJECT_ROOT)/bin
@mkdir -p $(GOPATH)/bin
@cp $(PROJECT_ROOT)/$(DEV_TARGET) $(PROJECT_ROOT)/bin/
@cp $(PROJECT_ROOT)/$(DEV_TARGET) $(GOPATH)/bin
.PHONY: all
all: clean $(foreach t,$(ALL_TARGETS),pkg/$(t)/openstate)
@echo "$(PREFIX) Results:"
@tree $(PROJECT_ROOT)/pkg
.PHONY: clean
clean: GOPATH=$(shell go env GOPATH)
clean:
@echo "$(PREFIX) Cleaning builds"
@rm -rf "$(PROJECT_ROOT)/bin/"
@rm -rf "$(PROJECT_ROOT)/pkg/"
@rm -f "$(GOPATH)/bin/openstate"
.PHONY: tidy
tidy:
@echo "$(PREFIX) Tidying module"
@go mod tidy
.PHONY: vendor
vendor: tidy
@echo "$(PREFIX) Vendoring deps"
@go mod vendor
.PHONY: test
test:
@if [ ! $(SKIP_OPENSTATE_TESTS) ]; then \
make test-openstate; \
fi
.PHONY: test-openstate
test-openstate: dev
@echo "$(PREFIX) Running OpenSates tests:"
$(GOTEST_CMD) -timeout=15m $(GOTEST_FILES)