source: BLFS/xsl/scripts.xsl@ bea551c

trunk
Last change on this file since bea551c was ca368ad, checked in by Pierre Labastie <pierre.labastie@…>, 13 months ago

Merge branch 'trunk' into ablfs-more

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