source: BLFS/xsl/scripts.xsl@ 7933ed7

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

Refactoring the output of installation instructions:

Create a template which processes the instruction tree fragment (only header
for now, the content is bogus), and call it from main sheet.

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