source: LFS/lfs.xsl@ 4ddaa8e

experimental
Last change on this file since 4ddaa8e was 4ddaa8e, checked in by Manuel Canales Esparcia <manuel@…>, 17 years ago

Removed DOCTYPE declarations due that looks like we don't need to use books entities anymore.
That could help a lot when implementing customizations due that might avoid the need to copy the XSL code into $JHALFSDIR.

  • Property mode set to 100644
File size: 18.5 KB
Line 
1<?xml version="1.0"?>
2
3<!-- $Id$ -->
4
5<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
6 xmlns:exsl="http://exslt.org/common"
7 extension-element-prefixes="exsl"
8 version="1.0">
9
10<!-- XSLT stylesheet to create shell scripts from LFS books. -->
11
12<!-- ####################### PARAMETERS ################################### -->
13
14 <!-- Run test suites?
15 0 = none
16 1 = only chapter06 Glibc, GCC and Binutils testsuites
17 2 = all chapter06 testsuites
18 3 = all chapter05 and chapter06 testsuites
19 -->
20 <xsl:param name="testsuite" select="1"/>
21
22 <!-- Bomb on test suites failures?
23 n = no, I want to build the full system and review the logs
24 y = yes, bomb at the first test suite failure to can review the build dir
25 -->
26 <xsl:param name="bomb-testsuite" select="n"/>
27
28 <!-- Install vim-lang package? -->
29 <xsl:param name="vim-lang" select="y"/>
30
31 <!-- Time zone -->
32 <xsl:param name="timezone" select="GMT"/>
33
34 <!-- Page size -->
35 <xsl:param name="page" select="letter"/>
36
37 <!-- Locale setting -->
38 <xsl:param name="lang" select="C"/>
39
40
41<!-- ####################################################################### -->
42
43<!-- ########### NAMED USER TEMPLATES TO ALLOW CUSTOMIZATIONS ############## -->
44
45 <!-- Hock for user header additions -->
46 <xsl:template name="user_header">
47 <xsl:text>&#xA;</xsl:text>
48 </xsl:template>
49
50
51 <!-- Hock for user envars or extra commands before cd into the sources dir -->
52 <xsl:template name="user_pre_commands">
53 <xsl:text>&#xA;</xsl:text>
54 </xsl:template>
55
56
57 <!-- Hock for user footer additions -->
58 <xsl:template name="user_footer">
59 <xsl:text>&#xA;</xsl:text>
60 </xsl:template>
61
62
63<!-- ####################################################################### -->
64
65<!-- ########################### NAMED TEMPLATES ########################### -->
66
67 <!-- Chapter directory name (the same used for HTML output) -->
68 <xsl:template name="dirname">
69 <xsl:variable name="pi-dir" select="processing-instruction('dbhtml')"/>
70 <xsl:variable name="pi-dir-value" select="substring-after($pi-dir,'dir=')"/>
71 <xsl:variable name="quote-dir" select="substring($pi-dir-value,1,1)"/>
72 <xsl:variable name="dirname" select="substring-before(substring($pi-dir-value,2),$quote-dir)"/>
73 <xsl:value-of select="$dirname"/>
74 </xsl:template>
75
76
77 <!-- Base file name (the same used for HTML output) -->
78 <xsl:template name="filename">
79 <xsl:variable name="pi-file" select="processing-instruction('dbhtml')"/>
80 <xsl:variable name="pi-file-value" select="substring-after($pi-file,'filename=')"/>
81 <xsl:variable name="filename" select="substring-before(substring($pi-file-value,2),'.html')"/>
82 <xsl:value-of select="$filename"/>
83 </xsl:template>
84
85
86 <!-- Script header -->
87 <xsl:template name="header">
88 <!-- Set the shabang -->
89 <xsl:choose>
90 <xsl:when test="@id='ch-system-creatingdirs' or
91 @id='ch-system-createfiles' or
92 @id='ch-system-strippingagain'">
93 <xsl:text>#!/tools/bin/bash&#xA;</xsl:text>
94 </xsl:when>
95 <xsl:otherwise>
96 <xsl:text>#!/bin/bash&#xA;</xsl:text>
97 </xsl:otherwise>
98 </xsl:choose>
99 <!-- Set +h -->
100 <xsl:text>set +h&#xA;</xsl:text>
101 <!-- Set -e -->
102 <xsl:if test="not(@id='ch-tools-stripping') and
103 not(@id='ch-system-strippingagain')">
104 <xsl:text>set -e&#xA;</xsl:text>
105 </xsl:if>
106 <xsl:text>&#xA;</xsl:text>
107 </xsl:template>
108
109
110 <!-- Extra previous commands needed by the book but not inside screen tags -->
111 <xsl:template name="pre_commands">
112 <xsl:if test="sect2[@role='installation']">
113 <xsl:text>cd $PKGDIR&#xA;</xsl:text>
114 </xsl:if>
115 <xsl:if test="@id='ch-system-vim' and $vim-lang = 'y'">
116 <xsl:text>tar -xvf ../$TARBALL_1 --strip-components=1&#xA;</xsl:text>
117 </xsl:if>
118 </xsl:template>
119
120
121 <!-- Extra post commands needed by the book but not inside screen tags -->
122 <xsl:template name="post_commands">
123 <xsl:if test="$testsuite='3' and @id='ch-tools-glibc'">
124 <xsl:copy-of select="//userinput[@remap='locale-test']"/>
125 <xsl:text>&#xA;</xsl:text>
126 </xsl:if>
127 </xsl:template>
128
129
130 <!-- Script footer -->
131 <xsl:template name="footer">
132 <!-- Dump the build time -->
133 <xsl:if test="not(@id='ch-system-chroot') and
134 not(@id='ch-system-revisedchroot')">
135 <xsl:text>&#xA;&#xA;echo -e "\n\nTotalseconds: $SECONDS\n"&#xA;</xsl:text>
136 </xsl:if>
137 <!-- Exit -->
138 <xsl:text>&#xA;exit&#xA;</xsl:text>
139 </xsl:template>
140
141
142 <!-- Extra commads needed at the start of some screen block
143 to allow automatization -->
144 <xsl:template name="top_screen_build_fixes">
145 <!-- Fix Udev reinstallation after a build failure or on iterative builds -->
146 <xsl:if test="contains(string(),'firmware,udev')">
147 <xsl:text>if [[ ! -d /lib/udev/devices ]] ; then&#xA;</xsl:text>
148 </xsl:if>
149 </xsl:template>
150
151
152 <!-- Extra commads needed at the end of some screen block
153 to allow automatization -->
154 <xsl:template name="bottom_screen_build_fixes">
155 <!-- Fix Udev reinstallation after a build failure or on iterative builds -->
156 <xsl:if test="contains(string(),'firmware,udev')">
157 <xsl:text>&#xA;fi</xsl:text>
158 </xsl:if>
159 <!-- Copying the kernel config file -->
160 <xsl:if test="string() = 'make mrproper'">
161 <xsl:text>&#xA;cp -v ../kernel-config .config</xsl:text>
162 </xsl:if>
163 <!-- Don't stop on strip run -->
164 <xsl:if test="contains(string(),'strip --strip')">
165 <xsl:text> || true</xsl:text>
166 </xsl:if>
167 </xsl:template>
168
169
170 <!-- Extract a package name from a package URL -->
171 <xsl:template name="package_name">
172 <xsl:param name="url" select="foo"/>
173 <xsl:param name="sub-url" select="substring-after($url,'/')"/>
174 <xsl:choose>
175 <xsl:when test="contains($sub-url,'/')">
176 <xsl:call-template name="package_name">
177 <xsl:with-param name="url" select="$sub-url"/>
178 </xsl:call-template>
179 </xsl:when>
180 <xsl:otherwise>
181 <xsl:value-of select="$sub-url"/>
182 </xsl:otherwise>
183 </xsl:choose>
184 </xsl:template>
185
186
187<!-- ######################################################################## -->
188
189<!-- ############################# MATCH TEMPLATES ########################## -->
190
191 <!-- Root element -->
192 <xsl:template match="/">
193 <!-- Start processing at chapter level -->
194 <xsl:apply-templates select="//chapter"/>
195 </xsl:template>
196
197
198 <!-- chapter -->
199 <xsl:template match="chapter">
200 <xsl:if test="@id='chapter-temporary-tools' or @id='chapter-building-system'
201 or @id='chapter-bootscripts' or @id='chapter-bootable'">
202 <!-- The dir name -->
203 <xsl:variable name="dirname">
204 <xsl:call-template name="dirname"/>
205 </xsl:variable>
206 <!-- The chapter order position -->
207 <xsl:variable name="ch_position" select="position()"/>
208 <xsl:variable name="ch_order">
209 <xsl:choose>
210 <xsl:when test="string-length($ch_position) = 1">
211 <xsl:text>0</xsl:text>
212 <xsl:value-of select="$ch_position"/>
213 </xsl:when>
214 <xsl:otherwise>
215 <xsl:value-of select="$ch_position"/>
216 </xsl:otherwise>
217 </xsl:choose>
218 </xsl:variable>
219 <!-- Process the childrens -->
220 <xsl:apply-templates select="sect1">
221 <xsl:with-param name="ch_order" select="$ch_order"/>
222 <xsl:with-param name="dirname" select="$dirname"/>
223 </xsl:apply-templates>
224 </xsl:if>
225 </xsl:template>
226
227
228 <!-- sect1 -->
229 <xsl:template match="sect1">
230 <!-- Inherited chapter order -->
231 <xsl:param name="ch_order" select="foo"/>
232 <!-- Inherited dir name -->
233 <xsl:param name="dirname" select="foo"/>
234 <!-- Process only files with actual build commands -->
235 <xsl:if test="count(descendant::screen/userinput) &gt; 0 and
236 count(descendant::screen/userinput) &gt;
237 count(descendant::screen[@role='nodump'])">
238 <!-- Base file name -->
239 <xsl:variable name="filename">
240 <xsl:call-template name="filename"/>
241 </xsl:variable>
242 <!-- Sect1 order position -->
243 <xsl:variable name="sect1_position" select="position()"/>
244 <xsl:variable name="sect1_order">
245 <xsl:choose>
246 <xsl:when test="string-length($sect1_position) = 1">
247 <xsl:text>0</xsl:text>
248 <xsl:value-of select="$sect1_position"/>
249 </xsl:when>
250 <xsl:otherwise>
251 <xsl:value-of select="$sect1_position"/>
252 </xsl:otherwise>
253 </xsl:choose>
254 </xsl:variable>
255 <!-- Script build order -->
256 <xsl:variable name="order" select="concat($ch_order,'_',$sect1_order)"/>
257 <!-- Creating dirs and files -->
258 <exsl:document href="{$dirname}/{$order}-{$filename}" method="text">
259 <xsl:call-template name="header"/>
260 <xsl:call-template name="user_header"/>
261 <xsl:apply-templates select="sect1info[@condition='script']">
262 <xsl:with-param name="phase" select="$filename"/>
263 </xsl:apply-templates>
264 <xsl:call-template name="user_pre_commands"/>
265 <xsl:call-template name="pre_commands"/>
266 <xsl:apply-templates select=".//screen"/>
267 <xsl:call-template name="post_commands"/>
268 <xsl:call-template name="user_footer"/>
269 <xsl:call-template name="footer"/>
270 </exsl:document>
271 </xsl:if>
272 </xsl:template>
273
274
275 <!-- sect1info -->
276 <xsl:template match="sect1info">
277 <!-- Build phase (base file name) to be used for PM -->
278 <xsl:param name="phase" select="foo"/>
279 <xsl:text>&#xA;PKG_PHASE=</xsl:text>
280 <xsl:value-of select="$phase"/>
281 <!-- Package name -->
282 <xsl:apply-templates select="productname"/>
283 <!-- Package version -->
284 <xsl:apply-templates select="productnumber"/>
285 <!-- Tarball name -->
286 <xsl:apply-templates select="address"/>
287 <xsl:text>&#xA;&#xA;</xsl:text>
288 </xsl:template>
289
290
291 <!-- productname -->
292 <xsl:template match="productname">
293 <xsl:text>&#xA;PACKAGE=</xsl:text>
294 <xsl:apply-templates/>
295 </xsl:template>
296
297
298 <!-- productnumber -->
299 <xsl:template match="productnumber">
300 <xsl:text>&#xA;VERSION=</xsl:text>
301 <xsl:apply-templates/>
302 </xsl:template>
303
304
305 <!-- address -->
306 <xsl:template match="address">
307 <xsl:text>&#xA;TARBALL=</xsl:text>
308 <xsl:call-template name="package_name">
309 <xsl:with-param name="url">
310 <xsl:apply-templates/>
311 </xsl:with-param>
312 </xsl:call-template>
313 <xsl:apply-templates select="otheraddr" mode="tarball"/>
314 </xsl:template>
315
316
317 <!-- otheraddr -->
318 <xsl:template match="otheraddr"/>
319 <xsl:template match="otheraddr" mode="tarball">
320 <xsl:text>&#xA;TARBALL_</xsl:text>
321 <xsl:value-of select="position()"/>
322 <xsl:text>=</xsl:text>
323 <xsl:call-template name="package_name">
324 <xsl:with-param name="url" select="."/>
325 </xsl:call-template>
326 </xsl:template>
327
328
329 <!-- screen -->
330 <xsl:template match="screen">
331 <xsl:if test="child::* = userinput and not(@role = 'nodump')">
332 <xsl:call-template name="top_screen_build_fixes"/>
333 <xsl:apply-templates/>
334 <xsl:call-template name="bottom_screen_build_fixes"/>
335 <xsl:text>&#xA;</xsl:text>
336 </xsl:if>
337 </xsl:template>
338
339
340 <!-- userinput @remap='pre' -->
341 <xsl:template match="userinput[@remap='pre']">
342 <xsl:apply-templates select="." mode="pre"/>
343 </xsl:template>
344
345
346 <!-- userinput @remap='configure' -->
347 <xsl:template match="userinput[@remap='configure']">
348 <xsl:apply-templates select="." mode="configure"/>
349 </xsl:template>
350
351
352 <!-- userinput @remap='make' -->
353 <xsl:template match="userinput[@remap='make']">
354 <xsl:apply-templates select="." mode="make"/>
355 </xsl:template>
356
357
358 <!-- userinput @remap='test' -->
359 <xsl:template match="userinput[@remap='test']">
360 <xsl:apply-templates select="." mode="test"/>
361 </xsl:template>
362
363
364 <!-- userinput @remap='install' -->
365 <xsl:template match="userinput[@remap='install']">
366 <xsl:apply-templates select="." mode="install"/>
367 </xsl:template>
368
369
370 <!-- userinput @remap='adjust' -->
371 <xsl:template match="userinput[@remap='adjust']">
372 <xsl:apply-templates select="." mode="adjust"/>
373 </xsl:template>
374
375
376 <!-- userinput @remap='locale-test' -->
377 <xsl:template match="userinput[@remap='locale-test']">
378 <xsl:apply-templates select="." mode="locale-test"/>
379 </xsl:template>
380
381
382 <!-- userinput @remap='locale-full' -->
383 <xsl:template match="userinput[@remap='locale-full']">
384 <xsl:apply-templates select="." mode="locale-full"/>
385 </xsl:template>
386
387
388
389 <!-- userinput without @remap -->
390 <xsl:template match="userinput">
391 <xsl:choose>
392 <xsl:when test="ancestor::sect2[@role='configuration']">
393 <xsl:apply-templates select="." mode="configuration_section"/>
394 </xsl:when>
395 <xsl:otherwise>
396 <xsl:apply-templates select="." mode="no_remap"/>
397 </xsl:otherwise>
398 </xsl:choose>
399 </xsl:template>
400
401
402 <!-- replaceable -->
403 <xsl:template match="replaceable">
404 <xsl:choose>
405 <!-- Configuring the Time Zone -->
406 <xsl:when test="ancestor::sect2[@id='conf-glibc'] and string()='&lt;xxx&gt;'">
407 <xsl:value-of select="$timezone"/>
408 </xsl:when>
409 <!-- Set paper size for Groff build -->
410 <xsl:when test="string()='&lt;paper_size&gt;'">
411 <xsl:value-of select="$page"/>
412 </xsl:when>
413 <!-- LANG setting in /etc/profile -->
414 <xsl:when test="contains(string(),'&lt;ll&gt;_&lt;CC&gt;')">
415 <xsl:value-of select="$lang"/>
416 </xsl:when>
417 <xsl:otherwise>
418 <xsl:text>**EDITME</xsl:text>
419 <xsl:apply-templates/>
420 <xsl:text>EDITME**</xsl:text>
421 </xsl:otherwise>
422 </xsl:choose>
423 </xsl:template>
424
425
426<!-- ######################################################################## -->
427
428<!-- ############################# MODE TEMPLATES ########################### -->
429
430
431 <!-- mode test -->
432 <xsl:template match="userinput" mode="test">
433 <xsl:choose>
434 <!-- No testsuites run on level 0 -->
435 <xsl:when test="$testsuite = '0'"/>
436 <!-- On level 1, only final system toolchain testsuites are run -->
437 <xsl:when test="$testsuite = '1' and
438 not(ancestor::sect1[@id='ch-system-gcc']) and
439 not(ancestor::sect1[@id='ch-system-glibc']) and
440 not(ancestor::sect1[@id='ch-system-binutils'])"/>
441 <!-- On level 2, temp tools testsuites are not run -->
442 <xsl:when test="$testsuite = '2' and
443 ancestor::chapter[@id='chapter-temporary-tools']"/>
444 <!-- Start testsuites command fixes -->
445 <xsl:otherwise>
446 <xsl:choose>
447 <!-- Final system Glibc -->
448 <xsl:when test="contains(string(),'glibc-check-log')">
449 <xsl:value-of select="substring-before(string(),'2&gt;&amp;1')"/>
450 <xsl:text>&gt;&gt; $TEST_LOG 2&gt;&amp;1 || true</xsl:text>
451 </xsl:when>
452 <!-- Module-Init-Tools -->
453 <xsl:when test="ancestor::sect1[@id='ch-system-module-init-tools']
454 and contains(string(),'make check')">
455 <xsl:value-of select="substring-before(string(),' check')"/>
456 <xsl:if test="$bomb-testsuite = 'n'">
457 <xsl:text> -k</xsl:text>
458 </xsl:if>
459 <xsl:text> check &gt;&gt; $TEST_LOG 2&gt;&amp;1</xsl:text>
460 <xsl:if test="$bomb-testsuite = 'n'">
461 <xsl:text> || true</xsl:text>
462 </xsl:if>
463 <xsl:value-of select="substring-after(string(),' check')"/>
464 </xsl:when>
465 <!-- If the book uses -k, the testsuite should never bomb -->
466 <xsl:when test="contains(string(),'make -k ')">
467 <xsl:apply-templates select="." mode="default"/>
468 <xsl:text> &gt;&gt; $TEST_LOG 2&gt;&amp;1 || true</xsl:text>
469 </xsl:when>
470 <!-- Extra commands in Binutils and GCC -->
471 <xsl:when test="contains(string(),'test_summary') or
472 contains(string(),'expect -c')">
473 <xsl:apply-templates select="." mode="default"/>
474 <xsl:text> &gt;&gt; $TEST_LOG</xsl:text>
475 </xsl:when>
476 <!-- Remaining extra testsuite commads that don't need be hacked -->
477 <xsl:when test="not(contains(string(),'make '))">
478 <xsl:apply-templates select="." mode="default"/>
479 </xsl:when>
480 <!-- Normal testsites run -->
481 <xsl:otherwise>
482 <xsl:choose>
483 <!-- No bomb on failures -->
484 <xsl:when test="$bomb-testsuite = 'n'">
485 <xsl:value-of select="substring-before(string(),'make ')"/>
486 <xsl:text>make -k </xsl:text>
487 <xsl:value-of select="substring-after(string(),'make ')"/>
488 <xsl:text> &gt;&gt; $TEST_LOG 2&gt;&amp;1 || true</xsl:text>
489 </xsl:when>
490 <!-- Bomb at the first failure -->
491 <xsl:otherwise>
492 <xsl:apply-templates select="." mode="default"/>
493 <xsl:text> &gt;&gt; $TEST_LOG 2&gt;&amp;1</xsl:text>
494 </xsl:otherwise>
495 </xsl:choose>
496 </xsl:otherwise>
497 </xsl:choose>
498 </xsl:otherwise>
499 </xsl:choose>
500 </xsl:template>
501
502
503 <!-- mode pre -->
504 <xsl:template match="userinput" mode="pre">
505 <xsl:apply-templates select="." mode="default"/>
506 </xsl:template>
507
508
509 <!-- mode configure -->
510 <xsl:template match="userinput" mode="configure">
511 <xsl:apply-templates select="." mode="default"/>
512 </xsl:template>
513
514
515 <!-- mode make -->
516 <xsl:template match="userinput" mode="make">
517 <xsl:apply-templates select="." mode="default"/>
518 </xsl:template>
519
520
521 <!-- mode install -->
522 <xsl:template match="userinput" mode="install">
523 <xsl:apply-templates select="." mode="default"/>
524 </xsl:template>
525
526
527 <!-- mode adjust -->
528 <xsl:template match="userinput" mode="adjust">
529 <xsl:apply-templates select="." mode="default"/>
530 </xsl:template>
531
532
533 <!-- mode locale-test -->
534 <xsl:template match="userinput" mode="locale-test">
535 <xsl:apply-templates select="." mode="default"/>
536 </xsl:template>
537
538
539 <!-- mode locale-full -->
540 <xsl:template match="userinput" mode="locale-full">
541 <xsl:apply-templates select="." mode="default"/>
542 </xsl:template>
543
544
545 <!-- mode configuration_section -->
546 <xsl:template match="userinput" mode="configuration_section">
547 <xsl:apply-templates select="." mode="default"/>
548 </xsl:template>
549
550
551 <!-- mode no_remap -->
552 <xsl:template match="userinput" mode="no_remap">
553 <xsl:apply-templates select="." mode="default"/>
554 </xsl:template>
555
556
557 <!-- mode default -->
558 <xsl:template match="userinput" mode="default">
559 <xsl:apply-templates/>
560 </xsl:template>
561
562</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.