source: BLFS/xsl/scripts.xsl@ 8fc6a47

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

BLFS/xsl: refactor the generation of installation instructions, owing to
the new remap="test/doc" attributes

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