summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-12-31 17:43:33 -0700
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-12-31 17:43:33 -0700
commitc52557f0a969e539138b0fdd4d7dd25f8795b509 (patch)
tree128bcfab061bc5f7c703dbbfed9ec6c209e71f7e /Makefile
parentdd2b6e83987786dbd53113fa984630119334925d (diff)
wip
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile46
1 files changed, 46 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..a9b703b
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,46 @@
+SHELL = bash -o pipefail
+
+RUBYLIB=$(realpath .)/bin
+export RUBYLIB
+
+# Usage: $(call patsubst,PATTERN1 PATTERN2...,REPLACEMENT,TEXT)
+#
+# Like $(patsubst), but takes multiple patterns that are all replaced
+# with the same replacement.
+patsubst-all = $(if $1,$(call patsubst-all,$(wordlist 2,$(words $1),$1),$2,$(patsubst $(firstword $1),$2,$3)),$3)
+
+# Which suffixes can we turn in to HTML?
+html.suffixes = md org
+# Find all source files with those suffixes
+html.src = $(shell find src -type f \( -false $(foreach s,$(html.suffixes), -o -name '*.$s' ) \))
+# Translate the source filenames into output filenames
+html.out = $(call patsubst-all,$(addprefix src/%.,$(html.suffixes)),out/%.html,$(html.src))
+
+all: $(html.out)
+
+bin/page = bin/page bin/util.rb bin/pandoc.rb
+
+# We have to repeat each `src/% -> out/%` rule twice; where once we
+# write it as `out/% -> out/%`. This allows us to chain rules.
+
+# Markdown
+out/%.html: src/%.md $(bin/page) bin/page.html.erb bin/write-atomic
+ mkdir -p $(@D)
+ bin/page html $< | bin/write-atomic $@
+out/%.html: out/%.md $(bin/page) bin/page.html.erb bin/write-atomic
+ bin/page html $< | bin/write-atomic $@
+
+# Org-Mode
+out/%.html: src/%.org $(bin/page) bin/page.html.erb bin/write-atomic
+ mkdir -p $(@D)
+ bin/page html $< | bin/write-atomic $@
+out/%.html: out/%.org $(bin/page) bin/page.html.erb bin/write-atomic
+ bin/page html $< | bin/write-atomic $@
+
+#out/index.md : index index.md.erb .var.articles $(addsuffix .md,$(articles)) util.rb Makefile write-atomic
+# ./index md $(filter %.md,$^) | ./write-atomic $@
+#out/index.atom: index index.atom.erb .var.articles $(addsuffix .md,$(articles)) util.rb Makefile write-atomic
+# ./index atom $(filter %.md,$^) | ./write-atomic $@
+
+.DELETE_ON_ERROR:
+.SECONDARY: