-
Notifications
You must be signed in to change notification settings - Fork 4
/
makefile
219 lines (188 loc) · 6.8 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
SHELL = /bin/sh
# ========================== #
# === Makefile Variables === #
# ========================== #
# Compilation Variables
ERLC = $(shell which erlc)
ERLFLAGS = -Werror -v -o
ERLFLAGS_NONSTRICT = -Wall -v -o
ERLFLAGS_DEBUG = -Ddebug +debug_info -W0 -o
ERLFLAGS_TEST = -DTEST -Ddebug +debug_info -W0 -o
# Directory Variables
SRCDIR = src/erl
LIBDIR = src/erl/lib
OUTDIR = ebin
DEBUGDIR = edebug
TESTDIR = etesting
UTILDIR = util
JSDIR = jsbin
# Utility Variables
DIALYZER = $(shell which dialyzer)
ELVIS = $(UTILDIR)/elvis rock --config $(UTILDIR)/elvis.config
ERLPKG = $(UTILDIR)/erlpkg
STDOUT = &1
DEVNULL = /dev/null
GULP = ./node_modules/.bin/gulp
JSLINT = $(GULP) lint
# Colors
RED = \033[0;31m
GREEN = \033[0;32m
BLUE = \033[0;34m
ORANGE = \033[0;33m
PURPLE = \033[0;35m
CYAN = \033[0;36m
NORMAL = \033[0m
# ====================== #
# === Target recipes === #
# ====================== #
release:
@ echo "$(GREEN)==> Building RELEASE$(NORMAL)"
@ echo " Any warnings or errors will stop the build."
$(call compile, $(ERLFLAGS), $(OUTDIR), $(GREEN), $(DEVNULL))
$(call package, $(OUTDIR), $(GREEN))
$(call gulp, $(GREEN), $(OUTDIR), default)
nonstrict:
@ echo "$(GREEN)==> Building RELEASE NONSTRICT$(NORMAL)"
@ echo " Any warnings or errors will be ignored during build, if they can be."
$(call compile, $(ERLFLAGS_NONSTRICT), $(OUTDIR), $(GREEN), $(STDOUT))
$(call package, $(OUTDIR), $(GREEN))
$(call gulp, $(GREEN), $(OUTDIR), default)
debug:
@ echo "$(BLUE)==> Building DEBUG$(NORMAL)"
@ echo " Compiling with debug options enabled."
@ echo " Debug macro enabled."
$(call compile, $(ERLFLAGS_DEBUG), $(DEBUGDIR), $(BLUE), $(STDOUT))
$(call package, $(DEBUGDIR), $(BLUE))
$(call gulp, $(BLUE), $(DEBUGDIR), es6)
test:
@ echo "$(CYAN)==> Building TEST$(NORMAL)"
@ echo " Compiling with debug options enabled."
@ echo " Debug macro enabled."
@ echo " Test macro enabled."
$(call compile, $(ERLFLAGS_TEST), $(TESTDIR), $(CYAN), $(STDOUT))
$(call gulp, $(CYAN), $(TESTDIR), es6)
es6:
@ echo "$(GREEN)==> Building Jarlang Browser Runtime (ES6+)$(NORMAL)"
$(call gulp, $(GREEN), $(JSDIR), es6)
es5:
@ echo "$(BLUE)==> Building Jarlang Browser Runtime (ES5)$(NORMAL)"
$(call gulp, $(BLUE), $(JSDIR), es5)
min:
@ echo "$(CYAN)==> Building Jarlang Browser Runtime (MINIFIED)$(NORMAL)"
$(call gulp, $(CYAN), $(JSDIR), min)
.PHONY: lint
lint:
@ echo "$(PURPLE)==> Linting Erlang Project with Elvis$(NORMAL)"
@ $(ELVIS) || true
@ echo " ok"
@ echo "$(PURPLE)==> Linting JS Project with JSHint$(NORMAL)"
@ $(JSLINT) || true
@ echo " Done\n"
.PHONY: dialyze
dialyze:
@ echo "$(ORANGE)==> Building DIALYZE$(NORMAL)"
@ echo " Compiling with debug options enabled."
@ echo " Debug macro enabled."
@ echo " Test macro enabled."
$(call compile, $(ERLFLAGS_DEBUG), $(TESTDIR), $(ORANGE), $(STDOUT))
$(call dialyze, $(TESTDIR), $(ORANGE))
.PHONY: clean
clean:
@ echo "$(RED)==> Cleaning builds"
@ find . -name "*.beam" -not -path "./doc/*" -delete
@ echo "==> Removing all BEAM files from workspace"
@ find . -name "*.core" -not -path "./doc/*" -delete
@ echo "==> Removing all CORE files from workspace"
@ find . -name "*.est" -not -path "./doc/*" -delete
@ echo "==> Removing all EST files from workspace"
@ find . -name "*.jst" -not -path "./doc/*" -delete
@ echo "==> Removing all JST files from workspace"
@ find . -name "*.dump" -not -path "./doc/*" -delete
@ echo "==> Removing all DUMP files from workspace"
@ rm -rf $(OUTDIR)
@ echo "==> Removing $(OUTDIR)/"
@ echo " Done"
@ rm -rf $(DEBUGDIR)
@ echo "==> Removing $(DEBUGDIR)/"
@ echo " Done"
@ rm -rf $(TESTDIR)
@ echo "==> Removing $(TESTDIR)/"
@ echo " Done"
@ rm -rf $(JSDIR)
@ echo "==> Removing $(JSDIR)/"
@ echo " Done"
@ echo "==> Cleaned\n$(NORMAL)"
# ========================= #
# === Recipe Procedures === #
# ========================= #
define compile
@ $(eval COMPILE_MODE = $(1))
@ $(eval OUTPUT_DIR = $(2))
@ $(eval COLOR = $(3))
@ $(eval PIPE_TO = $(4))
@ mkdir -p $(OUTPUT_DIR)
@ rm -rf $(OUTPUT_DIR)/*
@ echo "$(COLOR)==> Compiling Library Files$(RED)"
@ $(ERLC) $(COMPILE_MODE) $(OUTPUT_DIR) $(LIBDIR)/*.erl >$(PIPE_TO)
@ echo "$(NORMAL) Done"
@ echo "$(COLOR)==> Compiling Source Files$(RED)"
@ $(ERLC) $(COMPILE_MODE) $(OUTPUT_DIR) $(SRCDIR)/*.erl >$(PIPE_TO)
@ echo "$(NORMAL) Done"
@ echo "$(COLOR)==> Bootstrapping NodeJS Environment onto build$(RED)"
@ cp -f $(SRCDIR)/*.js $(OUTPUT_DIR) 2>$(DEVNULL) || true
@ cp -f $(LIBDIR)/*.js $(OUTPUT_DIR) 2>$(DEVNULL) || true
@ echo "$(NORMAL) Done"
@ $(call escodegen, $(COLOR), $(OUTPUT_DIR))
@ echo "$(COLOR)==> Compiling complete in: './$(OUTPUT_DIR)/'$(NORMAL)"
@ echo " Done\n"
endef
define package
@ $(eval OUTPUT_DIR = $(1))
@ $(eval COLOR = $(2))
@ echo "$(COLOR)==> Creating erlpkg package in './$(OUTPUT_DIR)/'$(NORMAL)"
@ cd $(OUTPUT_DIR); ../$(ERLPKG) *.beam *.js node_modules -e jarlang -o jarlang
@ chmod +x $(OUTPUT_DIR)/jarlang
@ echo "$(COLOR)==> Cleaning directory './$(OUTPUT_DIR)/'$(NORMAL)"
@ rm $(OUTPUT_DIR)/*.beam
@ rm $(OUTPUT_DIR)/*.js
@ rm -rf $(OUTPUT_DIR)/node_modules
@ echo " Done\n"
@ echo "$(COLOR)==> Packaging complete in: './$(OUTPUT_DIR)/'$(NORMAL)"
@ echo " Done\n"
endef
define dialyze
@ $(eval TARGET_DIR = $(1))
@ $(eval COLOR = $(2))
@ echo "$(COLOR)==> Running Dialyzer$(NORMAL)"
@ $(DIALYZER) $(TARGET_DIR)/*.beam || true
@ echo "$(COLOR)==> Dialyzing complete in: './$(TARGET_DIR)/'$(NORMAL)"
@ echo " Done\n"
endef
define gulp
@ $(eval COLOR = $(1))
@ $(eval TARGET_DIR = $(2))
@ $(eval GULPTASK = $(3))
@ mkdir -p $(TARGET_DIR)
@ echo "$(COLOR)==> Running GULP tasks$(NORMAL)"
@ $(GULP) $(GULPTASK)
@ echo "$(COLOR)==> Writing JS runtime to location: './$(TARGET_DIR)'$(NORMAL)"
@ mv gulpbuild/* $(TARGET_DIR)/
@ rm -rf gulpbuild/
@ echo " ok"
@ echo "$(COLOR)==> Writing HTML Template: './$(TARGET_DIR)'$(NORMAL)"
@ echo "<html><head><script src=\"jarlang.js\"></script></head></html>" > $(TARGET_DIR)/jarlang.html
@ echo " Done\n"
endef
define escodegen
@ $(eval COLOR = $(1))
@ $(eval TARGET_DIR = $(2))
@ echo "$(COLOR)==> Building ESCODEGEN node modules for packaging$(NORMAL)"
@ mkdir -p $(TARGET_DIR)/node_modules
@ cp -r node_modules/esprima $(TARGET_DIR)/node_modules/esprima
@ cp -r node_modules/estraverse $(TARGET_DIR)/node_modules/estraverse
@ cp -r node_modules/esutils $(TARGET_DIR)/node_modules/esutils
@ cp -r node_modules/optionator $(TARGET_DIR)/node_modules/optionator
@ cp -r node_modules/source-map $(TARGET_DIR)/node_modules/source-map
@ cp -r node_modules/escodegen $(TARGET_DIR)/node_modules/escodegen
@ echo " ok"
endef