summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile61
1 files changed, 43 insertions, 18 deletions
diff --git a/Makefile b/Makefile
index 259fab3..b17979b 100644
--- a/Makefile
+++ b/Makefile
@@ -1,25 +1,19 @@
+pathsearch = $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(PATH)))))
+
RM = rm -f
CP = cp
PATCH = patch
SASS = sass
-PHP = php
+PHP := $(firstword $(call pathsearch,php5) $(call pathsearch,php))
+SVG2PNG = rsvg-convert
+PNGCRUSH = $(firstword $(call pathsearch,pngcrush) $(call pathsearch,cp))
-srcfiles = \
- .gitignore \
- Makefile \
- license.txt \
- twentyeleven-fix.scss \
- style.scss \
- functions.php \
- screenshot.png \
- index.php.patch \
- header.php.patch \
- single.php.patch \
- content-single.php
+default: all
-all: style.css .gitignore header.php index.php single.php
+include theme.mk
+srcfiles += .gitignore theme.mk Makefile
-style.css: twentyeleven-fix.scss
+all: .gitignore $(targets)
%: %.patch ../twentyeleven/%
$(RM) $@
@@ -33,12 +27,43 @@ style.css: twentyeleven-fix.scss
$(PHP) -f $< > $@
%.png: %.svg
- rsvg-convert $< > $@.$$$$ && pngcrush $@.$$$$ $@ ; $(RM) $@.$$$$
+ $(SVG2PNG) $< > $@.$$$$ && $(PNGCRUSH) $@.$$$$ $@ ; $(RM) $@.$$$$
+
+################################################################################
-.gitignore: Makefile
+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:' >> '$@'
- for file in $(srcfiles); do echo !"$$file" >> '$@'; done
+ $(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: ;