summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile21
-rw-r--r--README.adoc3
-rwxr-xr-xbin/hash646
3 files changed, 29 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 4c1db12..19d7ebe 100644
--- a/Makefile
+++ b/Makefile
@@ -11,6 +11,7 @@ EPUBSTYLE := $(SHEETDIR)/epub/style/$(EPUB_STYLE)/cvt.xsl
HTMLSTYLE := $(SHEETDIR)/xhtml5/style/$(HTML_STYLE)/cvt.xsl
HTMLPSTP := $(SHEETDIR)/xhtml5/style/$(HTML_STYLE)/pstp.xsl
ADOCFIXUP := $(SHEETDIR)/common/asciidoctor-fixup.xsl
+BIBLIOID := $(SHEETDIR)/common/biblioid.xsl
FOP_CFG := /etc/fop/fop.xconf
@@ -29,6 +30,7 @@ STYLEARGS += --stringparam generate.toc "/ nop article nop book nop"
CUR = $<
SRC_SUFFIXES := .dbx .adoc
+TMP_SUFFIXES := .tmp .tmp2
GEN_SUFFIXES := .pdf .fo .rtf .txml .epub .html
DEPFILES := $(patsubst %.dbx,.%.d,$(wildcard *.dbx))
@@ -76,7 +78,22 @@ depend: $(DEPFILES)
cat $(CUR); \
else \
xsltproc --xinclude $(PROFARGS) $(PROFILE) $(CUR); \
- fi) > $@.tmp; $(DBTOEPUB) -o $@ -s $(EPUBSTYLE) $@.tmp; rm $@.tmp
+ fi) > $@.tmp
+ xsltproc -o $@.tmp2 \
+ --stringparam hash-name sha-256 \
+ --stringparam hash-base64 "$(bin/hash64 $@.tmp)" \
+ $(BIBLIOID) $@.tmp
+ $(DBTOEPUB) -v -o $@ -s $(EPUBSTYLE) $@.tmp2
+ rm $@.tmp $@.tmp2
+ # Repack the zip file for reproducibility.
+ mkdir $@.dir
+ (destpath="$$(pwd)/$(@F)" && cd $@.dir && unzip $$destpath)
+ find $@.dir | xargs touch -d 1970-01-01T00:00:00Z
+ rm $@
+ (destpath="$$(pwd)/$(@F)" && cd $@.dir && \
+ find . -print | sed 1d | sort | \
+ xargs zip -oX $$destpath)
+ $(RM) -fr $@.dir
.dbx.html .txml.html:
(str="$(CUR)"; if [ -z "$${str##*/*}" ]; \
@@ -89,6 +106,8 @@ depend: $(DEPFILES)
clean:
for i in $(GEN_SUFFIXES); do find -name "*$$i" | xargs rm -f; done
+ for i in $(TMP_SUFFIXES); do find -name "*$$i" | xargs rm -f; done
+ for i in .dir; do find -name "*$$i" | xargs rm -fr; done
find -name '*.d' | xargs -r rm
ifneq "$(MAKECMDGOALS)" "clean"
diff --git a/README.adoc b/README.adoc
index a6d666b..7688b7a 100644
--- a/README.adoc
+++ b/README.adoc
@@ -28,3 +28,6 @@ Building these requires a few dependencies:
for italics in verse blocks.
* Apache FOP is required.
* xsltproc is required.
+* dbtoepub is required.
+* zip and unzip are required.
+* Ruby is required.
diff --git a/bin/hash64 b/bin/hash64
new file mode 100755
index 0000000..409f9af
--- /dev/null
+++ b/bin/hash64
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+ruby -rdigest -rbase64 -e '
+ d = Digest::SHA256.new
+ d << $_ while ARGF.gets
+ print Base64.urlsafe_encode64(d.digest)' "$@"