source: BLFS/xsl/scripts.xsl@ 2758d94

ablfs-more legacy trunk
Last change on this file since 2758d94 was eabfc59, checked in by Pierre Labastie <pierre@…>, 6 years ago

Unset MAKELEVEL in BLFS scriptlets. Fixes #1720.

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