source: LFS/lfs.xsl@ e213e4c

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

Splitted userinput template.

  • Property mode set to 100644
File size: 17.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 <!-- 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 <!-- Process only files with actual build commands -->
211 <xsl:if test="count(descendant::screen/userinput) &gt; 0 and
212 count(descendant::screen/userinput) &gt;
213 count(descendant::screen[@role='nodump'])">
214 <!-- Base file name -->
215 <xsl:variable name="filename">
216 <xsl:call-template name="filename"/>
217 </xsl:variable>
218 <!-- Sect1 order position -->
219 <xsl:variable name="sect1_position" select="position()"/>
220 <xsl:variable name="sect1_order">
221 <xsl:choose>
222 <xsl:when test="string-length($sect1_position) = 1">
223 <xsl:text>0</xsl:text>
224 <xsl:value-of select="$sect1_position"/>
225 </xsl:when>
226 <xsl:otherwise>
227 <xsl:value-of select="$sect1_position"/>
228 </xsl:otherwise>
229 </xsl:choose>
230 </xsl:variable>
231 <!-- Script build order -->
232 <xsl:variable name="order" select="concat($ch_order,'_',$sect1_order)"/>
233 <!-- Creating dirs and files -->
234 <exsl:document href="{$dirname}/{$order}-{$filename}" method="text">
235 <xsl:call-template name="header"/>
236 <xsl:call-template name="user_header"/>
237 <xsl:apply-templates select="sect1info[@condition='script']">
238 <xsl:with-param name="phase" select="$filename"/>
239 </xsl:apply-templates>
240 <xsl:call-template name="user_pre_commands"/>
241 <xsl:call-template name="pre_commands"/>
242 <xsl:apply-templates select=".//screen"/>
243 <xsl:call-template name="post_commands"/>
244 <xsl:call-template name="user_footer"/>
245 <xsl:call-template name="footer"/>
246 </exsl:document>
247 </xsl:if>
248 </xsl:template>
249
250
251 <!-- sect1info -->
252 <xsl:template match="sect1info">
253 <!-- Build phase (base file name) to be used for PM -->
254 <xsl:param name="phase" select="foo"/>
255 <xsl:text>&#xA;PKG_PHASE=</xsl:text>
256 <xsl:value-of select="$phase"/>
257 <!-- Package name -->
258 <xsl:apply-templates select="productname"/>
259 <!-- Package version -->
260 <xsl:apply-templates select="productnumber"/>
261 <!-- Tarball name -->
262 <xsl:apply-templates select="address"/>
263 <xsl:text>&#xA;&#xA;</xsl:text>
264 </xsl:template>
265
266
267 <!-- productname -->
268 <xsl:template match="productname">
269 <xsl:text>&#xA;PACKAGE=</xsl:text>
270 <xsl:apply-templates/>
271 </xsl:template>
272
273
274 <!-- productnumber -->
275 <xsl:template match="productnumber">
276 <xsl:text>&#xA;VERSION=</xsl:text>
277 <xsl:apply-templates/>
278 </xsl:template>
279
280
281 <!-- address -->
282 <xsl:template match="address">
283 <xsl:text>&#xA;TARBALL=</xsl:text>
284 <xsl:call-template name="package_name">
285 <xsl:with-param name="url">
286 <xsl:apply-templates/>
287 </xsl:with-param>
288 </xsl:call-template>
289 <xsl:apply-templates select="otheraddr" mode="tarball"/>
290 </xsl:template>
291
292
293 <!-- otheraddr -->
294 <xsl:template match="otheraddr"/>
295 <xsl:template match="otheraddr" mode="tarball">
296 <xsl:text>&#xA;TARBALL_</xsl:text>
297 <xsl:value-of select="position()"/>
298 <xsl:text>=</xsl:text>
299 <xsl:call-template name="package_name">
300 <xsl:with-param name="url" select="."/>
301 </xsl:call-template>
302 </xsl:template>
303
304
305 <!-- screen -->
306 <xsl:template match="screen">
307 <xsl:if test="child::* = userinput and not(@role = 'nodump')">
308 <xsl:apply-templates select="userinput"/>
309 </xsl:if>
310 </xsl:template>
311
312
313 <!-- userinput -->
314 <xsl:template match="userinput">
315 <xsl:choose>
316 <xsl:when test="@remap = 'pre'">
317 <xsl:apply-templates select="." mode="pre"/>
318 </xsl:when>
319 <xsl:when test="@remap = 'configure'">
320 <xsl:apply-templates select="." mode="configure"/>
321 </xsl:when>
322 <xsl:when test="@remap = 'make'">
323 <xsl:apply-templates select="." mode="make"/>
324 </xsl:when>
325 <xsl:when test="@remap = 'test'">
326 <xsl:apply-templates select="." mode="test"/>
327 </xsl:when>
328 <xsl:when test="@remap = 'install'">
329 <xsl:apply-templates select="." mode="install"/>
330 </xsl:when>
331 <xsl:when test="@remap = 'adjust'">
332 <xsl:apply-templates select="." mode="adjust"/>
333 </xsl:when>
334 <xsl:when test="@remap = 'locale-test'">
335 <xsl:apply-templates select="." mode="locale-test"/>
336 </xsl:when>
337 <xsl:when test="@remap = 'locale-full'">
338 <xsl:apply-templates select="." mode="locale-full"/>
339 </xsl:when>
340 <xsl:otherwise>
341 <xsl:apply-templates select="." mode="default"/>
342 </xsl:otherwise>
343 </xsl:choose>
344 <xsl:text>&#xA;</xsl:text>
345 </xsl:template>
346
347
348 <!-- replaceable -->
349 <xsl:template match="replaceable">
350 <xsl:choose>
351 <!-- Configuring the Time Zone -->
352 <xsl:when test="ancestor::sect2[@id='conf-glibc'] and string()='&lt;xxx&gt;'">
353 <xsl:value-of select="$timezone"/>
354 </xsl:when>
355 <!-- Set paper size for Groff build -->
356 <xsl:when test="string()='&lt;paper_size&gt;'">
357 <xsl:value-of select="$page"/>
358 </xsl:when>
359 <!-- LANG setting in /etc/profile -->
360 <xsl:when test="contains(string(),'&lt;ll&gt;_&lt;CC&gt;')">
361 <xsl:value-of select="$lang"/>
362 </xsl:when>
363 <xsl:otherwise>
364 <xsl:text>**EDITME</xsl:text>
365 <xsl:apply-templates/>
366 <xsl:text>EDITME**</xsl:text>
367 </xsl:otherwise>
368 </xsl:choose>
369 </xsl:template>
370
371
372<!-- ######################################################################## -->
373
374<!-- ############################# MODE TEMPLATES ########################### -->
375
376 <!-- mode default -->
377 <xsl:template match="userinput" mode="default">
378 <!-- All ugly hacks required to fix automatization build issues,
379 except the ones related to testsuites, should go here,
380 no matter what @remap value have assigned -->
381 <xsl:choose>
382 <!-- Fix Udev reinstallation after a build failure -->
383 <xsl:when test="contains(string(),'firmware,udev')">
384 <xsl:text>if [[ ! -d /lib/udev/devices ]] ; then&#xA;</xsl:text>
385 <xsl:apply-templates/>
386 <xsl:text>&#xA;fi</xsl:text>
387 </xsl:when>
388 <!-- Copying the kernel config file -->
389 <xsl:when test="string() = 'make mrproper'">
390 <xsl:text>make mrproper&#xA;</xsl:text>
391 <xsl:text>cp -v ../kernel-config .config</xsl:text>
392 </xsl:when>
393 <!-- Don't stop on strip run -->
394 <xsl:when test="contains(string(),'strip --strip')">
395 <xsl:apply-templates/>
396 <xsl:text> || true</xsl:text>
397 </xsl:when>
398 <!-- The rest of commands -->
399 <xsl:otherwise>
400 <xsl:apply-templates/>
401 </xsl:otherwise>
402 </xsl:choose>
403 </xsl:template>
404
405
406 <!-- mode test -->
407 <xsl:template match="userinput" mode="test">
408 <xsl:choose>
409 <!-- No testsuites run on level 0 -->
410 <xsl:when test="$testsuite = '0'"/>
411 <!-- On level 1, only final system toolchain testsuites are run -->
412 <xsl:when test="$testsuite = '1' and
413 not(ancestor::sect1[@id='ch-system-gcc']) and
414 not(ancestor::sect1[@id='ch-system-glibc']) and
415 not(ancestor::sect1[@id='ch-system-binutils'])"/>
416 <!-- On level 2, temp tools testsuites are not run -->
417 <xsl:when test="$testsuite = '2' and
418 ancestor::chapter[@id='chapter-temporary-tools']"/>
419 <!-- Start testsuites command fixes -->
420 <xsl:otherwise>
421 <xsl:choose>
422 <!-- Final system Glibc -->
423 <xsl:when test="contains(string(),'glibc-check-log')">
424 <xsl:value-of select="substring-before(string(),'2&gt;&amp;1')"/>
425 <xsl:text>&gt;&gt; $TEST_LOG 2&gt;&amp;1 || true</xsl:text>
426 </xsl:when>
427 <!-- Module-Init-Tools -->
428 <xsl:when test="ancestor::sect1[@id='ch-system-module-init-tools']
429 and contains(string(),'make check')">
430 <xsl:value-of select="substring-before(string(),' check')"/>
431 <xsl:if test="$bomb-testsuite = 'n'">
432 <xsl:text> -k</xsl:text>
433 </xsl:if>
434 <xsl:text> check &gt;&gt; $TEST_LOG 2&gt;&amp;1</xsl:text>
435 <xsl:if test="$bomb-testsuite = 'n'">
436 <xsl:text> || true</xsl:text>
437 </xsl:if>
438 <xsl:value-of select="substring-after(string(),' check')"/>
439 </xsl:when>
440 <!-- If the book uses -k, the testsuite should never bomb -->
441 <xsl:when test="contains(string(),'make -k ')">
442 <xsl:apply-templates select="." mode="default"/>
443 <xsl:text> &gt;&gt; $TEST_LOG 2&gt;&amp;1 || true</xsl:text>
444 </xsl:when>
445 <!-- Extra commands in Binutils and GCC -->
446 <xsl:when test="contains(string(),'test_summary') or
447 contains(string(),'expect -c')">
448 <xsl:apply-templates select="." mode="default"/>
449 <xsl:text> &gt;&gt; $TEST_LOG</xsl:text>
450 </xsl:when>
451 <!-- Remaining extra testsuite commads that don't need be hacked -->
452 <xsl:when test="not(contains(string(),'make '))">
453 <xsl:apply-templates select="." mode="default"/>
454 </xsl:when>
455 <!-- Normal testsites run -->
456 <xsl:otherwise>
457 <xsl:choose>
458 <!-- No bomb on failures -->
459 <xsl:when test="$bomb-testsuite = 'n'">
460 <xsl:value-of select="substring-before(string(),'make ')"/>
461 <xsl:text>make -k </xsl:text>
462 <xsl:value-of select="substring-after(string(),'make ')"/>
463 <xsl:text> &gt;&gt; $TEST_LOG 2&gt;&amp;1 || true</xsl:text>
464 </xsl:when>
465 <!-- Bomb at the first failure -->
466 <xsl:otherwise>
467 <xsl:apply-templates select="." mode="default"/>
468 <xsl:text> &gt;&gt; $TEST_LOG 2&gt;&amp;1</xsl:text>
469 </xsl:otherwise>
470 </xsl:choose>
471 </xsl:otherwise>
472 </xsl:choose>
473 </xsl:otherwise>
474 </xsl:choose>
475 </xsl:template>
476
477
478 <!-- mode pre -->
479 <xsl:template match="userinput" mode="pre">
480 <xsl:apply-templates select="." mode="default"/>
481 </xsl:template>
482
483
484 <!-- mode configure -->
485 <xsl:template match="userinput" mode="configure">
486 <xsl:apply-templates select="." mode="default"/>
487 </xsl:template>
488
489
490 <!-- mode make -->
491 <xsl:template match="userinput" mode="make">
492 <xsl:apply-templates select="." mode="default"/>
493 </xsl:template>
494
495
496 <!-- mode install -->
497 <xsl:template match="userinput" mode="install">
498 <xsl:apply-templates select="." mode="default"/>
499 </xsl:template>
500
501
502 <!-- mode adjust -->
503 <xsl:template match="userinput" mode="adjust">
504 <xsl:apply-templates select="." mode="default"/>
505 </xsl:template>
506
507
508 <!-- mode locale-test -->
509 <xsl:template match="userinput" mode="locale-test">
510 <xsl:apply-templates select="." mode="default"/>
511 </xsl:template>
512
513
514 <!-- mode locale-full -->
515 <xsl:template match="userinput" mode="locale-full">
516 <xsl:apply-templates select="." mode="default"/>
517 </xsl:template>
518
519</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.