-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
115 lines (94 loc) · 2.55 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
104
105
106
107
108
109
110
111
112
113
114
115
VERBOSE_ORIGINS := "command line" "environment"
ifdef V
ifeq ($(filter $(VERBOSE_ORIGINS),$(origin V)),)
BUILD_VERBOSE := $(V)
endif
endif
ifndef BUILD_VERBOSE
BUILD_VERBOSE := 0
endif
ifeq ($(BUILD_VERBOSE),1)
Q :=
else
Q := @
endif
PHONY += all
CURDIR := $(shell pwd)
BUILD_DIR ?= $(CURDIR)/build
GOBIN_DIR := $(BUILD_DIR)/bin
GOBIN_EXAMPLE_DIR := $(BUILD_DIR)/bin/examples
HOST_DIR := $(BUILD_DIR)/host
HOSTBIN_DIR := $(HOST_DIR)/bin
GOTOOLSBIN_DIR := $(HOSTBIN_DIR)
GOTOOLS_DIR := $(CURDIR)/tools
TMP_DIR := $(BUILD_DIR)/tmp
DIRS := \
$(GOBIN_DIR) \
$(HOST_DIR) \
$(HOSTBIN_DIR) \
$(TMP_DIR) \
$(GOBIN_EXAMPLE_DIR)
HOST_OS := $(shell uname -s)
REV ?= $(shell git rev-parse --short HEAD 2> /dev/null)
GOPATH ?= $(shell go env GOPATH)
export PATH:=$(GOTOOLS_DIR):$(HOSTBIN_DIR):$(PATH)
export REV
define find-subdir
$(shell find $(1) -maxdepth 1 -mindepth 1 -type d -o -type l)
endef
APPS := $(sort $(notdir $(call find-subdir,cmd)))
PHONY += $(APPS)
all: $(APPS) examples
$(DIRS) :
$(Q)mkdir -p $@
EXAMPLES := $(sort $(notdir $(call find-subdir,examples)))
.SECONDEXPANSION:
$(EXAMPLES): $(addprefix $(GOBIN_EXAMPLE_DIR)/,$$@)
.PHONY: examples
examples: $(EXAMPLES)
$(GOBIN_EXAMPLE_DIR)/%: $(GOBIN_DIR) FORCE
$(Q)go build -o $@ ./examples/$(notdir $@)
@echo "Done building."
@echo "Run \"$(subst $(CURDIR),.,$@)\" to launch $(notdir $@)."
.SECONDEXPANSION:
$(APPS): $(addprefix $(GOBIN_DIR)/,$$@)
$(GOBIN_DIR)/%: $(GOBIN_DIR) FORCE
$(Q)go build -o $@ ./cmd/$(notdir $@)
@echo "Done building."
@echo "Run \"$(subst $(CURDIR),.,$@)\" to launch $(notdir $@)."
CODEGEN_DEPS := \
# $(GOTOOLS_DIR)/abigen
.PHONY: gen
gen: $(CODEGEN_DEPS)
$(Q)go generate -x ./...
.PHONY: test
test:
$(Q)go test -v ./...
.PHONY: clean
clean:
$(Q)rm -fr $(GOBIN_DIR) $(HOST_DIR)
.PHONY: help
help:
@echo 'Generic targets:'
@echo ' all - Build all targets marked with [*]'
@for app in $(APPS); do \
printf "* %s\n" $$app; done
@echo '* examples'
@echo ''
@echo 'Code generation targets:'
@echo ' gen - Generate Go code from various sources'
@echo ''
@echo 'Examples targets:'
@echo ' examples - Build all examples'
@echo ''
@echo 'Test targets:'
@echo ' test - Run all tests'
@echo ''
@echo 'Cleaning targets:'
@echo ' clean - Remove built executables'
@echo ''
@echo 'Execute "make" or "make all" to build all targets marked with [*] '
@echo 'For further info see the ./README.md file'
.PHONY: $(PHONY)
.PHONY: FORCE
FORCE: