pathsearch = $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(PATH))))) RM = rm -f CP = cp PATCH = patch SASS = sass PHP := $(firstword $(call pathsearch,php5) $(call pathsearch,php)) SVG2PNG = rsvg-convert PNGCRUSH = $(firstword $(call pathsearch,pngcrush) $(call pathsearch,cp)) default: all include theme.mk srcfiles += .gitignore theme.mk Makefile all: .gitignore $(targets) %: %.patch ../twentyeleven/% $(RM) $@ $(CP) ../twentyeleven/$@ $@ $(PATCH) $@ < $@.patch %.css: %.scss $(SASS) $< $@ %: %.php $(PHP) -f $< > $@ %.png: %.svg $(SVG2PNG) $< > $@.$$$$ && $(PNGCRUSH) $@.$$$$ $@ ; $(RM) $@.$$$$ ################################################################################ in_dir = $(patsubst ./%,%,$(dir $1)) my_dir = $(patsubst %/,%,$(dir $1)) define gitignore_file $(if $(in_dir), $(call gitignore_file,$(my_dir)) echo '$(my_dir)/*' >> '$@'; ) echo '!$1' >> '$@'; endef .gitignore: Makefile theme.mk echo "# DO NOT EDIT, this file is automatically made by \`Makefile'" >$@ echo '# ' >> '$@' echo '# ignore everyting' >> '$@' echo '*' >> '$@' echo '# but these:' >> '$@' $(foreach file,$(srcfiles),$(call gitignore_file,$(file))) ################################################################################ git2make = $1 $(subst *,.*,$1) gitignore_y = $(call git2make,$(shell sed -n 's/^[^\#!]/&/p' .gitignore)) gitignore_n = $(call git2make,$(shell sed -n 's/^!//p' .gitignore)) gitignore_i = . .. .git %/.. %/. gitignore = $(filter-out $(gitignore_i) $(wildcard $(gitignore_n)),$(wildcard $(gitignore_y))) clean: .gitignore PHONY $(RM) -r $(filter-out $(targets),$(gitignore)) distclean: .gitignore PHONY $(RM) -r $(gitignore) ################################################################################ .PHONY: FORCE PHONY FORCE: ; PHONY: ;