source: LFS/lfs.xsl@ c0f8256

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

Added hocks for custom-tools and blfs-tool scripts generation support.

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