source: LFS/lfs.xsl@ fa1b640

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

Moved remaining build hacks to named templates.
Added a lot of hocks for userinput customizations.

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