source: LFS/lfs.xsl@ 3778352

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

Started XSL redo.

  • Property mode set to 100644
File size: 15.2 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<!-- ########################### NAMED TEMPLATES ########################### -->
47
48 <!-- Chapter directory name (the same used for HTML output) -->
49 <xsl:template name="dirname">
50 <xsl:variable name="pi-dir" select="processing-instruction('dbhtml')"/>
51 <xsl:variable name="pi-dir-value" select="substring-after($pi-dir,'dir=')"/>
52 <xsl:variable name="quote-dir" select="substring($pi-dir-value,1,1)"/>
53 <xsl:variable name="dirname" select="substring-before(substring($pi-dir-value,2),$quote-dir)"/>
54 <xsl:value-of select="$dirname"/>
55 </xsl:template>
56
57
58 <!-- Base file name (the same used for HTML output) -->
59 <xsl:template name="filename">
60 <xsl:variable name="pi-file" select="processing-instruction('dbhtml')"/>
61 <xsl:variable name="pi-file-value" select="substring-after($pi-file,'filename=')"/>
62 <xsl:variable name="filename" select="substring-before(substring($pi-file-value,2),'.html')"/>
63 <xsl:value-of select="$filename"/>
64 </xsl:template>
65
66
67 <!-- Script header -->
68 <xsl:template name="header">
69 <xsl:choose>
70 <xsl:when test="@id='ch-system-creatingdirs' or
71 @id='ch-system-createfiles' or
72 @id='ch-system-strippingagain'">
73 <xsl:text>#!/tools/bin/bash&#xA;</xsl:text>
74 </xsl:when>
75 <xsl:otherwise>
76 <xsl:text>#!/bin/bash&#xA;</xsl:text>
77 </xsl:otherwise>
78 </xsl:choose>
79
80 <xsl:text>set +h&#xA;</xsl:text>
81
82 <xsl:if test="not(@id='ch-tools-stripping') and
83 not(@id='ch-system-strippingagain')">
84 <xsl:text>set -e&#xA;</xsl:text>
85 </xsl:if>
86
87 <xsl:text>&#xA;</xsl:text>
88 </xsl:template>
89
90
91 <!-- Extra previous commands needed by the book but not inside screen tags -->
92 <xsl:template name="pre_commands">
93 <xsl:if test="sect2[@role='installation']">
94 <xsl:text>cd $PKGDIR&#xA;</xsl:text>
95 </xsl:if>
96 <xsl:if test="@id='ch-system-vim' and $vim-lang = 'y'">
97 <xsl:text>tar -xvf ../vim-&vim-version;-lang.* --strip-components=1&#xA;</xsl:text>
98 </xsl:if>
99 </xsl:template>
100
101
102 <!-- Extra post commands needed by the book but not inside screen tags -->
103 <xsl:template name="post_commands">
104 <xsl:if test="$testsuite='3' and @id='ch-tools-glibc'">
105 <xsl:copy-of select="//userinput[@remap='locale-test']"/>
106 <xsl:text>&#xA;</xsl:text>
107 </xsl:if>
108 </xsl:template>
109
110
111 <!-- Script footer -->
112 <xsl:template name="footer">
113 <xsl:if test="not(@id='ch-system-chroot') and
114 not(@id='ch-system-revisedchroot')">
115 <xsl:text>echo -e "\n\nTotalseconds: $SECONDS\n"&#xA;</xsl:text>
116 </xsl:if>
117
118 <xsl:text>exit&#xA;</xsl:text>
119 </xsl:template>
120
121<!-- ######################################################################## -->
122
123<!-- ############################# MATCH TEMPLATES ########################## -->
124
125 <!-- Root element -->
126 <xsl:template match="/">
127 <xsl:apply-templates select="//chapter"/>
128 </xsl:template>
129
130
131 <!-- chapter -->
132 <xsl:template match="chapter">
133 <xsl:if test="@id='chapter-temporary-tools' or @id='chapter-building-system'
134 or @id='chapter-bootscripts' or @id='chapter-bootable'">
135
136 <!-- The dir name -->
137 <xsl:variable name="dirname">
138 <xsl:call-template name="dirname"/>
139 </xsl:variable>
140
141 <!-- The chapter order position -->
142 <xsl:variable name="ch_position" select="position()"/>
143 <xsl:variable name="ch_order">
144 <xsl:choose>
145 <xsl:when test="string-length($ch_position) = 1">
146 <xsl:text>0</xsl:text>
147 <xsl:value-of select="$ch_position"/>
148 </xsl:when>
149 <xsl:otherwise>
150 <xsl:value-of select="$ch_position"/>
151 </xsl:otherwise>
152 </xsl:choose>
153 </xsl:variable>
154
155 <xsl:apply-templates select="sect1">
156 <xsl:with-param name="ch_order" select="$ch_order"/>
157 <xsl:with-param name="dirname" select="$dirname"/>
158 </xsl:apply-templates>
159
160 </xsl:if>
161 </xsl:template>
162
163
164 <!-- sect1 -->
165 <xsl:template match="sect1">
166
167 <!-- Inherited chapter order -->
168 <xsl:param name="ch_order" select="foo"/>
169
170 <!-- Inherited dir name -->
171 <xsl:param name="dirname" select="foo"/>
172
173 <xsl:if test="count(descendant::screen/userinput) &gt; 0 and
174 count(descendant::screen/userinput) &gt;
175 count(descendant::screen[@role='nodump'])">
176
177 <!-- Base file name -->
178 <xsl:variable name="filename">
179 <xsl:call-template name="filename"/>
180 </xsl:variable>
181
182 <!-- Sect1 order position -->
183 <xsl:variable name="sect1_position" select="position()"/>
184 <xsl:variable name="sect1_order">
185 <xsl:choose>
186 <xsl:when test="string-length($sect1_position) = 1">
187 <xsl:text>0</xsl:text>
188 <xsl:value-of select="$sect1_position"/>
189 </xsl:when>
190 <xsl:otherwise>
191 <xsl:value-of select="$sect1_position"/>
192 </xsl:otherwise>
193 </xsl:choose>
194 </xsl:variable>
195
196 <!-- Script build order -->
197 <xsl:variable name="order" select="concat($ch_order,'_',$sect1_order)"/>
198
199 <!-- Creating dirs and files -->
200 <exsl:document href="{$dirname}/{$order}-{$filename}" method="text">
201 <xsl:call-template name="header"/>
202 <xsl:call-template name="pre_commands"/>
203 <xsl:apply-templates select=".//screen"/>
204 <xsl:call-template name="post_commands"/>
205 <xsl:call-template name="footer"/>
206 </exsl:document>
207
208 </xsl:if>
209 </xsl:template>
210
211
212
213
214
215
216 <xsl:template match="screen">
217 <xsl:if test="child::* = userinput and not(@role = 'nodump')">
218 <xsl:apply-templates select="userinput" mode="screen"/>
219 </xsl:if>
220 </xsl:template>
221
222 <xsl:template match="userinput" mode="screen">
223 <xsl:choose>
224 <!-- Estandarized package formats -->
225 <xsl:when test="contains(string(),'tar.gz')">
226 <xsl:value-of select="substring-before(string(),'tar.gz')"/>
227 <xsl:text>tar.*</xsl:text>
228 <xsl:value-of select="substring-after(string(),'tar.gz')"/>
229 <xsl:text>&#xA;</xsl:text>
230 </xsl:when>
231 <!-- Avoiding a race condition in a patch -->
232 <xsl:when test="contains(string(),'debian_fixes')">
233 <xsl:value-of select="substring-before(string(),'patch')"/>
234 <xsl:text>patch -Z</xsl:text>
235 <xsl:value-of select="substring-after(string(),'patch')"/>
236 <xsl:text>&#xA;</xsl:text>
237 </xsl:when>
238 <!-- Fix Udev reinstallation after a build failure -->
239 <xsl:when test="contains(string(),'firmware,udev')">
240 <xsl:text>if [[ ! -d /lib/udev/devices ]] ; then&#xA;</xsl:text>
241 <xsl:apply-templates/>
242 <xsl:text>&#xA;fi&#xA;</xsl:text>
243 </xsl:when>
244 <!-- Setting $LANG for /etc/profile -->
245 <xsl:when test="ancestor::sect1[@id='ch-scripts-profile'] and
246 contains(string(),'export LANG=')">
247 <xsl:value-of select="substring-before(string(),'export LANG=')"/>
248 <xsl:text>export LANG=</xsl:text>
249 <xsl:value-of select="$lang"/>
250 <xsl:value-of select="substring-after(string(),'modifiers>')"/>
251 <xsl:text>&#xA;</xsl:text>
252 </xsl:when>
253 <!-- Copying the kernel config file -->
254 <xsl:when test="string() = 'make mrproper'">
255 <xsl:text>make mrproper&#xA;</xsl:text>
256 <xsl:text>cp -v ../kernel-config .config&#xA;</xsl:text>
257 </xsl:when>
258 <!-- The Bash, Coreutils, and Module-Init-Tools test suites are optional -->
259 <xsl:when test="(ancestor::sect1[@id='ch-system-coreutils'] or
260 ancestor::sect1[@id='ch-system-bash'] or
261 ancestor::sect1[@id='ch-system-module-init-tools'])
262 and @remap = 'test'">
263 <xsl:choose>
264 <xsl:when test="$testsuite = '0' or $testsuite = '1'"/>
265 <xsl:otherwise>
266 <xsl:if test="not(contains(string(),'check')) and
267 not(contains(string(),'make tests'))">
268 <xsl:apply-templates/>
269 <xsl:text>&#xA;</xsl:text>
270 </xsl:if>
271 <!-- Coreutils and Module-Init-Tools -->
272 <xsl:if test="contains(string(),'check')">
273 <xsl:choose>
274 <xsl:when test="$bomb-testsuite = 'n'">
275 <xsl:value-of select="substring-before(string(),'check')"/>
276 <xsl:text>-k check</xsl:text>
277 <xsl:value-of select="substring-after(string(),'check')"/>
278 <xsl:text> &gt;&gt; $TEST_LOG 2&gt;&amp;1 || true&#xA;</xsl:text>
279 </xsl:when>
280 <xsl:otherwise>
281 <xsl:apply-templates/>
282 <xsl:text> &gt;&gt; $TEST_LOG 2&gt;&amp;1</xsl:text>
283 <xsl:if test="contains(string(),' -k ')">
284 <xsl:text> || true</xsl:text>
285 </xsl:if>
286 <xsl:text>&#xA;</xsl:text>
287 </xsl:otherwise>
288 </xsl:choose>
289 </xsl:if>
290 <!-- Bash -->
291 <xsl:if test="contains(string(),'make tests')">
292 <xsl:choose>
293 <xsl:when test="$bomb-testsuite = 'n'">
294 <xsl:value-of select="substring-before(string(),'tests')"/>
295 <xsl:text>-k tests</xsl:text>
296 <xsl:value-of select="substring-after(string(),'tests')"/>
297 <xsl:text> &gt;&gt; $TEST_LOG 2&gt;&amp;1 || true&#xA;</xsl:text>
298 </xsl:when>
299 <xsl:otherwise>
300 <xsl:apply-templates/>
301 <xsl:text> &gt;&gt; $TEST_LOG 2&gt;&amp;1</xsl:text>
302 <xsl:if test="contains(string(),' -k ')">
303 <xsl:text> || true</xsl:text>
304 </xsl:if>
305 <xsl:text>&#xA;</xsl:text>
306 </xsl:otherwise>
307 </xsl:choose>
308 </xsl:if>
309 </xsl:otherwise>
310 </xsl:choose>
311 </xsl:when>
312 <!-- Fixing toolchain test suites run -->
313 <xsl:when test="(string() = 'make check' or
314 string() = 'make -k check') and
315 (ancestor::sect1[@id='ch-system-gcc'] or
316 ancestor::sect1[@id='ch-system-glibc'] or
317 ancestor::sect1[@id='ch-system-binutils'] or
318 ancestor::sect1[@id='ch-tools-gcc-pass2'])">
319 <xsl:choose>
320 <xsl:when test="(($testsuite = '1' or $testsuite = '2') and
321 ancestor::chapter[@id='chapter-building-system']) or
322 $testsuite = '3'">
323 <xsl:choose>
324 <xsl:when test="$bomb-testsuite = 'n'">
325 <xsl:text>make -k check &gt;&gt; $TEST_LOG 2&gt;&amp;1 || true&#xA;</xsl:text>
326 </xsl:when>
327 <xsl:otherwise>
328 <xsl:apply-templates/>
329 <xsl:text> &gt;&gt; $TEST_LOG 2&gt;&amp;1</xsl:text>
330 <xsl:if test="contains(string(),' -k ')">
331 <xsl:text> || true</xsl:text>
332 </xsl:if>
333 <xsl:text>&#xA;</xsl:text>
334 </xsl:otherwise>
335 </xsl:choose>
336 </xsl:when>
337 </xsl:choose>
338 </xsl:when>
339 <xsl:when test="contains(string(),'glibc-check-log')">
340 <xsl:choose>
341 <xsl:when test="$testsuite != '0'">
342 <xsl:value-of select="substring-before(string(),'2&gt;&amp;1')"/>
343 <xsl:text>&gt;&gt; $TEST_LOG 2&gt;&amp;1 || true&#xA;</xsl:text>
344 </xsl:when>
345 </xsl:choose>
346 </xsl:when>
347 <xsl:when test="contains(string(),'test_summary') or
348 contains(string(),'expect -c')">
349 <xsl:choose>
350 <xsl:when test="(($testsuite = '1' or $testsuite = '2') and
351 ancestor::chapter[@id='chapter-building-system']) or
352 $testsuite = '3'">
353 <xsl:apply-templates/>
354 <xsl:text> &gt;&gt; $TEST_LOG&#xA;</xsl:text>
355 </xsl:when>
356 </xsl:choose>
357 </xsl:when>
358 <!-- The rest of testsuites -->
359 <xsl:when test="@remap = 'test'">
360 <xsl:choose>
361 <xsl:when test="$testsuite = '0'"/>
362 <xsl:when test="$testsuite = '1' and
363 not(ancestor::sect1[@id='ch-system-gcc']) and
364 not(ancestor::sect1[@id='ch-system-glibc']) and
365 not(ancestor::sect1[@id='ch-system-binutils'])"/>
366 <xsl:when test="$testsuite = '2' and
367 ancestor::chapter[@id='chapter-temporary-tools']"/>
368 <xsl:otherwise>
369 <xsl:choose>
370 <xsl:when test="$bomb-testsuite = 'n'">
371 <xsl:value-of select="substring-before(string(),'make')"/>
372 <xsl:text>make -k</xsl:text>
373 <xsl:value-of select="substring-after(string(),'make')"/>
374 <xsl:text> &gt;&gt; $TEST_LOG 2&gt;&amp;1 || true&#xA;</xsl:text>
375 </xsl:when>
376 <xsl:otherwise>
377 <xsl:apply-templates/>
378 <xsl:text> &gt;&gt; $TEST_LOG 2&gt;&amp;1</xsl:text>
379 <xsl:if test="contains(string(),' -k ')">
380 <xsl:text> || true</xsl:text>
381 </xsl:if>
382 <xsl:text>&#xA;</xsl:text>
383 </xsl:otherwise>
384 </xsl:choose>
385 </xsl:otherwise>
386 </xsl:choose>
387 </xsl:when>
388 <!-- Don't stop on strip run -->
389 <xsl:when test="contains(string(),'strip ')">
390 <xsl:apply-templates/>
391 <xsl:text> || true&#xA;</xsl:text>
392 </xsl:when>
393 <!-- The rest of commands -->
394 <xsl:otherwise>
395 <xsl:apply-templates/>
396 <xsl:text>&#xA;</xsl:text>
397 </xsl:otherwise>
398 </xsl:choose>
399 </xsl:template>
400
401 <xsl:template match="replaceable">
402 <xsl:choose>
403 <xsl:when test="ancestor::sect1[@id='ch-system-glibc']">
404 <xsl:value-of select="$timezone"/>
405 </xsl:when>
406 <xsl:when test="ancestor::sect1[@id='ch-system-groff']">
407 <xsl:value-of select="$page"/>
408 </xsl:when>
409 <xsl:otherwise>
410 <xsl:text>**EDITME</xsl:text>
411 <xsl:apply-templates/>
412 <xsl:text>EDITME**</xsl:text>
413 </xsl:otherwise>
414 </xsl:choose>
415 </xsl:template>
416
417</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.