X-Git-Url: https://git.yukkurigames.com/?p=string-lerp.git;a=blobdiff_plain;f=Makefile;h=6bddcb2a6800bc65d34cdbe72e75ee2c85a6184f;hp=9d74d814373014d9620887c3aabea43fdab0f306;hb=HEAD;hpb=3632f64eb824b67f22c9694866ae369f7bc43080 diff --git a/Makefile b/Makefile index 9d74d81..6bddcb2 100644 --- a/Makefile +++ b/Makefile @@ -1,81 +1,48 @@ #!/usr/bin/make -f PKGNAME := string-lerp - -fallback = $(firstword $(shell command -v $(1)) $(2)) - -git = $(shell GIT_DIR=$(firstword $(2) $(srcdir) .)/.git $(GIT) $(1)) -git_ls-tree = $(call git,ls-tree -r --name-only $(1),$(2)) -git_tag = $(call git,name-rev --tags --name-only $(call git,rev-parse $(1),$(2)),$(2)) +all: + $(info Interesting targets:) + $(info lint - validate source (with jshint)) + $(info test - run tests (with jstest)) + $(info ugly - generate minified source files) + $(info dist - generate redistributables (if git tagged)) + $(info ) + $(info (Running these may download packages from npm.)) + $(info ) + @: + +include javascript.mk GIT ?= git -NPM ?= npm -NPMBINDIR := ./node_modules/.bin -JSTEST ?= $(NPMBINDIR)/jstest -JSHINT ?= $(call fallback,jshint,$(NPMBINDIR)/jshint) -UGLIFY ?= $(call fallback,uglifyjs,$(NPMBINDIR)/uglifyjs) -SOURCES := string-lerp.js -UGLIFIED = $(SOURCES:.js=.min.js) +git-describe = $(shell $(GIT) describe --tags --always $1) -TESTS = $(wildcard tests/*.js) -LINT_TARGETS = $(patsubst %.js,build/stamp/%.lint,$(SOURCES)) -TEST_TARGETS = $(patsubst %.js,build/stamp/%.test,$(SOURCES)) \ - $(patsubst tests/%.js,build/stamp/%.test,$(TESTS)) +SOURCES := string-lerp.js +UGLIFIED := $(call uglify-stampify,$(SOURCES)) -.PHONY: all check lint test ugly dist clean distclean +JSHINTCONFIG := tests/jshint.config +JSSTAMPDIR := build/stamp -all: - @echo "Interesting targets:" - @echo " lint - validate source (with jshint)" - @echo " test - run tests (with jstest)" - @echo " ugly - generate minified/mangled source files" - @echo " dist - generate redistributables (if git tagged)" - @echo - @echo "(Running these may download packages from NPM.)" - @echo - -%.min.js: %.js | $(UGLIFY) - $(UGLIFY) --comments -m < $< > $@ - -build/stamp/%.lint: %.js | $(JSHINT) - @mkdir -p $(@D) - $(JSHINT) $< - @touch $@ +TESTS := $(wildcard tests/*.js) +LINTS := $(call jshint-stampify,$(SOURCES) $(TESTS)) +TEST_TARGETS = $(patsubst %.js,build/stamp/tests/%.js.test,$(SOURCES)) -build/stamp/%.test: tests/%.js %.js | $(JSTEST) - @mkdir -p $(@D) - @echo $(JSTEST) $< - @$(JSTEST) $< > $@ || (cat $@ && rm -f $@ && exit 1) - @touch $@ - -build/stamp/%.test: tests/%.js $(SOURCES) | $(JSTEST) - @mkdir -p $(@D) - @echo $(JSTEST) $< - @$(JSTEST) $< > $@ || (cat $@ && rm -f $@ && exit 1) - @touch $@ +.DELETE_ON_ERROR: +.PHONY: all check lint test ugly dist clean distclean install .FORCE check: lint test -lint: $(LINT_TARGETS) +lint: $(LINTS) test: $(TEST_TARGETS) -ugly: $(UGLIFIED) +ugly: check $(UGLIFIED) -build/dist/$(PKGNAME)-undefined.zip build/dist/$(PKGNAME)-undefined.tar.gz: - $(error Distributables must be tagged or explicitly versioned) - -.SECONDEXPANSION: -build/dist/$(PKGNAME)-%.zip: $$(call git_ls-tree,$$*) +$(PKGNAME)-%.zip $(PKGNAME)-%.tar.gz: .FORCE @mkdir -p $(@D) - git archive --prefix=$(PKGNAME)-$*/ --output=$@ $* + $(GIT) archive --prefix=$(PKGNAME)-$(*F)/ --output=$@ $(*F) -.SECONDEXPANSION: -build/dist/$(PKGNAME)-%.tar.gz: $$(call git_ls-tree,$$*) - @mkdir -p $(@D) - git archive --prefix=$(PKGNAME)-$*/ --output=$@ $* - -dist: check $(addprefix build/dist/$(PKGNAME)-$(call git_tag,HEAD),.zip .tar.gz) +dist: check $(addprefix build/dist/$(PKGNAME)-$(call git-describe),.zip .tar.gz) clean: $(RM) -r build @@ -84,11 +51,5 @@ clean: distclean: clean $(RM) -r node_modules -$(JSTEST): - $(NPM) install jstest - -$(JSHINT): - $(NPM) install jshint - -$(UGLIFY): - $(NPM) install uglify-js +install: check + $(NPM) install -g .