source: BLFS/xsl/scripts.xsl@ 72e9e68

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

Fix generation of install instructions, and remove those pesky && as much as
possible

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