source: BLFS/xsl/scripts.xsl@ d505128

ablfs-more legacy trunk
Last change on this file since d505128 was 625cb14, checked in by Pierre Labastie <pierre@…>, 6 years ago

Add possibility to automate bash shell startup files, vimrc, and rng.
This adds a new variable to the configuration (LANGUAGE).
Also automate the generation of various <replaceable> instructions

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