aboutsummaryrefslogtreecommitdiff
path: root/share/mk/doc.xml.mk
blob: 14ee8543deba256838cf2fec477dc9ded772e087 (plain) (blame)
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
# doc.xml.mk
# $FreeBSD$

XML_CATALOG_FILES=	file://${.OBJDIR}/catalog-cwd.xml \
			file://${DOC_PREFIX}/${LANGCODE}/share/xml/catalog.xml \
			file://${DOC_PREFIX}/share/xml/catalog.xml \
			file://${DOC_PREFIX}/share/xml/catalog-common.xml \
			file://${LOCALBASE}/share/xml/catalog

.if exists(${DOC_PREFIX}/share/xml/catalog-cwd.xml)
XML_CATALOG_CWD=	${DOC_PREFIX}/share/xml/catalog-cwd.xml
.endif

# Variables used in DEPENDSET

_DEPENDSET.all=	wwwstd transtable mirrors usergroups commercial \
		news press events advisories notices

# DEPENDSET: wwwstd  .........................................................
_DEPENDSET.wwwstd=	${XML_INCLUDES}
_XML_INCLIST=	libcommon.l10n.xsl \
		libcommon.xsl \
		navibar.l10n.ent \
		navibar.ent \
		common.ent \
		header.ent \
		header.l10n.ent \
		iso8879.ent \
		l10n.ent \
		release.ent
.for F in ${_INCLIST}
.if exists(${DOC_PREFIX}/${LANGCODE}/share/xml/${F})
XML_INCLUDES+=	${F}
.endif
.if exists(${DOC_PREFIX}/share/xml/${F})
XML_INCLUDES+=	${F}
.endif
.endfor

.if defined(XML_CATALOG_CWD)
XML_INCLUDES+=	${.OBJDIR}/catalog-cwd.xml
CLEANFILES+=	${.OBJDIR}/catalog-cwd.xml
${.OBJDIR}/catalog-cwd.xml: ${XML_CATALOG_CWD}
	${INSTALL} ${.ALLSRC} ${.TARGET}
.endif

XML_INCLUDES+=	${.OBJDIR}/autogen.ent
CLEANFILES+=	${.OBJDIR}/autogen.ent
${.OBJDIR}/autogen.ent:
.if ${LANGCODE} != en_US.ISO8859-1
	${ECHO_CMD} '<!ENTITY enbase "${DOC_PREFIX_REL}/..">' > ${.TARGET}
.endif
	${ECHO_CMD} '<!ENTITY base "${DOC_PREFIX_REL}">' >> ${.TARGET}

DEPENDSET.DEFAULT+=	wwwstd

# DEPENDSET: transtable  ......................................................
_DEPENDSET.transtable=	${XML_TRANSTABLE} ${XSL_TRANSTABLE} \
			${XSL_TRANSTABLE_MASTER} ${XSL_TRANSTABLE_COMMON}
_PARAMS.transtable=	--param transtable.xml "'${XML_TRANSTABLE}'"
XSL_TRANSTABLE_MASTER=	${DOC_PREFIX}/share/xml/transtable-master.xsl
XSL_TRANSTABLE_COMMON=	${DOC_PREFIX}/share/xml/transtable-common.xsl

.if exists(${DOC_PREFIX}/${LANGCODE}/share/xml/transtable-local.xsl)
XSL_TRANSTABLE=		${DOC_PREFIX}/${LANGCODE}/share/xml/transtable-local.xsl
.else
XSL_TRANSTABLE=		${DOC_PREFIX}/share/xml/transtable-local.xsl
.endif

.if exists(${DOC_PREFIX}/${LANGCODE}/share/xml/transtable.xml)
XML_TRANSTABLE=		${DOC_PREFIX}/${LANGCODE}/share/xml/transtable.xml
.else
XML_TRANSTABLE=		${DOC_PREFIX}/share/xml/transtable.xml
.endif

# DEPENDSET: mirrors .....................................................
_DEPENDSET.mirrors=	${XSL_MIRRORS} ${XML_MIRRORS}
_PARAMS.mirrors=	--param mirrors.xml "'${XML_MIRRORS}'"
XML_MIRRORS_MASTER=	${DOC_PREFIX}/share/xml/mirrors.xml
XML_MIRRORS=		${DOC_PREFIX}/${LANGCODE}/share/xml/mirrors.xml
XSL_MIRRORS_MASTER=	${DOC_PREFIX}/share/xml/mirrors-master.xsl
.if exists(${DOC_PREFIX}/${LANGCODE}/share/xml/mirrors-local.xsl)
XSL_MIRRORS=		${DOC_PREFIX}/${LANGCODE}/share/xml/mirrors-local.xsl
.else
XSL_MIRRORS=		${DOC_PREFIX}/share/xml/mirrors-local.xsl
.endif
${XSL_MIRRORS}: ${XSL_MIRRORS_MASTER} \
		${XSL_TRANSTABLE_COMMON}

${XML_MIRRORS}: ${XML_MIRRORS_MASTER} \
		${XSL_TRANSTABLE} ${XSL_TRANSTABLE_MASTER} ${XSL_TRANSTABLE_COMMON}
	${MKDIR} -p ${@:H}
	${XSLTPROC} ${XSLTPROCOPTS} \
		--param 'transtable.xml' "'${XML_TRANSTABLE}'" \
		--param 'transtable-target-element' "'country'" \
		--param 'transtable-word-group' "'country'" \
		--param 'transtable-mode' "'sortkey'" \
		${XSL_TRANSTABLE} ${XML_MIRRORS_MASTER} \
		| env -i LANG="${LANGCODE}" ${SORT} -f > $@.sort.tmp
	env -i ${GREP} "^<?xml" < $@.sort.tmp > $@.sort
	${ECHO} "<sortkeys>" >> $@.sort
	env -i ${AWK} '/@sortkey@/ {sub(/@sortkey@/, ++line); print;}' < $@.sort.tmp >> $@.sort
	${ECHO} '</sortkeys>' >> $@.sort
	${XSLTPROC} ${XSLTPROCOPTS} -o $@ \
		--param 'transtable.xml' "'${XML_TRANSTABLE}'" \
		--param 'transtable-target-element' "'country'" \
		--param 'transtable-word-group' "'country'" \
		--param 'transtable-sortkey.xml' "'$@.sort'" \
		${XSL_TRANSTABLE} ${XML_MIRRORS_MASTER}
	${RM} -f $@.sort $@.sort.tmp
.if ${LANGCODE} != .
CLEANFILES+=	${XML_MIRRORS}
CLEANFILES+=	${XML_MIRRORS}.sort
CLEANFILES+=	${XML_MIRRORS}.sort.tmp
.endif

# DEPENDSET: usergroups ......................................................
_DEPENDSET.usergroups=	${XML_USERGROUPS} ${XML_USERGROUPS_LOCAL} \
			${XSL_USERGROUPS_MASTER} ${XSL_USERGROUPS} \
			${XML_INCLUDES}
_PARAMS.usergroups=	--param usergroups.xml "'${XML_USERGROUPS}'" \
			--param usergroups-local.xml "'${XML_USERGROUPS_LOCAL}'"
XML_USERGROUPS=		${DOC_PREFIX}/share/xml/usergroups.xml
.if exists(${DOC_PREFIX}/${LANGCODE}/share/xml/usergroups.xml)
XML_USERGROUPS_LOCAL=	${DOC_PREFIX}/${LANGCODE}/share/xml/usergroups.xml
.else
XML_USERGROUPS_LOCAL=	${DOC_PREFIX}/share/xml/usergroups.xml
.endif
XSL_USERGROUPS_MASTER=	${DOC_PREFIX}/share/xml/templates.usergroups.xsl
.if exists(${DOC_PREFIX}/${LANGCODE}/share/xml/templates.usergroups.xsl)
XSL_USERGROUPS=	${DOC_PREFIX}/${LANGCODE}/share/xml/templates.usergroups.xsl
.else
XSL_USERGROUPS=	${DOC_PREFIX}/share/xml/templates.usergroups.xsl
.endif

# DEPENDSET: news ............................................................
_DEPENDSET.news=	${XML_NEWS_NEWS_MASTER} ${XML_NEWS_NEWS} \
			${XSL_NEWS_NEWSFLASH} \
			${XSL_NEWS_NEWS_RDF} \
			${XSL_NEWS_NEWS_RSS} \
			${XML_INCLUDES}
_PARAMS.news=		--param news.project.xml-master "'${XML_NEWS_NEWS_MASTER}'" \
			--param news.project.xml "'${XML_NEWS_NEWS}'"
XML_NEWS_NEWS_MASTER=	${DOC_PREFIX}/share/xml/news.xml
.if exists(${DOC_PREFIX}/${LANGCODE}/share/xml/news.xml)
XML_NEWS_NEWS=		${DOC_PREFIX}/${LANGCODE}/share/xml/news.xml
.else
XML_NEWS_NEWS=		${DOC_PREFIX}/share/xml/news.xml
.endif

XSL_NEWS_NEWSFLASH=	${DOC_PREFIX}/share/xml/templates.newsflash.xsl
XSL_NEWS_NEWSFLASH_OLD=	${DOC_PREFIX}/share/xml/templates.oldnewsflash.xsl
XSL_NEWS_NEWS_RDF=	${DOC_PREFIX}/share/xml/templates.news-rdf.xsl
XSL_NEWS_NEWS_RSS=	${DOC_PREFIX}/share/xml/templates.news-rss.xsl

# DEPENDSET: press  ..........................................................
_DEPENDSET.press=	${XML_NEWS_PRESS_MASTER} ${XML_NEWS_PRESS} \
			${XSL_NEWS_PRESS} \
			${XML_INCLUDES}
_PARAMS.press=		--param news.press.xml-master "'${XML_NEWS_PRESS_MASTER}'" \
			--param news.press.xml "'${XML_NEWS_PRESS}'"
XML_NEWS_PRESS_MASTER=	${DOC_PREFIX}/share/xml/press.xml
.if exists(${DOC_PREFIX}/${LANGCODE}/share/xml/press.xml)
XML_NEWS_PRESS=		${DOC_PREFIX}/${LANGCODE}/share/xml/press.xml
.else
XML_NEWS_PRESS=		${DOC_PREFIX}/share/xml/press.xml
.endif
XSL_NEWS_PRESS=		${DOC_PREFIX}/share/xml/templates.press.xsl
XSL_NEWS_PRESS_RSS=	${DOC_PREFIX}/share/xml/templates.press-rss.xsl
XSL_NEWS_PRESS_OLD=	${DOC_PREFIX}/share/xml/templates.oldpress.xsl

# DEPENDSET: events  ..........................................................
_DEPENDSET.events=	${XML_EVENTS_EVENTS_MASTER} ${XML_EVENTS_EVENTS} \
			${XML_EVENTS_EVENTS_MASTER_SUBFILES} \
			${XML_EVENTS_EVENTS_SUBFILES} \
			${XSL_EVENTS} \
			${XSL_EVENTS_ICS} \
			${XML_INCLUDES}
_PARAMS.events=		--param events.xml-master "'${XML_EVENTS_EVENTS_MASTER}'" \
			--param events.xml "'${XML_EVENTS_EVENTS}'"
XML_EVENTS_EVENTS_MASTER=${DOC_PREFIX}/share/xml/events.xml
XML_EVENTS_EVENTS_MASTER_SUBFILES=
.for Y in 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013
XML_EVENTS_EVENTS_MASTER_SUBFILES+=	${DOC_PREFIX}/share/xml/events${Y}.xml
.endfor
.if exists(${DOC_PREFIX}/${LANGCODE}/share/xml/events.xml)
XML_EVENTS_EVENTS=	${DOC_PREFIX}/${LANGCODE}/share/xml/events.xml
.else
XML_EVENTS_EVENTS=	${XML_EVENTS_EVENTS_MASTER}
.endif
XML_EVENTS_EVENTS_SUBFILES=
.for Y in 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013
.if exists(${DOC_PREFIX}/${LANGCODE}/share/xml/events${Y}.xml)
XML_EVENTS_EVENTS_SUBFILES+=	${DOC_PREFIX}/${LANGCODE}/share/xml/events${Y}.xml
.endif
.endfor
XSL_EVENTS=		${DOC_PREFIX}/share/xml/templates.events.xsl
XSL_EVENTS_ICS=		${DOC_PREFIX}/share/xml/templates.events2ics.xsl
XSL_EVENTS_PAST=	${DOC_PREFIX}/share/xml/templates.pastevents.xsl

# DEPENDSET: commercial ........................................................
_DEPENDSET.commercial=	${XML_COMMERCIAL_CONSULT} \
			${XML_COMMERCIAL_HARDWARE} \
			${XML_COMMERCIAL_ISP} \
			${XML_COMMERCIAL_MISC} \
			${XML_COMMERCIAL_SOFTWARE} \
			${XSL_ENTRIES} \
			${XML_INCLUDES}
_PARAMS.commercial=
XML_COMMERCIAL_CONSULT=	${DOC_PREFIX}/share/xml/commercial.consult.xml
XML_COMMERCIAL_HARDWARE=${DOC_PREFIX}/share/xml/commercial.hardware.xml
XML_COMMERCIAL_ISP=	${DOC_PREFIX}/share/xml/commercial.isp.xml
XML_COMMERCIAL_MISC=	${DOC_PREFIX}/share/xml/commercial.misc.xml
XML_COMMERCIAL_SOFTWARE=${DOC_PREFIX}/share/xml/commercial.software.xml

XSL_ENTRIES=		${DOC_PREFIX}/share/xml/templates.entries.xsl

# DEPENDSET: advisories  .....................................................
_DEPENDSET.advisories=	${XML_ADVISORIES} ${XML_INCLUDES}
_PARAMS.advisories=	--param advisories.xml "'${XML_ADVISORIES}'"
XML_ADVISORIES=		${DOC_PREFIX}/share/xml/advisories.xml

# DEPENDSET: notices  ........................................................
_DEPENDSET.notices=	${XML_NOTICES} ${XML_INCLUDES}
_PARAMS.notices=	--param notices.xml "'${XML_NOTICES}'"
XML_NOTICES=		${DOC_PREFIX}/share/xml/notices.xml

# ---
# .xml -> .html rendering rule
#
# The following variables are available:
#
# XMLDOCS: (ex. XMLDOCS= doc1 doc2 doc3)
#   Target document identifier, which is usually the same as the
#   base part of the filenames.  {XSLT,XML,TARGET}.<id> described below
#   can be specified in a short form like the following:
#   "docid:stylesheet:xml:target".
#
# TARGET.<id>: (ex. TARGET.doc1= doc1.html)
#   The target filename.  This is optional and <id>.html is defined
#   by default.
#
# XSLT.<id>: (ex. XSLT.doc1= doc1.xsl)
#   Filename of the XSLT stylesheet.  This is optional and <id>.xsl is
#   defined by default.  The following keywords are interpreted specially:
#
#    `xsl'             - <id>.xsl
#
# XSLT.DEFAULT:
#   The default filename or keyword of XSLT stylesheet.
#   When XSLT.<id> and one in the quadruplet are not specified,
#   this value is used.
#
# XML.<id>: (ex. XML.doc1= doc1.xml data.xml)
#   Filename of the XML document.  This is optional and /dev/null is
#   defined by default.  XML.DEFAULT is XML document for all <id>s.
#
# SRCS.<id>: (ex. SRCS.doc1= includes.xsl)
#   Dependencies.  SRCS.DEFAULT is dependencies for all <id>s.
#
# DEPENDSET.<id>: (ex. DEPENDSET.doc1= mirror)
#   Depencencies predefined as keywords listed in ${_DEPENDSET.all}.
#   DEPENDSET.DEFAULT is DEPENDSET for all <id>s.
#
# PARAMS.<id>: (ex. PARAMS.doc1= --params "foo" "'textproc/foo'")
#   Parameters passed to xsltproc(1).
#
# XSLTPROCOPTS.<id>: (ex. XSLTPROCOPTS.doc1= --nonet)
#   Parameters passed to xsltproc(1).
#
# NO_DATA.<id>
#   The ${TARGET.<id>} file will not be listed in $DATA if defined.
#   NO_DATA.DEFAULT is the setting for all <id>s.
#
XSLTPROC_ENV+=	SGML_CATALOG_FILES=
XSLTPROC_ENV+=	XML_CATALOG_FILES="${XML_CATALOG_FILES}"

XSLTPROCOPTS=	${XSLTPROCFLAGS}
XSLTPROCOPTS+=	--xinclude
XSLTPROCOPTS+=	--stringparam LOCALBASE ${LOCALBASE}
XSLTPROCOPTS+=	--stringparam DOC_PREFIX ${DOC_PREFIX}
.if defined(XML_CATALOG_FILES) && !empty(XML_CATALOG_FILES)
XSLTPROCOPTS+=	--nonet --catalogs
.endif
.if defined(WWWFREEBSDORG)
XSLTPROCOPTS+=	--param "html.header.script.google" "'INCLUDE'"
.endif
XSLTPROC=	env ${XSLTPROC_ENV} ${LOCALBASE}/bin/xsltproc

XMLLINTOPTS=	${XMLLINTFLAGS}
XMLLINTOPTS+=	--xinclude --valid --noout
.if defined(XML_CATALOG_FILES) && !empty(XML_CATALOG_FILES)
XMLLINTOPTS+=	--nonet --catalogs
.endif
XMLLINT=	env ${XSLTPROC_ENV} ${PREFIX}/bin/xmllint

.for D in ${XMLDOCS}
# parse "docid:xslt:xml:target".
# XXX: ${__ID} is used because ${A}=B does not work except
#      for the iterate variable in the .for statement.
__ID=${D:C,:.*$,,}

.for _ID in ${__ID}
_tmpD=	${D:M*\:*}
.if !empty(_tmpD)
XSLT.${_ID}=	${D:C,^[^:]*,,:M*\:*:C,^:,,:C,:.*$,,}
XML.${_ID}=	${D:C,^[^:]*,,:M*\:*:C,^:,,:C,^[^:]*,,:M*\:*:C,^:,,:C,:.*$,,}
TARGET.${_ID}=	${D:C,^[^:]*,,:M*\:*:C,^:,,:C,^[^:]*,,:M*\:*:C,^:,,:C,^[^:]*,,:M*\:*:C,^:,,:C,:.*$,,}
.endif

# Use default value if parameter not specified.
.if !defined(XSLT.${_ID}) || empty(XSLT.${_ID})
.if defined(XSLT.DEFAULT)
XSLT.${_ID}=	${XSLT.DEFAULT}
.else
XSLT.${_ID}=	${_ID}.xsl
.endif
.endif
.if !defined(XML.${_ID}) || empty(XML.${_ID})
.if defined(XML.DEFAULT)
XML.${_ID}=	${XML.DEFAULT}
.else
XML.${_ID}=	${_ID}.xml
.endif
.endif
.if !defined(TARGET.${_ID}) || empty(TARGET.${_ID})
TARGET.${_ID}=	${_ID}.html
.endif
.if !defined(DEPENDSET.${_ID}) || empty(DEPENDSET.${_ID})
.if defined(DEPENDSET.DEFAULT)
DEPENDSET.${_ID}=	${DEPENDSET.DEFAULT}
.else
DEPENDSET.${_ID}=
.endif
.endif
.if !defined(NO_DATA.${_ID}) || empty(NO_DATA.${_ID})
.if defined(NO_DATA.DEFAULT)
NO_DATA.${_ID}=	${NO_DATA.DEFAULT}
.else
NO_DATA.${_ID}=
.endif
.endif

XSLTPROCOPTS.${_ID}?=	${XSLTPROCOPTS}
GENDOCS+=	${TARGET.${_ID}}
SRCS+=		${TARGET.${_ID}}
.if !defined(NO_DATA.${_ID}) || empty(NO_DATA.${_ID})
DATA+=		${TARGET.${_ID}}
.endif
CLEANFILES+=	${TARGET.${_ID}}

.if ${XSLT.${_ID}} == xsl
XSLT.${_ID}=	${_ID}.xsl
DEPENDS.${_ID}+=	${XSLT.${_ID}}
.elif ${XSLT.${_ID}:Mhttp\://*} != ""
DEPENDS.${_ID}+=	${XSLT.${_ID}}
.else
DEPENDS.${_ID}+=	${XSLT.${_ID}}
.endif

.for S in ${_DEPENDSET.all}
. if ${DEPENDSET.${_ID}:M${S}} != ""
DEPENDS.${_ID}+=${_DEPENDSET.${S}}
PARAMS.${_ID}+=	${_PARAMS.${S}}
. endif
.endfor

.for S in ${SRCS.DEFAULT} ${SRCS.${_ID}}
DEPENDS.${_ID}+=	${S}
.endfor
${TARGET.${_ID}}: ${XML.${_ID}} ${DEPENDS.${_ID}}
	${XSLTPROC} ${XSLTPROCOPTS.${_ID}} \
		-o ${.TARGET} ${PARAMS.${_ID}} \
		${XSLT.${_ID}} ${XML.${_ID}}

VALIDATE_DOCS+=	VALIDATE.${_ID}
VALIDATE.${_ID}:
	@${ECHO} "==>[xmllint] ${XML.${_ID}}"
	-@${XMLLINT} ${XMLLINTOPTS} ${XML.${_ID}} 2>&1  \
		| ${SED} -e 's/^/ | /'
.  endfor
.endfor

lint: ${VALIDATE_DOCS}