Simplify glyph regexes.
[string-lerp.git] / Makefile
1 #!/usr/bin/make -f
2
3 PKGNAME := string-lerp
4
5 fallback = $(firstword $(shell command -v $(1)) $(2))
6
7 git = $(shell GIT_DIR=$(firstword $(2) $(srcdir) .)/.git $(GIT) $(1))
8 git_ls-tree = $(call git,ls-tree -r --name-only $(1),$(2))
9 git_tag = $(call git,name-rev --tags --name-only $(call git,rev-parse $(1),$(2)),$(2))
10
11 GIT ?= git
12 NPM ?= npm
13 NPMBINDIR := ./node_modules/.bin
14 JSTEST ?= $(NPMBINDIR)/jstest
15 JSHINT ?= $(call fallback,jshint,$(NPMBINDIR)/jshint)
16 UGLIFY ?= $(call fallback,uglifyjs,$(NPMBINDIR)/uglifyjs)
17 SOURCES := string-lerp.js
18 UGLIFIED = $(SOURCES:.js=.min.js)
19
20 TESTS = $(wildcard tests/*.js)
21 LINT_TARGETS = $(patsubst %.js,build/stamp/%.lint,$(SOURCES))
22 TEST_TARGETS = $(patsubst %.js,build/stamp/%.test,$(SOURCES)) \
23 $(patsubst tests/%.js,build/stamp/%.test,$(TESTS))
24
25 .PHONY: all check lint test ugly dist clean distclean install
26
27 all:
28 @echo "Interesting targets:"
29 @echo " lint - validate source (with jshint)"
30 @echo " test - run tests (with jstest)"
31 @echo " ugly - generate minified/mangled source files"
32 @echo " dist - generate redistributables (if git tagged)"
33 @echo
34 @echo "(Running these may download packages from npm.)"
35 @echo
36
37 %.min.js: %.js | $(UGLIFY)
38 $(UGLIFY) --comments -m < $< > $@
39
40 build/stamp/%.lint: %.js | $(JSHINT)
41 @mkdir -p $(@D)
42 $(JSHINT) $<
43 @touch $@
44
45 build/stamp/%.test: tests/%.js %.js | $(JSTEST)
46 @mkdir -p $(@D)
47 @echo $(JSTEST) $<
48 @$(JSTEST) $< > $@ || (cat $@ && rm -f $@ && exit 1)
49 @touch $@
50
51 build/stamp/%.test: tests/%.js $(SOURCES) | $(JSTEST)
52 @mkdir -p $(@D)
53 @echo $(JSTEST) $<
54 @$(JSTEST) $< > $@ || (cat $@ && rm -f $@ && exit 1)
55 @touch $@
56
57 check: lint test
58
59 lint: $(LINT_TARGETS)
60
61 test: $(TEST_TARGETS)
62
63 ugly: $(UGLIFIED)
64
65 build/dist/$(PKGNAME)-undefined.zip build/dist/$(PKGNAME)-undefined.tar.gz:
66 $(error Distributables must be tagged or explicitly versioned)
67
68 .SECONDEXPANSION:
69 build/dist/$(PKGNAME)-%.zip: $$(call git_ls-tree,$$*)
70 @mkdir -p $(@D)
71 $(GIT) archive --prefix=$(PKGNAME)-$*/ --output=$@ $*
72
73 .SECONDEXPANSION:
74 build/dist/$(PKGNAME)-%.tar.gz: $$(call git_ls-tree,$$*)
75 @mkdir -p $(@D)
76 $(GIT) archive --prefix=$(PKGNAME)-$*/ --output=$@ $*
77
78 dist: check $(addprefix build/dist/$(PKGNAME)-$(call git_tag,HEAD),.zip .tar.gz)
79
80 clean:
81 $(RM) -r build
82 $(RM) $(UGLIFIED)
83
84 distclean: clean
85 $(RM) -r node_modules
86
87 install: check
88 $(NPM) install -g .
89
90 $(JSTEST):
91 $(NPM) install jstest
92
93 $(JSHINT):
94 $(NPM) install jshint
95
96 $(UGLIFY):
97 $(NPM) install uglify-js