source: LFS/lfs.xsl@ e2dfa2c

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

Migrated optimizations support to XSL-based code.

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