source: BLFS/xsl/scripts.xsl@ 9daa202

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

BLFS tools: Take variables from config instead of envars.conf

Get them in gen_pkg_book, and pass them to sripts.xsl
use them in scripts.xsl. We set them at the beginning of
of the scriptlet, so that it is easy to modify them.

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