-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
174 lines (133 loc) · 3.95 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#-------------------------------------------------------------------------------
# Copyright (C) 2019- Cursor Insight
#
# All rights reserved.
#-------------------------------------------------------------------------------
# Common directories and paths
TOP_DIR := $(dir $(firstword $(MAKEFILE_LIST)))
ABS_DIR := $(abspath $(TOP_DIR))
# Specify default target
.PHONY: default
default:
# Check for and set up required tools
define set-up-tools-template
$(1) := $$(shell which $(2))
ifeq "$$(strip $$($(1)))" ""
$(1) := $(2)
endif
$$($(1)):
@echo Please install \`$$@\' manually!
@exit 1
endef
# Set up necessary tools
$(eval $(call set-up-tools-template,ELVIS,elvis))
$(eval $(call set-up-tools-template,ERL,erl))
$(eval $(call set-up-tools-template,GIT,git))
$(eval $(call set-up-tools-template,GREP,grep))
$(eval $(call set-up-tools-template,MKDIR,mkdir))
$(eval $(call set-up-tools-template,REBAR,rebar3))
$(eval $(call set-up-tools-template,SONAR_SCANNER,sonar-scanner))
$(eval $(call set-up-tools-template,TEE,tee))
# Project version
ifneq (,$(wildcard .git))
PROJECT_VERSION := $(shell $(GIT) describe --always --dirty --broken --long --tags)
else
# There is no .git directory, so we cannot call Git to calculate the project
# version.
PROJECT_VERSION := no-project-version
endif
# Common build directory
BUILD_DIR := $(TOP_DIR)/_build
# Specific Erlang flags that is compatible with this project
BEAM_FLAGS := ERL_FLAGS="$(ERL_FLAGS)"
ELVIS_FLAGS := $(ELVIS_FLAGS) -c $(TOP_DIR)/elvis.config --output-format parsable
# Necessary directories
TEST_LOGS_DIR := $(BUILD_DIR)/test/logs
# Cover files
COVER_DIR := $(BUILD_DIR)/test/cover
COVER_FILES := $(COVER_DIR)/eunit.coverdata $(COVER_DIR)/ct.coverdata
# Default targets
.PHONY: all
all: test
.PHONY: test
test: docs compile xref dialyzer eunit ct cover elvis-check
.PHONY: everything
everything: mrproper test
$(TEST_LOGS_DIR):
@mkdir -p $(TEST_LOGS_DIR)
#-------------------------------------------------------------------------------
# Helpers
#-------------------------------------------------------------------------------
# Copied from erlang.mk's `core.mk`
define newline
endef
# Copied from erlang.mk's `core.mk`
define escape_dquotes
$(subst ",\",$1)
endef
# Copied from erlang.mk's `core.mk`
define erlang
$(ERL) $2 -eval "$(subst $(newline),,$(call escape_dquotes,$1))" -- erlang.mk
endef
# Copied from erlang.mk's `cover.mk`
define cover_export.erl
$(foreach f,$(COVER_FILES),cover:import("$(f)") == ok orelse halt(1),)
cover:export("$(COVER_DIR)/$@"), halt(0).
endef
#-------------------------------------------------------------------------------
# Targets
#-------------------------------------------------------------------------------
.PHONY: mrproper
mrproper:
$(RM) -r $(BUILD_DIR) $(ABS_DIR)/doc $(ABS_DIR)/data.* \
$(ABS_DIR)/log.* $(ABS_DIR)/.scannerwork
.PHONY: clean
clean: $(REBAR)
$(REBAR) clean
.PHONY: install-deps
install-deps: $(REBAR)
$(REBAR) get-deps
.PHONY: deps
deps: $(REBAR)
$(REBAR) upgrade
.PHONY: docs doc
docs: doc
doc: $(REBAR)
$(REBAR) edoc
.PHONY: compile
compile: $(REBAR)
$(REBAR) compile
.PHONY: xref
xref: $(REBAR) $(TEST_LOGS_DIR)
$(REBAR) xref | grep -o "Warning: .*" > $(TEST_LOGS_DIR)/xref.log
.PHONY: dialyzer
dialyzer: $(REBAR)
$(REBAR) dialyzer > $(TEST_LOGS_DIR)/dialyzer.txt
.PHONY: eunit
eunit: $(REBAR)
$(BEAM_FLAGS) $(REBAR) eunit --cover -v
.PHONY: ct
ct: $(REBAR)
$(BEAM_FLAGS) $(REBAR) ct --cover -v
.PHONY: cover
cover: $(REBAR)
$(REBAR) cover --verbose
all.coverdata: $(REBAR)
$(call erlang,$(cover_export.erl))
.PHONY: merge-cover
merge-cover: all.coverdata
.PHONY: reset-cover
reset-cover: $(REBAR)
$(REBAR) cover --reset
.PHONY: sonar
sonar: $(SONAR_SCANNER)
$(SONAR_SCANNER) -X
.PHONY: shell
shell: $(REBAR)
$(BEAM_FLAGS) $(REBAR) shell
.PHONY: elvis-check
elvis-check: $(ELVIS) #: Run the Elvis style reviewer.
$(ELVIS) $(ELVIS_FLAGS) rock > $(TEST_LOGS_DIR)/elvis_rock.txt || exit 0
.PHONY: release
release: $(REBAR)
$(BEAM_FLAGS) $(REBAR) release