5 fallback
= $(firstword $(shell command
-v
$(1)) $(2))
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))
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
)
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
))
25 .PHONY
: all check lint
test ugly
dist clean distclean install
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)"
34 @echo
"(Running these may download packages from npm.)"
37 %.min.js
: %.js |
$(UGLIFY
)
38 $(UGLIFY
) --comments
-m
< $< > $@
40 build
/stamp
/%.lint
: %.js |
$(JSHINT
)
45 build
/stamp
/%.
test: tests
/%.js
%.js |
$(JSTEST
)
48 @
$(JSTEST
) $< > $@ ||
(cat
$@
&& rm -f
$@
&& exit
1)
51 build
/stamp
/%.
test: tests
/%.js
$(SOURCES
) |
$(JSTEST
)
54 @
$(JSTEST
) $< > $@ ||
(cat
$@
&& rm -f
$@
&& exit
1)
65 build
/dist/$(PKGNAME
)-undefined.zip build
/dist/$(PKGNAME
)-undefined.
tar.gz
:
66 $(error Distributables must be tagged or explicitly versioned
)
69 build
/dist/$(PKGNAME
)-%.zip
: $$(call git_ls-tree
,$$*)
71 $(GIT
) archive
--prefix=$(PKGNAME
)-$*/ --output
=$@
$*
74 build
/dist/$(PKGNAME
)-%.
tar.gz
: $$(call git_ls-tree
,$$*)
76 $(GIT
) archive
--prefix=$(PKGNAME
)-$*/ --output
=$@
$*
78 dist: check $(addprefix build
/dist/$(PKGNAME
)-$(call git_tag
,HEAD
),.zip .
tar.gz
)
97 $(NPM
) install uglify-js