source: BLFS/xsl/scripts.xsl@ 619b313

ablfs-more legacy trunk
Last change on this file since 619b313 was 619b313, checked in by Pierre Labastie <pierre@…>, 5 years ago

Various fixes and improvements coming from github:

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