source: LFS/lfs.xsl@ 55d2c3e

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

Generating blfs-tool dependencies scripts.

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