File: Makefile

package info (click to toggle)
freedombox 26.5
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 83,716 kB
  • sloc: python: 49,258; javascript: 1,772; xml: 481; makefile: 297; sh: 144; php: 32
file content (133 lines) | stat: -rw-r--r-- 5,335 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/make -f
# SPDX-License-Identifier: AGPL-3.0-or-later

MANUAL_LANGUAGES=en es

MANUAL_URL="https://wiki.debian.org/{lang-fragment}FreedomBox/Manual?action=show&mimetype=text%2Fdocbook"
MANUAL_URL_RAW="https://wiki.debian.org/{lang-fragment}FreedomBox/Manual?action=raw"
MANUAL_PAGE_URL_RAW="https://wiki.debian.org/{page}?action=raw"

INSTALL_DIR=$(DESTDIR)/usr/share/freedombox
MAN_INSTALL_DIR=$(DESTDIR)/usr/share/man
SCRIPTS_DIR=scripts

manual-pdfs=$(foreach lang,$(MANUAL_LANGUAGES),manual/$(lang)/freedombox-manual.pdf)
manual-xmls=$(patsubst %.pdf,%.xml,$(manual-pdfs))
OUTPUTS=$(manual-pdfs) plinth.1 freedombox-cmd.1

INSTALL_OPTS=-D --mode=644

# In order to debug various problems with the documents especially
# intermediate LaTeX state, run make as follows:
#
#   $ make DEBUG=true
#   or
#   $ make DEBUG=true <target>
#
XMLTO_DEBUG_FLAGS=
ifneq ($(DEBUG),)
	XMLTO_DEBUG_FLAGS=--noclean -p '--debug'
endif

.PHONY: all install
all: $(OUTPUTS) manual-pages

install: all
	install $(INSTALL_OPTS) -t $(MAN_INSTALL_DIR)/man1 plinth.1
	for file in $(manual-pages-part-html) $(manual-pdfs); do \
		install $(INSTALL_OPTS) -t $(INSTALL_DIR)/$$(dirname $${file}) \
			$${file} ; \
	done
	for lang in $(MANUAL_LANGUAGES); do \
		install $(INSTALL_OPTS) manual/$${lang}/images/*.png \
			manual/$${lang}/images/*.jpg \
			-t $(INSTALL_DIR)/manual/$${lang}/images ; \
	done

# Do not edit the manual page in this directory.  The manual is
# maintained as separate pages on the FreedomBox wiki and aggregated
# into a single page using the MoinMoin include feature.  Then it is
# exported as Docbook format and kept here.
#
# It is important to keep a copy of the manual in this source tree
# because Debian packages promise an entire source tree including the
# documentation.
#
# Use 'make fetch' to retrieve the latest manual from the wiki and
# commit it to the repository.  The wiki page is already reviewed, so
# commits that update the manual just using the 'fetch' target do not
# require further reviews.
fetch-main-list:=$(foreach lang,$(MANUAL_LANGUAGES),fetch-main-$(lang))
fetch-pages-list:=$(foreach lang,$(MANUAL_LANGUAGES),fetch-pages-$(lang))
fetch-cleanup-list:=$(foreach lang,$(MANUAL_LANGUAGES),fetch-cleanup-$(lang))

.PHONY: fetch $(fetch-main-list) $(fetch-pages-list) $(fetch-cleanup-list)
fetch: $(fetch-main-list) $(fetch-pages-list)

# Remove raw wiki pages and images before fetching to drop items deleted
# upstream.
fetch-cleanup-%: lang = $*
$(fetch-cleanup-list): fetch-cleanup-%:
	rm -f manual/$(lang)/*.raw.wiki
	rm -f manual/$(lang)/images/*.png manual/$(lang)/images/*.jpg

fetch-main-%: lang = $*
fetch-main-%: lang-fragment = $(subst en/,,$*/)
$(fetch-main-list): fetch-main-%: fetch-cleanup-%
	MANUAL_URL_RAW_LANG=$(subst {lang-fragment},$(lang-fragment),$(MANUAL_URL_RAW)) ; \
	wget --quiet --user-agent=Firefox \
	  -O manual/$(lang)/freedombox-manual.raw.wiki $${MANUAL_URL_RAW_LANG}
	MANUAL_URL_LANG=$(subst {lang-fragment},$(lang-fragment),$(MANUAL_URL)) ; \
	wget --quiet --user-agent=Firefox -O - $${MANUAL_URL_LANG} | \
	  xmllint --format --output manual/$(lang)/freedombox-manual.raw.xml -
	mkdir -p manual/$(lang)/images/
	xsltproc $(SCRIPTS_DIR)/fetch-images.xslt manual/$(lang)/freedombox-manual.raw.xml | \
	  sort -u | \
	  awk 'NF {print "wget --quiet -O manual/$(lang)/images/" $$1 " " $$2}' | \
	  sh -e
	rm manual/$(lang)/freedombox-manual.raw.xml

fetch-pages-%: lang = $*
fetch-pages-%: lang-fragment = $(subst en/,,$*/)
$(fetch-pages-list): fetch-pages-%: fetch-cleanup-%
	MANUAL_URL_LANG=$(subst {lang-fragment},$(lang-fragment),$(MANUAL_URL_RAW)) ; \
	PAGES=$$(wget --quiet --user-agent=Firefox -O - $${MANUAL_URL_LANG} | \
	  sed -n -e "s|.*<<Include(\([a-zA-Z0-9_/+-]*\),.*|\1|p" | sort -u) ; \
	for PAGE in $${PAGES} ; do \
	  PAGE_NAME=$$(basename $${PAGE}) ; \
	  echo "Downloading $(lang) $${PAGE}" ; \
	  RAW_FILE="manual/$(lang)/$${PAGE_NAME}.raw.wiki" ; \
	  RAW_URL=$$(echo $(MANUAL_PAGE_URL_RAW) | sed "s|{page}|$${PAGE}|") ; \
	  wget --quiet --user-agent=Firefox -O $${RAW_FILE} $${RAW_URL} ; \
	done

manual-pages-raw-wiki:=$(foreach lang,$(MANUAL_LANGUAGES),$(filter-out manual/%/freedombox-manual.raw.wiki,$(wildcard manual/$(lang)/*.raw.wiki)))
manual-pages-part-html:=$(patsubst %.raw.wiki, %.part.html, $(manual-pages-raw-wiki)) $(foreach lang,$(MANUAL_LANGUAGES),manual/$(lang)/freedombox-manual.part.html)
manual-pages-xml:=$(patsubst %.raw.wiki, %.xml, $(manual-pages-raw-wiki))

.PHONY: manual-pages
manual-pages: $(manual-pages-part-html)

$(manual-pdfs): %.pdf: %.xml
	@echo "[PDF]       $<"
	@xmlto $(XMLTO_DEBUG_FLAGS) --with-dblatex pdf -o $(dir $@) $< 2> /dev/null

$(manual-pages-part-html): %.part.html: %.xml
	@echo "[XSLT]      $<"
	@xsltproc /usr/share/xml/docbook/stylesheet/docbook-xsl/xhtml5/docbook.xsl $< 2> /dev/null | \
	perl -pe 'BEGIN {undef $$/} s/.*<body[^>]*>(.*)<\/body\s*>.*/$$1/si' > $@
	@rm -f docbook.css

$(manual-xmls) $(manual-pages-xml): %.xml: %.raw.wiki $(SCRIPTS_DIR)/wikiparser.py
	@echo "[WIKIPARSE] $<"
	@$(SCRIPTS_DIR)/wikiparser.py $< | xmllint --format - > $@

%.1: %.xml
	@echo "[MAN]       $<"
	@xmlto man $< 2> /dev/null

.PHONY: clean
clean:
	@echo "[RM]        {part-htmls} {xmls} {manuals} {outputs}"
	@rm -f $(manual-pages-part-html) $(manual-pages-xml) $(manual-xmls)
	@rm -f $(OUTPUTS)