]> pere.pagekite.me Git - text-madewithcc.git/blob - Makefile
Ask pandoc to create standalone docbook.
[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 TITLE="Hecho con Creative Commons"
14 TEXLANG=spanish
15 TEXLANGCODE=es
16
17 #TITLE="Laget med Creative Commons"
18 #TEXLANG=norsk
19 #TEXLANGCODE=nb
20
21 # pandoc version 1.17.2~dfsg-3 do not understand
22 # --top-level-diversion, while version 1.19.2.4~dfsg-1+b3 do.
23 PANDOC_OPTS = \
24 --standalone \
25 --top-level-division=part \
26 -t docbook \
27 -f markdown+inline_notes+ascii_identifiers \
28 --variable 'author:Paul Stacey' --variable 'author:Sarah Hinchliff Pearson' \
29 --variable 'title:$(TITLE)'
30
31 LANGS := $(shell ls po/*/mwcc.po|cut -d/ -f2)
32
33 all: pdf epub
34
35 distclean: clean
36 rm -f $(SOURCE).md
37 for LANG in $(LANGS); do \
38 rm -f $(SOURCE).$$LANG.md ;\
39 done
40 clean:
41 for EXT in aux cb cb2 glo idx lof log tex toc xml pdf; do \
42 rm -f $(SOURCE).$$EXT ;\
43 for LANG in $(LANGS); do \
44 rm -f $(SOURCE).$$LANG.$$EXT ;\
45 done; \
46 done
47
48 $(SOURCE).md: $(SOURCE).odt fixup.rb
49 TEMP=`tempfile -p mwcc` && \
50 pandoc -f odt $(SOURCE).odt -t markdown > $$TEMP && \
51 ruby fixup.rb $$TEMP $(SOURCE).md && \
52 rm $$TEMP
53
54 pot: po/mwcc.pot po/*/mwcc.po
55 po/mwcc.pot: $(SOURCE).md
56 TEMP=`tempfile -p mwcc` && \
57 po4a-gettextize -f text -m $(SOURCE).md -p $$TEMP -M utf-8 --package-name 'Made with Creative Commons' --package-version $(VERSION) && \
58 echo '# MADE WITH CREATIVE COMMONS' > $@ && \
59 echo '# Copyright (C) 2017 by Creative Commons.' >> $@ && \
60 echo '# This file is published under a Creative Commons Attribution-ShareAlike license (CC BY-SA), version 4.0' >> $@ && \
61 echo '# Authors: Paul Stacey and Sarah Hinchliff Pearson' >> $@ && \
62 tail --lines=+5 $$TEMP >> $@ && \
63 rm $$TEMP
64 set -e; for LANG in po/*/mwcc.po; do \
65 echo -n $$LANG\ ; \
66 msgmerge $$LANG po/mwcc.pot -U ; \
67 done
68
69 $(SOURCE).es.md: $(SOURCE).md po/es/mwcc.po
70 po4a-translate -f text -m $(SOURCE).md -p po/es/mwcc.po -l $@ -l $@ -L utf8 -M utf8 -k 0
71
72 $(SOURCE).nb.md: $(SOURCE).md po/nb/mwcc.po
73 po4a-translate -f text -m $(SOURCE).md -p po/nb/mwcc.po -l $@ -l $@ -L utf8 -M utf8 -k 0
74
75 %.xml: %.md
76 pandoc -s -o $@ $(PANDOC_OPTS) $^
77 perl -p -i -e 's/!DOCTYPE article/!DOCTYPE book/ ; \
78 s!<(/?)article(info|)?>!<$$1book$$2>!' $@
79
80 pdf: $(SOURCE).pdf
81 %.pdf: %.tex
82 pdflatex $^
83 pdflatex $^
84
85 epub: $(SOURCE).epub
86 %.epub: %.xml
87 dbtoepub $^
88
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/\\setcounter\{tocdepth\}.*/\\setcounter{tocdepth}{1}/; \
93 s/\\setcounter\{secnumdepth\}.*/\\setcounter{secnumdepth}{-1}/; \
94 s/\\caption\\end/\\caption{} \\end/; \
95 s!\\maketitle!\\input{extra/$(TEXLANGCODE)/cover.tex}!; \
96 s/\\author\{and\}/\\author{Paul Stacey \\and Sarah Hinchliff Pearson}/; \
97 s/\\DBKinditem\{\\writtenby\}\{and\}/\\DBKinditem{\writtenby}{Paul Stacey and Sarah Hinchliff Pearson}/; \
98 s/\\listoffigures//; \
99 s/\\part\{(Foreword|Prefacio|Introduction|Introducción)\}/\\chapter*{$$1} \\addcontentsline{toc}{chapter}{$$1}/; \
100 s/\\section\{(Notes|Notas)\}/\\section*{$$1}/; \
101 s/(Web links?|Vínculos Web)/\\section*{$$1}/; \
102 s/^\s*(Revenue model|Interview date|Interviewees?|(Modelo de ingresos|Fecha de la entrevista|Entrevistad(?:o|a|os|as)))/\\textbf{$$1}/;' $@
103 perl -p -i -e '$$work=1 if /chapter.Arduino/; $$work=0 if /chapter.(Bibliography|Bibliografía)/; \
104 next unless $$work; \
105 s/(\\label\{[-\.\wáéíóúñ]+\}\\hyperlabel\{[-\.\wáéíóúñ]+\}%)/$$1\n\\begin{quote}/i; \
106 s/(Profile written by.+|Perfil escrito por.+|Profilen skrevet av.+)/$$1\n\\end{quote}/' $@
107
108 XMLLINTOPTS = --nonet --noout --xinclude --postvalid
109 lint: $(SOURCE).xml
110 xmllint $(XMLLINTOPTS) $^
111 lint-es: $(SOURCE).nb.xml
112 xmllint $(XMLLINTOPTS) $^
113 lint-nb: $(SOURCE).nb.xml
114 xmllint $(XMLLINTOPTS) $^
115
116 status:
117 for LANG in $(LANGS); do \
118 printf "$$LANG "; msgfmt -o /dev/null --statistics po/$$LANG/mwcc.po; \
119 done
120
121 .SUFFIXES: .xml .md