]> pere.pagekite.me Git - text-madewithcc.git/blob - Makefile
Restructure to use DocBook XML as po4a input.
[text-madewithcc.git] / Makefile
1 #
2 # As of October 2017, I'm doing some Spanish-specific adjustments to
3 # this Makefile; they should be generalized... But I'm taking a step at a time :)
4 # -GW
5 #
6 SOURCE=MadewithCreativeCommonsmostup-to-dateversion
7
8 # Versioning: I'm using the date on which I got the source document
9 # (2017-06-09), plus an incrementing local part, that *should*
10 # increase every time the generated Markdown is modified.
11 VERSION=20170609-2
12
13 TEXLANG=spanish
14 TEXLANGCODE=es
15
16 #TEXLANG=norsk
17 #TEXLANGCODE=nb
18
19 # pandoc version 1.17.2~dfsg-3 do not understand
20 # --top-level-diversion, while version 1.19.2.4~dfsg-1+b3 do.
21 PANDOC_OPTS = \
22 --standalone \
23 --top-level-division=part \
24 -t docbook \
25 -f markdown+inline_notes+ascii_identifiers
26
27 LANGS := $(shell ls po/*/mwcc.po|cut -d/ -f2)
28
29 all: pdf epub
30
31 distclean: clean
32 rm -f $(SOURCE).md
33 for LANG in $(LANGS); do \
34 rm -f $(SOURCE).$$LANG.md ;\
35 done
36 clean:
37 for EXT in aux cb cb2 glo idx lof log tex toc xml pdf epub; do \
38 rm -f $(SOURCE).$$EXT ;\
39 for LANG in $(LANGS); do \
40 rm -f $(SOURCE).$$LANG.$$EXT ;\
41 done; \
42 done
43 $(RM) *~
44
45 $(SOURCE).md: $(SOURCE).odt fixup.rb
46 TEMP=`tempfile -p mwcc` && \
47 pandoc -f odt $(SOURCE).odt -t markdown > $$TEMP && \
48 ruby fixup.rb $$TEMP $(SOURCE).md && \
49 rm $$TEMP
50
51 pot: po/mwcc.pot po/*/mwcc.po
52 po/mwcc.pot: $(SOURCE).xml
53 TEMP=`tempfile -p mwcc` && \
54 po4a-gettextize -f docbook -m $(SOURCE).xml -p $$TEMP -M utf-8 --package-name 'Made with Creative Commons' --package-version $(VERSION) && \
55 echo '# MADE WITH CREATIVE COMMONS' > $@ && \
56 echo '# Copyright (C) 2017 by Creative Commons.' >> $@ && \
57 echo '# This file is published under a Creative Commons Attribution-ShareAlike license (CC BY-SA), version 4.0' >> $@ && \
58 echo '# Authors: Paul Stacey and Sarah Hinchliff Pearson' >> $@ && \
59 tail --lines=+5 $$TEMP >> $@ && \
60 rm $$TEMP
61
62 po/*/mwcc.po: po/mwcc.pot
63 msgmerge --previous $@ po/mwcc.pot -U
64 touch $@
65
66 $(SOURCE).es.xml: $(SOURCE).xml po/es/mwcc.po
67 po4a-translate -f docbook -m $(SOURCE).xml -p po/es/mwcc.po -l $@ -l $@ -L utf-8 -M utf-8 -k 0
68
69 $(SOURCE).nb.xml: $(SOURCE).xml po/nb/mwcc.po
70 po4a-translate -f docbook -m $(SOURCE).xml -p po/nb/mwcc.po -l $@ -l $@ -L utf-8 -M utf-8 -k 0
71
72 $(SOURCE).xml: $(SOURCE).md fixup-docbook.rb
73 TEMP=`tempfile -p mwcc` && \
74 pandoc -s -o $$TEMP $(PANDOC_OPTS) $(SOURCE).md && \
75 ruby fixup-docbook.rb $$TEMP $@ && \
76 rm $$TEMP
77
78 pdf: $(SOURCE).pdf
79 %.pdf: %.tex
80 pdflatex $^
81 pdflatex $^
82
83 epub: $(SOURCE).epub
84 %.epub: %.xml
85 dbtoepub $^
86
87 # Replace Unicode Hair Space (U+200A) with space, as   is not
88 # handled by LaTeX/dblatex, see <URL: https://bugs.debian.org/889603 >.
89 %.tex: %.xml
90 dblatex -t tex -b xetex $^
91 perl -p -i -e 's/\[latin1\]\{inputenc\}/[utf8]{inputenc}\n\\usepackage[$(TEXLANG)]{babel}/; \
92 s/ / /g; \
93 s/\\setcounter\{tocdepth\}.*/\\setcounter{tocdepth}{1}/; \
94 s/\\setcounter\{secnumdepth\}.*/\\setcounter{secnumdepth}{-1}/; \
95 s/\\caption\\end/\\caption{} \\end/; \
96 s!\\maketitle!\\input{extra/$(TEXLANGCODE)/cover.tex}!; \
97 s/\\author\{and\}/\\author{Paul Stacey \\and Sarah Hinchliff Pearson}/; \
98 s/\\DBKinditem\{\\writtenby\}\{and\}/\\DBKinditem{\writtenby}{Paul Stacey and Sarah Hinchliff Pearson}/; \
99 s/\\listoffigures//; \
100 s/\\chapter\{(Colophon|Dedication)\}/\\chapter*{}/; \
101 s/\\chapter\{(Foreword|Prefacio|Introduction|Introducción)\}/\\chapter*{$$1} \\addcontentsline{toc}{chapter}{$$1}/; \
102 s/\\section\{(Notes|Notas)\}/\\section*{$$1}/; \
103 s/(Web links?|Vínculos Web)/\\section*{$$1}/; \
104 s/^\s*(Revenue model|Interview date|Interviewees?|(Modelo de ingresos|Fecha de la entrevista|Entrevistad(?:o|a|os|as)))/\\textbf{$$1}/;' $@
105 perl -p -i -e '$$work=1 if /chapter.Arduino/; $$work=0 if /chapter.(Bibliography|Bibliografía)/; \
106 next unless $$work; \
107 s/(\\label\{[-\.\wáéíóúñ]+\}\\hyperlabel\{[-\.\wáéíóúñ]+\}%)/$$1\n\\begin{quote}/i; \
108 s/(Profile written by.+|Perfil escrito por.+|Profilen skrevet av.+)/$$1\n\\end{quote}/' $@
109
110 XMLLINTOPTS = --nonet --noout --xinclude --postvalid
111 lint: $(SOURCE).xml
112 xmllint $(XMLLINTOPTS) $^
113 lint-es: $(SOURCE).nb.xml
114 xmllint $(XMLLINTOPTS) $^
115 lint-nb: $(SOURCE).nb.xml
116 xmllint $(XMLLINTOPTS) $^
117
118 check-urls:
119 retval=0; for u in $$(perl -n -e'/<ulink url="(.+)"\/>/ && print "$$1\n"' MadewithCreativeCommonsmostup-to-dateversion.xml | sort -u); do \
120 HEAD -H "User-Agent: Docbook XML URL checker" "$$u" > /dev/null || echo "error fetching $$u"; retval=1; \
121 done; exit $$retval
122
123 # Experimental build rule to test Docbook XSL + FOP processor
124 xsl-fo-%.pdf: %.xml
125 xsltproc --output $(subst .pdf,.fo,$@) \
126 extra/stylesheet-fo.xsl $^; \
127 fop -fo $(subst .pdf,.fo,$@) -pdf $@
128
129 status:
130 for LANG in $(LANGS); do \
131 printf "$$LANG "; msgfmt -o /dev/null --statistics po/$$LANG/mwcc.po; \
132 done
133
134 .SUFFIXES: .xml .md