forked from JamBrain/JamBrain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
366 lines (293 loc) · 13.9 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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
-include config.mk # Create and use this file to override any of 'Settings' #
# Settings #
SRC ?= src
OUT ?= .output
.BUILD ?= .build
NODEJS ?= node_modules
# Use 'TARGET=public-ludumdare.com' if you want to build a specific build (such as public-ludumdare.com) #
ifneq ($(strip $(TARGET)),)
THE_MAKEFILES := $(SRC)/$(subst /,,$(TARGET))/Makefile
endif # BUILD
# if JOBS are specified in config.mk, then use that to start a parallel build
ifdef JOBS
ifndef MAIN_FOLDER
$(info [*] Running with $(JOBS) JOBS)
endif # MAIN_FOLDER
JOBS := -j $(JOBS)
endif # JOBS
ifndef MAIN_FOLDER
ifdef DEBUG
$(info [*] Debug output enabled)
endif # DEBUG
endif # MAIN_FOLDER
ifndef MAIN_FOLDER
ifdef SOURCEMAPS
$(info [*] Source Maps enabled)
endif # SOURCEMAPS
endif # MAIN_FOLDER
# TODO: REMOVE THIS
STATIC_DOMAIN ?= static.jammer.work
# Copy un-minified files
ifdef WINDOWS_HOST
ifndef MAIN_FOLDER
$(info [*] Running on WINDOWS_HOST)
endif # MAIN_FOLDER
endif # WINDOWS_HOST
# Include Folders (modified by recursive scripts) #
ifdef INCLUDE_FOLDERS
INCLUDE_FOLDERS += src/compat/
endif # INCLUDE_FOLDERS
INCLUDE_FOLDERS ?= $(SRC)/
BUILD_FOLDER := $(OUT)/$(.BUILD)/$(subst /,,$(TARGET))
# Functions (must use '=', and not ':=') #
REMOVE_UNDERSCORE = $(foreach v,$(1),$(if $(findstring /_,$(v)),,$(v)))
INCLUDE_INCLUDES = $(filter $(addsuffix %,$(dir $(INCLUDE_FOLDERS))),$(1))
FIND_FILE = $(call REMOVE_UNDERSCORE,$(call INCLUDE_INCLUDES,$(shell find $(1) -name '$(2)')))
# NOTE: My standard build tree rule is to ignore any file/folder prefixed with an underscore #
# Files #
ALL_JS_FILES := $(filter-out %.min.js,$(call FIND_FILE,$(SRC)/,*.js))
ALL_LESS_FILES := $(filter-out %.min.less,$(call FIND_FILE,$(SRC)/,*.less))
ALL_CSS_FILES := $(filter-out %.min.css,$(call FIND_FILE,$(SRC)/,*.css))
ALL_SVG_FILES := $(filter-out %.min.svg,$(call FIND_FILE,$(SRC)/,*.svg))
ALL_ESIGNORE_FILES := $(call FIND_FILE,$(SRC)/,.es6ignore)
ESIGNORE_FOLDERS := $(addsuffix %,$(dir $(ALL_ESIGNORE_FILES)))
# Transforms #
ES_FILES := $(filter-out $(ESIGNORE_FOLDERS),$(ALL_JS_FILES))
JS_FILES := $(filter $(ESIGNORE_FOLDERS),$(ALL_JS_FILES))
LESS_FILES := $(ALL_LESS_FILES)
CSS_FILES := $(ALL_CSS_FILES)
SVG_FILES := $(ALL_SVG_FILES)
OUT_ES_FILES := $(subst $(SRC)/,$(OUT)/,$(ES_FILES:.js=.es.js))
OUT_JS_FILES := $(subst $(SRC)/,$(OUT)/,$(JS_FILES:.js=.o.js))
OUT_LESS_FILES := $(subst $(SRC)/,$(OUT)/,$(LESS_FILES:.less=.less.css))
OUT_CSS_FILES := $(subst $(SRC)/,$(OUT)/,$(CSS_FILES:.css=.o.css))
OUT_SVG_FILES := $(subst $(SRC)/,$(OUT)/,$(SVG_FILES:.svg=.min.svg))
OUT_FILES_SVG := $(OUT_SVG_FILES)
OUT_FILES_CSS := $(OUT_CSS_FILES) $(OUT_LESS_FILES)
OUT_FILES_JS := $(OUT_JS_FILES) $(OUT_ES_FILES)
OUT_FILES := $(OUT_FILES_SVG) $(OUT_FILES_CSS) $(OUT_FILES_JS)
DEP_FILES := $(addsuffix .dep,$(OUT_ES_FILES) $(OUT_LESS_FILES))
OUT_FOLDERS := $(sort $(dir $(OUT_FILES) $(BUILD_FOLDER)/))
TARGET_FILES_SVG := $(TARGET_FOLDER)/all.min.svg
TARGET_FILES_CSS := $(TARGET_FOLDER)/all.min.css
TARGET_FILES_JS := $(TARGET_FOLDER)/all.min.js
ifdef DEBUG
TARGET_FILES_CSS += $(TARGET_FOLDER)/all.debug.css
TARGET_FILES_JS += $(TARGET_FOLDER)/all.debug.js
endif # DEBUG
TARGET_FILES := $(TARGET_FILES_SVG) $(TARGET_FILES_CSS) $(TARGET_FILES_JS)
# Tools #
# Ecmascript Linter: http://eslint.org/
ESLINT_ARGS := --config src/config/eslint.config.json
ESLINT = $(NODEJS)/eslint/bin/eslint.js $(1) $(ESLINT_ARGS)
# ES Compiler: https://buble.surge.sh/guide/
BUBLE_ARGS := --no modules --jsx h --objectAssign Object.assign
#ifdef SOURCEMAPS
#BUBLE_ARGS += -m inline
#endif # SOURCEMAPS
BUBLE = $(NODEJS)/buble/bin/buble $(BUBLE_ARGS) -i $(1) -o $(2)
# ES Include/Require Resolver: http://rollupjs.org/guide/
ROLLUP_ARGS := -c src/config/rollup.config.js
ifdef SOURCEMAPS
ROLLUP_ARGS += -m inline
endif # SOURCEMAPS
ROLLUP = $(NODEJS)/rollup/bin/rollup $(ROLLUP_ARGS) $(1) > $(2)
# JS Preprocessor: https://github.com/moisesbaez/preprocess-cli-tool
JS_PP_DEBUG = $(NODEJS)/preprocess-cli-tool/bin/preprocess.js -f $(1) -d $(2) -c '{"DEBUG": true}' -t js
JS_PP_RELEASE = $(NODEJS)/preprocess-cli-tool/bin/preprocess.js -f $(1) -d $(2) -t js
# JS Minifier: https://github.com/mishoo/UglifyJS2
MINIFY_JS_RESERVED := VERSION_STRING,STATIC_DOMAIN
MINIFY_JS_ARGS := --compress --mangle -r "$(MINIFY_JS_RESERVED)"
MINIFY_JS = $(NODEJS)/uglify-js/bin/uglifyjs $(MINIFY_JS_ARGS) -o $(2) -- $(1)
# CSS Compiler: http://lesscss.org/
LESS_COMMON := --global-var='STATIC_DOMAIN=$(STATIC_DOMAIN)' --include-path=$(MAIN_FOLDER)
LESS_ARGS := --autoprefix
LESS_DEP = $(NODEJS)/less/bin/lessc $(LESS_COMMON) --depends $(1) $(2)>$(2).dep
LESS = $(NODEJS)/less/bin/lessc $(LESS_COMMON) $(LESS_ARGS) $(1) $(2)
# CSS Minifier: https://github.com/jakubpawlowicz/clean-css/
MINIFY_CSS = cat $(1) | $(NODEJS)/clean-css-cli/bin/cleancss -o $(2)
# CSS Linter: http://stylelint.io/
STYLELINT_ARGS := --syntax less --config src/config/.stylelintrc --config-basedir ../../
STYLELINT = $(NODEJS)/stylelint/bin/stylelint.js $(1) $(STYLELINT_ARGS)
# SVG "Compiler", same as the minifier: https://github.com/svg/svgo
SVGO_ARGS := -q --disable=removeTitle --disable=removeDimensions --disable=removeViewBox
SVGO = $(NODEJS)/svgo/bin/svgo $(SVGO_ARGS) -i $(1) -o $(2)
# Mike's SVG Sprite Packer: https://github.com/povrazor/svg-sprite-tools
SVG_PACK = src/tools/svg-sprite-pack $(1) > $(2)
# SVG Minifier: https://github.com/svg/svgo
MINIFY_SVG_ARGS := --multipass --disable=cleanupIDs -q
MINIFY_SVG = $(NODEJS)/svgo/bin/svgo $(MINIFY_SVG_ARGS) -i $(1) -o $(2)
# Remove Empty Directories
RM_EMPTY_DIRS = find $(1) -type d -empty -delete 2>/dev/null |true
# Get size in bytes (compress and uncompressed)
SIZE = cat $(1) | wc -c
GZIP_SIZE = gzip -c $(1) | wc -c
# Rules #
default: target
report: $(TARGET_FILES)
@echo \
"[JS_RAW] GZIP: `$(call GZIP_SIZE,$(BUILD_FOLDER)/all.js 2>/dev/null)` MINIFY: N/A ORIGINAL: `$(call SIZE,$(BUILD_FOLDER)/all.js 2>/dev/null)`\n" \
"[JS_DEBUG] GZIP: `$(call GZIP_SIZE,$(TARGET_FOLDER)/all.debug.js 2>/dev/null)` MINIFY: `$(call SIZE,$(TARGET_FOLDER)/all.debug.js 2>/dev/null)`* ORIGINAL: `$(call SIZE,$(BUILD_FOLDER)/all.debug.js 2>/dev/null)`\n" \
"[JS_RELEASE] GZIP: `$(call GZIP_SIZE,$(TARGET_FOLDER)/all.min.js 2>/dev/null)` MINIFY: `$(call SIZE,$(TARGET_FOLDER)/all.min.js 2>/dev/null)` ORIGINAL: `$(call SIZE,$(BUILD_FOLDER)/all.release.js 2>/dev/null)`\n" \
"[CSS] GZIP: `$(call GZIP_SIZE,$(TARGET_FOLDER)/all.min.css 2>/dev/null)` MINIFY: `$(call SIZE,$(TARGET_FOLDER)/all.min.css 2>/dev/null)` ORIGINAL: `$(call SIZE,$(BUILD_FOLDER)/all.css 2>/dev/null)`\n" \
"[SVG] GZIP: `$(call GZIP_SIZE,$(TARGET_FOLDER)/all.min.svg 2>/dev/null)` MINIFY: `$(call SIZE,$(TARGET_FOLDER)/all.min.svg 2>/dev/null)` ORIGINAL: `$(call SIZE,$(BUILD_FOLDER)/all.svg 2>/dev/null)`\n" \
| column -t
# If not called recursively, figure out who the targes are and call them #
ifndef MAIN_FOLDER # ---- #
# MAKEFILES is a reserved word, so we're using THE_MAKEFILES
THE_MAKEFILES ?= $(call FIND_FILE,$(SRC)/,Makefile)
BUILDS := $(subst $(SRC)/,$(OUT)/$(.BUILD)/,$(THE_MAKEFILES))
ALL_MAKEFILES := $(call FIND_FILE,$(SRC)/,Makefile)
ALL_BUILDS := $(subst $(SRC)/,$(OUT)/$(.BUILD)/,$(ALL_MAKEFILES))
# Recursively re-call this makefile for all TARGETs
clean:
@$(foreach b,$(THE_MAKEFILES),$(MAKE) clean -r --no-print-directory -C . -f $(subst $(OUT)/$(.BUILD)/,$(SRC)/,$(b));)
clean-svg:
@$(foreach b,$(THE_MAKEFILES),$(MAKE) clean-svg -r --no-print-directory -C . -f $(subst $(OUT)/$(.BUILD)/,$(SRC)/,$(b));)
clean-css:
@$(foreach b,$(THE_MAKEFILES),$(MAKE) clean-css -r --no-print-directory -C . -f $(subst $(OUT)/$(.BUILD)/,$(SRC)/,$(b));)
clean-js:
@$(foreach b,$(THE_MAKEFILES),$(MAKE) clean-js -r --no-print-directory -C . -f $(subst $(OUT)/$(.BUILD)/,$(SRC)/,$(b));)
clean-lint:
@$(foreach b,$(THE_MAKEFILES),$(MAKE) clean-lint -r --no-print-directory -C . -f $(subst $(OUT)/$(.BUILD)/,$(SRC)/,$(b));)
clean-all:
@$(foreach b,$(ALL_MAKEFILES),$(MAKE) clean -r --no-print-directory -C . -f $(subst $(OUT)/$(.BUILD)/,$(SRC)/,$(b));)
clean-all-svg:
@$(foreach b,$(ALL_MAKEFILES),$(MAKE) clean-svg -r --no-print-directory -C . -f $(subst $(OUT)/$(.BUILD)/,$(SRC)/,$(b));)
clean-all-css:
@$(foreach b,$(ALL_MAKEFILES),$(MAKE) clean-css -r --no-print-directory -C . -f $(subst $(OUT)/$(.BUILD)/,$(SRC)/,$(b));)
clean-all-js:
@$(foreach b,$(ALL_MAKEFILES),$(MAKE) clean-js -r --no-print-directory -C . -f $(subst $(OUT)/$(.BUILD)/,$(SRC)/,$(b));)
clean-all-lint:
@$(foreach b,$(ALL_MAKEFILES),$(MAKE) clean-lint -r --no-print-directory -C . -f $(subst $(OUT)/$(.BUILD)/,$(SRC)/,$(b));)
clean-version:
rm $(OUT)/git-version.php
mini: clean-version target
lint: lint-svg lint-css lint-js lint-php
lint-svg:
@$(foreach b,$(THE_MAKEFILES),$(MAKE) lint-svg -r --no-print-directory -C . -f $(subst $(OUT)/$(.BUILD)/,$(SRC)/,$(b));)
lint-css:
@$(foreach b,$(THE_MAKEFILES),$(MAKE) lint-css -r --no-print-directory -C . -f $(subst $(OUT)/$(.BUILD)/,$(SRC)/,$(b));)
lint-js:
@$(foreach b,$(THE_MAKEFILES),$(MAKE) lint-js -r --no-print-directory -C . -f $(subst $(OUT)/$(.BUILD)/,$(SRC)/,$(b));)
lint-php:
@$(foreach b,$(THE_MAKEFILES),$(MAKE) lint-php -r --no-print-directory -C . -f $(subst $(OUT)/$(.BUILD)/,$(SRC)/,$(b));)
lint-all: lint-all-svg lint-all-css lint-all-js lint-all-php
lint-all-svg:
@$(foreach b,$(ALL_MAKEFILES),$(MAKE) lint-svg -r --no-print-directory -C . -f $(subst $(OUT)/$(.BUILD)/,$(SRC)/,$(b));)
lint-all-css:
@$(foreach b,$(ALL_MAKEFILES),$(MAKE) lint-css -r --no-print-directory -C . -f $(subst $(OUT)/$(.BUILD)/,$(SRC)/,$(b));)
lint-all-js:
@$(foreach b,$(ALL_MAKEFILES),$(MAKE) lint-js -r --no-print-directory -C . -f $(subst $(OUT)/$(.BUILD)/,$(SRC)/,$(b));)
lint-all-php:
@$(foreach b,$(ALL_MAKEFILES),$(MAKE) lint-php -r --no-print-directory -C . -f $(subst $(OUT)/$(.BUILD)/,$(SRC)/,$(b));)
all: $(ALL_BUILDS) $(OUT)/git-version.php
target: $(BUILDS) $(OUT)/git-version.php
# NOTE: git-version should be last! Generation of this file doubles as the "install complete" notification.
$(ALL_BUILDS):
@echo "[+] Building \"$(subst /Makefile,,$(subst $(OUT)/$(.BUILD)/,,$@))\"..."
@$(MAKE) --no-print-directory $(JOBS) -C . -f $(subst $(OUT)/$(.BUILD)/,$(SRC)/,$@)
else # MAIN_FOLDER # ---- #
# Folder Rules #
$(OUT_FOLDERS):
mkdir -p $@
lint-svg:
lint-css: $(LESS_FILES)
$(call STYLELINT,$^)
lint-js: $(ES_FILES)
$(call ESLINT,$^)
lint-php:
clean-lint:
rm -fr $(BUILD_FOLDER)/buble.lint $(BUILD_FOLDER)/less.lint
$(BUILD_FOLDER)/buble.lint: $(ES_FILES)
$(call ESLINT,$?)
@touch $@
$(BUILD_FOLDER)/less.lint: $(LESS_FILES)
$(call STYLELINT,$?)
@touch $@
# File Rules #
$(OUT)/%.es.js:$(SRC)/%.js
$(call BUBLE,$<,$@)
$(OUT)/%.o.js:$(SRC)/%.js
cp $< $@
$(OUT)/%.less.css:$(SRC)/%.less
$(call LESS,$<,$@); $(call LESS_DEP,$<,$@)
$(OUT)/%.o.css:$(SRC)/%.css
cp $< $@
$(OUT)/%.min.svg:$(SRC)/%.svg
$(call SVGO,$<,$@)
clean:
rm -fr $(OUT) $(TARGET_FILES)
clean-svg:
rm -fr $(OUT_FILES_SVG) $(OUT_FILES_SVG:.svg=.svg.out) $(TARGET_FILES_SVG) $(BUILD_FOLDER)/svg.svg $(BUILD_FOLDER)/all.svg
-$(call RM_EMPTY_DIRS,.output)
clean-css:
rm -fr $(OUT_CSS_FILES) $(OUT_LESS_FILES) $(OUT_LESS_FILES:.less.css=.less) $(OUT_LESS_FILES:.less.css=.less.css.dep) $(TARGET_FILES_CSS) $(BUILD_FOLDER)/less.css $(BUILD_FOLDER)/css.css $(BUILD_FOLDER)/less.lint $(BUILD_FOLDER)/all.css
-$(call RM_EMPTY_DIRS,.output)
clean-js:
rm -fr $(OUT_JS_FILES) $(OUT_ES_FILES) $(OUT_ES_FILES:.es.js=.js) $(OUT_ES_FILES:.es.js=.js.dep) $(TARGET_FILES_JS) $(BUILD_FOLDER)/js.js $(BUILD_FOLDER)/buble.js $(BUILD_FOLDER)/buble.lint $(BUILD_FOLDER)/all.js
-$(call RM_EMPTY_DIRS,.output)
OUT_MAIN_JS := $(subst $(SRC)/,$(OUT)/,$(MAIN_JS:.js=.es.js))
# JavaScript #
$(BUILD_FOLDER)/js.js: $(OUT_JS_FILES)
cat $^ > $@
$(BUILD_FOLDER)/buble.js: $(OUT_MAIN_JS) $(OUT_ES_FILES)
$(call ROLLUP,$<,[email protected])
rm -f $@
mv [email protected] $@
$(BUILD_FOLDER)/all.js: $(BUILD_FOLDER)/js.js $(BUILD_FOLDER)/buble.js
cat $^ > $@
$(BUILD_FOLDER)/all.release.js: $(BUILD_FOLDER)/all.js
$(call JS_PP_RELEASE,$<,$@)
$(TARGET_FOLDER)/all.min.js: $(BUILD_FOLDER)/all.release.js
$(call MINIFY_JS,$<,$@)
$(BUILD_FOLDER)/all.debug.js: $(BUILD_FOLDER)/all.js
$(call JS_PP_DEBUG,$<,$@)
$(TARGET_FOLDER)/all.debug.js: $(BUILD_FOLDER)/all.debug.js
cp -f --remove-destination $< $@
# $(call JS_PP_DEBUG,$<,$(@D)/all.debug.js)
# $(call MINIFY_JS,$<,$@)
#
#ifdef DEBUG
# cp -f --remove-destination $(<D)/all.debug.js $(@D)/all.debug.js
#endif
# CSS #
$(BUILD_FOLDER)/css.css: $(OUT_CSS_FILES)
cat $^ > $@
$(BUILD_FOLDER)/less.css: $(OUT_LESS_FILES)
cat $^ > $@
$(BUILD_FOLDER)/all.css: $(BUILD_FOLDER)/css.css $(BUILD_FOLDER)/less.css
cat $^ > $@
$(TARGET_FOLDER)/all.min.css: $(BUILD_FOLDER)/all.css
$(call MINIFY_CSS,$<,$@)
$(TARGET_FOLDER)/all.debug.css: $(BUILD_FOLDER)/all.css
cp -f --remove-destination $< $@
#ifdef DEBUG
# cp -f --remove-destination $< $(@D)/all.debug.css
#endif
# SVG # src/icons/icomoon/icons.svg
$(BUILD_FOLDER)/svg.svg: $(OUT_SVG_FILES)
$(call SVG_PACK,$^,[email protected])
rm -f $@
mv [email protected] $@
# NOTE: needs to work like this, 'cause SVG_PACK outputs to stdout. Otherwise we wont stop on SVG errors
$(BUILD_FOLDER)/all.svg: $(BUILD_FOLDER)/svg.svg
cat $^ > $@
$(TARGET_FOLDER)/all.min.svg: $(BUILD_FOLDER)/all.svg
$(call MINIFY_SVG,$<,$@)
# Target #
target: $(OUT_FOLDERS) $(BUILD_FOLDER)/buble.lint $(BUILD_FOLDER)/less.lint $(TARGET_FILES) report
@echo "[-] Done \"$(subst /,,$(TARGET))\""
endif # MAIN_FOLDER # ---- #
# Generate GIT VERSION file #
$(OUT)/git-version.php:
@echo "[+] Generating \"$@\"..."
@echo "<?php">$@
@echo "// WARNING! DO NOT MODIFY! This file is automatically generated by Makefile!">>$@
@echo "">>$@
@echo "const GIT_VERSION = '$(shell git rev-list HEAD | wc -l)-$(shell git describe --always)';">>$@
@echo "[-] Done \"$@\""
# Phony Rules #
.PHONY: default build target all clean clean-all clean-target clean-version clean-lint clean-svg clean-css clean-js clean-all-svg clean-all-css clean-all-js lint lint-all lint-svg lint-css lint-js lint-php lint-all-svg lint-all-css lint-all-js lint-all-php fail report $(BUILDS)
# Dependencies #
-include $(DEP_FILES)