-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathMakefile
74 lines (67 loc) · 1.99 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
# 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
#
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOINSTALL=$(GOCMD) install
GOTEST=$(GOCMD) test
GOLINT=golint
GODEP=$(GOTEST) -i
GOFMT=gofmt -w
BINARYNAME=gotgbot
# Package lists
TOPLEVEL_PKG := .
# INT_LIST := tgtypes #<-- Interface directories
# IMPL_LIST := tgtypes #<-- Implementation directories
CMD_LIST := example/manualexample example/echoexample example/simpleexample #<-- Command directories
# List building
ALL_LIST = $(TOPLEVEL_PKG) $(CMD_LIST) # $(INT_LIST) $(IMPL_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)
LINT_LIST = $(foreach int, $(ALL_LIST), $(int)_lint)
FMT_TEST = $(foreach int, $(ALL_LIST), $(int)_fmt)
# All are .PHONY for now because dependencyness is hard
.PHONY: $(CLEAN_LIST) $(TEST_LIST) $(FMT_LIST) $(LINT_LIST) $(INSTALL_LIST) $(BUILD_LIST) $(IREF_LIST)
all: build
build: $(BUILD_LIST)
clean: $(CLEAN_LIST)
rm $(BINARYNAME)
install: $(INSTALL_LIST)
test: $(TEST_LIST)
lint: $(LINT_LIST)
iref: $(IREF_LIST)
fmt: $(FMT_TEST)
run: build
./$(BINARYNAME)
$(BUILD_LIST): %_build: %_fmt %_lint %_iref %_test
$(GOBUILD) -o $(TOPLEVEL_PKG)/$(BINARYNAME) $(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)/$*
$(LINT_LIST): %_lint:
$(GOLINT) $(TOPLEVEL_PKG)/$*
$(FMT_TEST): %_fmt:
$(GOFMT) ./$*