source: LFS/lfs.xsl@ 13b4ab5

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

Added sect1info templates and some customization hocks.

  • Property mode set to 100644
File size: 18.4 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 ../vim-&vim-version;-lang.* --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 <!-- Extract a package name from a package URL -->
147 <xsl:template name="package_name">
148 <xsl:param name="url" select="foo"/>
149 <xsl:param name="sub-url" select="substring-after($url,'/')"/>
150 <xsl:choose>
151 <xsl:when test="contains($sub-url,'/')">
152 <xsl:call-template name="package_name">
153 <xsl:with-param name="url" select="$sub-url"/>
154 </xsl:call-template>
155 </xsl:when>
156 <xsl:otherwise>
157 <xsl:value-of select="$sub-url"/>
158 </xsl:otherwise>
159 </xsl:choose>
160 </xsl:template>
161
162
163<!-- ######################################################################## -->
164
165<!-- ############################# MATCH TEMPLATES ########################## -->
166
167 <!-- Root element -->
168 <xsl:template match="/">
169 <!-- Start processing at chapter level -->
170 <xsl:apply-templates select="//chapter"/>
171 </xsl:template>
172
173
174 <!-- chapter -->
175 <xsl:template match="chapter">
176 <xsl:if test="@id='chapter-temporary-tools' or @id='chapter-building-system'
177 or @id='chapter-bootscripts' or @id='chapter-bootable'">
178 <!-- The dir name -->
179 <xsl:variable name="dirname">
180 <xsl:call-template name="dirname"/>
181 </xsl:variable>
182 <!-- The chapter order position -->
183 <xsl:variable name="ch_position" select="position()"/>
184 <xsl:variable name="ch_order">
185 <xsl:choose>
186 <xsl:when test="string-length($ch_position) = 1">
187 <xsl:text>0</xsl:text>
188 <xsl:value-of select="$ch_position"/>
189 </xsl:when>
190 <xsl:otherwise>
191 <xsl:value-of select="$ch_position"/>
192 </xsl:otherwise>
193 </xsl:choose>
194 </xsl:variable>
195 <!-- Process the childrens -->
196 <xsl:apply-templates select="sect1">
197 <xsl:with-param name="ch_order" select="$ch_order"/>
198 <xsl:with-param name="dirname" select="$dirname"/>
199 </xsl:apply-templates>
200 </xsl:if>
201 </xsl:template>
202
203
204 <!-- sect1 -->
205 <xsl:template match="sect1">
206 <!-- Inherited chapter order -->
207 <xsl:param name="ch_order" select="foo"/>
208 <!-- Inherited dir name -->
209 <xsl:param name="dirname" select="foo"/>
210 <xsl:if test="count(descendant::screen/userinput) &gt; 0 and
211 count(descendant::screen/userinput) &gt;
212 count(descendant::screen[@role='nodump'])">
213 <!-- Base file name -->
214 <xsl:variable name="filename">
215 <xsl:call-template name="filename"/>
216 </xsl:variable>
217 <!-- Sect1 order position -->
218 <xsl:variable name="sect1_position" select="position()"/>
219 <xsl:variable name="sect1_order">
220 <xsl:choose>
221 <xsl:when test="string-length($sect1_position) = 1">
222 <xsl:text>0</xsl:text>
223 <xsl:value-of select="$sect1_position"/>
224 </xsl:when>
225 <xsl:otherwise>
226 <xsl:value-of select="$sect1_position"/>
227 </xsl:otherwise>
228 </xsl:choose>
229 </xsl:variable>
230 <!-- Script build order -->
231 <xsl:variable name="order" select="concat($ch_order,'_',$sect1_order)"/>
232 <!-- Creating dirs and files -->
233 <exsl:document href="{$dirname}/{$order}-{$filename}" method="text">
234 <xsl:call-template name="header"/>
235 <xsl:call-template name="user_header"/>
236 <xsl:apply-templates select="sect1info[@condition='script']">
237 <xsl:with-param name="phase" select="$filename"/>
238 </xsl:apply-templates>
239 <xsl:call-template name="user_pre_commands"/>
240 <xsl:call-template name="pre_commands"/>
241 <xsl:apply-templates select=".//screen"/>
242 <xsl:call-template name="post_commands"/>
243 <xsl:call-template name="user_footer"/>
244 <xsl:call-template name="footer"/>
245 </exsl:document>
246 </xsl:if>
247 </xsl:template>
248
249
250 <!-- sect1info -->
251 <xsl:template match="sect1info">
252 <!-- Build phase (base file name) to be used for PM -->
253 <xsl:param name="phase" select="foo"/>
254 <xsl:text>&#xA;PKG_PHASE=</xsl:text>
255 <xsl:value-of select="$phase"/>
256 <!-- Package name -->
257 <xsl:apply-templates select="productname"/>
258 <!-- Package version -->
259 <xsl:apply-templates select="productnumber"/>
260 <!-- Tarball name -->
261 <xsl:apply-templates select="address"/>
262 <xsl:text>&#xA;&#xA;</xsl:text>
263 </xsl:template>
264
265
266 <!-- productname -->
267 <xsl:template match="productname">
268 <xsl:text>&#xA;PACKAGE=</xsl:text>
269 <xsl:apply-templates/>
270 </xsl:template>
271
272
273 <!-- productnumber -->
274 <xsl:template match="productnumber">
275 <xsl:text>&#xA;VERSION=</xsl:text>
276 <xsl:apply-templates/>
277 </xsl:template>
278
279
280 <!-- address -->
281 <xsl:template match="address">
282 <xsl:text>&#xA;TARBALL=</xsl:text>
283 <xsl:call-template name="package_name">
284 <xsl:with-param name="url">
285 <xsl:apply-templates/>
286 </xsl:with-param>
287 </xsl:call-template>
288 <xsl:apply-templates select="otheraddr" mode="tarball"/>
289 </xsl:template>
290
291
292 <!-- otheraddr -->
293 <xsl:template match="otheraddr"/>
294 <xsl:template match="otheraddr" mode="tarball">
295 <xsl:text>&#xA;TARBALL_</xsl:text>
296 <xsl:value-of select="position()"/>
297 <xsl:text>=</xsl:text>
298 <xsl:call-template name="package_name">
299 <xsl:with-param name="url" select="."/>
300 </xsl:call-template>
301 </xsl:template>
302
303
304 <!-- screen -->
305 <xsl:template match="screen">
306 <xsl:if test="child::* = userinput and not(@role = 'nodump')">
307 <xsl:apply-templates select="userinput"/>
308 </xsl:if>
309 </xsl:template>
310
311
312 <!-- userinput -->
313 <xsl:template match="userinput">
314 <xsl:choose>
315 <!-- Estandarized package formats -->
316 <xsl:when test="contains(string(),'tar.gz')">
317 <xsl:value-of select="substring-before(string(),'tar.gz')"/>
318 <xsl:text>tar.*</xsl:text>
319 <xsl:value-of select="substring-after(string(),'tar.gz')"/>
320 <xsl:text>&#xA;</xsl:text>
321 </xsl:when>
322 <!-- Avoiding a race condition in a patch -->
323 <xsl:when test="contains(string(),'debian_fixes')">
324 <xsl:value-of select="substring-before(string(),'patch')"/>
325 <xsl:text>patch -Z</xsl:text>
326 <xsl:value-of select="substring-after(string(),'patch')"/>
327 <xsl:text>&#xA;</xsl:text>
328 </xsl:when>
329 <!-- Fix Udev reinstallation after a build failure -->
330 <xsl:when test="contains(string(),'firmware,udev')">
331 <xsl:text>if [[ ! -d /lib/udev/devices ]] ; then&#xA;</xsl:text>
332 <xsl:apply-templates/>
333 <xsl:text>&#xA;fi&#xA;</xsl:text>
334 </xsl:when>
335 <!-- Setting $LANG for /etc/profile -->
336 <xsl:when test="ancestor::sect1[@id='ch-scripts-profile'] and
337 contains(string(),'export LANG=')">
338 <xsl:value-of select="substring-before(string(),'export LANG=')"/>
339 <xsl:text>export LANG=</xsl:text>
340 <xsl:value-of select="$lang"/>
341 <xsl:value-of select="substring-after(string(),'modifiers>')"/>
342 <xsl:text>&#xA;</xsl:text>
343 </xsl:when>
344 <!-- Copying the kernel config file -->
345 <xsl:when test="string() = 'make mrproper'">
346 <xsl:text>make mrproper&#xA;</xsl:text>
347 <xsl:text>cp -v ../kernel-config .config&#xA;</xsl:text>
348 </xsl:when>
349 <!-- The Bash, Coreutils, and Module-Init-Tools test suites are optional -->
350 <xsl:when test="(ancestor::sect1[@id='ch-system-coreutils'] or
351 ancestor::sect1[@id='ch-system-bash'] or
352 ancestor::sect1[@id='ch-system-module-init-tools'])
353 and @remap = 'test'">
354 <xsl:choose>
355 <xsl:when test="$testsuite = '0' or $testsuite = '1'"/>
356 <xsl:otherwise>
357 <xsl:if test="not(contains(string(),'check')) and
358 not(contains(string(),'make tests'))">
359 <xsl:apply-templates/>
360 <xsl:text>&#xA;</xsl:text>
361 </xsl:if>
362 <!-- Coreutils and Module-Init-Tools -->
363 <xsl:if test="contains(string(),'check')">
364 <xsl:choose>
365 <xsl:when test="$bomb-testsuite = 'n'">
366 <xsl:value-of select="substring-before(string(),'check')"/>
367 <xsl:text>-k check</xsl:text>
368 <xsl:value-of select="substring-after(string(),'check')"/>
369 <xsl:text> &gt;&gt; $TEST_LOG 2&gt;&amp;1 || true&#xA;</xsl:text>
370 </xsl:when>
371 <xsl:otherwise>
372 <xsl:apply-templates/>
373 <xsl:text> &gt;&gt; $TEST_LOG 2&gt;&amp;1</xsl:text>
374 <xsl:if test="contains(string(),' -k ')">
375 <xsl:text> || true</xsl:text>
376 </xsl:if>
377 <xsl:text>&#xA;</xsl:text>
378 </xsl:otherwise>
379 </xsl:choose>
380 </xsl:if>
381 <!-- Bash -->
382 <xsl:if test="contains(string(),'make tests')">
383 <xsl:choose>
384 <xsl:when test="$bomb-testsuite = 'n'">
385 <xsl:value-of select="substring-before(string(),'tests')"/>
386 <xsl:text>-k tests</xsl:text>
387 <xsl:value-of select="substring-after(string(),'tests')"/>
388 <xsl:text> &gt;&gt; $TEST_LOG 2&gt;&amp;1 || true&#xA;</xsl:text>
389 </xsl:when>
390 <xsl:otherwise>
391 <xsl:apply-templates/>
392 <xsl:text> &gt;&gt; $TEST_LOG 2&gt;&amp;1</xsl:text>
393 <xsl:if test="contains(string(),' -k ')">
394 <xsl:text> || true</xsl:text>
395 </xsl:if>
396 <xsl:text>&#xA;</xsl:text>
397 </xsl:otherwise>
398 </xsl:choose>
399 </xsl:if>
400 </xsl:otherwise>
401 </xsl:choose>
402 </xsl:when>
403 <!-- Fixing toolchain test suites run -->
404 <xsl:when test="(string() = 'make check' or
405 string() = 'make -k check') and
406 (ancestor::sect1[@id='ch-system-gcc'] or
407 ancestor::sect1[@id='ch-system-glibc'] or
408 ancestor::sect1[@id='ch-system-binutils'] or
409 ancestor::sect1[@id='ch-tools-gcc-pass2'])">
410 <xsl:choose>
411 <xsl:when test="(($testsuite = '1' or $testsuite = '2') and
412 ancestor::chapter[@id='chapter-building-system']) or
413 $testsuite = '3'">
414 <xsl:choose>
415 <xsl:when test="$bomb-testsuite = 'n'">
416 <xsl:text>make -k check &gt;&gt; $TEST_LOG 2&gt;&amp;1 || true&#xA;</xsl:text>
417 </xsl:when>
418 <xsl:otherwise>
419 <xsl:apply-templates/>
420 <xsl:text> &gt;&gt; $TEST_LOG 2&gt;&amp;1</xsl:text>
421 <xsl:if test="contains(string(),' -k ')">
422 <xsl:text> || true</xsl:text>
423 </xsl:if>
424 <xsl:text>&#xA;</xsl:text>
425 </xsl:otherwise>
426 </xsl:choose>
427 </xsl:when>
428 </xsl:choose>
429 </xsl:when>
430 <xsl:when test="contains(string(),'glibc-check-log')">
431 <xsl:choose>
432 <xsl:when test="$testsuite != '0'">
433 <xsl:value-of select="substring-before(string(),'2&gt;&amp;1')"/>
434 <xsl:text>&gt;&gt; $TEST_LOG 2&gt;&amp;1 || true&#xA;</xsl:text>
435 </xsl:when>
436 </xsl:choose>
437 </xsl:when>
438 <xsl:when test="contains(string(),'test_summary') or
439 contains(string(),'expect -c')">
440 <xsl:choose>
441 <xsl:when test="(($testsuite = '1' or $testsuite = '2') and
442 ancestor::chapter[@id='chapter-building-system']) or
443 $testsuite = '3'">
444 <xsl:apply-templates/>
445 <xsl:text> &gt;&gt; $TEST_LOG&#xA;</xsl:text>
446 </xsl:when>
447 </xsl:choose>
448 </xsl:when>
449 <!-- The rest of testsuites -->
450 <xsl:when test="@remap = 'test'">
451 <xsl:choose>
452 <xsl:when test="$testsuite = '0'"/>
453 <xsl:when test="$testsuite = '1' and
454 not(ancestor::sect1[@id='ch-system-gcc']) and
455 not(ancestor::sect1[@id='ch-system-glibc']) and
456 not(ancestor::sect1[@id='ch-system-binutils'])"/>
457 <xsl:when test="$testsuite = '2' and
458 ancestor::chapter[@id='chapter-temporary-tools']"/>
459 <xsl:otherwise>
460 <xsl:choose>
461 <xsl:when test="$bomb-testsuite = 'n'">
462 <xsl:value-of select="substring-before(string(),'make')"/>
463 <xsl:text>make -k</xsl:text>
464 <xsl:value-of select="substring-after(string(),'make')"/>
465 <xsl:text> &gt;&gt; $TEST_LOG 2&gt;&amp;1 || true&#xA;</xsl:text>
466 </xsl:when>
467 <xsl:otherwise>
468 <xsl:apply-templates/>
469 <xsl:text> &gt;&gt; $TEST_LOG 2&gt;&amp;1</xsl:text>
470 <xsl:if test="contains(string(),' -k ')">
471 <xsl:text> || true</xsl:text>
472 </xsl:if>
473 <xsl:text>&#xA;</xsl:text>
474 </xsl:otherwise>
475 </xsl:choose>
476 </xsl:otherwise>
477 </xsl:choose>
478 </xsl:when>
479 <!-- Don't stop on strip run -->
480 <xsl:when test="contains(string(),'strip ')">
481 <xsl:apply-templates/>
482 <xsl:text> || true&#xA;</xsl:text>
483 </xsl:when>
484 <!-- The rest of commands -->
485 <xsl:otherwise>
486 <xsl:apply-templates/>
487 <xsl:text>&#xA;</xsl:text>
488 </xsl:otherwise>
489 </xsl:choose>
490 </xsl:template>
491
492 <xsl:template match="replaceable">
493 <xsl:choose>
494 <xsl:when test="ancestor::sect1[@id='ch-system-glibc']">
495 <xsl:value-of select="$timezone"/>
496 </xsl:when>
497 <xsl:when test="ancestor::sect1[@id='ch-system-groff']">
498 <xsl:value-of select="$page"/>
499 </xsl:when>
500 <xsl:otherwise>
501 <xsl:text>**EDITME</xsl:text>
502 <xsl:apply-templates/>
503 <xsl:text>EDITME**</xsl:text>
504 </xsl:otherwise>
505 </xsl:choose>
506 </xsl:template>
507
508</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.