-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
103 lines (78 loc) · 2.77 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
ifneq ($(wildcard ./.env),)
$(info using variables from .env file)
include ./.env
endif
GO ?=go
RSYNC ?=rsync
RSYNC_FLAGS ?=-rv --partial --progress
SERVER_PACKAGE :=./grinklers_server
SERVER_BINARY :=./grinklers_server/grinklers_server
CLIENT_PACKAGE :=./grinklers_client
CLIENT_BINARY :=./grinklers_client/grinklers_client
GO_TOP :=git.amikhalev.com/amikhalev/grinklers
GO_PACKAGES :=$(shell go list ./...)
GO_PACKAGE_PATHS :=$(subst $(GO_TOP),.,$(GO_PACKAGES))
GO_SOURCES :=$(shell find . -type f -name '*.go' -not -name '*_test.go')
GO_TESTS :=$(shell find . -type f -name '*_test.go')
$(info GO_PACKAGE_PATHS: $(GO_PACKAGE_PATHS))
STATIC_FILES :=config.example.json grinklers.service
TEST_TIMEOUT ?=10s
TEST_FLAGS ?=-timeout $(TEST_TIMEOUT)
COV_OUTPUTS :=$(addsuffix /coverage.out,$(GO_PACKAGE_PATHS))
COV_ALL :=./coverage.all.out
COV_HTML :=./coverage.html
DEPLOY_DIR :=./rpi_deploy
DEPLOY_BINARY :=$(DEPLOY_DIR)/grinklers
DEPLOY_FILES :=$(addprefix $(DEPLOY_DIR)/,$(STATIC_FILES))
DEPLOY_ENV ?=GOOS=linux GOARCH=arm GOARM=6
DEPLOY_HOST [email protected]
DEPLOY_PATH ?=/opt/sprinklers
CLEAN_FILES :=$(SERVER_BINARY) $(CLIENT_BINARY) $(DEPLOY_DIR) $(COV_OUTPUTS) $(COV_ALL) $(COV_HTML)
.PHONY: all
all: $(SERVER_BINARY) $(CLIENT_BINARY) vet test cover
.PHONY: clean
clean:
$(GO) clean -cache -testcache
rm -rf $(CLEAN_FILES)
$(SERVER_BINARY): $(GO_SOURCES)
$(GO) build -o $(SERVER_BINARY) $(SERVER_PACKAGE)
$(CLIENT_BINARY): $(GO_SOURCES)
$(GO) build -o $(CLIENT_BINARY) $(CLIENT_PACKAGE)
.PHONY: get-deps
get-deps: $(GO_SOURCES)
$(GO) get -t ./...
.PHONY: run
start: $(SERVER_BINARY)
$(SERVER_BINARY)
.PHONY: client
client: $(CLIENT_BINARY)
$(CLIENT_BINARY)
.PHONY: vet
vet: $(GO_SOURCES)
$(GO) vet ./...
.PHONY: test
test: $(GO_SOURCES) $(GO_TESTS)
$(GO) test $(TEST_FLAGS) ./...
$(COV_OUTPUTS): %: $(GO_SOURCES) $(GO_TESTS)
$(GO) test ./$(@D) $(TEST_FLAGS) -coverprofile=$@
@if [ ! -f $@ ]; then touch $@; fi
$(COV_ALL): $(COV_OUTPUTS)
@echo "generating $@"
@echo "mode: set" > $@
@for out in $^ ; do cat $$out | grep -v "mode: set" >> $@; done || true
$(COV_HTML): $(COV_ALL)
@echo "generating $@"
@$(GO) tool cover -html=$(COV_ALL) -o $(COV_HTML)
.PHONY: cover
cover: $(COV_HTML)
@echo "coverage generated. open file://$(realpath $<) in your web browser to view"
$(DEPLOY_DIR):
mkdir -p $(DEPLOY_DIR)
$(DEPLOY_BINARY): $(GO_SOURCES) $(DEPLOY_DIR)
$(DEPLOY_ENV) $(GO) build -o $(DEPLOY_BINARY) $(SERVER_PACKAGE)
$(DEPLOY_FILES): $(DEPLOY_DIR)/%: ./%
cp $< $@
.PHONY: deploy
deploy: $(DEPLOY_DIR) $(DEPLOY_BINARY) $(DEPLOY_FILES)
$(RSYNC) $(RSYNC_FLAGS) $(DEPLOY_DIR)/ $(DEPLOY_HOST):$(DEPLOY_PATH)/
@echo "deploy successfully completed"