-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
362 lines (252 loc) · 8.45 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
#
#
#
# ------------------------------------------------------------------------
#
# Generel stuff
#
# Detect OS
OS = $(shell uname -s)
# Defaults
ECHO = echo
# Make adjustments based on OS
# http://stackoverflow.com/questions/3466166/how-to-check-if-running-in-cygwin-mac-or-linux/27776822#27776822
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
# 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 = $(ECHO) "$(ACTION)--->" `egrep "^\# target: $(1) " $(THIS_MAKEFILE) | sed "s/\# target: $(1)[ ]*-[ ]* / /g"` "$(NO_COLOR)"
# ------------------------------------------------------------------------
#
# Specifics
#
# Add local bin path for test tools
#PATH := "./.bin:./vendor/bin:./node_modules/.bin:$(PATH)"
#SHELL := env PATH=$(PATH) $(SHELL)
BIN := .bin
PHPUNIT := $(BIN)/phpunit
PHPLOC := $(BIN)/phploc
PHPCS := $(BIN)/phpcs
PHPCBF := $(BIN)/phpcbf
PHPMD := $(BIN)/phpmd
PHPDOC := $(BIN)/phpdoc
BEHAT := $(BIN)/behat
SHELLCHECK := $(BIN)/shellcheck
BATS := $(BIN)/bats
# target: help - Displays help.
.PHONY: help
help:
@$(call HELPTEXT,$@)
@$(ECHO) "Usage:"
@$(ECHO) " make [target] ..."
@$(ECHO) "target:"
@egrep "^# target:" $(THIS_MAKEFILE) | sed 's/# target: / /g'
# target: prepare - Prepare for tests and build
.PHONY: prepare
prepare:
@$(call HELPTEXT,$@)
[ -d .bin ] || mkdir .bin
[ -d build ] || mkdir build
rm -rf build/*
# target: clean - Removes generated files and directories.
.PHONY: clean
clean:
@$(call HELPTEXT,$@)
rm -rf build
# target: clean-cache - Clean the cache.
.PHONY: clean-cache
clean-cache:
@$(call HELPTEXT,$@)
rm -rf cache/*/*
# target: clean-all - Removes generated files and directories.
.PHONY: clean-all
clean-all:
@$(call HELPTEXT,$@)
rm -rf .bin build vendor
# target: check - Check version of installed tools.
.PHONY: check
check: check-tools-bash check-tools-php
@$(call HELPTEXT,$@)
# target: test - Run all tests.
.PHONY: test
test: initdb bats phpunit phpcs phpmd phploc behat # shellcheck
@$(call HELPTEXT,$@)
composer validate
# target: doc - Generate documentation.
.PHONY: doc
doc: phpdoc
@$(call HELPTEXT,$@)
# target: build - Do all build
.PHONY: build
build: test doc #theme less-compile less-minify js-minify
@$(call HELPTEXT,$@)
# target: install - Install all tools
.PHONY: install
install: prepare install-tools-bash install-tools-php
@$(call HELPTEXT,$@)
# target: update - Update the codebase and tools.
.PHONY: update
update:
@$(call HELPTEXT,$@)
[ ! -d .git ] || git pull
composer update
# target: tag-prepare - Prepare to tag new version.
.PHONY: tag-prepare
tag-prepare:
@$(call HELPTEXT,$@)
# ------------------------------------------------------------------------
#
# PHP
#
# target: install-tools-php - Install PHP development tools.
.PHONY: install-tools-php
install-tools-php:
@$(call HELPTEXT,$@)
curl -Lso $(PHPDOC) https://www.phpdoc.org/phpDocumentor.phar && chmod 755 $(PHPDOC)
curl -Lso $(PHPCS) https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar && chmod 755 $(PHPCS)
curl -Lso $(PHPCBF) https://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar && chmod 755 $(PHPCBF)
curl -Lso $(PHPMD) http://static.phpmd.org/php/latest/phpmd.phar && chmod 755 $(PHPMD)
curl -Lso $(PHPUNIT) https://phar.phpunit.de/phpunit-5.7.9.phar && chmod 755 $(PHPUNIT)
curl -Lso $(PHPLOC) https://phar.phpunit.de/phploc.phar && chmod 755 $(PHPLOC)
curl -Lso $(BEHAT) https://github.com/Behat/Behat/releases/download/v3.3.0/behat.phar && chmod 755 $(BEHAT)
composer install
# target: check-tools-php - Check versions of PHP tools.
.PHONY: check-tools-php
check-tools-php:
@$(call HELPTEXT,$@)
which $(PHPUNIT) && $(PHPUNIT) --version
which $(PHPLOC) && $(PHPLOC) --version
which $(PHPCS) && $(PHPCS) --version && echo
which $(PHPMD) && $(PHPMD) --version && echo
which $(PHPCBF) && $(PHPCBF) --version && echo
which $(PHPDOC) && $(PHPDOC) --version && echo
which $(BEHAT) && $(BEHAT) --version && echo
# target: phpunit - Run unit tests for PHP.
.PHONY: phpunit
phpunit: prepare
@$(call HELPTEXT,$@)
[ ! -f .phpunit.xml ] || $(PHPUNIT) --configuration .phpunit.xml
# target: phpcs - Codestyle for PHP.
.PHONY: phpcs
phpcs: prepare
@$(call HELPTEXT,$@)
[ ! -f .phpcs.xml ] || $(PHPCS) --standard=.phpcs.xml | tee build/phpcs
# target: phpcbf - Fix codestyle for PHP.
.PHONY: phpcbf
phpcbf:
@$(call HELPTEXT,$@)
[ ! -f .phpcs.xml ] || $(PHPCBF) --standard=.phpcs.xml
# target: phpmd - Mess detector for PHP.
.PHONY: phpmd
phpmd: prepare
@$(call HELPTEXT,$@)
- [ ! -f .phpmd.xml ] || $(PHPMD) . text .phpmd.xml | tee build/phpmd
# target: phploc - Code statistics for PHP.
.PHONY: phploc
phploc: prepare
@$(call HELPTEXT,$@)
$(PHPLOC) src > build/phploc
# target: phpdoc - Create documentation for PHP.
.PHONY: phpdoc
phpdoc:
@$(call HELPTEXT,$@)
[ ! -f .phpdoc.xml ] || $(PHPDOC) --config=.phpdoc.xml
# target: behat - Run behat for feature tests.
.PHONY: behat
behat:
@$(call HELPTEXT,$@)
[ ! -d features ] || $(BEHAT)
# ------------------------------------------------------------------------
#
# Bash
#
# target: install-tools-bash - Install Bash development tools.
.PHONY: install-tools-bash
install-tools-bash:
@$(call HELPTEXT,$@)
# Shellcheck
curl -s https://storage.googleapis.com/shellcheck/shellcheck-latest.linux.x86_64.tar.xz | tar -xJ -C build/ && rm -f .bin/shellcheck && ln build/shellcheck-latest/shellcheck .bin/
# Bats
curl -Lso $(BIN)/bats-exec-suite https://raw.githubusercontent.com/sstephenson/bats/master/libexec/bats-exec-suite
curl -Lso $(BIN)/bats-exec-test https://raw.githubusercontent.com/sstephenson/bats/master/libexec/bats-exec-test
curl -Lso $(BIN)/bats-format-tap-stream https://raw.githubusercontent.com/sstephenson/bats/master/libexec/bats-format-tap-stream
curl -Lso $(BIN)/bats-preprocess https://raw.githubusercontent.com/sstephenson/bats/master/libexec/bats-preprocess
curl -Lso $(BATS) https://raw.githubusercontent.com/sstephenson/bats/master/libexec/bats
chmod 755 $(BIN)/bats*
# target: check-tools-bash - Check versions of Bash tools.
.PHONY: check-tools-bash
check-tools-bash:
@$(call HELPTEXT,$@)
which $(SHELLCHECK) && $(SHELLCHECK) --version
which $(BATS) && $(BATS) --version
# target: shellcheck - Run shellcheck for bash files.
.PHONY: shellcheck
shellcheck:
@$(call HELPTEXT,$@)
[ ! -d src ] || $(SHELLCHECK) --shell=bash src/*.bash
# target: bats - Run bats for unit testing bash files.
.PHONY: bats
bats:
@$(call HELPTEXT,$@)
[ ! -d test ] || $(BATS) test/
# clean db before tests
.PHONY: initdb
initdb:
@$(call HELPTEXT,$@)
./initdb.sh
# ------------------------------------------------------------------------
#
# Theme
#
# target: theme - Do make build install in theme/ if available.
.PHONY: theme
theme:
@$(call HELPTEXT,$@)
[ ! -d theme ] || ( cd theme && make build install )
# ------------------------------------------------------------------------
#
# Cimage
#
define CIMAGE_CONFIG
<?php
return [
"mode" => "development",
"image_path" => __DIR__ . "/../img/",
"cache_path" => __DIR__ . "/../../cache/cimage/",
"autoloader" => __DIR__ . "/../../vendor/autoload.php",
];
endef
export CIMAGE_CONFIG
define GITIGNORE_EMPTY_DIR
# Ignore everything in this directory
*
# Except this file
!.gitignore
endef
export GITIGNORE_EMPTY_DIR
# target: cimage-update - Install/update Cimage to latest version.
.PHONY: cimage-update
cimage-update:
@$(call HELPTEXT,$@)
composer require mos/cimage
install -d htdocs/cimage cache/cimage
$(ECHO) "$$GITIGNORE_EMPTY_DIR" | bash -c 'cat > cache/cimage/.gitignore'
chmod 777 cache/cimage
cp vendor/mos/cimage/webroot/img.php htdocs/cimage
cp vendor/mos/cimage/webroot/img/car.png htdocs/img/
touch htdocs/cimage/img_config.php
# target: cimage-config-create - Create configfile for Cimage.
.PHONY: cimage-config-create
cimage-config-create:
@$(call HELPTEXT,$@)
$(ECHO) "$$CIMAGE_CONFIG" | bash -c 'cat > htdocs/cimage/img_config.php'
cat htdocs/cimage/img_config.php