summaryrefslogtreecommitdiffstats
path: root/Makefile.common
blob: ad341b5318daba44fe51b4da0aa3a6fcc4e53dbc (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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
#########################################################################
# Makefile.common
#
# This file, to be included from every document's local Makefile, provides
# the basic targets used by the Fedora Docs Project:
# all			-- Default target, builds HTML document only
# ${DOCNAME}/index.html	-- Builds HTML version of document
# html			-- See "${DOCNAME}/index.html"
# html-nochunks		-- See "${DOCNAME}.html"; single HTML file
# ${DOCNAME}.tar.gz	-- Packages HTML document into a tar archive
# tarball		-- See "${DOCNAME}.tar.gz"
# clean			-- Deletes all generated files and directories
# distclean		-- See "clean"
# ${DOCNAME}.pdf	-- Builds PDF version of document
# pdf			-- See "${DOCNAME}.pdf"
#########################################################################
# PDF generation is still fragile and probably won't work on your document.
# Yet.
#########################################################################
# Note: all targets within this Makefile.common must be defined as 
# double-colon (::) targets so that additional steps can be added by
# providing additional rules, also marked with double-colons, in the
# document Makefile.
#########################################################################
# N.B.: Don't use "$@" in a template.  It doesn't work.  I tried ;-(
#########################################################################
# Allow client document to provide "Make.paths" file to locate our files
# This is a "silent include", so if it's missing there is no problem.
# This file, if present, must be in the DOCUMENT directory, not here in
# docs-common.  Even if this file is present, defining FTPDIR via the
# command line will take precedence.
sinclude Make.paths
#########################################################################
# Supply default values for the boilerplate files _unless_ the user has
# provided their own values.
ifeq	"${FDPDIR}" ""
FDPDIR	         = $(PWD)/..
endif
ifeq	"${FDPBIN}" ""
FDPBIN	         = ${FDPDIR}/docs-common/bin
endif
ifeq	"${XSLPDF}" ""
XSLPDF		= ${FDPDIR}/docs-common/xsl/main-pdf.xsl
endif
ifeq	"${XSLHTML}" ""
XSLHTML        	= ${FDPDIR}/docs-common/xsl/main-html.xsl
endif
ifeq	"${XSLHTMLNOCHUNKS}" ""
XSLHTMLNOCHUNKS	= ${FDPDIR}/docs-common/xsl/main-html-nochunks.xsl
endif
ifeq	"${HTMLCSS}" ""
HTMLCSS		= ${FDPDIR}/docs-common/css/fedora-draft.css
endif
ifeq	"${DRAFT}" ""
DRAFT	= yes
endif
ifeq	"${PRI_LANG}" ""
PRI_LANG= en
endif
ifeq	"${RPMINFO}" ""
# Don't panic, we need this only to get the latest RPM package version
# All other rpm-info usages are driven by XSLT scripts.
RPMINFO		= ${PWD}/${PRI_LANG}/rpm-info-${PRI_LANG}.xml
endif
ifeq	"${RPMPREP}" ""
RPMPREP=yes
endif
ifeq	"${RPMPOST}" ""
RPMPOST=yes
endif
#########################################################################
# Define a macro to locate xmlto(1) so we can choose a specific version
# by "make XMLTO=/path/to/xmlto", if we so desire.
XMLTO	=xmlto
# Let's also do this for xsltproc(1).
XSLTPROC=xsltproc
XMLFORMAT=xmlformat
XMLFOPTS=-f $(FDPDIR)/docs-common/bin/xmlformat-fdp.conf
XML2PO	=xml2po
#########################################################################
# Rules to produce .po files from .xml files.  Get the tools to do this
# from the gnome-doc-utils RPM.
.SUFFIXES: .po .xml
%.po:	%.xml
	${XML2PO} $< >$@
#########################################################################
# Use our very own "docs-common/bin/fdpsh" as the command interpreter
# This automatically has ${FDPBIN} as first in the ${PATH}
SHELL	=${FDPBIN}/fdpsh
#########################################################################
VERSION:=$(shell version doc)
RELEASE:=$(shell version rpm)
PWD	:=$(shell /bin/pwd)
#########################################################################
RPMFLAGS=--define "docbase $(DOCBASE)" 					\
	 --define "_topdir $(PWD)/rpm" 					\
	 --define "fdpdir $(FDPDIR)"

SPECFILE=fedora-doc-$(DOCBASE).spec

ifeq	"${RPMDEBUG}" "1"
RPMDFLAG	= -vv
endif
#########################################################################
# Set a provisional ${LANG} value.  We'll dynamically change this as 
# needed.  The "en" value is used because that is the original language
# of most of our current documentation.
LANG	=en
#########################################################################
# PUT NO TARGETS BEFORE THIS ONE, not even in your base Makefile
# In a properly-constructed Makefile, this will be the default target

TARGETS=all clean distclean fdp-info html html-nochunks pdf po showvars \
        tarball rpm rpm-common noarch srpm package-prep package-post	\
	src-tarball
.PHONY:	${TARGETS}
.PHONY:	$(foreach LANG,${LANGUAGES},html-${LANG})
.PHONY:	$(foreach LANG,${LANGUAGES},html-nochunks-${LANG})
.PHONY:	$(foreach LANG,${LANGUAGES},pdf-${LANG})

all::	html html-nochunks tarball # pdf

${TARGETS}::

#########################################################################
# For each LANG in LANGUAGES, generate a target and rule similar to:
# mydoc-en/index.html:: mydoc-en.xml ${XMLEXTRAFILES}-en
#  LANG=en.UTF-8 ${XMLTO} html -x $(XSLHTML) -o mydoc-en mydoc-en.xml
#  mkdir -p mydoc-en/stylesheet-images
#  cp ${FDPDIR}/docs-common/stylesheet-images/*.png mydoc-en/stylesheet-images/
#  cp ${HTMLCSS} mydoc-en/fedora.css
#  cp ${HTMLCSSEXTRA} mydoc-en/watermark.png
#  cp ${FDPDIR}/docs-common/images/watermark.png mydoc-en/
#  ${FDPDIR}/docs-common/bin/copy-figs -f '*.png' figs mydoc-en/
# but we do avoid copying EPS files since they are nonsense to the HTML world.
#
define	HTML_template
html-$(1) ${DOCBASE}-$(1)/index.html:: $(1)/${DOCBASE}-$(1).xml $$(XMLEXTRAFILES-$(1)) $(1)/fdp-info-$(1).xml
	LANG=$(1).UTF-8 ${XMLTO} html -x $(XSLHTML) -o $(DOCBASE)-$(1) $(1)/$(DOCBASE)-$(1).xml
	mkdir -p $(DOCBASE)-$(1)/stylesheet-images/
	cp ${FDPDIR}/docs-common/stylesheet-images/*.png $(DOCBASE)-$(1)/stylesheet-images
	cp ${HTMLCSS} $(DOCBASE)-$(1)/fedora.css
ifeq	"${DRAFT}" "yes"
	cp ${FDPDIR}/docs-common/images/watermark-$(1).png $(DOCBASE)-$(1)/watermark.png
endif
	[ ! -d figs ] || copy-figs -v -f '*.png' 			\
				-l $(1) figs $(DOCBASE)-$(1)
endef
#
$(foreach LANG,${LANGUAGES},$(eval $(call HTML_template,${LANG})))

html::	$(foreach LANG,${LANGUAGES},html-${LANG})
#
#########################################################################
# For each language in ${LANGUAGES}, generate a single HTML file
define	HTMLNOCHUNK_template
html-nochunks-$(1) ${DOCBASE}-$(1).html::	$(1)/${DOCBASE}-$(1).xml $$(XMLEXTRAFILES-$(1)) $(1)/fdp-info-$(1).xml
	${XMLTO} html-nochunks -x $(XSLHTMLNOCHUNKS) $(1)/$(DOCBASE)-$(1).xml
	mkdir -p stylesheet-images/
	cp ${FDPDIR}/docs-common/stylesheet-images/*.png stylesheet-images/
	cp ${HTMLCSS} fedora.css
	[ -z "${HTMLCSSEXTRA}" ] || 					\
		cp ${HTMLCSSEXTRA} watermark.png
endef
#
$(foreach LANG,${LANGUAGES},$(eval $(call HTMLNOCHUNK_template,${LANG})))

html-nochunks::	$(foreach LANG,${LANGUAGES},html-nochunks-$(LANG))
#
#########################################################################
# For each language in ${LANGUAGES}, build a tarball of the HTML and
# image files.  Any ".eps" files are ignored.
#
define	HTMLTAR_template
${DOCBASE}-$(1).tar.gz:: ${DOCBASE}-$(1)/index.html
	tar -zc --exclude '*.eps' -f ${DOCBASE}-$(1).tar.gz ${DOCBASE}-$(1)
endef
#
tarball::	$(foreach LANG,${LANGUAGES},$(DOCBASE)-$(LANG).tar.gz)

$(foreach LANG,${LANGUAGES},$(eval $(call HTMLTAR_template,${LANG})))
#
#########################################################################
# For each language in ${LANGUAGES}, generate an Adobe Portable Document
# Format (PDF) file.
define	PDF_template
pdf-$(1) ${DOCBASE}-$(1).pdf:: $(1)/${DOCBASE}-$(1).xml $$(XMLEXTRAFILES-$(1))
	${XMLTO} pdf -x $(XSLPDF) $(1)/$(DOCBASE)-$(1).xml
endef
#
$(foreach LANG,${LANGUAGES},$(eval $(call PDF_template,${LANG})))

pdf::	$(foreach LANG,${LANGUAGES},pdf-$(LANG))
#
#########################################################################
# For each language in ${LANGUAGES}, clean up!
define	CLEAN_template
${DOCBASE}-$(1)-clean::
	${RM} $(1)/fdp-info-$(1).xml
endef
#
$(foreach LANG,${LANGUAGES},$(eval $(call CLEAN_template,${LANG})))
#
clean:: $(foreach LANG,${LANGUAGES},${DOCBASE}-${LANG}-clean)
	${RM} *.tmp
#########################################################################
define	DISTCLEAN_template
${DOCBASE}-$(1)-distclean:: ${DOCBASE}-$(1)-clean
	${RM} -r ${DOCBASE}-$(1)
	${RM} -r ${DOCBASE}-$(1).html stylesheet-images
	${RM} -r ${DOCBASE}-$(1).pdf
	${RM} -r ${DOCBASE}-$(1).tar.gz
	${RM} *-$(1).omf
	${RM} *-$(1).desktop
	${RM} fedora.css watermark-${LANG}.png watermark.png
	${RM} $(1)/*.po
endef
#
$(foreach LANG,${LANGUAGES},$(eval $(call DISTCLEAN_template,${LANG})))
#
distclean:: $(foreach LANG,${LANGUAGES},${DOCBASE}-${LANG}-distclean)
#########################################################################
# Target "po" produces ".po" files from the manifested XML files for
# the current language.
POFILES	=${LANG}/${DOCBASE}-${LANG}.po ${XMLEXTRAFILES-${LANG}:.xml=.po}
po::	${POFILES}
#########################################################################
#
showvars::
	@echo "DOCBASE=\"$(DOCBASE)\""
	@echo "LANGUAGES=\"$(LANGUAGES)\""
#
#########################################################################
# Show differences between two file revisions. To use this tool:
# 	$ make OLD=old.xml NEW=new.xml diff
# The ${DIFFS} macro can select a different output format:
# 	$ make DIFFS=-C OLD=old.xml NEW=new.xml diff

OLD	=define-me-old.xml
NEW	=define-me-new.xml
DIFFS	=-u

diff::
	xmldiff ${DIFFS} ${OLD} ${NEW}
#
#########################################################################
# The "fdp-info-${LANG}.xml" file contains the <articleinfo> or 
# <bookinfo> stanza.  It is automatically generated from data in the
# "rpm-info.xml" file whenever that file changes.
#
define fdp-info_template
$(1)/fdp-info-$(1).xml::	$(RPMINFO)
	${XSLTPROC} --stringparam lang $(1)				\
		--stringparam fdpdir $(FDPDIR)				\
		--stringparam doctype $(shell				\
			doctype $(1)/$(DOCBASE)-$(1).xml		\
		) ${FDPDIR}/docs-common/packaging/bookinfo.xsl 		\
		$(RPMINFO) 					| 	\
	$(XMLFORMAT) $(XMLFOPTS) > $(1)/fdp-info-$(1).xml.tmp	&&	\
	move-if-change $(1)/fdp-info-$(1).xml.tmp $(1)/fdp-info-$(1).xml
endef
#
$(foreach LANG,${LANGUAGES},$(eval $(call fdp-info_template,${LANG})))
#
fdp-info::  $(foreach LANG,${LANGUAGES},$(LANG)/fdp-info-$(LANG).xml)
#
#########################################################################
# Make a new changelog entry for an existing rpm-info.xml file.

clog:: $(RPMINFO)
	insert-changelog $(RPMINFO).tmp && 	\
		move-if-change $(RPMINFO).tmp $(RPMINFO)

#
#########################################################################
# Make a new colophon entry for an existing rpm-info.xml file.

colophon:: $(RPMINFO)
	insert-colophon $(RPMINFO).tmp && 	\
		move-if-change $(RPMINFO).tmp $(RPMINFO)

#
#########################################################################
# End of Makefile.common
#########################################################################


clean::
	${RM} $(DOCBASE)-$(VERSION)*.src.tar.gz
	${RM} -r $(DOCBASE)-$(VERSION)/
	${RM} *.omf *.desktop $(SPECFILE)
	${RM} *~

distclean::
	${RM} -r rpm
	${RM} fedora-doc-$(DOCBASE)*.rpm
	${RM} fedora-doc-$(DOCBASE)*.omf
	${RM} fedora-doc-$(DOCBASE)*.desktop
	${RM} fedora-doc-$(DOCBASE)*.spec
	${RM} $(DOCBASE)*.src.tar.gz

spec::	${SPECFILE}

${SPECFILE}::	${RPMINFO}
	$(XSLTPROC) --stringparam docbase "${DOCBASE}"			\
		${FDPDIR}/docs-common/packaging/spec.xsl ${RPMINFO}	\
		>$@.tmp && move-if-change $@.tmp $@


gnome.desktop::	fedora-doc-${DOCBASE}-gnome.desktop

fedora-doc-${DOCBASE}-gnome.desktop:: ${RPMINFO}
	$(XSLTPROC) --stringparam docbase "${DOCBASE}"			\
		${FDPDIR}/docs-common/packaging/gnome-desktop.xsl	\
		${RPMINFO} >$@.tmp && move-if-change $@.tmp $@

kde.desktop::	fedora-doc-${DOCBASE}-kde.desktop

fedora-doc-${DOCBASE}-kde.desktop:: ${RPMINFO}
	$(XSLTPROC) --stringparam docbase "${DOCBASE}"			\
		${FDPDIR}/docs-common/packaging/kde-desktop.xsl 	\
		${RPMINFO} >$@.tmp && move-if-change $@.tmp $@

khelp.desktop::		fedora-doc-${DOCBASE}-khelp.desktop

fedora-doc-${DOCBASE}-khelp.desktop:: ${RPMINFO}
	$(XSLTPROC) --stringparam docbase "${DOCBASE}"			\
		${FDPDIR}/docs-common/packaging/khelpcenter-plugin.xsl 	\
		${RPMINFO} >$@.tmp && move-if-change $@.tmp $@


define omf_template
omf-$(1)::	fedora-doc-${DOCBASE}-$(1).omf

fedora-doc-${DOCBASE}-$(1).omf:: ${RPMINFO}
	${XSLTPROC} --stringparam docbase "${DOCBASE}" 			\
		--stringparam lang "$(1)"				\
		${FDPDIR}/docs-common/packaging/omf.xsl ${RPMINFO}    |	\
	$(XMLFORMAT) $(XMLFOPTS) >fedora-doc-${DOCBASE}-$(1).omf.tmp &&	\
	move-if-change fedora-doc-${DOCBASE}-$(1).omf.tmp fedora-doc-${DOCBASE}-$(1).omf
endef

fedora-doc-${DOCBASE}-C.omf::	fedora-doc-${DOCBASE}-en.omf
	cp fedora-doc-$(DOCBASE)-en.omf $@

$(foreach LANG,${LANGUAGES},$(eval $(call omf_template,${LANG})))

omf::  $(foreach LANG,${LANGUAGES},omf-$(LANG)) fedora-doc-${DOCBASE}-C.omf


src-tarball $(DOCBASE)-$(VERSION).src.tar.gz::
	${MAKE} fdp-info
	${MAKE} gnome.desktop
	${MAKE} kde.desktop
	${MAKE} khelp.desktop
	${MAKE} omf
	${RM} -r $(DOCBASE)-$(VERSION)
	mkdir -p $(DOCBASE)-$(VERSION)
	find . '('							\
		-name '*#*'						\
		-o -name 'CVS'						\
		-o -name 'rpm'						\
		-o -name '*.rpm'					\
		-o -name '*~'						\
		-o -name '*.tar.gz'					\
		-o -name '*.tmp'					\
		-o -name '${DOCBASE}-${VERSION}'			\
	')' -prune -o -print | cpio -pamdv $(DOCBASE)-$(VERSION)
	tar -zcvf $(DOCBASE)-$(VERSION).src.tar.gz $(DOCBASE)-$(VERSION)/
	${RM} -r $(DOCBASE)-$(VERSION)

package-prep::
	${MAKE} distclean
	${MAKE} ${DOCBASE}-${shell version doc}.src.tar.gz
	${MAKE} ${SPECFILE}
	${MAKE} omf
	${MAKE} kde.desktop
	${MAKE} khelp.desktop
	mkdir -p rpm/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
	mkdir -p rpm/RPMS/{i386,i486,i586,i686,noarch,ppc,x86_64}
	cp -f $(DOCBASE)-$(shell version doc).src.tar.gz rpm/SOURCES/
	cp -f ${SPECFILE} rpm/SPECS
	cp -f *.omf *.desktop rpm/SOURCES

rpm-common::
	if test $(shell get_latest_revision rpm) = 0 ; then		\
		echo "*** Creating revision log entry for rpm ***" ;	\
		ROLE=rpm $(MAKE) clog ;					\
	fi
	${RM} *.rpm
	if test $(RPMPREP) != "no" ; then ${MAKE} package-prep ; fi

noarch:: rpm-common
	rpmbuild -bb $(RPMDFLAG) $(RPMFLAGS) rpm/SPECS/$(SPECFILE)
	if test $(RPMPOST) != "no" ; then $(MAKE) package-post ; fi

srpm:: rpm-common
	rpmbuild -bs $(RPMDFLAG) $(RPMFLAGS) rpm/SPECS/$(SPECFILE)
	if test $(RPMPOST) != "no" ; then $(MAKE) package-post ; fi

rpm:: rpm-common
	rpmbuild -ba $(RPMDFLAG) $(RPMFLAGS) rpm/SPECS/$(SPECFILE)
	if test $(RPMPOST) != "no" ; then $(MAKE) package-post ; fi

package-post::
	$(MAKE) clean  # If needed, review materials in rpm/BUILD/
	find rpm/ -name '*.rpm' -exec ln '{}' . ';'
	ls *.rpm

showvars::
	@echo "VERSION=$(VERSION)"
	@echo "RELEASE=$(RELEASE)"
	@echo "PWD=$(PWD)"


# Local variables:
# mode: makefile
# End: