aboutsummaryrefslogtreecommitdiff
path: root/share/mk/doc.xml.mk
blob: 29ebfab85fc3ae95c278797f2920c51aa2553ee8 (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
# doc.xml.mk
# $FreeBSD: www/share/mk/doc.xml.mk,v 1.4 2005/10/04 17:18:41 hrs Exp $

XML_CATALOG_FILES=	file://${DOC_PREFIX}/${LANGCODE}/share/sgml/catalog.xml \
			file://${DOC_PREFIX}/share/sgml/catalog.xml \
			file://${DOC_PREFIX}/share/sgml/catalog-common.xml \
			file://${WEB_PREFIX}/${WWW_LANGCODE}/share/sgml/catalog.xml \
			file://${WEB_PREFIX}/share/sgml/catalog-common.xml \
			file://${LOCALBASE}/share/xml/catalog

# Variables used in DEPENDSET

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

# DEPENDSET: wwwstd  .........................................................
_DEPENDSET.wwwstd=	${XML_INCLUDES}
XML_INCLUDES=	${WEB_PREFIX}/${WWW_LANGCODE}/includes.xsl \
		${WEB_PREFIX}/share/sgml/includes.header.xsl \
		${WEB_PREFIX}/share/sgml/includes.misc.xsl \
		${WEB_PREFIX}/share/sgml/includes.release.xsl \
		${WEB_PREFIX}/share/sgml/includes.xsl

# 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/sgml/transtable-master.xsl
XSL_TRANSTABLE_COMMON=	${DOC_PREFIX}/share/sgml/transtable-common.xsl

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

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

# DEPENDSET: mirrors .....................................................
_DEPENDSET.mirrors=	${XSL_MIRRORS} ${XML_MIRRORS}
_PARAMS.mirrors=	--param mirrors.xml "'${XML_MIRRORS}'"
XML_MIRRORS_MASTER=	${DOC_PREFIX}/share/sgml/mirrors.xml
XML_MIRRORS=		${DOC_PREFIX}/${LANGCODE}/share/sgml/mirrors.xml
XSL_MIRRORS_MASTER=	${DOC_PREFIX}/share/sgml/mirrors-master.xsl
.if exists(${DOC_PREFIX}/${LANGCODE}/share/sgml/mirrors-local.xsl)
XSL_MIRRORS=		${DOC_PREFIX}/${LANGCODE}/share/sgml/mirrors-local.xsl
.else
XSL_MIRRORS=		${DOC_PREFIX}/share/sgml/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=		${WEB_PREFIX}/share/sgml/usergroups.xml
.if exists(${WEB_PREFIX}/${WWW_LANGCODE}/share/sgml/usergroups.xml)
XML_USERGROUPS_LOCAL=	${WEB_PREFIX}/${WWW_LANGCODE}/share/sgml/usergroups.xml
.else
XML_USERGROUPS_LOCAL=	${WEB_PREFIX}/share/sgml/usergroups.xml
.endif
XSL_USERGROUPS_MASTER=	${WEB_PREFIX}/share/sgml/templates.usergroups.xsl
.if exists(${WEB_PREFIX}/${WWW_LANGCODE}/share/sgml/templates.usergroups.xsl)
XSL_USERGROUPS=	${WEB_PREFIX}/${WWW_LANGCODE}/share/sgml/templates.usergroups.xsl
.else
XSL_USERGROUPS=	${WEB_PREFIX}/share/sgml/templates.usergroups.xsl
.endif

# DEPENDSET: news ............................................................
_DEPENDSET.news=	${XML_NEWS_NEWS_MASTER} ${XML_NEWS_NEWS} \
			${XML_NEWS_INCLUDES_MASTER} ${XML_NEWS_INCLUDES} \
			${XML_INCLUDES}
_PARAMS.news=		--param news.project.xml-master "'${XML_NEWS_NEWS_MASTER}'" \
			--param news.project.xml "'${XML_NEWS_NEWS}'"
XML_NEWS_INCLUDES_MASTER=${WEB_PREFIX}/en/news/includes.xsl
XML_NEWS_INCLUDES=	${WEB_PREFIX}/${WWW_LANGCODE}/news/includes.xsl
XML_NEWS_NEWS_MASTER=	${WEB_PREFIX}/en/news/news.xml
XML_NEWS_NEWS=		${WEB_PREFIX}/${WWW_LANGCODE}/news/news.xml

# DEPENDSET: press  ..........................................................
_DEPENDSET.press=	${XML_NEWS_PRESS_MASTER} ${XML_NEWS_PRESS} \
			${XML_NEWS_INCLUDES_MASTER} ${XML_NEWS_INCLUDES} \
			${XML_INCLUDES}
_PARAMS.press=		--param news.press.xml-master "'${XML_NEWS_PRESS_MASTER}'" \
			--param news.press.xml "'${XML_NEWS_PRESS}'"
XML_NEWS_INCLUDES_MASTER=${WEB_PREFIX}/en/news/includes.xsl
XML_NEWS_INCLUDES=	${WEB_PREFIX}/${WWW_LANGCODE}/news/includes.xsl
XML_NEWS_PRESS_MASTER=	${WEB_PREFIX}/en/news/press.xml
XML_NEWS_PRESS=		${WEB_PREFIX}/${WWW_LANGCODE}/news/press.xml

# DEPENDSET: events  ..........................................................
_DEPENDSET.events=	${XML_EVENTS_EVENTS_MASTER} ${XML_EVENTS_EVENTS} \
			${XML_EVENTS_CURDATE} ${XML_INCLUDES}
_PARAMS.events=		--param events.xml-master "'${XML_EVENTS_EVENTS_MASTER}'" \
			--param events.xml "'${XML_EVENTS_EVENTS}'" \
			--param curdate.xml "'${XML_EVENTS_CURDATE}'"
XML_EVENTS_EVENTS_MASTER=${WEB_PREFIX}/en/events/events.xml
.if exists(${WEB_PREFIX}/${WWW_LANGCODE}/events/events.xml)
XML_EVENTS_EVENTS=	${WEB_PREFIX}/${WWW_LANGCODE}/events/events.xml
.else
XML_EVENTS_EVENTS=	${XML_EVENTS_EVENTS_MASTER}
.endif
XML_EVENTS_CURDATE=	${WEB_PREFIX}/en/events/curdate.xml

DATE?=	/bin/date
TR?=	/usr/bin/tr

${XML_EVENTS_CURDATE}:
	@${ECHO} "Generating ${.TARGET}"
	@${ECHO_CMD} '<?xml version="1.0"?>'     > ${.TARGET}
	@${ECHO_CMD} '<curdate>'                >> ${.TARGET}
	@${ECHO_CMD} -n '  <year>'              >> ${.TARGET}
	@${DATE} +%Y | ${TR} -d "\n"            >> ${.TARGET}
	@${ECHO_CMD} '</year>'                  >> ${.TARGET}
	@${ECHO_CMD} -n '  <month>'             >> ${.TARGET}
	@${DATE} +%m | ${TR} -d "\n"            >> ${.TARGET}
	@${ECHO_CMD} '</month>'                 >> ${.TARGET}
	@${ECHO_CMD} -n '  <day>'               >> ${.TARGET}
	@${DATE} +%d | ${TR} -d "\n"            >> ${.TARGET}
	@${ECHO_CMD} '</day>'                   >> ${.TARGET}
	@${ECHO_CMD} '</curdate>'               >> ${.TARGET}

CLEANFILES+=	${XML_EVENTS_CURDATE}

# DEPENDSET: navigation  .....................................................
_DEPENDSET.navigation=	${XML_NAVIGATION} ${XML_INCLUDES}
_PARAMS.navigation=	--param navigation.xml "'${XML_NAVIGATION}'"
XML_NAVIGATION=		${WEB_PREFIX}/${WWW_LANGCODE}/navigation.xml

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

# DEPENDSET: notices  ........................................................
_DEPENDSET.notices=	${XML_NOTICES} ${XML_INCLUDES}
_PARAMS.notices=	--param notices.xml "'${XML_NOTICES}'"
XML_NOTICES=		${WEB_PREFIX}/share/sgml/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.
#
# NO_TIDY.<id>
#   The ${TARGET.<id>} file will not be processed by tidy if defined.
#   NO_TIDY.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 WEB_PREFIX ${WEB_PREFIX}
.if defined(XML_CATALOG_FILES) && !empty(XML_CATALOG_FILES)
XSLTPROCOPTS+=	--nonet --catalogs
.endif
XSLTPROC=	env ${XSLTPROC_ENV} ${LOCALBASE}/bin/xsltproc

.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_TIDY.${_ID}) || empty(NO_TIDY.${_ID})
.if defined(NO_TIDY.DEFAULT)
NO_TIDY.${_ID}=	${NO_TIDY.DEFAULT}
.else
NO_TIDY.${_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}}
. if !defined(NO_TIDY) || empty(NO_TIDY)
.  if !defined(NO_TIDY.${_ID}) || empty(NO_TIDY.${_ID})
	-${TIDY} ${TIDYOPTS} ${.TARGET}
.  endif
. endif
.endfor
.endfor