Switch back to mediump, which works (better) on iOS.
[pwl6.git] / rules / javascript.mk
1 # This is free and unencumbered software released into the public
2 # domain. To the extent possible under law, the author of this file
3 # waives all copyright and related or neighboring rights to it.
4
5 .DELETE_ON_ERROR:
6
7 javascript>fallback = $(firstword $(shell command -v $1) $2 $1)
8
9 NPM ?= npm
10 NPMROOT ?= $(CURDIR)
11
12 npmbindir = $(NPMROOT)/node_modules/.bin
13 .PRECIOUS: $(npmbindir)/%
14
15 npmbin = $(call javascript>fallback,$1,$(npmbindir)/$1)
16
17 JSTEST ?= $(npmbindir)/jstest
18 JSHINT ?= $(call npmbin,jshint)
19
20 uglifyjs_npm_package := uglify-js
21
22 UGLIFY ?= $(call npmbin,uglifyjs)
23 UGLIFYFLAGS ?= --comments \
24 --compress $(UGLIFYCOMPRESSFLAGS) \
25 --mangle $(UGLIFYMANGLEFLAGS)
26
27 BUILDDIR ?= build/
28 JSSTAMPDIR ?= $(BUILDDIR)/stamp
29 JSHINTDIR ?= $(JSSTAMPDIR)
30 JSTESTDIR ?= $(JSSTAMPDIR)
31 JSUGLYDIR ?= $(CURDIR)
32
33 JSHINTFLAGS += $(if $(JSHINTCONFIG),--config $(JSHINTCONFIG))
34 JSTESTFLAGS += $(if $(JSTESTFORMAT),--format $(JSTESTFORMAT))
35 JSTESTENV += $(if $(JSTEST_NODE_PATH),NODE_PATH=$(JSTEST_NODE_PATH))
36 JSTESTFORMAT ?= spec
37
38 jshint-stampify = $(patsubst %.js,$(JSHINTDIR)/%.js.lint,$1)
39 jstest-stampify = $(patsubst %.js,$(JSTESTDIR)/%.js.test,$1)
40 uglify-stampify = $(patsubst %.js,$(JSUGLYDIR)/%.min.js,$1)
41
42 javascript>capture-to-target = @echo "$1" && $1 > $@ || (cat $@ && exit 1)
43
44 UGLIFY.js = $(UGLIFY) $(UGLIFYFLAGS)
45 LINT.js = $(JSHINT) $(JSHINTFLAGS)
46 TEST.js = $(JSTESTENV) $(JSTEST) $(JSTESTFLAGS)
47
48 $(JSUGLYDIR)/%.min.js: %.js | $(UGLIFY)
49 mkdir -p $(@D)
50 $(UGLIFY.js) < $< > $@
51
52 $(JSHINTDIR)/%.js.lint: %.js | $(JSHINT)
53 mkdir -p $(@D)
54 $(LINT.js) $<
55 touch $@
56
57 $(JSTESTDIR)/%.js.test: %.js | $(JSTEST)
58 mkdir -p $(@D)
59 $(call javascript>capture-to-target,$(TEST.js) $<)
60
61 $(npmbindir)/%:
62 $(NPM) install $(firstword $(value $(@F)_npm_package) $(@F))