-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Makefile
355 lines (267 loc) · 7.53 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
#!/bin/make -f
# -*- makefile -*-
# SPDX-License-Identifier: MPL-2.0
#{
# Copyright 2018-present Samsung Electronics France SAS, and other contributors
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.*
#}
default: help all
project ?= webthing-iotjs
tmp_dir ?= tmp
runtime ?= iotjs
export runtime
eslint ?= node_modules/eslint/bin/eslint.js
babel ?= ./node_modules/.bin/babel
babelrc ?= ${CURDIR}/extra/${runtime}/.babelrc
babel_stamp_file += ${CURDIR}/extra/${runtime}/babel.txt
babel_out_dir ?= tmp/babel/runtime/${runtime}/dist
srcs_dir ?= lib example
lib_srcs ?= $(wildcard *.js lib/*.js | sort | uniq)
srcs?=${lib_srcs}
example_srcs?=$(shell find example -iname "*_modules" -prune -iname "*.js" \
| sort | uniq)
srcs+=${example_srcs}
run_args ?=
run_timeout ?= 10
main_src ?= example/multiple-things.js
NODE_PATH := .:${NODE_PATH}
export NODE_PATH
iotjs_modules_dir?=${CURDIR}/iotjs_modules
iotjs-express_url?=https://github.com/rzr/iotjs-express
iotjs-express_revision?=v0.0.21
iotjs_modules_dirs+=${iotjs_modules_dir}/iotjs-express
deploy_modules_dir ?= ${CURDIR}/tmp/deploy/iotjs_modules
deploy_module_dir ?= ${deploy_modules_dir}/${project}
deploy_dirs += ${deploy_module_dir}
deploy_dirs += ${deploy_modules_dir}/iotjs-express
deploy_srcs += $(addprefix ${deploy_module_dir}/, ${srcs})
port?=8888
ssl_port?=4443
hostname?=localhost
url?=http://${hostname}:${port}
https_url?=https://${hostname}:${port}
port?=8888
url?=http://localhost:${port}
help:
@echo "## Usage: "
@echo "# make start"
all: build
setup/%:
${@F}
node_modules: package.json
npm install
modules: ${runtime}_modules
ls $<
node/modules: node_modules
ls $<
modules: ${runtime}/modules
@echo "log: $@: $^"
package-lock.json: package.json
rm -fv "$@"
npm install
ls "$@"
setup/node: node_modules
@echo "NODE_PATH=$${NODE_PATH}"
node --version
npm --version
setup: setup/${runtime}
build/%: setup ${runtime}/modules
@echo "log: $@: $^"
build/node: setup node_modules
@echo "log: $@: $^"
build: build/${runtime}
@echo "log: $@: $^"
run/%: ${main_src} build modules
${@F} $< ${run_args}
run/npm: ${main_src} setup
npm start
run: run/${runtime}
-sync
node/run: ${main_src}
node $<
clean:
rm -rf ${tmp_dir}
cleanall: clean
rm -f *~
distclean: cleanall
rm -rf node_modules
${tmp_dir}/rule/test/pid/%: ${main_src} build modules
@mkdir -p "${@D}"
${@F} $< & echo $$! > "$@"
sleep ${run_timeout}
cat $@
test/%: ${tmp_dir}/rule/test/pid/%
cat $<
curl ${url} || curl -I ${url}
@echo ""
curl --fail ${url}/0/properties
@echo ""
curl --fail ${url}/1/properties
@echo ""
kill $$(cat $<) ||:
kill -9 $$(cat $<) ||:
test/npm: package.json
npm test
test: test/${runtime}
start: run
-sync
start/board/%: example/platform/Makefile example/platform/board/%.js modules
${MAKE} -C ${<D} board/${@F}
start/ssl/%:
npm run ${@F} -- "${ssl_port}" "${hostname}" --ssl
ssl/%:
mkdir -p $@
openssl req -nodes -new -x509 -keyout ${@}/ssl.key -out ${@}/ssl.cert
@echo "curl -k ${https_url}"
ssl: ssl/${hostname} start/ssl/simplest
@echo "log: $@: $<"
check/%: ${lib_srcs}
${MAKE} setup modules
@echo "log: SHELL=$${SHELL}"
status=0 ; \
for src in $^; do \
echo "log: check: $${src}: ($@)" ; \
${@F} $${src} \
&& echo "log: check: $${src}: OK" \
|| status=1 ; \
done ; \
exit $${status}
check/npm:
npm run lint
check: check/${runtime}
git/commit/%:
-git commit -sam "${runtime}: WIP: About to do something (${@})"
eslint/devel: .eslintrc.js ${eslint}
@rm -rf tmp/dist
${eslint} --no-color --fix . ||:
${eslint} --no-color .
git diff --exit-code
eslint: .eslintrc.js ${eslint}
@rm -rf tmp/dist
${eslint} --no-color --fix . ||:
${eslint} --no-color .
-git commit -sam "${runtime}: Linting sources (${@})"
eslint/setup: node_modules
ls ${eslint} || npm install eslint-plugin-node eslint
${eslint} --version
${eslint}:
ls $@ || make eslint/setup
touch $@
.eslintrc.js: ${eslint}
ls $@ || $< --init
lint/%: eslint
sync
lint: lint/${runtime}
sync
### Babel
#
babel/setup: Makefile
ls node_modules || ${MAKE} node_modules
-git commit -sam "WIP: babel: About to setup"
npm install --save-dev @babel/cli
npm install --save-dev @babel/core
npm install --save-dev @babel/plugin-transform-arrow-functions
npm install --save-dev @babel/plugin-transform-block-scoping
npm install --save-dev @babel/plugin-transform-template-literals
npm install --save-dev @babel/plugin-transform-parameters
@echo "TODO: npm install @babel/plugin-transform-for-of"
@echo "TODO: npm install @babel/plugin-transform-classes"
npm install --save-dev @babel/preset-env
-git commit -sam "WIP: babel: Installed tools"
${babel}:
ls $@ || ${MAKE} babel/setup
${babelrc}: ${babel}
ls $@ || echo '{ "ignore": [ "node_modules/**.js" ] }' > $@
cat $@
${babel_out_dir}: ${babelrc} ${babel}
${babel} \
--no-babelrc \
--config-file "$<" \
--delete-dir-on-start \
--ignore 'node_modules/**,dist/**' \
-d "${CURDIR}/$@/" \
--verbose \
.
ls ${babel_out_dir}
babel/run: ${babel_out_dir}
ls $<
babel/build: babel/run
rsync -avx ${babel_out_dir}/ ./
@rm -rf ${babel_out_dir}
${babel_stamp_file}: ${srcs_dir}
${MAKE} babel/build
${babel} --version | tee ${babel_stamp_file}
babel/runtime/%: ${babel_stamp_file}
ls $<
babel/runtime: babel/runtime/${runtime}
babel/commit/%: git/commit/babel/build/${runtime}
${MAKE} babel/runtime/${runtime}
-git commit -sm "${runtime}: babel: Transpiled (${@})" ${srcs_dir} ${srcs}
-git add "${babel_stamp_file}"
-git commit -sm "${runtime}: babel: Add stamp file" "${babel_stamp_file}"
babel/commit: babel/commit/${runtime}
babel: babel/runtime
sync
babel/done:
ls ${babel_stamp_file} && exit 0 || echo "log: Assuming it is not transpiled yet"
ls ${babel_stamp_file} || ${MAKE} ${@D}/commit
ls ${babel_stamp_file}
babel/clean:
rm -rf ${babel_out_dir}
babel/rebuild: babel/clean babel/build
sync
transpile/revert:
@echo "TODO: move $@ (babel) patches (2) for ${runtime} at end of list"
-git commit -sam "WIP: babel: About to $@"
git rebase -i remotes/upstream/master
git revert HEAD
git revert HEAD~2
transpile: git/commit/transpile/${runtime} lint/${runtime} babel/commit
retranspile: babel/done transpile/revert
${MAKE} transpile
git rebase -i remotes/upstream/master
### IoT.js related rules:
prep: ${runtime}/modules
echo "log: $@: $^"
#TODO install subdir
iotjs/modules: ${iotjs_modules_dirs}
ls $^
${iotjs_modules_dirs}: ${iotjs_modules_dir}/iotjs-express
ls $@
${iotjs_modules_dir}/iotjs-express:
mkdir -p ${@D}
git clone --recursive --depth 1 ${${@F}_url} -b ${${@F}_revision} $@
-rm -rf ${@}/.git
setup/iotjs/devel: ${eslint} ${babel}
setup/iotjs:
iotjs \
|| echo "log: Should have printed iotjs's usage..."
-which iotjs
build/iotjs/devel: setup lint ${babel_stamp_file}
echo "log: $@: $^"
build/iotjs: setup babel/done
lint/iotjs/eslint:
if [ ! -e ${babel_stamp_file} ] ; then make eslint ; fi
lint/iotjs/babel:
if [ -e ${babel_stamp_file} ] ; then make babel/run ; fi
lint/iotjs: lint/iotjs/eslint lint/iotjs/babel
#babel/runtime/iotjs:
# ${MAKE} babel/runtime/node
# ${MAKE} babel/runtime/iotjs
babel/runtimes: babel/runtime/iotjs babel/runtime/node
-sync
${deploy_module_dir}/%: %
@echo "# TODO: minify: $< to $@"
install -d ${@D}
install $< $@
${deploy_modules_dir}/iotjs-express: ${iotjs_modules_dir}/iotjs-express
make -C $< deploy deploy_modules_dir="${deploy_modules_dir}"
deploy/deps: ${deploy_dirs}
ls $<
deploy/srcs: ${deploy_srcs}
ls $<
deploy: deploy/deps deploy/srcs
@echo "# log: $@: $^"