summaryrefslogtreecommitdiffstats
path: root/Makefile.common
blob: 7a1655e2f0f0556ceb449337cdd323fab52c35d2 (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
#########################################################################
# 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.
#########################################################################
# 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	       = ..
endif
ifeq	(${XSLPDF},)
XSLPDF		= ${FDPDIR}/docs-common/xsl/main-pdf.xsl
endif
ifeq	(${XSLHTML},)
XSLHTML        	= ${FDPDIR}/docs-common/xsl/main-html.xsl
endif
ifeq	(${XSHTMLNOCHUNKS},)
XSLHTMLNOCHUNKS	= ${FDPDIR}/docs-common/xsl/main-html-nochunks.xsl
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
#########################################################################
# 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 tarball pdf html html-nochunks clean distclean showvars
.PHONY:	${TARGETS}

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 ${FDPDIR}/docs-common/css/fedora.css mydoc-en/
#  mkdir -p mydoc-en/figs
#  cp -p figs/*-${LANG}.* mydoc-en/figs
# but we do avoid copying EPS files since they are nonsense to the HTML world.
# Also, we create the figs directory only if the document dir has a "figs/".
# I don't think we need to do this for a nochunks output, though.
#
define	HTML_template
${DOCBASE}-$(1)/index.html:: ${DOCBASE}-$(1).xml $$(XMLEXTRAFILES-$(1))
	LANG=$(1).UTF-8 ${XMLTO} html -x $(XSLHTML) -o $(DOCBASE)-$(1) $(DOCBASE)-$(1).xml
	mkdir -p $(DOCBASE)-$(1)/stylesheet-images/
	cp ${FDPDIR}/docs-common/stylesheet-images/*.png $(DOCBASE)-$(1)/stylesheet-images
	cp ${FDPDIR}/docs-common/css/fedora.css $$(DOCBASE)-$(1)/
	[ ! -d figs ] || (						\
		mkdir -p ${DOCBASE}-$(1)/figs;				\
		find figs -type f -iname '*.*' -print		|	\
		egrep -vi '*.eps'				|	\
		egrep '(.*-$(1)..*)|([^-]*[.][^-]*)'		|	\
		while read x; do cp -f $$$${x} ${DOCBASE}-$(1)/figs; done \
	) && exit 0
endef
#
html::	$(foreach LANG,${LANGUAGES},$(DOCBASE)-$(LANG)/index.html)

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

$(foreach LANG,${LANGUAGES},$(eval $(call HTMLNOCHUNK_template,${LANG})))
#
#########################################################################
# For each language in ${LANGUAGES}, build a tarball of the HTML files.
#
define	TAR_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 TAR_template,${LANG})))
#
#########################################################################
# For each language in ${LANGUAGES}, generate an Adobe Portable Document
# Format (PDF) file.
define	PDF_template
${DOCBASE}-$(1).pdf:: ${DOCBASE}-$(1).xml $$(XMLEXTRAFILES-$(1))
	${XMLTO} pdf -x $(XSLPDF) $(DOCBASE)-$(1).xml
endef
#
pdf::	$(foreach LANG,${LANGUAGES},$(DOCBASE)-$(LANG).pdf)

$(foreach LANG,${LANGUAGES},$(eval $(call PDF_template,${LANG})))
#
#########################################################################
# For each language in ${LANGUAGES}, clean up!
define	CLEAN_template
${DOCBASE}-$(1)-clean::
	${RM} -r ${DOCBASE}-$(1)
	${RM} -r ${DOCBASE}-$(1).html stylesheet-images fedora.css
	${RM} -r ${DOCBASE}-$(1).pdf
	${RM} -r ${DOCBASE}-$(1).tar.gz
endef
#
distclean clean:: $(foreach LANG,${LANGUAGES},${DOCBASE}-${LANG}-clean)

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

showvars::
	@echo "DOCBASE=\"$(DOCBASE)\""
	@echo "LANGUAGES=\"$(LANGUAGES)\""
#
#########################################################################
# End of Makefile.common
#########################################################################