-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
232 lines (154 loc) · 4.79 KB
/
Makefile
File metadata and controls
232 lines (154 loc) · 4.79 KB
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
#!/usr/bin/env make
#
# Asteroids, a JavaScript game played in a web browser.
# See organisation on GitHub: https://github.com/janaxs
# ------------------------------------------------------------------------
#
# General stuff, reusable for all Makefiles.
#
# Detect OS
OS = $(shell uname -s)
# Defaults
ECHO = echo
# Make adjustments based on OS
ifneq (, $(findstring CYGWIN, $(OS)))
ECHO = /bin/echo -e
endif
# Colors and helptext
NO_COLOR = \033[0m
ACTION = \033[32;01m
OK_COLOR = \033[32;01m
ERROR_COLOR = \033[31;01m
WARN_COLOR = \033[33;01m
# Print out colored action message
ACTION_MESSAGE = $(ECHO) "$(ACTION)---> $(1)$(NO_COLOR)"
# Which makefile am I in?
WHERE-AM-I = $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
THIS_MAKEFILE := $(call WHERE-AM-I)
# Echo some nice helptext based on the target comment
HELPTEXT = $(call ACTION_MESSAGE, $(shell egrep "^\# target: $(1) " $(THIS_MAKEFILE) | sed "s/\# target: $(1)[ ]*-[ ]* / /g"))
# Check version and path to command and display on one line
CHECK_VERSION = printf "%-15s %-13s %s\n" "`basename $(1)`" "`$(1) --version $(2)`" "`which $(1)`"
# Get current working directory, it may not exist as environment variable.
PWD = $(shell pwd)
# target: help - Displays help.
.PHONY: help
help:
@$(call HELPTEXT,$@)
@sed '/^$$/q' $(THIS_MAKEFILE) | tail +3 | sed 's/#\s*//g'
@$(ECHO) "Usage:"
@$(ECHO) " make [target] ..."
@$(ECHO) "target:"
@egrep "^# target:" $(THIS_MAKEFILE) | sed 's/# target: / /g'
# ------------------------------------------------------------------------
#
# Specifics for this project.
#
# The fileset
JS_FILES = src/js/asteroids.js
JS_MINIFIED = $(JS_FILES:.js=.min.js)
LESS_FILES = src/less/asteroids.less
LESS_COMPILED = $(LESS_FILES:.less=.css)
LESS_MINIFIED = $(LESS_FILES:.less=.min.css)
HTML_FILES = $(wildcard *.html)
BIN = node_modules/.bin
#
# Tool to compile and minify less code
#
LESS_COMPILE = $(BIN)/lessc
LESS_COMPILE_OPTIONS =
LESS_MINIFY = $(LESS_COMPILE)
LESS_MINIFY_OPTIONS = --clean-css
LESS_LINT = $(LESS_COMPILE)
LESS_LINT_OPTIONS = --lint
# Tool to compile, check and minimize javascript code
JS_CODESTYLE = $(BIN)/jscs
JS_CODESTYLE_OPTIONS =
JS_LINT = $(BIN)/jshint
JS_LINT_OPTIONS =
JS_MINIFY = $(BIN)/uglifyjs
JS_MINIFY_OPTIONS = --mangle --compress --screw-ie8 --comments
JS_COMPILE = $(BIN)/webpack
JS_COMPILE_OPTIONS = --config .webpack.config.js
#
# Tool to lint HTML code
#
HTML_LINT = $(BIN)/htmlhint
HTML_LINT_OPTIONS =
# target: install - Install development tools.
PHONY: install
install:
@$(call HELPTEXT,$@)
npm install
# target: all - Default target, run tests and build
#all: test build
all: js-compile
# target: js-compile - Compile JavaScript.
PHONY: js-compile
js-compile:
@echo $(call HELPTEXT,$@)
$(JS_COMPILE) $(JS_COMPILE_OPTIONS)
# ------------------------------------------------------------------------
#
# General and combined targets
#
# target: test - Do all tests
test: js-cs js-lint less-lint html-lint
# target: build - Do all build
build: less-compile less-minify js-minify
# target: clean - Removes generated files and directories.
clean:
@echo "Target clean not implemented."
#rm -f $(CSS_MINIFIED) $(JS_MINIFIED)
# ------------------------------------------------------------------------
#
# LESS
#
# target: less-compile - Compile LESS to CSS
less-compile: $(LESS_FILES) $(LESS_COMPILED)
%.css: %.less
@echo "==> LESS compiling $<"
$(LESS_COMPILE) $(LESS_COMPILE_OPTIONS) $< $@
# target: less-minify - Minify LESS files to min.css
less-minify: $(LESS_FILES) $(LESS_MINIFIED)
%.min.css: %.less
@echo "==> LESS minifying $<"
$(LESS_MINIFY) $(LESS_MINIFY_OPTIONS) $< $@
# target: less-lint - Lint LESS files
less-lint: $(LESS_FILES)
@echo "==> LESS linting $<"
$(LESS_LINT) $(LESS_LINT_OPTIONS) $<
# ------------------------------------------------------------------------
#
# JavaScript
#
.PHONY: js-cs js-lint
# target: js-minify - Minify JavaScript files to min.js
js-minify: $(JS_FILES) $(JS_MINIFIED)
%.min.js: %.js
@echo "==> Minifying $<"
#$(JS_MINIFY) $(JS_MINIFY_OPTIONS) --output $@ $<
# target: js-cs - Check codestyle in javascript files
js-cs:
@for file in $(JS_FILES); do \
echo "==> JavaScript codestyle $$file"; \
$(JS_CODESTYLE) $(JS_CODESTYLE_OPTIONS) $$file; \
done
# target: js-lint - Lint javascript files
js-lint:
@for file in $(JS_FILES); do \
echo "==> JavaScript lint $$file"; \
$(JS_LINT) $(JS_LINT_OPTIONS) $$file; \
done
@echo
# ------------------------------------------------------------------------
#
# HTML
#
.PHONY: html-lint
# target: html-lint - Lint HTML files
html-lint:
@for file in $(HTML_FILES); do \
echo -n "==> HTML linting $$file"; \
$(HTML_LINT) $(HTML_LINT_OPTIONS) $$file | grep -v "Config loaded: "; \
done