source: BLFS/xsl/scripts.xsl@ 50cf934

ablfs-more legacy trunk
Last change on this file since 50cf934 was bfc99d1, checked in by Pierre Labastie <pierre@…>, 4 years ago

Typo

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