/
Makefile
91 lines (82 loc) · 2.91 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
# Makefile for a go project
#
# Author: Jon Eisen
# site: joneisen.me
#
# Targets:
# all: Builds the code
# build: Builds the code
# fmt: Formats the source files
# clean: cleans the code
# install: Installs the code to the GOPATH
# iref: Installs referenced projects
# test: Runs the tests
#
# Blog post on it: http://joneisen.me/post/25503842796
#
FLAGS=GOARCH=386 GOOS=linux
GITID=$(shell git rev-parse --short HEAD)
SSH=ssh -o StrictHostKeyChecking=no root@edison.local.
SCP=scp -o StrictHostKeyChecking=no
# Go parameters
GOCMD=$(FLAGS) go
GOBUILD=$(GOCMD) build -ldflags "-X main.Version='$(GITID)'"
GOCLEAN=$(GOCMD) clean
GOINSTALL=$(GOCMD) install
GOTEST=go test -cover
GODEP=$(GOCMD) test -i
GOFMT=gofmt -w
# Package lists
TOPLEVEL_PKG := github.com/ssoudan/edisonIsThePilot
INT_LIST := #<-- Interface directories
IMPL_LIST := conf control alarm dashboard pilot gps \
steering stepper drivers/pwm drivers/mcp4725 drivers/sincos \
drivers/gpio drivers/motor tracer infrastructure/types infrastructure/logger \
infrastructure/pid #<-- Implementation directories
CMD_LIST := cmd/edisonIsThePilot cmd/webserver cmd/mario cmd/ap100Control \
cmd/systemCalibration cmd/motorControl cmd/ledControl cmd/motorCalibration \
cmd/alarmControl #<-- Command directories
# List building
ALL_LIST = $(INT_LIST) $(IMPL_LIST) $(CMD_LIST)
BUILD_LIST = $(foreach int, $(ALL_LIST), $(int)_build)
CLEAN_LIST = $(foreach int, $(ALL_LIST), $(int)_clean)
INSTALL_LIST = $(foreach int, $(ALL_LIST), $(int)_install)
IREF_LIST = $(foreach int, $(ALL_LIST), $(int)_iref)
TEST_LIST = $(foreach int, $(ALL_LIST), $(int)_test)
FMT_LIST = $(foreach int, $(ALL_LIST), $(int)_fmt)
# All are .PHONY for now because dependencyness is hard
.PHONY: $(CLEAN_LIST) $(TEST_LIST) $(FMT_LIST) $(INSTALL_LIST) $(BUILD_LIST) $(IREF_LIST) ui
all: build
lint:
golint ./...
ui:
cd ui ; npm install ; npm run bundle
build: lint $(BUILD_LIST) ui
clean: $(CLEAN_LIST)
rm -f cmd/webserver/*.svg cmd/webserver/*.html cmd/webserver/*.js cmd/webserver/*.log
rm -f cmd/webserver/*.ttf cmd/webserver/*.woff* cmd/webserver/*.eot cmd/webserver/webserver
rm -f ui/dist/*
install: $(INSTALL_LIST)
test: $(TEST_LIST)
iref: $(IREF_LIST)
fmt: $(FMT_LIST)
deploy: build test ui
$(SSH) systemctl stop edisonIsThePilot
sleep 3
$(SCP) mario edisonIsThePilot motorControl systemCalibration alarmControl ledControl motorCalibration edisonIsThePilot.service edisonIsThePilot.properties ui/dist/* root@edison.local.:
$(SSH) cp edisonIsThePilot.service /lib/systemd/system
$(SSH) cp edisonIsThePilot.properties /etc/
$(SSH) systemctl daemon-reload
$(SSH) systemctl start edisonIsThePilot
$(BUILD_LIST): %_build: %_fmt %_iref
$(GOBUILD) $(TOPLEVEL_PKG)/$*
$(CLEAN_LIST): %_clean:
$(GOCLEAN) $(TOPLEVEL_PKG)/$*
$(INSTALL_LIST): %_install:
$(GOINSTALL) $(TOPLEVEL_PKG)/$*
$(IREF_LIST): %_iref:
$(GODEP) $(TOPLEVEL_PKG)/$*
$(TEST_LIST): %_test:
$(GOTEST) $(TOPLEVEL_PKG)/$*
$(FMT_TEST): %_fmt:
$(GOFMT) ./$*