source: BLFS/xsl/scripts.xsl@ 342c862

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

Merge new_feature branch r3884 to3886:

  • Adapt BLFS/envars.conf to modern BLFS books
  • Fix try order for downloading BLFS packages
  • Fixes to use the XORG Legacy page in BLFS
  • Property mode set to 100644
File size: 19.2 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 <!-- Download from upstream http -->
219 <xsl:if test="string-length($httpurl) &gt; 10">
220 <xsl:text> wget -T 30 -t 5 </xsl:text>
221 <xsl:value-of select="$httpurl"/>
222 <xsl:text> ||&#xA;</xsl:text>
223 </xsl:if>
224 <!-- Download from upstream ftp -->
225 <xsl:if test="string-length($ftpurl) &gt; 10">
226 <xsl:text> wget -T 30 -t 5 </xsl:text>
227 <xsl:value-of select="$ftpurl"/>
228 <xsl:text> ||&#xA;</xsl:text>
229 </xsl:if>
230 <!-- The FTP_SERVER mirror as a last resort -->
231 <xsl:text> wget -T 30 -t 5 ${FTP_SERVER}svn/</xsl:text>
232 <xsl:value-of select="$first_letter"/>
233 <xsl:text>/$</xsl:text>
234 <xsl:value-of select="$varname"/>
235 <xsl:text>
236 cp $</xsl:text>
237 <xsl:value-of select="$varname"/>
238 <xsl:text> $SRC_ARCHIVE
239 fi
240fi
241</xsl:text>
242 <xsl:if test="string-length($md5) &gt; 10">
243 <xsl:text>echo "</xsl:text>
244 <xsl:value-of select="$md5"/>
245 <xsl:text>&#x20;&#x20;$</xsl:text>
246 <xsl:value-of select="$varname"/>
247 <xsl:text>" | md5sum -c -
248</xsl:text>
249 </xsl:if>
250 </xsl:template>
251
252 <!-- Extract the MD5 sum information -->
253 <xsl:template match="para" mode="md5">
254 <xsl:choose>
255 <xsl:when test="contains(substring-after(string(),'sum: '),'&#xA;')">
256 <xsl:value-of select="substring-before(substring-after(string(),'sum: '),'&#xA;')"/>
257 </xsl:when>
258 <xsl:otherwise>
259 <xsl:value-of select="substring-after(string(),'sum: ')"/>
260 </xsl:otherwise>
261 </xsl:choose>
262 </xsl:template>
263
264 <!-- We have several templates itemizedlist, depending on whether we
265 expect the package information, or additional package(s) or patch(es)
266 information. Select the appropriate mode here. -->
267 <xsl:template match="bridgehead">
268 <xsl:choose>
269 <!-- Special case for Openjdk -->
270 <xsl:when test="contains(string(),'Source Package Information')">
271 <xsl:apply-templates
272 select="following-sibling::itemizedlist[1]//simplelist">
273 <xsl:with-param name="varname" select="'PACKAGE'"/>
274 </xsl:apply-templates>
275 <xsl:apply-templates select="following-sibling::itemizedlist
276 [preceding-sibling::bridgehead[1]=current()
277 and position() &gt;1]//simplelist">
278 <xsl:with-param name="varname" select="'PACKAGE1'"/>
279 </xsl:apply-templates>
280 </xsl:when>
281 <!-- Package information -->
282 <xsl:when test="contains(string(),'Package Information')">
283 <xsl:apply-templates select="following-sibling::itemizedlist
284 [preceding-sibling::bridgehead[1]=current()]"
285 mode="package"/>
286 </xsl:when>
287 <!-- Additional package information -->
288 <!-- special case for llvm -->
289 <xsl:when test="contains(string(),'Optional Download')">
290 <xsl:apply-templates select="following-sibling::itemizedlist"
291 mode="additional"/>
292 </xsl:when>
293 <!-- All other additional packages have "Additional" -->
294 <xsl:when test="contains(string(),'Additional')">
295 <xsl:apply-templates select="following-sibling::itemizedlist"
296 mode="additional"/>
297 </xsl:when>
298 <!-- Do not do anything if the dev has created another type of
299 bridgehead. -->
300 <xsl:otherwise/>
301 </xsl:choose>
302 </xsl:template>
303
304 <!-- Call the download code template with appropriate parameters -->
305 <xsl:template match="itemizedlist" mode="package">
306 <xsl:call-template name="download-file">
307 <xsl:with-param name="httpurl">
308 <xsl:value-of select="./listitem[1]/para/ulink/@url"/>
309 </xsl:with-param>
310 <xsl:with-param name="ftpurl">
311 <xsl:value-of select="./listitem/para[contains(string(),'FTP')]/ulink/@url"/>
312 </xsl:with-param>
313 <xsl:with-param name="md5">
314 <xsl:apply-templates select="./listitem/para[contains(string(),'MD5')]"
315 mode="md5"/>
316 </xsl:with-param>
317 <xsl:with-param name="varname" select="'PACKAGE'"/>
318 </xsl:call-template>
319 </xsl:template>
320
321 <xsl:template match="itemizedlist" mode="additional">
322 <!-- The normal layout is "one listitem"<->"one url", but some devs
323 find amusing to have FTP and/or MD5sum listitems, or to
324 enclose the download information inside a simplelist tag... -->
325 <xsl:for-each select="listitem[.//ulink]">
326 <xsl:choose>
327 <!-- hopefully, there was a HTTP line before -->
328 <xsl:when test="contains(string(./para),'FTP')"/>
329 <xsl:when test=".//simplelist">
330 <xsl:apply-templates select=".//simplelist">
331 <xsl:with-param name="varname" select="'PACKAGE1'"/>
332 </xsl:apply-templates>
333 </xsl:when>
334 <xsl:otherwise>
335 <xsl:call-template name="download-file">
336 <xsl:with-param name="httpurl">
337 <xsl:value-of select="./para/ulink/@url"/>
338 </xsl:with-param>
339 <xsl:with-param name="ftpurl">
340 <xsl:value-of
341 select="following-sibling::listitem[1]/
342 para[contains(string(),'FTP')]/ulink/@url"/>
343 </xsl:with-param>
344 <xsl:with-param name="md5">
345 <xsl:apply-templates
346 select="following-sibling::listitem[position()&lt;3]/
347 para[contains(string(),'MD5')]"
348 mode="md5"/>
349 </xsl:with-param>
350 <xsl:with-param name="varname">
351 <xsl:choose>
352 <xsl:when test="contains(./para/ulink/@url,'.patch')">
353 <xsl:text>PATCH</xsl:text>
354 </xsl:when>
355 <xsl:otherwise>
356 <xsl:text>PACKAGE1</xsl:text>
357 </xsl:otherwise>
358 </xsl:choose>
359 </xsl:with-param>
360 </xsl:call-template>
361 </xsl:otherwise>
362 </xsl:choose>
363 </xsl:for-each>
364 </xsl:template>
365
366 <!-- the simplelist case. Hopefully, the layout is one member for
367 url, one for md5 and others for various information, that we do not
368 use -->
369 <xsl:template match="simplelist">
370 <xsl:param name="varname" select="'PACKAGE1'"/>
371 <xsl:call-template name="download-file">
372 <xsl:with-param name="httpurl" select=".//ulink/@url"/>
373 <xsl:with-param name="md5">
374 <xsl:value-of select="substring-after(member[contains(string(),'MD5')],'sum: ')"/>
375 </xsl:with-param>
376 <xsl:with-param name="varname" select="$varname"/>
377 </xsl:call-template>
378 </xsl:template>
379<!--======================== Commands code ==========================-->
380
381 <xsl:template match="screen">
382 <xsl:if test="child::* = userinput and not(@role = 'nodump')">
383 <xsl:choose>
384 <xsl:when test="@role = 'root'">
385 <xsl:if test="$sudo = 'y'">
386 <xsl:text>sudo -E sh &lt;&lt; ROOT_EOF&#xA;</xsl:text>
387 </xsl:if>
388 <xsl:apply-templates mode="root"/>
389 <xsl:if test="$sudo = 'y'">
390 <xsl:text>&#xA;ROOT_EOF</xsl:text>
391 </xsl:if>
392 </xsl:when>
393 <xsl:otherwise>
394 <xsl:apply-templates select="userinput"/>
395 </xsl:otherwise>
396 </xsl:choose>
397 <xsl:text>&#xA;</xsl:text>
398 </xsl:if>
399 </xsl:template>
400
401 <xsl:template match="screen" mode="config">
402 <xsl:if test="preceding-sibling::para[1]/xref[@linkend='bootscripts']">
403 <xsl:text>[[ ! -d $SRC_DIR/blfs-bootscripts ]] &amp;&amp; mkdir $SRC_DIR/blfs-bootscripts
404pushd $SRC_DIR/blfs-bootscripts
405URL=</xsl:text>
406 <xsl:value-of select="id('bootscripts')//itemizedlist//ulink/@url"/><xsl:text>
407BOOTPACKG=$(basename $URL)
408if [[ ! -f $BOOTPACKG ]] ; then
409 if [[ -f $SRC_ARCHIVE/$PKG_DIR/$BOOTPACKG ]] ; then
410 cp $SRC_ARCHIVE/$PKG_DIR/$BOOTPACKG $BOOTPACKG
411 elif [[ -f $SRC_ARCHIVE/$BOOTPACKG ]] ; then
412 cp $SRC_ARCHIVE/$BOOTPACKG $BOOTPACKG
413 else
414 wget -T 30 -t 5 $URL
415 cp $BOOTPACKG $SRC_ARCHIVE
416 fi
417 rm -f unpacked
418fi
419
420if [[ -e unpacked ]] ; then
421 BOOTUNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
422 if ! [[ -d $BOOTUNPACKDIR ]]; then
423 rm unpacked
424 tar -xvf $BOOTPACKG > unpacked
425 BOOTUNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
426 fi
427else
428 tar -xvf $BOOTPACKG > unpacked
429 BOOTUNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
430fi
431cd $BOOTUNPACKDIR
432</xsl:text>
433 </xsl:if>
434 <xsl:apply-templates select='.'/>
435 <xsl:if test="preceding-sibling::para[1]/xref[@linkend='bootscripts']">
436 <xsl:text>
437popd</xsl:text>
438 </xsl:if>
439 <xsl:text>&#xA;</xsl:text>
440 </xsl:template>
441
442 <xsl:template match="para/command">
443 <xsl:variable name="ns" select="normalize-space(string())"/>
444 <xsl:if test="(contains($ns,'test') or
445 contains($ns,'check'))">
446 <xsl:text>#</xsl:text>
447 <xsl:value-of select="substring-before($ns,'make ')"/>
448 <xsl:text>make </xsl:text>
449 <xsl:if test="not(contains($ns,'-k'))">
450 <xsl:text>-k </xsl:text>
451 </xsl:if>
452 <xsl:value-of select="substring-after($ns,'make ')"/>
453 <xsl:text> || true&#xA;</xsl:text>
454 </xsl:if>
455 </xsl:template>
456
457 <xsl:template match="userinput">
458 <xsl:apply-templates/>
459 </xsl:template>
460
461 <xsl:template match="text()" mode="root">
462 <xsl:call-template name="output-root">
463 <xsl:with-param name="out-string" select="string()"/>
464 </xsl:call-template>
465 </xsl:template>
466
467 <xsl:template name="output-root">
468 <xsl:param name="out-string" select="''"/>
469 <xsl:choose>
470 <xsl:when test="contains($out-string,'make ')">
471 <xsl:call-template name="output-root">
472 <xsl:with-param name="out-string"
473 select="substring-before($out-string,'make ')"/>
474 </xsl:call-template>
475 <xsl:text>make -j1 </xsl:text>
476 <xsl:call-template name="output-root">
477 <xsl:with-param name="out-string"
478 select="substring-after($out-string,'make ')"/>
479 </xsl:call-template>
480 </xsl:when>
481 <xsl:when test="contains($out-string,'$') and $sudo = 'y'">
482 <xsl:call-template name="output-root">
483 <xsl:with-param name="out-string"
484 select="substring-before($out-string,'$')"/>
485 </xsl:call-template>
486 <xsl:text>\$</xsl:text>
487 <xsl:call-template name="output-root">
488 <xsl:with-param name="out-string"
489 select="substring-after($out-string,'$')"/>
490 </xsl:call-template>
491 </xsl:when>
492 <xsl:when test="contains($out-string,'`') and $sudo = 'y'">
493 <xsl:call-template name="output-root">
494 <xsl:with-param name="out-string"
495 select="substring-before($out-string,'`')"/>
496 </xsl:call-template>
497 <xsl:text>\`</xsl:text>
498 <xsl:call-template name="output-root">
499 <xsl:with-param name="out-string"
500 select="substring-after($out-string,'`')"/>
501 </xsl:call-template>
502 </xsl:when>
503 <xsl:when test="contains($out-string,'\') and $sudo = 'y'">
504 <xsl:call-template name="output-root">
505 <xsl:with-param name="out-string"
506 select="substring-before($out-string,'\')"/>
507 </xsl:call-template>
508 <xsl:text>\\</xsl:text>
509 <xsl:call-template name="output-root">
510 <xsl:with-param name="out-string"
511 select="substring-after($out-string,'\')"/>
512 </xsl:call-template>
513 </xsl:when>
514 <xsl:otherwise>
515 <xsl:value-of select="$out-string"/>
516 </xsl:otherwise>
517 </xsl:choose>
518 </xsl:template>
519
520 <xsl:template match="replaceable">
521 <xsl:text>**EDITME</xsl:text>
522 <xsl:apply-templates/>
523 <xsl:text>EDITME**</xsl:text>
524 </xsl:template>
525
526 <xsl:template match="replaceable" mode="root">
527 <xsl:text>**EDITME</xsl:text>
528 <xsl:apply-templates/>
529 <xsl:text>EDITME**</xsl:text>
530 </xsl:template>
531
532</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.