summaryrefslogtreecommitdiff
path: root/Makefile
blob: 13ba6c66161733a7f638b98ea4f5e1a768a60a2a (plain)
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# Build rules for Debian Policy.
#
# This is not completely standalone and independent of the Debian packaging
# in that it uses debian/changelog to get the version number and release
# date for incorporation into other documents.  Except for that, however,
# the design goal of these build rules is to build the Policy documents
# independent of their Debian packaging in the debian directory.

# Basic package information.
PACKAGE   := $(shell dpkg-parsechangelog -SSource)
TIMESTAMP := $(shell dpkg-parsechangelog -STimestamp)
DATE      := $(shell date -d '@$(TIMESTAMP)' +'%Y-%m-%d')
VERSION   := $(shell dpkg-parsechangelog -SVersion)

# Conversion programs to use.  Export these so that they're visible to
# submakes.
export DBLATEX  = dblatex -p xsl/dblatex.xsl
export MDWN     = multimarkdown
export XMLLINT  = xmllint --nonet --noout --postvalid --xinclude
export XSLTPROC = xsltproc --nonet --xinclude
export DIA      = dia

# Installation directories.  Normally this is only used by debian/rules
# build, which will set DESTDIR to put the installation under the temporary
# Debian packaging directory.
prefix      = /usr
datarootdir = $(prefix)/share
datadir     = $(datarootdir)
docdir      = $(datadir)/doc/$(PACKAGE)

# Installation programs to use.
INSTALL = install -p -o root -g root -m 644
MKDIR   = install -d -o root -g root -m 755

# Files included by debconf_specification.xml.
DEBCONF_INCLUDES := debconf/commands.xml debconf/priorities.xml	\
	            debconf/statuscodes.xml debconf/types.xml

# doc-base description files for the documents we include.
DESC_FILES  := autopkgtest copyright-format-1.0 debconf-spec debian-policy \
	       debian-menu-policy debian-perl-policy fhs

# Our local copy of the File Hierarchy Standard.  We don't build this from
# source, but we do have a copy of the source in FHS_ARCHIVE.
FHS_ARCHIVE := fhs-2.3-source.tar.gz
FHS_FILES   := fhs-2.3.html fhs-2.3.ps.gz fhs-2.3.txt.gz fhs-2.3.pdf.gz

# Markdown source files in the top-level directory.  We generate text and
# HTML versions from these.
MDWN_FILES  := README autopkgtest

# Dia diagrams in the dia/ subdirectory.
DIA_FILES   := install.dia install-conffiles.dia upgrade.dia \
               remove.dia purge.dia remove-purge.dia

# Dia diagrams converted to PNG in img/ subdirectory.
DIA_PNGS    := $(addprefix img/, $(DIA_FILES:.dia=.png))

# Dia diagrams converted to PNG in img/ subdirectory.
DIA_SVGS    := $(addprefix img/, $(DIA_FILES:.dia=.svg))

# DocBook source files in the top-level directory.  We do some common actions
# with each of these: build text, HTML, and one-page HTML output.
XML_FILES   := menu-policy perl-policy policy

# DocBook source files in the top-level directory that should only generate
# single-page HTML output (no split HTML output).
XML_SINGLE_FILES := copyright-format-1.0 debconf_specification

# The upgrading-checklist used to be a document of its own, which was merged
# with the conversion to DocBook. Keep backwards compatibility files.
XML_SPLIT_FILES := upgrading-checklist

# XML document version files.  These are generated at build time from the
# current version and date information from the Debian changelog.
XML_VERSION := copyright-format/version.xml debconf_spec/include/version.xml \
	       version.xml

# A list of the simple Policy files that we build at the top level and in
# subdirectories and include in the documentation directory of the generated
# package.  The directories of HTML output are handled separately.
POLICY_FILES := $(MDWN_FILES:=.html)		\
		$(MDWN_FILES:=.txt)		\
		$(XML_FILES:=-1.html)		\
		$(XML_FILES:=.txt)		\
		$(XML_SINGLE_FILES:=.html)	\
		$(XML_SINGLE_FILES:=.txt)	\
		$(XML_SPLIT_FILES:=-1.html)	\
		$(XML_SPLIT_FILES:=.txt)	\
		README.css			\
		policy.ps policy.pdf		\
		virtual-package-names-list.txt

# Used by the clean rules.  FILES_TO_CLEAN are individual generated files to
# remove.  DIRS_TO_CLEAN are entire directories to remove.
DIRS_TO_CLEAN  := $(XML_FILES:=.html) fhs
FILES_TO_CLEAN := $(MDWN_FILES:=.html)			\
		  $(MDWN_FILES:=.txt)			\
		  $(XML_FILES:=.html.tar.gz)		\
		  $(XML_FILES:=-1.html)			\
		  $(XML_FILES:=.txt)			\
		  $(XML_FILES:=.validate)		\
		  $(XML_SINGLE_FILES:=.html)		\
		  $(XML_SINGLE_FILES:=.txt)		\
		  $(XML_SINGLE_FILES:=.validate)	\
		  $(XML_SPLIT_FILES:=-1.html)		\
		  $(XML_SPLIT_FILES:=.txt)		\
		  $(DIA_PNGS)				\
		  $(DIA_SVGS)				\
		  version.md version.xml		\
		  policy.pdf policy.ps


#
# General build targets.  These are the ones a human may build from the
# command line, or that are used by the Debian build system.
#

all: $(XML_FILES:=.validate) $(XML_SINGLE_FILES:=.validate) \
     $(XML_FILES:=.html.tar.gz) $(POLICY_FILES)

clean distclean:
	rm -f $(FILES_TO_CLEAN)
	rm -rf $(DIRS_TO_CLEAN)

install:
	$(MKDIR) $(DESTDIR)$(docdir)
	$(MKDIR) $(DESTDIR)$(docdir)/fhs
	$(INSTALL) $(POLICY_FILES) $(DESTDIR)$(docdir)
	$(INSTALL) $(FHS_FILES)    $(DESTDIR)$(docdir)/fhs
	@set -ex; for file in $(XML_FILES); do		\
	    tar -C $(DESTDIR)$(docdir) -zxf $$file.html.tar.gz;	\
	done

.PHONY: all clean distclean install


#
# Version files.  These incorporate the version and release date of the
# debian-policy package into the various specifications as their version and
# publication date.
#

version.md: debian/changelog
	rm -f $@
	echo					 > $@
	echo '---'				 >> $@
	echo 'Debian Policy $(VERSION), $(DATE)' >> $@

version.xml: debian/changelog
	rm -f $@
	echo '<?xml version="1.0" encoding="utf-8"?>' > $@
	echo '<!ENTITY version "$(VERSION)">'	     >> $@
	echo '<!ENTITY date    "$(DATE)">'	     >> $@


#
# Individual file and pattern build rules.
#

# There doesn't seem to be a better way of adding this include dependency.
debconf_specification.html: $(DEBCONF_INCLUDES)
debconf_specification.txt: $(DEBCONF_INCLUDES)
debconf_specification.validate: $(DEBCONF_INCLUDES)
policy-1.html: upgrading-checklist.xml
policy.html/index.html: upgrading-checklist.xml
policy.pdf: upgrading-checklist.xml
policy.ps: upgrading-checklist.xml
policy.txt: upgrading-checklist.xml
policy.validate: upgrading-checklist.xml

policy.html/index.html: $(PNG_FILES)

$(MDWN_FILES:=.txt): %.txt: %.md version.md
	cat $^ > $@
	test "$@" != "README.txt"  ||				\
           perl -pli -e 's,./Process.md,Process.txt,g' $@

$(MDWN_FILES:=.html): %.html: %.md version.md
	cat $^ | $(MDWN) > $@

$(DIA_PNGS): img/%.png: dia/%.dia
	$(DIA) -e $@ $^

$(DIA_SVGS): img/%.svg: dia/%.dia
	$(DIA) -e $@ $^

# Suppress the table of contents for the standalone upgrading checklist.
upgrading-checklist-1.html: XSLPARAMS = --stringparam generate.toc ''
upgrading-checklist.txt: XSLPARAMS = --stringparam generate.toc ''

%.validate: %.xml version.xml
	$(XMLLINT) $<
	touch $@

%.html/index.html: %.xml xsl/html-chunk.xsl version.xml
	mkdir -p $(@D)
	$(XSLTPROC) $(XSLPARAMS)		\
	    --stringparam base.dir $(@D)/	\
	    xsl/html-chunk.xsl $<

$(XML_SINGLE_FILES:=.html): %.html: %.xml xsl/html-single.xsl version.xml
	$(XSLTPROC) $(XSLPARAMS) xsl/html-single.xsl $< > $@

%-1.html: %.xml xsl/html-single.xsl version.xml
	$(XSLTPROC) $(XSLPARAMS) xsl/html-single.xsl $< > $@

%.html.tar.gz: %.html/index.html
	tar -czf $(<:/index.html=.tar.gz) $(<:/index.html=)

$(XML_FILES:=.txt) $(XML_SINGLE_FILES:=.txt) $(XML_SPLIT_FILES:=.txt): \
%.txt: %.xml version.xml
	$(XSLTPROC) $(XSLPARAMS) xsl/text.xsl $< > $@.html
	links -codepage utf-8 -dump $@.html | perl -pe 's/[\r\0]//g' > $@
	rm -f $@.html

%.ps: %.xml version.xml
	$(DBLATEX) --ps $<

%.pdf: %.xml version.xml
	$(DBLATEX) --pdf $<


#
# GNU make configuration.
#

# If a rule bombs out, delete the target.
.DELETE_ON_ERROR:

# No default suffixes work here, don't waste time on them.
.SUFFIXES: