source: BLFS/xsl/scripts.xsl@ 60e539b

ablfs-more legacy trunk
Last change on this file since 60e539b was 59c4761, checked in by Pierre Labastie <pierre.labastie@…>, 3 years ago

Display the size of $BUILD_DIR for stats

Displaying the size of /, but excluding other filesystems is not
good if BUILD_DIR is on another filesystem. Furthermore, when
doing stats, the DESTDIR is inside $BUILD_DIR, so the full size is
recorded. The only thing that is not recorded is if the
build system downloads files to the user's home (cargo, maven, ...).

  • Property mode set to 100644
File size: 35.0 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<!-- XSLT stylesheet to create shell scripts from "linear build" BLFS books. -->
9
[c048987]10<!-- parameters and global variables -->
11 <!-- Check whether the book is sysv or systemd -->
[70d73d1]12 <xsl:variable name="rev">
13 <xsl:choose>
14 <xsl:when test="//bookinfo/title/phrase[@revision='systemd']">
15 systemd
16 </xsl:when>
17 <xsl:otherwise>
18 sysv
19 </xsl:otherwise>
20 </xsl:choose>
21 </xsl:variable>
22
[945ccaa]23 <!-- Wrap "root" commands inside a wrapper function, allowing
24 "porg style" package management -->
25 <xsl:param name="wrap-install" select="'n'"/>
26
[67c3df4]27 <!-- list of packages needing stats -->
28 <xsl:param name="list-stat" select="''"/>
29
[dc7fd7b]30 <!-- Remove libtool .la files -->
31 <xsl:param name="del-la-files" select="'y'"/>
32
[e576789]33 <!-- Build as user (y) or as root (n)? -->
34 <xsl:param name="sudo" select="'y'"/>
35
[dc7fd7b]36<!-- simple instructions for removing .la files. -->
[619b313]37<!-- We'll use the rule that any text output begins with a linefeed if needed
38 so that we do not need to output one at the end-->
[dc7fd7b]39 <xsl:variable name="la-files-instr">
40
41for libdir in /lib /usr/lib $(find /opt -name lib); do
[2969cdf]42 find $libdir -name \*.la \
43 ! -path \*ImageMagick\* \
44 -delete
[619b313]45done</xsl:variable>
[67c3df4]46
[c048987]47 <xsl:variable name="list-stat-norm"
48 select="concat(' ', normalize-space($list-stat),' ')"/>
49
50<!-- To be able to use the single quote in tests -->
51 <xsl:variable name="APOS">'</xsl:variable>
52
53<!-- end parameters and global variables -->
54
[7933ed7]55<!-- include the template for processing screen children of
56 role="install" sect2 -->
57 <xsl:include href="process-install.xsl"/>
[c048987]58
[96d7e44]59<!-- include the template for replaceable tags -->
60 <xsl:include href="process-replaceable.xsl"/>
61
[c048987]62<!--=================== Begin processing ========================-->
[67c3df4]63
[e576789]64 <xsl:template match="/">
[c048987]65 <xsl:apply-templates select="//sect1[@id != 'bootscripts' and
66 @id != 'systemd-units']"/>
[e576789]67 </xsl:template>
68
69<!--=================== Master chunks code ======================-->
70
71 <xsl:template match="sect1">
72
[619b313]73 <!-- Are stat requested for this page? -->
74 <xsl:variable name="want-stats"
75 select="contains($list-stat-norm,
76 concat(' ',@id,' '))"/>
77
[c048987]78 <!-- The file names -->
79 <xsl:variable name="filename" select="@id"/>
[e576789]80
[c048987]81 <!-- The build order -->
82 <xsl:variable name="position" select="position()"/>
83 <xsl:variable name="order">
84 <xsl:choose>
85 <xsl:when test="string-length($position) = 1">
86 <xsl:text>00</xsl:text>
87 <xsl:value-of select="$position"/>
88 </xsl:when>
89 <xsl:when test="string-length($position) = 2">
90 <xsl:text>0</xsl:text>
91 <xsl:value-of select="$position"/>
92 </xsl:when>
93 <xsl:otherwise>
94 <xsl:value-of select="$position"/>
95 </xsl:otherwise>
96 </xsl:choose>
97 </xsl:variable>
[e576789]98
99 <!-- Depuration code -->
[c048987]100 <xsl:message>
101 <xsl:text>SCRIPT is </xsl:text>
102 <xsl:value-of select="concat($order,'-z-',$filename)"/>
103 <xsl:text>&#xA; FTPDIR is </xsl:text>
104 <xsl:value-of select="$filename"/>
105 <xsl:text>&#xA;&#xA;</xsl:text>
106 </xsl:message>
107
108 <!-- Creating the scripts -->
109 <exsl:document href="{$order}-z-{$filename}" method="text">
110 <xsl:text>#!/bin/bash
[eabfc59]111set -e
112unset MAKELEVEL
113</xsl:text>
[8fc6a47]114<!-- Unsetting MAKELEVEL is needed for some packages which assume that
115 their top level Makefile is at level zero -->
[c048987]116 <xsl:choose>
117 <!-- Package page -->
118 <xsl:when test="sect2[@role='package']">
119 <!-- We build in a subdirectory, whose name may be needed
120 if using package management (see envars.conf), so
121 "export" it -->
[619b313]122 <xsl:text>
123export JH_PKG_DIR=</xsl:text>
[c048987]124 <xsl:value-of select="$filename"/>
125 <xsl:text>
[1fa0dee]126SRC_DIR=${JH_SRC_ARCHIVE}${JH_SRC_SUBDIRS:+/${JH_PKG_DIR}}
127BUILD_DIR=${JH_BUILD_ROOT}${JH_BUILD_SUBDIRS:+/${JH_PKG_DIR}}
[39dc04a]128mkdir -p $SRC_DIR
129mkdir -p $BUILD_DIR
130</xsl:text>
[67c3df4]131
132<!-- If stats are requested, include some definitions and intitializations -->
[619b313]133 <xsl:if test="$want-stats">
134 <xsl:text>
135INFOLOG=$(pwd)/info-${JH_PKG_DIR}
[9e0c4b6]136TESTLOG=$(pwd)/test-${JH_PKG_DIR}
[67c3df4]137unset MAKEFLAGS
138#MAKEFLAGS=-j4
139echo MAKEFLAGS: $MAKEFLAGS > $INFOLOG
[c048987]140: > $TESTLOG
[67c3df4]141PKG_DEST=${BUILD_DIR}/dest
142rm -rf $PKG_DEST
143</xsl:text>
[c048987]144 </xsl:if>
145 <!-- Download code and build commands -->
[619b313]146 <xsl:apply-templates select="sect2">
147 <xsl:with-param name="want-stats" select="$want-stats"/>
148 </xsl:apply-templates>
[c048987]149 <!-- Clean-up -->
[619b313]150 <xsl:text>
151
152cd $BUILD_DIR
[1fa0dee]153[[ -n "$JH_KEEP_FILES" ]] || </xsl:text>
[c048987]154 <!-- In some case, some files in the build tree are owned
155 by root -->
156 <xsl:if test="$sudo='y'">
157 <xsl:text>sudo </xsl:text>
158 </xsl:if>
[619b313]159 <xsl:text>rm -rf $JH_UNPACKDIR unpacked
160</xsl:text>
[c048987]161 </xsl:when>
162 <!-- Non-package page -->
163 <xsl:otherwise>
164 <xsl:apply-templates select=".//screen" mode="not-pack"/>
165 </xsl:otherwise>
166 </xsl:choose>
[619b313]167 <xsl:text>
168exit
169</xsl:text><!-- include a \n at the end of document-->
[c048987]170 </exsl:document>
[e576789]171 </xsl:template>
172
173<!--======================= Sub-sections code =======================-->
174
175 <xsl:template match="sect2">
[619b313]176 <xsl:param name="want-stats" select="false"/>
[e576789]177 <xsl:choose>
[c048987]178
[e576789]179 <xsl:when test="@role = 'package'">
[619b313]180 <xsl:text>
181cd $SRC_DIR</xsl:text>
[642722f]182 <!-- Download information is in bridgehead tags -->
[e576789]183 <xsl:apply-templates select="bridgehead[@renderas='sect3']"/>
[c048987]184 </xsl:when><!-- @role="package" -->
185
[967b819]186 <xsl:when test="@role = 'qt4-prefix' or @role = 'qt5-prefix'">
[625cb14]187 <xsl:apply-templates select=".//screen[./userinput]"/>
[967b819]188 </xsl:when>
[c048987]189
[0a0b609]190 <xsl:when test="@role = 'installation' and
191 not(preceding-sibling::sect2[@role = 'installation'])">
[e576789]192 <xsl:text>
[39dc04a]193cd $BUILD_DIR
[07f7eff]194find . -maxdepth 1 -mindepth 1 -type d | xargs </xsl:text>
195 <xsl:if test="$sudo='y'">
196 <xsl:text>sudo </xsl:text>
197 </xsl:if>
198 <xsl:text>rm -rf
[67c3df4]199</xsl:text>
[619b313]200 <!-- If stats are requested, insert the start size -->
201 <xsl:if test="$want-stats">
202 <xsl:text>
[59c4761]203echo Start Size: $(sudo du -skx --exclude home $BUILD_DIR) >> $INFOLOG
[67c3df4]204</xsl:text>
205 </xsl:if>
206
[619b313]207 <xsl:text>
208case $PACKAGE in
[e6967a1]209 *.tar.gz|*.tar.bz2|*.tar.xz|*.tgz|*.tar.lzma)
[39dc04a]210 tar -xvf $SRC_DIR/$PACKAGE &gt; unpacked
[1fa0dee]211 JH_UNPACKDIR=`grep '[^./]\+' unpacked | head -n1 | sed 's@^\./@@;s@/.*@@'`
[6eaae5e]212 ;;
213 *.tar.lz)
[39dc04a]214 bsdtar -xvf $SRC_DIR/$PACKAGE 2&gt; unpacked
[1fa0dee]215 JH_UNPACKDIR=`head -n1 unpacked | cut -d" " -f2 | sed 's@^\./@@;s@/.*@@'`
[67992a0]216 ;;
217 *.zip)
[39dc04a]218 zipinfo -1 $SRC_DIR/$PACKAGE &gt; unpacked
[1fa0dee]219 JH_UNPACKDIR="$(sed 's@/.*@@' unpacked | uniq )"
220 if test $(wc -w &lt;&lt;&lt; $JH_UNPACKDIR) -eq 1; then
[39dc04a]221 unzip $SRC_DIR/$PACKAGE
[67992a0]222 else
[1fa0dee]223 JH_UNPACKDIR=${PACKAGE%.zip}
224 unzip -d $JH_UNPACKDIR $SRC_DIR/$PACKAGE
[67992a0]225 fi
226 ;;
227 *)
[1fa0dee]228 JH_UNPACKDIR=$JH_PKG_DIR-build
229 mkdir $JH_UNPACKDIR
230 cp $SRC_DIR/$PACKAGE $JH_UNPACKDIR
[619b313]231 ADDITIONAL="$(find . -mindepth 1 -maxdepth 1 -type l)"
232 if [ -n "$ADDITIONAL" ]; then
233 cp $ADDITIONAL $JH_UNPACKDIR
234 fi
[67992a0]235 ;;
236esac
[1fa0dee]237export JH_UNPACKDIR
[619b313]238cd $JH_UNPACKDIR
[67992a0]239</xsl:text>
[619b313]240 <!-- If stats are requested, insert the start time -->
241 <xsl:if test="$want-stats">
242 <xsl:text>
243echo Start Time: ${SECONDS} >> $INFOLOG
[67c3df4]244</xsl:text>
245 </xsl:if>
246
[7933ed7]247 <xsl:call-template name="process-install">
248 <xsl:with-param
249 name="instruction-tree"
[625cb14]250 select=".//screen[not(@role = 'nodump') and ./userinput] |
[c048987]251 .//para/command[contains(text(),'check') or
[7933ed7]252 contains(text(),'test')]"/>
[619b313]253 <xsl:with-param name="want-stats" select="$want-stats"/>
[7933ed7]254 <xsl:with-param name="root-seen" select="boolean(0)"/>
255 <xsl:with-param name="install-seen" select="boolean(0)"/>
256 <xsl:with-param name="test-seen" select="boolean(0)"/>
257 <xsl:with-param name="doc-seen" select="boolean(0)"/>
258 </xsl:call-template>
[619b313]259 <xsl:text>
260</xsl:text>
[e576789]261 <xsl:if test="$sudo = 'y'">
262 <xsl:text>sudo /sbin/</xsl:text>
263 </xsl:if>
[619b313]264 <xsl:text>ldconfig</xsl:text>
[c048987]265 </xsl:when><!-- @role="installation" -->
266
[e576789]267 <xsl:when test="@role = 'configuration'">
[619b313]268 <xsl:text>&#xA;</xsl:text>
[625cb14]269 <xsl:apply-templates mode="config"
270 select=".//screen[not(@role = 'nodump') and ./userinput]"/>
[c048987]271 </xsl:when><!-- @role="configuration" -->
272
[e576789]273 </xsl:choose>
274 </xsl:template>
275
276<!--==================== Download code =======================-->
277
[642722f]278 <!-- template for extracting the filename from an url in the form:
279 proto://internet.name/dir1/.../dirn/filename?condition.
280 Needed, because substring-after(...,'/') returns only the
281 substring after the first '/'. -->
[e576789]282 <xsl:template name="package_name">
283 <xsl:param name="url" select="foo"/>
284 <xsl:param name="sub-url" select="substring-after($url,'/')"/>
285 <xsl:choose>
286 <xsl:when test="contains($sub-url,'/')">
287 <xsl:call-template name="package_name">
288 <xsl:with-param name="url" select="$sub-url"/>
289 </xsl:call-template>
290 </xsl:when>
291 <xsl:otherwise>
292 <xsl:choose>
293 <xsl:when test="contains($sub-url,'?')">
294 <xsl:value-of select="substring-before($sub-url,'?')"/>
295 </xsl:when>
296 <xsl:otherwise>
297 <xsl:value-of select="$sub-url"/>
298 </xsl:otherwise>
299 </xsl:choose>
300 </xsl:otherwise>
301 </xsl:choose>
302 </xsl:template>
303
[642722f]304 <!-- Generates the code to download a package, an additional package or
305 a patch. -->
306 <xsl:template name="download-file">
307 <xsl:param name="httpurl" select="''"/>
308 <xsl:param name="ftpurl" select="''"/>
309 <xsl:param name="md5" select="''"/>
310 <xsl:param name="varname" select="''"/>
311 <xsl:variable name="package">
312 <xsl:call-template name="package_name">
313 <xsl:with-param name="url">
[e576789]314 <xsl:choose>
[642722f]315 <xsl:when test="string-length($httpurl) &gt; 10">
316 <xsl:value-of select="$httpurl"/>
[e576789]317 </xsl:when>
318 <xsl:otherwise>
[642722f]319 <xsl:value-of select="$ftpurl"/>
[e576789]320 </xsl:otherwise>
321 </xsl:choose>
[642722f]322 </xsl:with-param>
323 </xsl:call-template>
324 </xsl:variable>
325 <xsl:variable name="first_letter"
326 select="translate(substring($package,1,1),
327 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
328 'abcdefghijklmnopqrstuvwxyz')"/>
329 <xsl:text>&#xA;</xsl:text>
330 <xsl:value-of select="$varname"/>
331 <xsl:text>=</xsl:text>
332 <xsl:value-of select="$package"/>
333 <xsl:text>&#xA;if [[ ! -f $</xsl:text>
334 <xsl:value-of select="$varname"/>
[8dc4646]335 <xsl:text> ]] ; then
[1fa0dee]336 if [[ -f $JH_SRC_ARCHIVE/$</xsl:text>
[642722f]337 <xsl:value-of select="$varname"/>
338 <xsl:text> ]] ; then&#xA;</xsl:text>
[1fa0dee]339 <xsl:text> cp $JH_SRC_ARCHIVE/$</xsl:text>
[642722f]340 <xsl:value-of select="$varname"/>
341 <xsl:text> $</xsl:text>
342 <xsl:value-of select="$varname"/>
[8dc4646]343 <xsl:text>
344 else&#xA;</xsl:text>
[342c862]345 <!-- Download from upstream http -->
[642722f]346 <xsl:if test="string-length($httpurl) &gt; 10">
[8dc4646]347 <xsl:text> wget -T 30 -t 5 </xsl:text>
[642722f]348 <xsl:value-of select="$httpurl"/>
[342c862]349 <xsl:text> ||&#xA;</xsl:text>
[642722f]350 </xsl:if>
[342c862]351 <!-- Download from upstream ftp -->
[642722f]352 <xsl:if test="string-length($ftpurl) &gt; 10">
[8dc4646]353 <xsl:text> wget -T 30 -t 5 </xsl:text>
[642722f]354 <xsl:value-of select="$ftpurl"/>
[342c862]355 <xsl:text> ||&#xA;</xsl:text>
[642722f]356 </xsl:if>
[342c862]357 <!-- The FTP_SERVER mirror as a last resort -->
[1fa0dee]358 <xsl:text> wget -T 30 -t 5 ${JH_FTP_SERVER}svn/</xsl:text>
[342c862]359 <xsl:value-of select="$first_letter"/>
360 <xsl:text>/$</xsl:text>
361 <xsl:value-of select="$varname"/>
[1fa0dee]362 <xsl:text>
[8dc4646]363 fi
[619b313]364fi</xsl:text>
[642722f]365 <xsl:if test="string-length($md5) &gt; 10">
[619b313]366 <xsl:text>
367echo "</xsl:text>
[642722f]368 <xsl:value-of select="$md5"/>
369 <xsl:text>&#x20;&#x20;$</xsl:text>
370 <xsl:value-of select="$varname"/>
[619b313]371 <xsl:text>" | md5sum -c -</xsl:text>
[39dc04a]372 </xsl:if>
373<!-- link additional packages into $BUILD_DIR, because they are supposed to
374 be there-->
375 <xsl:if test="string($varname) != 'PACKAGE'">
[619b313]376 <xsl:text>
377[[ "$SRC_DIR" != "$BUILD_DIR" ]] &amp;&amp; ln -sf $SRC_DIR/$</xsl:text>
[39dc04a]378 <xsl:value-of select="$varname"/>
[619b313]379 <xsl:text> $BUILD_DIR</xsl:text>
[642722f]380 </xsl:if>
[619b313]381 <xsl:text>&#xA;</xsl:text>
[642722f]382 </xsl:template>
383
384 <!-- Extract the MD5 sum information -->
385 <xsl:template match="para" mode="md5">
386 <xsl:choose>
387 <xsl:when test="contains(substring-after(string(),'sum: '),'&#xA;')">
388 <xsl:value-of select="substring-before(substring-after(string(),'sum: '),'&#xA;')"/>
[e576789]389 </xsl:when>
[642722f]390 <xsl:otherwise>
391 <xsl:value-of select="substring-after(string(),'sum: ')"/>
392 </xsl:otherwise>
[e576789]393 </xsl:choose>
394 </xsl:template>
395
[642722f]396 <!-- We have several templates itemizedlist, depending on whether we
397 expect the package information, or additional package(s) or patch(es)
398 information. Select the appropriate mode here. -->
399 <xsl:template match="bridgehead">
[e576789]400 <xsl:choose>
[642722f]401 <!-- Special case for Openjdk -->
402 <xsl:when test="contains(string(),'Source Package Information')">
403 <xsl:apply-templates
404 select="following-sibling::itemizedlist[1]//simplelist">
405 <xsl:with-param name="varname" select="'PACKAGE'"/>
406 </xsl:apply-templates>
407 <xsl:apply-templates select="following-sibling::itemizedlist
408 [preceding-sibling::bridgehead[1]=current()
409 and position() &gt;1]//simplelist">
410 <xsl:with-param name="varname" select="'PACKAGE1'"/>
411 </xsl:apply-templates>
[e576789]412 </xsl:when>
[642722f]413 <!-- Package information -->
414 <xsl:when test="contains(string(),'Package Information')">
415 <xsl:apply-templates select="following-sibling::itemizedlist
416 [preceding-sibling::bridgehead[1]=current()]"
417 mode="package"/>
[e576789]418 </xsl:when>
[642722f]419 <!-- Additional package information -->
[2873df6]420 <!-- special cases for llvm -->
[bfc99d1]421 <xsl:when test="contains(string(),'Recommended Download')">
[2873df6]422 <xsl:apply-templates select="following-sibling::itemizedlist[1]"
423 mode="additional"/>
424 </xsl:when>
[ba57e61]425 <xsl:when test="contains(string(),'Optional Download')">
426 <xsl:apply-templates select="following-sibling::itemizedlist"
427 mode="additional"/>
428 </xsl:when>
429 <!-- All other additional packages have "Additional" -->
[642722f]430 <xsl:when test="contains(string(),'Additional')">
431 <xsl:apply-templates select="following-sibling::itemizedlist"
432 mode="additional"/>
[e576789]433 </xsl:when>
[642722f]434 <!-- Do not do anything if the dev has created another type of
435 bridgehead. -->
436 <xsl:otherwise/>
[e576789]437 </xsl:choose>
438 </xsl:template>
439
[642722f]440 <!-- Call the download code template with appropriate parameters -->
441 <xsl:template match="itemizedlist" mode="package">
442 <xsl:call-template name="download-file">
443 <xsl:with-param name="httpurl">
444 <xsl:value-of select="./listitem[1]/para/ulink/@url"/>
445 </xsl:with-param>
446 <xsl:with-param name="ftpurl">
447 <xsl:value-of select="./listitem/para[contains(string(),'FTP')]/ulink/@url"/>
448 </xsl:with-param>
449 <xsl:with-param name="md5">
450 <xsl:apply-templates select="./listitem/para[contains(string(),'MD5')]"
451 mode="md5"/>
452 </xsl:with-param>
453 <xsl:with-param name="varname" select="'PACKAGE'"/>
454 </xsl:call-template>
[e576789]455 </xsl:template>
456
[642722f]457 <xsl:template match="itemizedlist" mode="additional">
458 <!-- The normal layout is "one listitem"<->"one url", but some devs
459 find amusing to have FTP and/or MD5sum listitems, or to
460 enclose the download information inside a simplelist tag... -->
461 <xsl:for-each select="listitem[.//ulink]">
462 <xsl:choose>
463 <!-- hopefully, there was a HTTP line before -->
464 <xsl:when test="contains(string(./para),'FTP')"/>
465 <xsl:when test=".//simplelist">
466 <xsl:apply-templates select=".//simplelist">
467 <xsl:with-param name="varname" select="'PACKAGE1'"/>
468 </xsl:apply-templates>
469 </xsl:when>
470 <xsl:otherwise>
471 <xsl:call-template name="download-file">
472 <xsl:with-param name="httpurl">
473 <xsl:value-of select="./para/ulink/@url"/>
474 </xsl:with-param>
475 <xsl:with-param name="ftpurl">
476 <xsl:value-of
477 select="following-sibling::listitem[1]/
478 para[contains(string(),'FTP')]/ulink/@url"/>
479 </xsl:with-param>
480 <xsl:with-param name="md5">
481 <xsl:apply-templates
482 select="following-sibling::listitem[position()&lt;3]/
483 para[contains(string(),'MD5')]"
484 mode="md5"/>
485 </xsl:with-param>
486 <xsl:with-param name="varname">
487 <xsl:choose>
488 <xsl:when test="contains(./para/ulink/@url,'.patch')">
489 <xsl:text>PATCH</xsl:text>
490 </xsl:when>
491 <xsl:otherwise>
492 <xsl:text>PACKAGE1</xsl:text>
493 </xsl:otherwise>
494 </xsl:choose>
495 </xsl:with-param>
496 </xsl:call-template>
497 </xsl:otherwise>
498 </xsl:choose>
499 </xsl:for-each>
[e576789]500 </xsl:template>
501
[642722f]502 <!-- the simplelist case. Hopefully, the layout is one member for
503 url, one for md5 and others for various information, that we do not
504 use -->
505 <xsl:template match="simplelist">
506 <xsl:param name="varname" select="'PACKAGE1'"/>
507 <xsl:call-template name="download-file">
508 <xsl:with-param name="httpurl" select=".//ulink/@url"/>
509 <xsl:with-param name="md5">
510 <xsl:value-of select="substring-after(member[contains(string(),'MD5')],'sum: ')"/>
511 </xsl:with-param>
512 <xsl:with-param name="varname" select="$varname"/>
513 </xsl:call-template>
514 </xsl:template>
[625cb14]515
516<!--====================== Non package code =========================-->
517
518 <xsl:template match="screen" mode="not-pack">
519 <xsl:choose>
[6622409]520 <xsl:when test="@role='nodump'"/>
[625cb14]521 <xsl:when test="ancestor::sect1[@id='postlfs-config-vimrc']">
522 <xsl:text>
523cat > ~/.vimrc &lt;&lt;EOF
524</xsl:text>
525 <xsl:apply-templates/>
526 <xsl:text>
527EOF
528</xsl:text>
529 </xsl:when>
530 <xsl:otherwise>
531 <xsl:apply-templates select="." mode="config"/>
532 </xsl:otherwise>
533 </xsl:choose>
534 </xsl:template>
[e576789]535<!--======================== Commands code ==========================-->
[c048987]536<!-- Code for installation instructions is in gen-install.xsl -->
[e576789]537
538 <xsl:template match="screen">
[c048987]539 <xsl:choose>
540<!-- instructions run as root (configuration mainly) -->
541 <xsl:when test="@role = 'root'">
[aeb8539]542<!-- templates begin/end-root are in gen-install.xsl -->
[c048987]543 <xsl:if test="not(preceding-sibling::screen[1][@role='root'])">
[aeb8539]544 <xsl:call-template name="begin-root"/>
[c048987]545 </xsl:if>
546 <xsl:apply-templates mode="root"/>
547 <xsl:if test="not(following-sibling::screen[1][@role='root'])">
[aeb8539]548 <xsl:call-template name="end-root"/>
[c048987]549 </xsl:if>
550 </xsl:when>
[67c3df4]551<!-- then all the instructions run as user -->
[c048987]552 <xsl:otherwise>
553 <xsl:apply-templates select="userinput"/>
554 </xsl:otherwise>
555 </xsl:choose>
[e576789]556 </xsl:template>
557
[8fc6a47]558<!-- Templates for bootscripts/units installation -->
[70d73d1]559 <xsl:template name="set-bootpkg-dir">
560 <xsl:param name="bootpkg" select="'bootscripts'"/>
561 <xsl:param name="url" select="''"/>
[619b313]562 <xsl:text>
563BOOTPKG_DIR=blfs-</xsl:text>
[70d73d1]564 <xsl:copy-of select="$bootpkg"/>
565 <xsl:text>
[619b313]566
[1fa0dee]567BOOTSRC_DIR=${JH_SRC_ARCHIVE}${JH_SRC_SUBDIRS:+/${BOOTPKG_DIR}}
568BOOTBUILD_DIR=${JH_BUILD_ROOT}${JH_BUILD_SUBDIRS:+/${BOOTPKG_DIR}}
[973c767]569mkdir -p $BOOTSRC_DIR
570mkdir -p $BOOTBUILD_DIR
571
572pushd $BOOTSRC_DIR
[e576789]573URL=</xsl:text>
[70d73d1]574 <xsl:value-of select="$url"/>
575 <xsl:text>
[e576789]576BOOTPACKG=$(basename $URL)
[bbcdeab]577if [[ ! -f $BOOTPACKG ]] ; then
[1fa0dee]578 if [[ -f $JH_SRC_ARCHIVE/$BOOTPACKG ]] ; then
579 cp $JH_SRC_ARCHIVE/$BOOTPACKG $BOOTPACKG
[bbcdeab]580 else
581 wget -T 30 -t 5 $URL
582 fi
[973c767]583 rm -f $BOOTBUILD_DIR/unpacked
[bbcdeab]584fi
585
[973c767]586cd $BOOTBUILD_DIR
[e576789]587if [[ -e unpacked ]] ; then
[f079f8f]588 BOOTUNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
589 if ! [[ -d $BOOTUNPACKDIR ]]; then
[973c767]590 tar -xvf $BOOTSRC_DIR/$BOOTPACKG > unpacked
[f079f8f]591 BOOTUNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
[e576789]592 fi
593else
[973c767]594 tar -xvf $BOOTSRC_DIR/$BOOTPACKG > unpacked
[f079f8f]595 BOOTUNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
[e576789]596fi
[619b313]597cd $BOOTUNPACKDIR</xsl:text>
[70d73d1]598 </xsl:template>
599
600 <xsl:template match="screen" mode="config">
601 <xsl:if test="preceding-sibling::para[1]/xref[@linkend='bootscripts']">
[aeb8539]602<!-- if the preceding "screen" tag is role="root", and we are role="root"
603 the end-root has not been called. So do it -->
[619b313]604 <xsl:if
605 test="preceding-sibling::screen[1][@role='root'] and @role='root'">
[aeb8539]606 <xsl:call-template name="end-root"/>
607 </xsl:if>
[70d73d1]608 <xsl:call-template name="set-bootpkg-dir">
609 <xsl:with-param name="bootpkg" select="'bootscripts'"/>
610 <xsl:with-param name="url"
611 select="id('bootscripts')//itemizedlist//ulink/@url"/>
612 </xsl:call-template>
[aeb8539]613<!-- if the preceding "screen" tag is role="root", and we are role="root"
614 the begin-root will not be called. So do it -->
[619b313]615 <xsl:if
616 test="preceding-sibling::screen[1][@role='root'] and @role='root'">
[aeb8539]617 <xsl:call-template name="begin-root"/>
618 </xsl:if>
[70d73d1]619 </xsl:if>
620 <xsl:if test="preceding-sibling::para[1]/xref[@linkend='systemd-units']">
[aeb8539]621<!-- if the preceding "screen" tag is role="root", and we are role="root"
622 the end-root has not been called. So do it -->
[619b313]623 <xsl:if
624 test="preceding-sibling::screen[1][@role='root'] and @role='root'">
[aeb8539]625 <xsl:call-template name="end-root"/>
626 </xsl:if>
[70d73d1]627 <xsl:call-template name="set-bootpkg-dir">
628 <xsl:with-param name="bootpkg" select="'systemd-units'"/>
629 <xsl:with-param name="url"
630 select="id('systemd-units')//itemizedlist//ulink/@url"/>
631 </xsl:call-template>
[aeb8539]632<!-- if the preceding "screen" tag is role="root", and we are role="root"
633 the begin-root will not be called. So do it -->
[619b313]634 <xsl:if
635 test="preceding-sibling::screen[1][@role='root'] and @role='root'">
[aeb8539]636 <xsl:call-template name="begin-root"/>
637 </xsl:if>
[e576789]638 </xsl:if>
639 <xsl:apply-templates select='.'/>
[70d73d1]640 <xsl:if test="preceding-sibling::para[1]/xref[@linkend='bootscripts' or
641 @linkend='systemd-units']">
[aeb8539]642<!-- if the next "screen" tag is role="root", and we are role="root"
643 the end-root has not been called. So do it -->
[619b313]644 <xsl:if
645 test="following-sibling::screen[1][@role='root'] and @role='root'">
[aeb8539]646 <xsl:call-template name="end-root"/>
647 </xsl:if>
[619b313]648 <xsl:text>
649popd</xsl:text>
[aeb8539]650<!-- if the next "screen" tag is role="root", and we are role="root"
651 the begin-root will not be called. So do it -->
[619b313]652 <xsl:if
653 test="following-sibling::screen[1][@role='root'] and @role='root'">
[aeb8539]654 <xsl:call-template name="begin-root"/>
655 </xsl:if>
[e576789]656 </xsl:if>
657 </xsl:template>
658
[c048987]659 <xsl:template match="command" mode="installation">
[619b313]660 <xsl:param name="want-stats" select="false"/>
[a743e57]661 <xsl:variable name="ns" select="normalize-space(string())"/>
[c048987]662 <xsl:variable name="first"
663 select="not(
664 boolean(
665 preceding-sibling::command[contains(text(),'check') or
666 contains(text(),'test')]))"/>
667 <xsl:variable name="last"
668 select="not(
669 boolean(
670 following-sibling::command[contains(text(),'check') or
671 contains(text(),'test')]))"/>
672 <xsl:choose>
[619b313]673 <xsl:when test="$want-stats">
[c048987]674 <xsl:if test="$first">
[67c3df4]675 <xsl:text>
[619b313]676
[67c3df4]677echo Time after make: ${SECONDS} >> $INFOLOG
[59c4761]678echo Size after make: $(sudo du -skx --exclude home $BUILD_DIR) >> $INFOLOG
[67c3df4]679echo Time before test: ${SECONDS} >> $INFOLOG
[c048987]680
[67c3df4]681</xsl:text>
[c048987]682 </xsl:if>
683 </xsl:when>
684 <xsl:otherwise>
[619b313]685 <xsl:text>
686#</xsl:text>
[c048987]687 </xsl:otherwise>
688 </xsl:choose>
689 <xsl:choose>
690 <xsl:when test="contains($ns,'make')">
691 <xsl:value-of select="substring-before($ns,'make ')"/>
692 <xsl:text>make </xsl:text>
693 <xsl:if test="not(contains($ns,'-k'))">
694 <xsl:text>-k </xsl:text>
695 </xsl:if>
696 <xsl:value-of select="substring-after($ns,'make ')"/>
697 </xsl:when>
698 <xsl:otherwise>
699 <xsl:copy-of select="$ns"/>
700 </xsl:otherwise>
701 </xsl:choose>
[619b313]702 <xsl:if test="$want-stats">
[c048987]703 <xsl:text> &gt;&gt; $TESTLOG 2&gt;&amp;1</xsl:text>
[e576789]704 </xsl:if>
[619b313]705 <xsl:text> || true</xsl:text>
706 <xsl:if test="$want-stats">
[c048987]707 <xsl:text>
[619b313]708
[c048987]709echo Time after test: ${SECONDS} >> $INFOLOG
[59c4761]710echo Size after test: $(sudo du -skx --exclude home $BUILD_DIR) >> $INFOLOG
[c048987]711echo Time before install: ${SECONDS} >> $INFOLOG
712</xsl:text>
713 </xsl:if>
[e576789]714 </xsl:template>
715
[8fc6a47]716 <xsl:template match="userinput|command">
[619b313]717 <xsl:text>
718</xsl:text>
[e576789]719 <xsl:apply-templates/>
720 </xsl:template>
721
[619b313]722 <xsl:template match="userinput" mode="root">
723 <xsl:text>
724</xsl:text>
725 <xsl:apply-templates mode="root"/>
726 </xsl:template>
727
[aeb8539]728 <xsl:template match="text()">
729 <xsl:call-template name="remove-ampersand">
730 <xsl:with-param name="out-string" select="string()"/>
731 </xsl:call-template>
732 </xsl:template>
733
[e576789]734 <xsl:template match="text()" mode="root">
735 <xsl:call-template name="output-root">
736 <xsl:with-param name="out-string" select="string()"/>
737 </xsl:call-template>
738 </xsl:template>
739
740 <xsl:template name="output-root">
741 <xsl:param name="out-string" select="''"/>
742 <xsl:choose>
743 <xsl:when test="contains($out-string,'$') and $sudo = 'y'">
744 <xsl:call-template name="output-root">
745 <xsl:with-param name="out-string"
746 select="substring-before($out-string,'$')"/>
747 </xsl:call-template>
748 <xsl:text>\$</xsl:text>
749 <xsl:call-template name="output-root">
750 <xsl:with-param name="out-string"
751 select="substring-after($out-string,'$')"/>
752 </xsl:call-template>
753 </xsl:when>
754 <xsl:when test="contains($out-string,'`') and $sudo = 'y'">
755 <xsl:call-template name="output-root">
756 <xsl:with-param name="out-string"
757 select="substring-before($out-string,'`')"/>
758 </xsl:call-template>
759 <xsl:text>\`</xsl:text>
760 <xsl:call-template name="output-root">
761 <xsl:with-param name="out-string"
762 select="substring-after($out-string,'`')"/>
763 </xsl:call-template>
764 </xsl:when>
765 <xsl:when test="contains($out-string,'\') and $sudo = 'y'">
766 <xsl:call-template name="output-root">
767 <xsl:with-param name="out-string"
768 select="substring-before($out-string,'\')"/>
769 </xsl:call-template>
770 <xsl:text>\\</xsl:text>
771 <xsl:call-template name="output-root">
772 <xsl:with-param name="out-string"
773 select="substring-after($out-string,'\')"/>
774 </xsl:call-template>
775 </xsl:when>
776 <xsl:otherwise>
[aeb8539]777 <xsl:call-template name="remove-ampersand">
778 <xsl:with-param name="out-string" select="$out-string"/>
779 </xsl:call-template>
780<!-- <xsl:value-of select="$out-string"/> -->
[e576789]781 </xsl:otherwise>
782 </xsl:choose>
783 </xsl:template>
784
[67c3df4]785 <xsl:template name="output-destdir">
786 <xsl:apply-templates
787 select="userinput|following-sibling::screen[@role='root']/userinput"
788 mode="destdir"/>
789 <xsl:text>
[619b313]790
[67c3df4]791echo Time after install: ${SECONDS} >> $INFOLOG
[59c4761]792echo Size after install: $(sudo du -skx --exclude home $BUILD_DIR) >> $INFOLOG
[67c3df4]793</xsl:text>
794 </xsl:template>
795
796 <xsl:template match="userinput" mode="destdir">
[8fc6a47]797 <xsl:text>
798</xsl:text>
[67c3df4]799 <xsl:choose>
800 <xsl:when test="./literal">
801 <xsl:call-template name="outputpkgdest">
802 <xsl:with-param name="outputstring" select="text()[1]"/>
803 </xsl:call-template>
804 <xsl:apply-templates select="literal"/>
805 <xsl:call-template name="outputpkgdest">
806 <xsl:with-param name="outputstring" select="text()[2]"/>
807 </xsl:call-template>
808 </xsl:when>
809 <xsl:otherwise>
810 <xsl:call-template name="outputpkgdest">
811 <xsl:with-param name="outputstring" select="string()"/>
812 </xsl:call-template>
813 </xsl:otherwise>
814 </xsl:choose>
815 </xsl:template>
816
817 <xsl:template name="outputpkgdest">
818 <xsl:param name="outputstring" select="'foo'"/>
819 <xsl:choose>
820 <xsl:when test="contains($outputstring,'make ')">
821 <xsl:choose>
822 <xsl:when test="not(starts-with($outputstring,'make'))">
823 <xsl:call-template name="outputpkgdest">
824 <xsl:with-param name="outputstring"
825 select="substring-before($outputstring,'make')"/>
826 </xsl:call-template>
827 <xsl:call-template name="outputpkgdest">
828 <xsl:with-param
829 name="outputstring"
830 select="substring-after($outputstring,
831 substring-before($outputstring,'make'))"/>
832 </xsl:call-template>
833 </xsl:when>
834 <xsl:otherwise>
[619b313]835 <xsl:text>
836make DESTDIR=$PKG_DEST</xsl:text>
[67c3df4]837 <xsl:call-template name="outputpkgdest">
838 <xsl:with-param
839 name="outputstring"
840 select="substring-after($outputstring,'make')"/>
841 </xsl:call-template>
842 </xsl:otherwise>
843 </xsl:choose>
844 </xsl:when>
845 <xsl:when test="contains($outputstring,'ninja install')">
846 <xsl:choose>
847 <xsl:when test="not(starts-with($outputstring,'ninja install'))">
848 <xsl:call-template name="outputpkgdest">
849 <xsl:with-param name="outputstring"
850 select="substring-before($outputstring,'ninja install')"/>
851 </xsl:call-template>
852 <xsl:call-template name="outputpkgdest">
853 <xsl:with-param
854 name="outputstring"
855 select="substring-after($outputstring,
856 substring-before($outputstring,'ninja install'))"/>
857 </xsl:call-template>
858 </xsl:when>
859 <xsl:otherwise>
[619b313]860 <xsl:text>
861DESTDIR=$PKG_DEST ninja</xsl:text>
[67c3df4]862 <xsl:call-template name="outputpkgdest">
863 <xsl:with-param
864 name="outputstring"
865 select="substring-after($outputstring,'ninja')"/>
866 </xsl:call-template>
867 </xsl:otherwise>
868 </xsl:choose>
869 </xsl:when>
870 <xsl:otherwise> <!-- no make nor ninja in this string -->
871 <xsl:choose>
872 <xsl:when test="contains($outputstring,'&gt;/') and
873 not(contains(substring-before($outputstring,'&gt;/'),' /'))">
[aeb8539]874 <xsl:call-template name="remove-ampersand">
875 <xsl:with-param name="out-string"
876 select="substring-before($outputstring,'&gt;/')"/>
877 </xsl:call-template>
878<!-- <xsl:value-of select="substring-before($outputstring,'&gt;/')"/>-->
[67c3df4]879 <xsl:text>&gt;$PKG_DEST/</xsl:text>
880 <xsl:call-template name="outputpkgdest">
881 <xsl:with-param name="outputstring" select="substring-after($outputstring,'&gt;/')"/>
882 </xsl:call-template>
883 </xsl:when>
884 <xsl:when test="contains($outputstring,' /')">
[aeb8539]885 <xsl:call-template name="remove-ampersand">
886 <xsl:with-param name="out-string"
887 select="substring-before($outputstring,' /')"/>
888 </xsl:call-template>
889<!-- <xsl:value-of select="substring-before($outputstring,' /')"/>-->
[67c3df4]890 <xsl:text> $PKG_DEST/</xsl:text>
891 <xsl:call-template name="outputpkgdest">
892 <xsl:with-param name="outputstring" select="substring-after($outputstring,' /')"/>
893 </xsl:call-template>
894 </xsl:when>
895 <xsl:otherwise>
[aeb8539]896 <xsl:call-template name="remove-ampersand">
897 <xsl:with-param name="out-string" select="$outputstring"/>
898 </xsl:call-template>
899<!-- <xsl:value-of select="$outputstring"/>-->
[67c3df4]900 </xsl:otherwise>
901 </xsl:choose>
902 </xsl:otherwise>
903 </xsl:choose>
904 </xsl:template>
905
[aeb8539]906 <xsl:template name="remove-ampersand">
907 <xsl:param name="out-string" select="''"/>
908 <xsl:choose>
909 <xsl:when test="contains($out-string,'&amp;&amp;&#xA;')">
910 <xsl:variable name="instruction-before">
911 <xsl:call-template name="last-line">
912 <xsl:with-param
913 name="instructions"
914 select="substring-before($out-string,'&amp;&amp;&#xA;')"/>
915 </xsl:call-template>
916 </xsl:variable>
917 <xsl:call-template name="remove-end-space">
918 <xsl:with-param
919 name="instructions"
920 select="substring-before($out-string,'&amp;&amp;&#xA;')"/>
921 </xsl:call-template>
922 <xsl:if test="contains($instruction-before,' ]') or
923 contains($instruction-before,'test ') or
924 contains($instruction-before,'pgrep -l')">
925 <xsl:text> &amp;&amp;</xsl:text>
926 </xsl:if>
[619b313]927 <xsl:text>
928</xsl:text>
[aeb8539]929 <xsl:call-template name="remove-ampersand">
930 <xsl:with-param name="out-string"
931 select="substring-after($out-string,
932 '&amp;&amp;&#xA;')"/>
933 </xsl:call-template>
934 </xsl:when>
935 <xsl:otherwise>
936 <xsl:copy-of select="$out-string"/>
937 </xsl:otherwise>
938 </xsl:choose>
939 </xsl:template>
940
941 <xsl:template name="last-line">
942 <xsl:param name="instructions" select="''"/>
943 <xsl:choose>
944 <xsl:when test="contains($instructions,'&#xA;')">
945 <xsl:call-template name="last-line">
946 <xsl:with-param
947 name="instructions"
948 select="substring-after($instructions,'&#xA;')"/>
949 </xsl:call-template>
950 </xsl:when>
951 <xsl:otherwise>
952 <xsl:copy-of select="normalize-space($instructions)"/>
953 </xsl:otherwise>
954 </xsl:choose>
955 </xsl:template>
956
957 <xsl:template name="remove-end-space">
958 <xsl:param name="instructions" select="''"/>
959 <xsl:choose>
[619b313]960 <xsl:when
961 test="substring($instructions,string-length($instructions))=' '">
[aeb8539]962 <xsl:call-template name="remove-end-space">
963 <xsl:with-param
964 name="instructions"
[619b313]965 select="substring($instructions,
966 1,
967 string-length($instructions)-1)"/>
[aeb8539]968 </xsl:call-template>
969 </xsl:when>
970 <xsl:otherwise>
[619b313]971 <xsl:copy-of select="$instructions"/>
[aeb8539]972 </xsl:otherwise>
973 </xsl:choose>
974 </xsl:template>
975
[e576789]976</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.