source: BLFS/xsl/scripts.xsl@ b9c3497

2.4 ablfs-more legacy new_features trunk
Last change on this file since b9c3497 was a743e57, checked in by Pierre Labastie <pierre@…>, 10 years ago

Avoid spurious linebreaks
in test commands, because some developpers
include them for formatting the xml

  • Property mode set to 100644
File size: 18.7 KB
RevLine 
[e576789]1<?xml version="1.0"?>
2
3<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4 xmlns:exsl="http://exslt.org/common"
5 extension-element-prefixes="exsl"
6 version="1.0">
7
8<!-- $Id: scripts.xsl 34 2012-02-21 16:05:09Z labastie $ -->
9
10<!-- XSLT stylesheet to create shell scripts from "linear build" BLFS books. -->
11
12 <!-- Build as user (y) or as root (n)? -->
13 <xsl:param name="sudo" select="'y'"/>
14
15 <xsl:template match="/">
16 <xsl:apply-templates select="//sect1"/>
17 </xsl:template>
18
19<!--=================== Master chunks code ======================-->
20
21 <xsl:template match="sect1">
22
23 <xsl:if test="@id != 'bootscripts'">
24 <!-- The file names -->
25 <xsl:variable name="filename" select="@id"/>
26
27 <!-- The build order -->
28 <xsl:variable name="position" select="position()"/>
29 <xsl:variable name="order">
30 <xsl:choose>
31 <xsl:when test="string-length($position) = 1">
32 <xsl:text>00</xsl:text>
33 <xsl:value-of select="$position"/>
34 </xsl:when>
35 <xsl:when test="string-length($position) = 2">
36 <xsl:text>0</xsl:text>
37 <xsl:value-of select="$position"/>
38 </xsl:when>
39 <xsl:otherwise>
40 <xsl:value-of select="$position"/>
41 </xsl:otherwise>
42 </xsl:choose>
43 </xsl:variable>
44
45 <!-- Depuration code -->
46 <xsl:message>
47 <xsl:text>SCRIPT is </xsl:text>
48 <xsl:value-of select="concat($order,'-z-',$filename)"/>
49 <xsl:text>&#xA; FTPDIR is </xsl:text>
50 <xsl:value-of select="$filename"/>
51 <xsl:text>&#xA;&#xA;</xsl:text>
52 </xsl:message>
53
54 <!-- Creating the scripts -->
55 <exsl:document href="{$order}-z-{$filename}" method="text">
56 <xsl:text>#!/bin/bash&#xA;set -e&#xA;&#xA;</xsl:text>
57 <xsl:choose>
58 <!-- Package page -->
[642722f]59 <xsl:when test="sect2[@role='package']">
60 <!-- We build in a subdirectory -->
61 <xsl:text>PKG_DIR=</xsl:text>
[e576789]62 <xsl:value-of select="$filename"/>
63 <xsl:text>&#xA;</xsl:text>
64 <!-- Download code and build commands -->
65 <xsl:apply-templates select="sect2"/>
66 <!-- Clean-up -->
[642722f]67 <xsl:text>cd $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
[e576789]68 <!-- In some case, some files in the build tree are owned
69 by root -->
[642722f]70 <xsl:if test="$sudo='y'">
71 <xsl:text>sudo </xsl:text>
[e576789]72 </xsl:if>
[642722f]73 <xsl:text>rm -rf $UNPACKDIR unpacked&#xA;&#xA;</xsl:text>
[e576789]74 </xsl:when>
75 <!-- Non-package page -->
76 <xsl:otherwise>
77 <xsl:apply-templates select=".//screen"/>
78 </xsl:otherwise>
79 </xsl:choose>
80 <xsl:text>exit</xsl:text>
81 </exsl:document>
82 </xsl:if>
83 </xsl:template>
84
85<!--======================= Sub-sections code =======================-->
86
87 <xsl:template match="sect2">
88 <xsl:choose>
89 <xsl:when test="@role = 'package'">
90 <xsl:text>mkdir -p $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
91 <xsl:text>cd $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
[642722f]92 <!-- Download information is in bridgehead tags -->
[e576789]93 <xsl:apply-templates select="bridgehead[@renderas='sect3']"/>
94 <xsl:text>&#xA;</xsl:text>
95 </xsl:when>
96 <xsl:when test="@role = 'installation'">
97 <xsl:text>
98if [ "${PACKAGE%.zip}" = "${PACKAGE}" ]; then
99 if [[ -e unpacked ]] ; then
100 UNPACKDIR=`grep '[^./]\+' unpacked | head -n1 | sed 's@^./@@;s@/.*@@'`
101 [[ -n $UNPACKDIR ]] &amp;&amp; [[ -d $UNPACKDIR ]] &amp;&amp; rm -rf $UNPACKDIR
102 fi
103 tar -xvf $PACKAGE > unpacked
104 UNPACKDIR=`grep '[^./]\+' unpacked | head -n1 | sed 's@^./@@;s@/.*@@'`
105else
106 UNPACKDIR=${PACKAGE%.zip}
107 [[ -n $UNPACKDIR ]] &amp;&amp; [[ -d $UNPACKDIR ]] &amp;&amp; rm -rf $UNPACKDIR
108 unzip -d $UNPACKDIR ${PACKAGE}
109fi
[642722f]110cd $UNPACKDIR&#xA;&#xA;</xsl:text>
[e576789]111 <xsl:apply-templates select=".//screen | .//para/command"/>
112 <xsl:if test="$sudo = 'y'">
113 <xsl:text>sudo /sbin/</xsl:text>
114 </xsl:if>
115 <xsl:text>ldconfig&#xA;&#xA;</xsl:text>
116 </xsl:when>
117 <xsl:when test="@role = 'configuration'">
118 <xsl:apply-templates select=".//screen" mode="config"/>
119 </xsl:when>
120 </xsl:choose>
121 </xsl:template>
122
123<!--==================== Download code =======================-->
124
[642722f]125 <!-- template for extracting the filename from an url in the form:
126 proto://internet.name/dir1/.../dirn/filename?condition.
127 Needed, because substring-after(...,'/') returns only the
128 substring after the first '/'. -->
[e576789]129 <xsl:template name="package_name">
130 <xsl:param name="url" select="foo"/>
131 <xsl:param name="sub-url" select="substring-after($url,'/')"/>
132 <xsl:choose>
133 <xsl:when test="contains($sub-url,'/')">
134 <xsl:call-template name="package_name">
135 <xsl:with-param name="url" select="$sub-url"/>
136 </xsl:call-template>
137 </xsl:when>
138 <xsl:otherwise>
139 <xsl:choose>
140 <xsl:when test="contains($sub-url,'?')">
141 <xsl:value-of select="substring-before($sub-url,'?')"/>
142 </xsl:when>
143 <xsl:otherwise>
144 <xsl:value-of select="$sub-url"/>
145 </xsl:otherwise>
146 </xsl:choose>
147 </xsl:otherwise>
148 </xsl:choose>
149 </xsl:template>
150
[642722f]151 <!-- Generates the code to download a package, an additional package or
152 a patch. -->
153 <xsl:template name="download-file">
154 <xsl:param name="httpurl" select="''"/>
155 <xsl:param name="ftpurl" select="''"/>
156 <xsl:param name="md5" select="''"/>
157 <xsl:param name="varname" select="''"/>
158 <xsl:variable name="package">
159 <xsl:call-template name="package_name">
160 <xsl:with-param name="url">
[e576789]161 <xsl:choose>
[642722f]162 <xsl:when test="string-length($httpurl) &gt; 10">
163 <xsl:value-of select="$httpurl"/>
[e576789]164 </xsl:when>
165 <xsl:otherwise>
[642722f]166 <xsl:value-of select="$ftpurl"/>
[e576789]167 </xsl:otherwise>
168 </xsl:choose>
[642722f]169 </xsl:with-param>
170 </xsl:call-template>
171 </xsl:variable>
172 <xsl:variable name="first_letter"
173 select="translate(substring($package,1,1),
174 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
175 'abcdefghijklmnopqrstuvwxyz')"/>
176 <xsl:text>&#xA;</xsl:text>
177 <xsl:value-of select="$varname"/>
178 <xsl:text>=</xsl:text>
179 <xsl:value-of select="$package"/>
180 <xsl:text>&#xA;if [[ ! -f $</xsl:text>
181 <xsl:value-of select="$varname"/>
182 <xsl:text> ]] ; then&#xA;</xsl:text>
183 <!-- SRC_ARCHIVE may have subdirectories or not -->
184 <xsl:text> if [[ -f $SRC_ARCHIVE/$PKG_DIR/$</xsl:text>
185 <xsl:value-of select="$varname"/>
186 <xsl:text> ]] ; then&#xA;</xsl:text>
187 <xsl:text> cp $SRC_ARCHIVE/$PKG_DIR/$</xsl:text>
188 <xsl:value-of select="$varname"/>
189 <xsl:text> $</xsl:text>
190 <xsl:value-of select="$varname"/>
191 <xsl:text>&#xA;</xsl:text>
192 <xsl:text> elif [[ -f $SRC_ARCHIVE/$</xsl:text>
193 <xsl:value-of select="$varname"/>
194 <xsl:text> ]] ; then&#xA;</xsl:text>
195 <xsl:text> cp $SRC_ARCHIVE/$</xsl:text>
196 <xsl:value-of select="$varname"/>
197 <xsl:text> $</xsl:text>
198 <xsl:value-of select="$varname"/>
199 <xsl:text>&#xA; else&#xA;</xsl:text>
200 <!-- The FTP_SERVER mirror -->
201 <xsl:text> wget -T 30 -t 5 ${FTP_SERVER}svn/</xsl:text>
202 <xsl:value-of select="$first_letter"/>
203 <xsl:text>/$</xsl:text>
204 <xsl:value-of select="$varname"/>
205 <xsl:if test="string-length($httpurl) &gt; 10">
206 <xsl:text> ||
207 wget -T 30 -t 5 </xsl:text>
208 <xsl:value-of select="$httpurl"/>
209 </xsl:if>
210 <xsl:if test="string-length($ftpurl) &gt; 10">
211 <xsl:text> ||
212 wget -T 30 -t 5 </xsl:text>
213 <xsl:value-of select="$ftpurl"/>
214 </xsl:if>
215 <xsl:text>
216 cp $</xsl:text>
217 <xsl:value-of select="$varname"/>
218 <xsl:text> $SRC_ARCHIVE
[e576789]219 fi
220fi
221</xsl:text>
[642722f]222 <xsl:if test="string-length($md5) &gt; 10">
223 <xsl:text>echo "</xsl:text>
224 <xsl:value-of select="$md5"/>
225 <xsl:text>&#x20;&#x20;$</xsl:text>
226 <xsl:value-of select="$varname"/>
227 <xsl:text>" | md5sum -c -
[e576789]228</xsl:text>
[642722f]229 </xsl:if>
230 </xsl:template>
231
232 <!-- Extract the MD5 sum information -->
233 <xsl:template match="para" mode="md5">
234 <xsl:choose>
235 <xsl:when test="contains(substring-after(string(),'sum: '),'&#xA;')">
236 <xsl:value-of select="substring-before(substring-after(string(),'sum: '),'&#xA;')"/>
[e576789]237 </xsl:when>
[642722f]238 <xsl:otherwise>
239 <xsl:value-of select="substring-after(string(),'sum: ')"/>
240 </xsl:otherwise>
[e576789]241 </xsl:choose>
242 </xsl:template>
243
[642722f]244 <!-- We have several templates itemizedlist, depending on whether we
245 expect the package information, or additional package(s) or patch(es)
246 information. Select the appropriate mode here. -->
247 <xsl:template match="bridgehead">
[e576789]248 <xsl:choose>
[642722f]249 <!-- Special case for Openjdk -->
250 <xsl:when test="contains(string(),'Source Package Information')">
251 <xsl:apply-templates
252 select="following-sibling::itemizedlist[1]//simplelist">
253 <xsl:with-param name="varname" select="'PACKAGE'"/>
254 </xsl:apply-templates>
255 <xsl:apply-templates select="following-sibling::itemizedlist
256 [preceding-sibling::bridgehead[1]=current()
257 and position() &gt;1]//simplelist">
258 <xsl:with-param name="varname" select="'PACKAGE1'"/>
259 </xsl:apply-templates>
[e576789]260 </xsl:when>
[642722f]261 <!-- Package information -->
262 <xsl:when test="contains(string(),'Package Information')">
263 <xsl:apply-templates select="following-sibling::itemizedlist
264 [preceding-sibling::bridgehead[1]=current()]"
265 mode="package"/>
[e576789]266 </xsl:when>
[642722f]267 <!-- Additional package information -->
[ba57e61]268 <!-- special case for llvm -->
269 <xsl:when test="contains(string(),'Optional Download')">
270 <xsl:apply-templates select="following-sibling::itemizedlist"
271 mode="additional"/>
272 </xsl:when>
273 <!-- All other additional packages have "Additional" -->
[642722f]274 <xsl:when test="contains(string(),'Additional')">
275 <xsl:apply-templates select="following-sibling::itemizedlist"
276 mode="additional"/>
[e576789]277 </xsl:when>
[642722f]278 <!-- Do not do anything if the dev has created another type of
279 bridgehead. -->
280 <xsl:otherwise/>
[e576789]281 </xsl:choose>
282 </xsl:template>
283
[642722f]284 <!-- Call the download code template with appropriate parameters -->
285 <xsl:template match="itemizedlist" mode="package">
286 <xsl:call-template name="download-file">
287 <xsl:with-param name="httpurl">
288 <xsl:value-of select="./listitem[1]/para/ulink/@url"/>
289 </xsl:with-param>
290 <xsl:with-param name="ftpurl">
291 <xsl:value-of select="./listitem/para[contains(string(),'FTP')]/ulink/@url"/>
292 </xsl:with-param>
293 <xsl:with-param name="md5">
294 <xsl:apply-templates select="./listitem/para[contains(string(),'MD5')]"
295 mode="md5"/>
296 </xsl:with-param>
297 <xsl:with-param name="varname" select="'PACKAGE'"/>
298 </xsl:call-template>
[e576789]299 </xsl:template>
300
[642722f]301 <xsl:template match="itemizedlist" mode="additional">
302 <!-- The normal layout is "one listitem"<->"one url", but some devs
303 find amusing to have FTP and/or MD5sum listitems, or to
304 enclose the download information inside a simplelist tag... -->
305 <xsl:for-each select="listitem[.//ulink]">
306 <xsl:choose>
307 <!-- hopefully, there was a HTTP line before -->
308 <xsl:when test="contains(string(./para),'FTP')"/>
309 <xsl:when test=".//simplelist">
310 <xsl:apply-templates select=".//simplelist">
311 <xsl:with-param name="varname" select="'PACKAGE1'"/>
312 </xsl:apply-templates>
313 </xsl:when>
314 <xsl:otherwise>
315 <xsl:call-template name="download-file">
316 <xsl:with-param name="httpurl">
317 <xsl:value-of select="./para/ulink/@url"/>
318 </xsl:with-param>
319 <xsl:with-param name="ftpurl">
320 <xsl:value-of
321 select="following-sibling::listitem[1]/
322 para[contains(string(),'FTP')]/ulink/@url"/>
323 </xsl:with-param>
324 <xsl:with-param name="md5">
325 <xsl:apply-templates
326 select="following-sibling::listitem[position()&lt;3]/
327 para[contains(string(),'MD5')]"
328 mode="md5"/>
329 </xsl:with-param>
330 <xsl:with-param name="varname">
331 <xsl:choose>
332 <xsl:when test="contains(./para/ulink/@url,'.patch')">
333 <xsl:text>PATCH</xsl:text>
334 </xsl:when>
335 <xsl:otherwise>
336 <xsl:text>PACKAGE1</xsl:text>
337 </xsl:otherwise>
338 </xsl:choose>
339 </xsl:with-param>
340 </xsl:call-template>
341 </xsl:otherwise>
342 </xsl:choose>
343 </xsl:for-each>
[e576789]344 </xsl:template>
345
[642722f]346 <!-- the simplelist case. Hopefully, the layout is one member for
347 url, one for md5 and others for various information, that we do not
348 use -->
349 <xsl:template match="simplelist">
350 <xsl:param name="varname" select="'PACKAGE1'"/>
351 <xsl:call-template name="download-file">
352 <xsl:with-param name="httpurl" select=".//ulink/@url"/>
353 <xsl:with-param name="md5">
354 <xsl:value-of select="substring-after(member[contains(string(),'MD5')],'sum: ')"/>
355 </xsl:with-param>
356 <xsl:with-param name="varname" select="$varname"/>
357 </xsl:call-template>
358 </xsl:template>
[e576789]359<!--======================== Commands code ==========================-->
360
361 <xsl:template match="screen">
362 <xsl:if test="child::* = userinput and not(@role = 'nodump')">
363 <xsl:choose>
364 <xsl:when test="@role = 'root'">
365 <xsl:if test="$sudo = 'y'">
366 <xsl:text>sudo -E sh &lt;&lt; ROOT_EOF&#xA;</xsl:text>
367 </xsl:if>
368 <xsl:apply-templates mode="root"/>
369 <xsl:if test="$sudo = 'y'">
370 <xsl:text>&#xA;ROOT_EOF</xsl:text>
371 </xsl:if>
372 </xsl:when>
373 <xsl:otherwise>
374 <xsl:apply-templates select="userinput"/>
375 </xsl:otherwise>
376 </xsl:choose>
377 <xsl:text>&#xA;</xsl:text>
378 </xsl:if>
379 </xsl:template>
380
381 <xsl:template match="screen" mode="config">
382 <xsl:if test="preceding-sibling::para[1]/xref[@linkend='bootscripts']">
383 <xsl:text>[[ ! -d $SRC_DIR/blfs-bootscripts ]] &amp;&amp; mkdir $SRC_DIR/blfs-bootscripts
384pushd $SRC_DIR/blfs-bootscripts
385URL=</xsl:text>
386 <xsl:value-of select="id('bootscripts')//itemizedlist//ulink/@url"/><xsl:text>
387BOOTPACKG=$(basename $URL)
[bbcdeab]388if [[ ! -f $BOOTPACKG ]] ; then
389 if [[ -f $SRC_ARCHIVE/$PKG_DIR/$BOOTPACKG ]] ; then
390 cp $SRC_ARCHIVE/$PKG_DIR/$BOOTPACKG $BOOTPACKG
391 elif [[ -f $SRC_ARCHIVE/$BOOTPACKG ]] ; then
392 cp $SRC_ARCHIVE/$BOOTPACKG $BOOTPACKG
393 else
394 wget -T 30 -t 5 $URL
395 cp $BOOTPACKG $SRC_ARCHIVE
396 fi
397 rm -f unpacked
398fi
399
[e576789]400if [[ -e unpacked ]] ; then
[f079f8f]401 BOOTUNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
402 if ! [[ -d $BOOTUNPACKDIR ]]; then
[e576789]403 rm unpacked
404 tar -xvf $BOOTPACKG > unpacked
[f079f8f]405 BOOTUNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
[e576789]406 fi
407else
408 tar -xvf $BOOTPACKG > unpacked
[f079f8f]409 BOOTUNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
[e576789]410fi
[f079f8f]411cd $BOOTUNPACKDIR
[e576789]412</xsl:text>
413 </xsl:if>
414 <xsl:apply-templates select='.'/>
415 <xsl:if test="preceding-sibling::para[1]/xref[@linkend='bootscripts']">
416 <xsl:text>
417popd</xsl:text>
418 </xsl:if>
419 <xsl:text>&#xA;</xsl:text>
420 </xsl:template>
421
422 <xsl:template match="para/command">
[a743e57]423 <xsl:variable name="ns" select="normalize-space(string())"/>
424 <xsl:if test="(contains($ns,'test') or
425 contains($ns,'check'))">
[e576789]426 <xsl:text>#</xsl:text>
[a743e57]427 <xsl:value-of select="substring-before($ns,'make ')"/>
[9c5ea2f]428 <xsl:text>make </xsl:text>
[a743e57]429 <xsl:if test="not(contains($ns,'-k'))">
[9c5ea2f]430 <xsl:text>-k </xsl:text>
431 </xsl:if>
[a743e57]432 <xsl:value-of select="substring-after($ns,'make ')"/>
[e576789]433 <xsl:text> || true&#xA;</xsl:text>
434 </xsl:if>
435 </xsl:template>
436
437 <xsl:template match="userinput">
438 <xsl:apply-templates/>
439 </xsl:template>
440
441 <xsl:template match="text()" mode="root">
442 <xsl:call-template name="output-root">
443 <xsl:with-param name="out-string" select="string()"/>
444 </xsl:call-template>
445 </xsl:template>
446
447 <xsl:template name="output-root">
448 <xsl:param name="out-string" select="''"/>
449 <xsl:choose>
[9c5ea2f]450 <xsl:when test="contains($out-string,'make ')">
[e576789]451 <xsl:call-template name="output-root">
452 <xsl:with-param name="out-string"
[9c5ea2f]453 select="substring-before($out-string,'make ')"/>
[e576789]454 </xsl:call-template>
[9c5ea2f]455 <xsl:text>make -j1 </xsl:text>
[e576789]456 <xsl:call-template name="output-root">
457 <xsl:with-param name="out-string"
[9c5ea2f]458 select="substring-after($out-string,'make ')"/>
[e576789]459 </xsl:call-template>
460 </xsl:when>
461 <xsl:when test="contains($out-string,'$') and $sudo = 'y'">
462 <xsl:call-template name="output-root">
463 <xsl:with-param name="out-string"
464 select="substring-before($out-string,'$')"/>
465 </xsl:call-template>
466 <xsl:text>\$</xsl:text>
467 <xsl:call-template name="output-root">
468 <xsl:with-param name="out-string"
469 select="substring-after($out-string,'$')"/>
470 </xsl:call-template>
471 </xsl:when>
472 <xsl:when test="contains($out-string,'`') and $sudo = 'y'">
473 <xsl:call-template name="output-root">
474 <xsl:with-param name="out-string"
475 select="substring-before($out-string,'`')"/>
476 </xsl:call-template>
477 <xsl:text>\`</xsl:text>
478 <xsl:call-template name="output-root">
479 <xsl:with-param name="out-string"
480 select="substring-after($out-string,'`')"/>
481 </xsl:call-template>
482 </xsl:when>
483 <xsl:when test="contains($out-string,'\') and $sudo = 'y'">
484 <xsl:call-template name="output-root">
485 <xsl:with-param name="out-string"
486 select="substring-before($out-string,'\')"/>
487 </xsl:call-template>
488 <xsl:text>\\</xsl:text>
489 <xsl:call-template name="output-root">
490 <xsl:with-param name="out-string"
491 select="substring-after($out-string,'\')"/>
492 </xsl:call-template>
493 </xsl:when>
494 <xsl:otherwise>
495 <xsl:value-of select="$out-string"/>
496 </xsl:otherwise>
497 </xsl:choose>
498 </xsl:template>
499
500 <xsl:template match="replaceable">
501 <xsl:text>**EDITME</xsl:text>
502 <xsl:apply-templates/>
503 <xsl:text>EDITME**</xsl:text>
504 </xsl:template>
505
506 <xsl:template match="replaceable" mode="root">
507 <xsl:text>**EDITME</xsl:text>
508 <xsl:apply-templates/>
509 <xsl:text>EDITME**</xsl:text>
510 </xsl:template>
511
512</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.