source: BLFS/xsl/scripts.xsl@ 0495e57e

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

BLFS tools: Source /etc/profile in scripts

Since this is not done anymore in envars.conf...

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