source: BLFS/xsl/scripts.xsl@ e6967a1

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

Add possibility for lzma extension when untarring in BLFS tools

  • Property mode set to 100644
File size: 19.0 KB
Line 
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 -->
59 <xsl:when test="sect2[@role='package']">
60 <!-- We build in a subdirectory -->
61 <xsl:text>PKG_DIR=</xsl:text>
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 -->
67 <xsl:text>cd $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
68 <!-- In some case, some files in the build tree are owned
69 by root -->
70 <xsl:if test="$sudo='y'">
71 <xsl:text>sudo </xsl:text>
72 </xsl:if>
73 <xsl:text>rm -rf $UNPACKDIR unpacked&#xA;&#xA;</xsl:text>
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>
92 <!-- Download information is in bridgehead tags -->
93 <xsl:apply-templates select="bridgehead[@renderas='sect3']"/>
94 <xsl:text>&#xA;</xsl:text>
95 </xsl:when>
96 <xsl:when test="@role = 'qt4-prefix' or @role = 'qt5-prefix'">
97 <xsl:apply-templates select=".//screen"/>
98 </xsl:when>
99 <xsl:when test="@role = 'installation'">
100 <xsl:text>
101find . -maxdepth 1 -mindepth 1 -type d | xargs </xsl:text>
102 <xsl:if test="$sudo='y'">
103 <xsl:text>sudo </xsl:text>
104 </xsl:if>
105 <xsl:text>rm -rf
106case $PACKAGE in
107 *.tar.gz|*.tar.bz2|*.tar.xz|*.tgz|*.tar.lzma)
108 tar -xvf $PACKAGE &gt; unpacked
109 UNPACKDIR=`grep '[^./]\+' unpacked | head -n1 | sed 's@^./@@;s@/.*@@'`
110 ;;
111 *.zip)
112 zipinfo -1 $PACKAGE &gt; unpacked
113 UNPACKDIR="$(sed 's@/.*@@' unpacked | uniq )"
114 if test $(wc -w &lt;&lt;&lt; $UNPACKDIR) -eq 1; then
115 unzip $PACKAGE
116 else
117 UNPACKDIR=${PACKAGE%.zip}
118 unzip -d $UNPACKDIR $PACKAGE
119 fi
120 ;;
121 *)
122 UNPACKDIR=$PKG_DIR-build
123 mkdir $UNPACKDIR
124 cp $PACKAGE $UNPACKDIR
125 ;;
126esac
127cd $UNPACKDIR&#xA;
128</xsl:text>
129 <xsl:apply-templates select=".//screen | .//para/command"/>
130 <xsl:if test="$sudo = 'y'">
131 <xsl:text>sudo /sbin/</xsl:text>
132 </xsl:if>
133 <xsl:text>ldconfig&#xA;&#xA;</xsl:text>
134 </xsl:when>
135 <xsl:when test="@role = 'configuration'">
136 <xsl:apply-templates select=".//screen" mode="config"/>
137 </xsl:when>
138 </xsl:choose>
139 </xsl:template>
140
141<!--==================== Download code =======================-->
142
143 <!-- template for extracting the filename from an url in the form:
144 proto://internet.name/dir1/.../dirn/filename?condition.
145 Needed, because substring-after(...,'/') returns only the
146 substring after the first '/'. -->
147 <xsl:template name="package_name">
148 <xsl:param name="url" select="foo"/>
149 <xsl:param name="sub-url" select="substring-after($url,'/')"/>
150 <xsl:choose>
151 <xsl:when test="contains($sub-url,'/')">
152 <xsl:call-template name="package_name">
153 <xsl:with-param name="url" select="$sub-url"/>
154 </xsl:call-template>
155 </xsl:when>
156 <xsl:otherwise>
157 <xsl:choose>
158 <xsl:when test="contains($sub-url,'?')">
159 <xsl:value-of select="substring-before($sub-url,'?')"/>
160 </xsl:when>
161 <xsl:otherwise>
162 <xsl:value-of select="$sub-url"/>
163 </xsl:otherwise>
164 </xsl:choose>
165 </xsl:otherwise>
166 </xsl:choose>
167 </xsl:template>
168
169 <!-- Generates the code to download a package, an additional package or
170 a patch. -->
171 <xsl:template name="download-file">
172 <xsl:param name="httpurl" select="''"/>
173 <xsl:param name="ftpurl" select="''"/>
174 <xsl:param name="md5" select="''"/>
175 <xsl:param name="varname" select="''"/>
176 <xsl:variable name="package">
177 <xsl:call-template name="package_name">
178 <xsl:with-param name="url">
179 <xsl:choose>
180 <xsl:when test="string-length($httpurl) &gt; 10">
181 <xsl:value-of select="$httpurl"/>
182 </xsl:when>
183 <xsl:otherwise>
184 <xsl:value-of select="$ftpurl"/>
185 </xsl:otherwise>
186 </xsl:choose>
187 </xsl:with-param>
188 </xsl:call-template>
189 </xsl:variable>
190 <xsl:variable name="first_letter"
191 select="translate(substring($package,1,1),
192 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
193 'abcdefghijklmnopqrstuvwxyz')"/>
194 <xsl:text>&#xA;</xsl:text>
195 <xsl:value-of select="$varname"/>
196 <xsl:text>=</xsl:text>
197 <xsl:value-of select="$package"/>
198 <xsl:text>&#xA;if [[ ! -f $</xsl:text>
199 <xsl:value-of select="$varname"/>
200 <xsl:text> ]] ; then&#xA;</xsl:text>
201 <!-- SRC_ARCHIVE may have subdirectories or not -->
202 <xsl:text> if [[ -f $SRC_ARCHIVE/$PKG_DIR/$</xsl:text>
203 <xsl:value-of select="$varname"/>
204 <xsl:text> ]] ; then&#xA;</xsl:text>
205 <xsl:text> cp $SRC_ARCHIVE/$PKG_DIR/$</xsl:text>
206 <xsl:value-of select="$varname"/>
207 <xsl:text> $</xsl:text>
208 <xsl:value-of select="$varname"/>
209 <xsl:text>&#xA;</xsl:text>
210 <xsl:text> elif [[ -f $SRC_ARCHIVE/$</xsl:text>
211 <xsl:value-of select="$varname"/>
212 <xsl:text> ]] ; then&#xA;</xsl:text>
213 <xsl:text> cp $SRC_ARCHIVE/$</xsl:text>
214 <xsl:value-of select="$varname"/>
215 <xsl:text> $</xsl:text>
216 <xsl:value-of select="$varname"/>
217 <xsl:text>&#xA; else&#xA;</xsl:text>
218 <!-- The FTP_SERVER mirror -->
219 <xsl:text> wget -T 30 -t 5 ${FTP_SERVER}svn/</xsl:text>
220 <xsl:value-of select="$first_letter"/>
221 <xsl:text>/$</xsl:text>
222 <xsl:value-of select="$varname"/>
223 <xsl:if test="string-length($httpurl) &gt; 10">
224 <xsl:text> ||
225 wget -T 30 -t 5 </xsl:text>
226 <xsl:value-of select="$httpurl"/>
227 </xsl:if>
228 <xsl:if test="string-length($ftpurl) &gt; 10">
229 <xsl:text> ||
230 wget -T 30 -t 5 </xsl:text>
231 <xsl:value-of select="$ftpurl"/>
232 </xsl:if>
233 <xsl:text>
234 cp $</xsl:text>
235 <xsl:value-of select="$varname"/>
236 <xsl:text> $SRC_ARCHIVE
237 fi
238fi
239</xsl:text>
240 <xsl:if test="string-length($md5) &gt; 10">
241 <xsl:text>echo "</xsl:text>
242 <xsl:value-of select="$md5"/>
243 <xsl:text>&#x20;&#x20;$</xsl:text>
244 <xsl:value-of select="$varname"/>
245 <xsl:text>" | md5sum -c -
246</xsl:text>
247 </xsl:if>
248 </xsl:template>
249
250 <!-- Extract the MD5 sum information -->
251 <xsl:template match="para" mode="md5">
252 <xsl:choose>
253 <xsl:when test="contains(substring-after(string(),'sum: '),'&#xA;')">
254 <xsl:value-of select="substring-before(substring-after(string(),'sum: '),'&#xA;')"/>
255 </xsl:when>
256 <xsl:otherwise>
257 <xsl:value-of select="substring-after(string(),'sum: ')"/>
258 </xsl:otherwise>
259 </xsl:choose>
260 </xsl:template>
261
262 <!-- We have several templates itemizedlist, depending on whether we
263 expect the package information, or additional package(s) or patch(es)
264 information. Select the appropriate mode here. -->
265 <xsl:template match="bridgehead">
266 <xsl:choose>
267 <!-- Special case for Openjdk -->
268 <xsl:when test="contains(string(),'Source Package Information')">
269 <xsl:apply-templates
270 select="following-sibling::itemizedlist[1]//simplelist">
271 <xsl:with-param name="varname" select="'PACKAGE'"/>
272 </xsl:apply-templates>
273 <xsl:apply-templates select="following-sibling::itemizedlist
274 [preceding-sibling::bridgehead[1]=current()
275 and position() &gt;1]//simplelist">
276 <xsl:with-param name="varname" select="'PACKAGE1'"/>
277 </xsl:apply-templates>
278 </xsl:when>
279 <!-- Package information -->
280 <xsl:when test="contains(string(),'Package Information')">
281 <xsl:apply-templates select="following-sibling::itemizedlist
282 [preceding-sibling::bridgehead[1]=current()]"
283 mode="package"/>
284 </xsl:when>
285 <!-- Additional package information -->
286 <!-- special case for llvm -->
287 <xsl:when test="contains(string(),'Optional Download')">
288 <xsl:apply-templates select="following-sibling::itemizedlist"
289 mode="additional"/>
290 </xsl:when>
291 <!-- All other additional packages have "Additional" -->
292 <xsl:when test="contains(string(),'Additional')">
293 <xsl:apply-templates select="following-sibling::itemizedlist"
294 mode="additional"/>
295 </xsl:when>
296 <!-- Do not do anything if the dev has created another type of
297 bridgehead. -->
298 <xsl:otherwise/>
299 </xsl:choose>
300 </xsl:template>
301
302 <!-- Call the download code template with appropriate parameters -->
303 <xsl:template match="itemizedlist" mode="package">
304 <xsl:call-template name="download-file">
305 <xsl:with-param name="httpurl">
306 <xsl:value-of select="./listitem[1]/para/ulink/@url"/>
307 </xsl:with-param>
308 <xsl:with-param name="ftpurl">
309 <xsl:value-of select="./listitem/para[contains(string(),'FTP')]/ulink/@url"/>
310 </xsl:with-param>
311 <xsl:with-param name="md5">
312 <xsl:apply-templates select="./listitem/para[contains(string(),'MD5')]"
313 mode="md5"/>
314 </xsl:with-param>
315 <xsl:with-param name="varname" select="'PACKAGE'"/>
316 </xsl:call-template>
317 </xsl:template>
318
319 <xsl:template match="itemizedlist" mode="additional">
320 <!-- The normal layout is "one listitem"<->"one url", but some devs
321 find amusing to have FTP and/or MD5sum listitems, or to
322 enclose the download information inside a simplelist tag... -->
323 <xsl:for-each select="listitem[.//ulink]">
324 <xsl:choose>
325 <!-- hopefully, there was a HTTP line before -->
326 <xsl:when test="contains(string(./para),'FTP')"/>
327 <xsl:when test=".//simplelist">
328 <xsl:apply-templates select=".//simplelist">
329 <xsl:with-param name="varname" select="'PACKAGE1'"/>
330 </xsl:apply-templates>
331 </xsl:when>
332 <xsl:otherwise>
333 <xsl:call-template name="download-file">
334 <xsl:with-param name="httpurl">
335 <xsl:value-of select="./para/ulink/@url"/>
336 </xsl:with-param>
337 <xsl:with-param name="ftpurl">
338 <xsl:value-of
339 select="following-sibling::listitem[1]/
340 para[contains(string(),'FTP')]/ulink/@url"/>
341 </xsl:with-param>
342 <xsl:with-param name="md5">
343 <xsl:apply-templates
344 select="following-sibling::listitem[position()&lt;3]/
345 para[contains(string(),'MD5')]"
346 mode="md5"/>
347 </xsl:with-param>
348 <xsl:with-param name="varname">
349 <xsl:choose>
350 <xsl:when test="contains(./para/ulink/@url,'.patch')">
351 <xsl:text>PATCH</xsl:text>
352 </xsl:when>
353 <xsl:otherwise>
354 <xsl:text>PACKAGE1</xsl:text>
355 </xsl:otherwise>
356 </xsl:choose>
357 </xsl:with-param>
358 </xsl:call-template>
359 </xsl:otherwise>
360 </xsl:choose>
361 </xsl:for-each>
362 </xsl:template>
363
364 <!-- the simplelist case. Hopefully, the layout is one member for
365 url, one for md5 and others for various information, that we do not
366 use -->
367 <xsl:template match="simplelist">
368 <xsl:param name="varname" select="'PACKAGE1'"/>
369 <xsl:call-template name="download-file">
370 <xsl:with-param name="httpurl" select=".//ulink/@url"/>
371 <xsl:with-param name="md5">
372 <xsl:value-of select="substring-after(member[contains(string(),'MD5')],'sum: ')"/>
373 </xsl:with-param>
374 <xsl:with-param name="varname" select="$varname"/>
375 </xsl:call-template>
376 </xsl:template>
377<!--======================== Commands code ==========================-->
378
379 <xsl:template match="screen">
380 <xsl:if test="child::* = userinput and not(@role = 'nodump')">
381 <xsl:choose>
382 <xsl:when test="@role = 'root'">
383 <xsl:if test="$sudo = 'y'">
384 <xsl:text>sudo -E sh &lt;&lt; ROOT_EOF&#xA;</xsl:text>
385 </xsl:if>
386 <xsl:apply-templates mode="root"/>
387 <xsl:if test="$sudo = 'y'">
388 <xsl:text>&#xA;ROOT_EOF</xsl:text>
389 </xsl:if>
390 </xsl:when>
391 <xsl:otherwise>
392 <xsl:apply-templates select="userinput"/>
393 </xsl:otherwise>
394 </xsl:choose>
395 <xsl:text>&#xA;</xsl:text>
396 </xsl:if>
397 </xsl:template>
398
399 <xsl:template match="screen" mode="config">
400 <xsl:if test="preceding-sibling::para[1]/xref[@linkend='bootscripts']">
401 <xsl:text>[[ ! -d $SRC_DIR/blfs-bootscripts ]] &amp;&amp; mkdir $SRC_DIR/blfs-bootscripts
402pushd $SRC_DIR/blfs-bootscripts
403URL=</xsl:text>
404 <xsl:value-of select="id('bootscripts')//itemizedlist//ulink/@url"/><xsl:text>
405BOOTPACKG=$(basename $URL)
406if [[ ! -f $BOOTPACKG ]] ; then
407 if [[ -f $SRC_ARCHIVE/$PKG_DIR/$BOOTPACKG ]] ; then
408 cp $SRC_ARCHIVE/$PKG_DIR/$BOOTPACKG $BOOTPACKG
409 elif [[ -f $SRC_ARCHIVE/$BOOTPACKG ]] ; then
410 cp $SRC_ARCHIVE/$BOOTPACKG $BOOTPACKG
411 else
412 wget -T 30 -t 5 $URL
413 cp $BOOTPACKG $SRC_ARCHIVE
414 fi
415 rm -f unpacked
416fi
417
418if [[ -e unpacked ]] ; then
419 BOOTUNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
420 if ! [[ -d $BOOTUNPACKDIR ]]; then
421 rm unpacked
422 tar -xvf $BOOTPACKG > unpacked
423 BOOTUNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
424 fi
425else
426 tar -xvf $BOOTPACKG > unpacked
427 BOOTUNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
428fi
429cd $BOOTUNPACKDIR
430</xsl:text>
431 </xsl:if>
432 <xsl:apply-templates select='.'/>
433 <xsl:if test="preceding-sibling::para[1]/xref[@linkend='bootscripts']">
434 <xsl:text>
435popd</xsl:text>
436 </xsl:if>
437 <xsl:text>&#xA;</xsl:text>
438 </xsl:template>
439
440 <xsl:template match="para/command">
441 <xsl:variable name="ns" select="normalize-space(string())"/>
442 <xsl:if test="(contains($ns,'test') or
443 contains($ns,'check'))">
444 <xsl:text>#</xsl:text>
445 <xsl:value-of select="substring-before($ns,'make ')"/>
446 <xsl:text>make </xsl:text>
447 <xsl:if test="not(contains($ns,'-k'))">
448 <xsl:text>-k </xsl:text>
449 </xsl:if>
450 <xsl:value-of select="substring-after($ns,'make ')"/>
451 <xsl:text> || true&#xA;</xsl:text>
452 </xsl:if>
453 </xsl:template>
454
455 <xsl:template match="userinput">
456 <xsl:apply-templates/>
457 </xsl:template>
458
459 <xsl:template match="text()" mode="root">
460 <xsl:call-template name="output-root">
461 <xsl:with-param name="out-string" select="string()"/>
462 </xsl:call-template>
463 </xsl:template>
464
465 <xsl:template name="output-root">
466 <xsl:param name="out-string" select="''"/>
467 <xsl:choose>
468 <xsl:when test="contains($out-string,'make ')">
469 <xsl:call-template name="output-root">
470 <xsl:with-param name="out-string"
471 select="substring-before($out-string,'make ')"/>
472 </xsl:call-template>
473 <xsl:text>make -j1 </xsl:text>
474 <xsl:call-template name="output-root">
475 <xsl:with-param name="out-string"
476 select="substring-after($out-string,'make ')"/>
477 </xsl:call-template>
478 </xsl:when>
479 <xsl:when test="contains($out-string,'$') and $sudo = 'y'">
480 <xsl:call-template name="output-root">
481 <xsl:with-param name="out-string"
482 select="substring-before($out-string,'$')"/>
483 </xsl:call-template>
484 <xsl:text>\$</xsl:text>
485 <xsl:call-template name="output-root">
486 <xsl:with-param name="out-string"
487 select="substring-after($out-string,'$')"/>
488 </xsl:call-template>
489 </xsl:when>
490 <xsl:when test="contains($out-string,'`') and $sudo = 'y'">
491 <xsl:call-template name="output-root">
492 <xsl:with-param name="out-string"
493 select="substring-before($out-string,'`')"/>
494 </xsl:call-template>
495 <xsl:text>\`</xsl:text>
496 <xsl:call-template name="output-root">
497 <xsl:with-param name="out-string"
498 select="substring-after($out-string,'`')"/>
499 </xsl:call-template>
500 </xsl:when>
501 <xsl:when test="contains($out-string,'\') and $sudo = 'y'">
502 <xsl:call-template name="output-root">
503 <xsl:with-param name="out-string"
504 select="substring-before($out-string,'\')"/>
505 </xsl:call-template>
506 <xsl:text>\\</xsl:text>
507 <xsl:call-template name="output-root">
508 <xsl:with-param name="out-string"
509 select="substring-after($out-string,'\')"/>
510 </xsl:call-template>
511 </xsl:when>
512 <xsl:otherwise>
513 <xsl:value-of select="$out-string"/>
514 </xsl:otherwise>
515 </xsl:choose>
516 </xsl:template>
517
518 <xsl:template match="replaceable">
519 <xsl:text>**EDITME</xsl:text>
520 <xsl:apply-templates/>
521 <xsl:text>EDITME**</xsl:text>
522 </xsl:template>
523
524 <xsl:template match="replaceable" mode="root">
525 <xsl:text>**EDITME</xsl:text>
526 <xsl:apply-templates/>
527 <xsl:text>EDITME**</xsl:text>
528 </xsl:template>
529
530</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.