source: BLFS/xsl/scripts.xsl@ d7c07e0

2.4 ablfs-more legacy new_features trunk
Last change on this file since d7c07e0 was 967b819, checked in by Pierre Labastie <pierre@…>, 9 years ago

Add a new possibility for role tag in sect2

  • Property mode set to 100644
File size: 18.8 KB
RevLine 
[e576789]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: scripts.xsl 34 2012-02-21 16:05:09Z labastie $ -->
9
10<!-- XSLT stylesheet to create shell scripts from "linear build" BLFS books. -->
11
12 <!-- Build as user (y) or as root (n)? -->
13 <xsl:param name="sudo" select="'y'"/>
14
15 <xsl:template match="/">
16 <xsl:apply-templates select="//sect1"/>
17 </xsl:template>
18
19<!--=================== Master chunks code ======================-->
20
21 <xsl:template match="sect1">
22
23 <xsl:if test="@id != 'bootscripts'">
24 <!-- The file names -->
25 <xsl:variable name="filename" select="@id"/>
26
27 <!-- The build order -->
28 <xsl:variable name="position" select="position()"/>
29 <xsl:variable name="order">
30 <xsl:choose>
31 <xsl:when test="string-length($position) = 1">
32 <xsl:text>00</xsl:text>
33 <xsl:value-of select="$position"/>
34 </xsl:when>
35 <xsl:when test="string-length($position) = 2">
36 <xsl:text>0</xsl:text>
37 <xsl:value-of select="$position"/>
38 </xsl:when>
39 <xsl:otherwise>
40 <xsl:value-of select="$position"/>
41 </xsl:otherwise>
42 </xsl:choose>
43 </xsl:variable>
44
45 <!-- Depuration code -->
46 <xsl:message>
47 <xsl:text>SCRIPT is </xsl:text>
48 <xsl:value-of select="concat($order,'-z-',$filename)"/>
49 <xsl:text>&#xA; FTPDIR is </xsl:text>
50 <xsl:value-of select="$filename"/>
51 <xsl:text>&#xA;&#xA;</xsl:text>
52 </xsl:message>
53
54 <!-- Creating the scripts -->
55 <exsl:document href="{$order}-z-{$filename}" method="text">
56 <xsl:text>#!/bin/bash&#xA;set -e&#xA;&#xA;</xsl:text>
57 <xsl:choose>
58 <!-- Package page -->
[642722f]59 <xsl:when test="sect2[@role='package']">
60 <!-- We build in a subdirectory -->
61 <xsl:text>PKG_DIR=</xsl:text>
[e576789]62 <xsl:value-of select="$filename"/>
63 <xsl:text>&#xA;</xsl:text>
64 <!-- Download code and build commands -->
65 <xsl:apply-templates select="sect2"/>
66 <!-- Clean-up -->
[642722f]67 <xsl:text>cd $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
[e576789]68 <!-- In some case, some files in the build tree are owned
69 by root -->
[642722f]70 <xsl:if test="$sudo='y'">
71 <xsl:text>sudo </xsl:text>
[e576789]72 </xsl:if>
[642722f]73 <xsl:text>rm -rf $UNPACKDIR unpacked&#xA;&#xA;</xsl:text>
[e576789]74 </xsl:when>
75 <!-- Non-package page -->
76 <xsl:otherwise>
77 <xsl:apply-templates select=".//screen"/>
78 </xsl:otherwise>
79 </xsl:choose>
80 <xsl:text>exit</xsl:text>
81 </exsl:document>
82 </xsl:if>
83 </xsl:template>
84
85<!--======================= Sub-sections code =======================-->
86
87 <xsl:template match="sect2">
88 <xsl:choose>
89 <xsl:when test="@role = 'package'">
90 <xsl:text>mkdir -p $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
91 <xsl:text>cd $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
[642722f]92 <!-- Download information is in bridgehead tags -->
[e576789]93 <xsl:apply-templates select="bridgehead[@renderas='sect3']"/>
94 <xsl:text>&#xA;</xsl:text>
95 </xsl:when>
[967b819]96 <xsl:when test="@role = 'qt4-prefix' or @role = 'qt5-prefix'">
97 <xsl:apply-templates select=".//screen"/>
98 </xsl:when>
[e576789]99 <xsl:when test="@role = 'installation'">
100 <xsl:text>
101if [ "${PACKAGE%.zip}" = "${PACKAGE}" ]; then
102 if [[ -e unpacked ]] ; then
103 UNPACKDIR=`grep '[^./]\+' unpacked | head -n1 | sed 's@^./@@;s@/.*@@'`
104 [[ -n $UNPACKDIR ]] &amp;&amp; [[ -d $UNPACKDIR ]] &amp;&amp; rm -rf $UNPACKDIR
105 fi
106 tar -xvf $PACKAGE > unpacked
107 UNPACKDIR=`grep '[^./]\+' unpacked | head -n1 | sed 's@^./@@;s@/.*@@'`
108else
109 UNPACKDIR=${PACKAGE%.zip}
110 [[ -n $UNPACKDIR ]] &amp;&amp; [[ -d $UNPACKDIR ]] &amp;&amp; rm -rf $UNPACKDIR
111 unzip -d $UNPACKDIR ${PACKAGE}
112fi
[642722f]113cd $UNPACKDIR&#xA;&#xA;</xsl:text>
[e576789]114 <xsl:apply-templates select=".//screen | .//para/command"/>
115 <xsl:if test="$sudo = 'y'">
116 <xsl:text>sudo /sbin/</xsl:text>
117 </xsl:if>
118 <xsl:text>ldconfig&#xA;&#xA;</xsl:text>
119 </xsl:when>
120 <xsl:when test="@role = 'configuration'">
121 <xsl:apply-templates select=".//screen" mode="config"/>
122 </xsl:when>
123 </xsl:choose>
124 </xsl:template>
125
126<!--==================== Download code =======================-->
127
[642722f]128 <!-- template for extracting the filename from an url in the form:
129 proto://internet.name/dir1/.../dirn/filename?condition.
130 Needed, because substring-after(...,'/') returns only the
131 substring after the first '/'. -->
[e576789]132 <xsl:template name="package_name">
133 <xsl:param name="url" select="foo"/>
134 <xsl:param name="sub-url" select="substring-after($url,'/')"/>
135 <xsl:choose>
136 <xsl:when test="contains($sub-url,'/')">
137 <xsl:call-template name="package_name">
138 <xsl:with-param name="url" select="$sub-url"/>
139 </xsl:call-template>
140 </xsl:when>
141 <xsl:otherwise>
142 <xsl:choose>
143 <xsl:when test="contains($sub-url,'?')">
144 <xsl:value-of select="substring-before($sub-url,'?')"/>
145 </xsl:when>
146 <xsl:otherwise>
147 <xsl:value-of select="$sub-url"/>
148 </xsl:otherwise>
149 </xsl:choose>
150 </xsl:otherwise>
151 </xsl:choose>
152 </xsl:template>
153
[642722f]154 <!-- Generates the code to download a package, an additional package or
155 a patch. -->
156 <xsl:template name="download-file">
157 <xsl:param name="httpurl" select="''"/>
158 <xsl:param name="ftpurl" select="''"/>
159 <xsl:param name="md5" select="''"/>
160 <xsl:param name="varname" select="''"/>
161 <xsl:variable name="package">
162 <xsl:call-template name="package_name">
163 <xsl:with-param name="url">
[e576789]164 <xsl:choose>
[642722f]165 <xsl:when test="string-length($httpurl) &gt; 10">
166 <xsl:value-of select="$httpurl"/>
[e576789]167 </xsl:when>
168 <xsl:otherwise>
[642722f]169 <xsl:value-of select="$ftpurl"/>
[e576789]170 </xsl:otherwise>
171 </xsl:choose>
[642722f]172 </xsl:with-param>
173 </xsl:call-template>
174 </xsl:variable>
175 <xsl:variable name="first_letter"
176 select="translate(substring($package,1,1),
177 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
178 'abcdefghijklmnopqrstuvwxyz')"/>
179 <xsl:text>&#xA;</xsl:text>
180 <xsl:value-of select="$varname"/>
181 <xsl:text>=</xsl:text>
182 <xsl:value-of select="$package"/>
183 <xsl:text>&#xA;if [[ ! -f $</xsl:text>
184 <xsl:value-of select="$varname"/>
185 <xsl:text> ]] ; then&#xA;</xsl:text>
186 <!-- SRC_ARCHIVE may have subdirectories or not -->
187 <xsl:text> if [[ -f $SRC_ARCHIVE/$PKG_DIR/$</xsl:text>
188 <xsl:value-of select="$varname"/>
189 <xsl:text> ]] ; then&#xA;</xsl:text>
190 <xsl:text> cp $SRC_ARCHIVE/$PKG_DIR/$</xsl:text>
191 <xsl:value-of select="$varname"/>
192 <xsl:text> $</xsl:text>
193 <xsl:value-of select="$varname"/>
194 <xsl:text>&#xA;</xsl:text>
195 <xsl:text> elif [[ -f $SRC_ARCHIVE/$</xsl:text>
196 <xsl:value-of select="$varname"/>
197 <xsl:text> ]] ; then&#xA;</xsl:text>
198 <xsl:text> cp $SRC_ARCHIVE/$</xsl:text>
199 <xsl:value-of select="$varname"/>
200 <xsl:text> $</xsl:text>
201 <xsl:value-of select="$varname"/>
202 <xsl:text>&#xA; else&#xA;</xsl:text>
203 <!-- The FTP_SERVER mirror -->
204 <xsl:text> wget -T 30 -t 5 ${FTP_SERVER}svn/</xsl:text>
205 <xsl:value-of select="$first_letter"/>
206 <xsl:text>/$</xsl:text>
207 <xsl:value-of select="$varname"/>
208 <xsl:if test="string-length($httpurl) &gt; 10">
209 <xsl:text> ||
210 wget -T 30 -t 5 </xsl:text>
211 <xsl:value-of select="$httpurl"/>
212 </xsl:if>
213 <xsl:if test="string-length($ftpurl) &gt; 10">
214 <xsl:text> ||
215 wget -T 30 -t 5 </xsl:text>
216 <xsl:value-of select="$ftpurl"/>
217 </xsl:if>
218 <xsl:text>
219 cp $</xsl:text>
220 <xsl:value-of select="$varname"/>
221 <xsl:text> $SRC_ARCHIVE
[e576789]222 fi
223fi
224</xsl:text>
[642722f]225 <xsl:if test="string-length($md5) &gt; 10">
226 <xsl:text>echo "</xsl:text>
227 <xsl:value-of select="$md5"/>
228 <xsl:text>&#x20;&#x20;$</xsl:text>
229 <xsl:value-of select="$varname"/>
230 <xsl:text>" | md5sum -c -
[e576789]231</xsl:text>
[642722f]232 </xsl:if>
233 </xsl:template>
234
235 <!-- Extract the MD5 sum information -->
236 <xsl:template match="para" mode="md5">
237 <xsl:choose>
238 <xsl:when test="contains(substring-after(string(),'sum: '),'&#xA;')">
239 <xsl:value-of select="substring-before(substring-after(string(),'sum: '),'&#xA;')"/>
[e576789]240 </xsl:when>
[642722f]241 <xsl:otherwise>
242 <xsl:value-of select="substring-after(string(),'sum: ')"/>
243 </xsl:otherwise>
[e576789]244 </xsl:choose>
245 </xsl:template>
246
[642722f]247 <!-- We have several templates itemizedlist, depending on whether we
248 expect the package information, or additional package(s) or patch(es)
249 information. Select the appropriate mode here. -->
250 <xsl:template match="bridgehead">
[e576789]251 <xsl:choose>
[642722f]252 <!-- Special case for Openjdk -->
253 <xsl:when test="contains(string(),'Source Package Information')">
254 <xsl:apply-templates
255 select="following-sibling::itemizedlist[1]//simplelist">
256 <xsl:with-param name="varname" select="'PACKAGE'"/>
257 </xsl:apply-templates>
258 <xsl:apply-templates select="following-sibling::itemizedlist
259 [preceding-sibling::bridgehead[1]=current()
260 and position() &gt;1]//simplelist">
261 <xsl:with-param name="varname" select="'PACKAGE1'"/>
262 </xsl:apply-templates>
[e576789]263 </xsl:when>
[642722f]264 <!-- Package information -->
265 <xsl:when test="contains(string(),'Package Information')">
266 <xsl:apply-templates select="following-sibling::itemizedlist
267 [preceding-sibling::bridgehead[1]=current()]"
268 mode="package"/>
[e576789]269 </xsl:when>
[642722f]270 <!-- Additional package information -->
[ba57e61]271 <!-- special case for llvm -->
272 <xsl:when test="contains(string(),'Optional Download')">
273 <xsl:apply-templates select="following-sibling::itemizedlist"
274 mode="additional"/>
275 </xsl:when>
276 <!-- All other additional packages have "Additional" -->
[642722f]277 <xsl:when test="contains(string(),'Additional')">
278 <xsl:apply-templates select="following-sibling::itemizedlist"
279 mode="additional"/>
[e576789]280 </xsl:when>
[642722f]281 <!-- Do not do anything if the dev has created another type of
282 bridgehead. -->
283 <xsl:otherwise/>
[e576789]284 </xsl:choose>
285 </xsl:template>
286
[642722f]287 <!-- Call the download code template with appropriate parameters -->
288 <xsl:template match="itemizedlist" mode="package">
289 <xsl:call-template name="download-file">
290 <xsl:with-param name="httpurl">
291 <xsl:value-of select="./listitem[1]/para/ulink/@url"/>
292 </xsl:with-param>
293 <xsl:with-param name="ftpurl">
294 <xsl:value-of select="./listitem/para[contains(string(),'FTP')]/ulink/@url"/>
295 </xsl:with-param>
296 <xsl:with-param name="md5">
297 <xsl:apply-templates select="./listitem/para[contains(string(),'MD5')]"
298 mode="md5"/>
299 </xsl:with-param>
300 <xsl:with-param name="varname" select="'PACKAGE'"/>
301 </xsl:call-template>
[e576789]302 </xsl:template>
303
[642722f]304 <xsl:template match="itemizedlist" mode="additional">
305 <!-- The normal layout is "one listitem"<->"one url", but some devs
306 find amusing to have FTP and/or MD5sum listitems, or to
307 enclose the download information inside a simplelist tag... -->
308 <xsl:for-each select="listitem[.//ulink]">
309 <xsl:choose>
310 <!-- hopefully, there was a HTTP line before -->
311 <xsl:when test="contains(string(./para),'FTP')"/>
312 <xsl:when test=".//simplelist">
313 <xsl:apply-templates select=".//simplelist">
314 <xsl:with-param name="varname" select="'PACKAGE1'"/>
315 </xsl:apply-templates>
316 </xsl:when>
317 <xsl:otherwise>
318 <xsl:call-template name="download-file">
319 <xsl:with-param name="httpurl">
320 <xsl:value-of select="./para/ulink/@url"/>
321 </xsl:with-param>
322 <xsl:with-param name="ftpurl">
323 <xsl:value-of
324 select="following-sibling::listitem[1]/
325 para[contains(string(),'FTP')]/ulink/@url"/>
326 </xsl:with-param>
327 <xsl:with-param name="md5">
328 <xsl:apply-templates
329 select="following-sibling::listitem[position()&lt;3]/
330 para[contains(string(),'MD5')]"
331 mode="md5"/>
332 </xsl:with-param>
333 <xsl:with-param name="varname">
334 <xsl:choose>
335 <xsl:when test="contains(./para/ulink/@url,'.patch')">
336 <xsl:text>PATCH</xsl:text>
337 </xsl:when>
338 <xsl:otherwise>
339 <xsl:text>PACKAGE1</xsl:text>
340 </xsl:otherwise>
341 </xsl:choose>
342 </xsl:with-param>
343 </xsl:call-template>
344 </xsl:otherwise>
345 </xsl:choose>
346 </xsl:for-each>
[e576789]347 </xsl:template>
348
[642722f]349 <!-- the simplelist case. Hopefully, the layout is one member for
350 url, one for md5 and others for various information, that we do not
351 use -->
352 <xsl:template match="simplelist">
353 <xsl:param name="varname" select="'PACKAGE1'"/>
354 <xsl:call-template name="download-file">
355 <xsl:with-param name="httpurl" select=".//ulink/@url"/>
356 <xsl:with-param name="md5">
357 <xsl:value-of select="substring-after(member[contains(string(),'MD5')],'sum: ')"/>
358 </xsl:with-param>
359 <xsl:with-param name="varname" select="$varname"/>
360 </xsl:call-template>
361 </xsl:template>
[e576789]362<!--======================== Commands code ==========================-->
363
364 <xsl:template match="screen">
365 <xsl:if test="child::* = userinput and not(@role = 'nodump')">
366 <xsl:choose>
367 <xsl:when test="@role = 'root'">
368 <xsl:if test="$sudo = 'y'">
369 <xsl:text>sudo -E sh &lt;&lt; ROOT_EOF&#xA;</xsl:text>
370 </xsl:if>
371 <xsl:apply-templates mode="root"/>
372 <xsl:if test="$sudo = 'y'">
373 <xsl:text>&#xA;ROOT_EOF</xsl:text>
374 </xsl:if>
375 </xsl:when>
376 <xsl:otherwise>
377 <xsl:apply-templates select="userinput"/>
378 </xsl:otherwise>
379 </xsl:choose>
380 <xsl:text>&#xA;</xsl:text>
381 </xsl:if>
382 </xsl:template>
383
384 <xsl:template match="screen" mode="config">
385 <xsl:if test="preceding-sibling::para[1]/xref[@linkend='bootscripts']">
386 <xsl:text>[[ ! -d $SRC_DIR/blfs-bootscripts ]] &amp;&amp; mkdir $SRC_DIR/blfs-bootscripts
387pushd $SRC_DIR/blfs-bootscripts
388URL=</xsl:text>
389 <xsl:value-of select="id('bootscripts')//itemizedlist//ulink/@url"/><xsl:text>
390BOOTPACKG=$(basename $URL)
[bbcdeab]391if [[ ! -f $BOOTPACKG ]] ; then
392 if [[ -f $SRC_ARCHIVE/$PKG_DIR/$BOOTPACKG ]] ; then
393 cp $SRC_ARCHIVE/$PKG_DIR/$BOOTPACKG $BOOTPACKG
394 elif [[ -f $SRC_ARCHIVE/$BOOTPACKG ]] ; then
395 cp $SRC_ARCHIVE/$BOOTPACKG $BOOTPACKG
396 else
397 wget -T 30 -t 5 $URL
398 cp $BOOTPACKG $SRC_ARCHIVE
399 fi
400 rm -f unpacked
401fi
402
[e576789]403if [[ -e unpacked ]] ; then
[f079f8f]404 BOOTUNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
405 if ! [[ -d $BOOTUNPACKDIR ]]; then
[e576789]406 rm unpacked
407 tar -xvf $BOOTPACKG > unpacked
[f079f8f]408 BOOTUNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
[e576789]409 fi
410else
411 tar -xvf $BOOTPACKG > unpacked
[f079f8f]412 BOOTUNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
[e576789]413fi
[f079f8f]414cd $BOOTUNPACKDIR
[e576789]415</xsl:text>
416 </xsl:if>
417 <xsl:apply-templates select='.'/>
418 <xsl:if test="preceding-sibling::para[1]/xref[@linkend='bootscripts']">
419 <xsl:text>
420popd</xsl:text>
421 </xsl:if>
422 <xsl:text>&#xA;</xsl:text>
423 </xsl:template>
424
425 <xsl:template match="para/command">
[a743e57]426 <xsl:variable name="ns" select="normalize-space(string())"/>
427 <xsl:if test="(contains($ns,'test') or
428 contains($ns,'check'))">
[e576789]429 <xsl:text>#</xsl:text>
[a743e57]430 <xsl:value-of select="substring-before($ns,'make ')"/>
[9c5ea2f]431 <xsl:text>make </xsl:text>
[a743e57]432 <xsl:if test="not(contains($ns,'-k'))">
[9c5ea2f]433 <xsl:text>-k </xsl:text>
434 </xsl:if>
[a743e57]435 <xsl:value-of select="substring-after($ns,'make ')"/>
[e576789]436 <xsl:text> || true&#xA;</xsl:text>
437 </xsl:if>
438 </xsl:template>
439
440 <xsl:template match="userinput">
441 <xsl:apply-templates/>
442 </xsl:template>
443
444 <xsl:template match="text()" mode="root">
445 <xsl:call-template name="output-root">
446 <xsl:with-param name="out-string" select="string()"/>
447 </xsl:call-template>
448 </xsl:template>
449
450 <xsl:template name="output-root">
451 <xsl:param name="out-string" select="''"/>
452 <xsl:choose>
[9c5ea2f]453 <xsl:when test="contains($out-string,'make ')">
[e576789]454 <xsl:call-template name="output-root">
455 <xsl:with-param name="out-string"
[9c5ea2f]456 select="substring-before($out-string,'make ')"/>
[e576789]457 </xsl:call-template>
[9c5ea2f]458 <xsl:text>make -j1 </xsl:text>
[e576789]459 <xsl:call-template name="output-root">
460 <xsl:with-param name="out-string"
[9c5ea2f]461 select="substring-after($out-string,'make ')"/>
[e576789]462 </xsl:call-template>
463 </xsl:when>
464 <xsl:when test="contains($out-string,'$') and $sudo = 'y'">
465 <xsl:call-template name="output-root">
466 <xsl:with-param name="out-string"
467 select="substring-before($out-string,'$')"/>
468 </xsl:call-template>
469 <xsl:text>\$</xsl:text>
470 <xsl:call-template name="output-root">
471 <xsl:with-param name="out-string"
472 select="substring-after($out-string,'$')"/>
473 </xsl:call-template>
474 </xsl:when>
475 <xsl:when test="contains($out-string,'`') and $sudo = 'y'">
476 <xsl:call-template name="output-root">
477 <xsl:with-param name="out-string"
478 select="substring-before($out-string,'`')"/>
479 </xsl:call-template>
480 <xsl:text>\`</xsl:text>
481 <xsl:call-template name="output-root">
482 <xsl:with-param name="out-string"
483 select="substring-after($out-string,'`')"/>
484 </xsl:call-template>
485 </xsl:when>
486 <xsl:when test="contains($out-string,'\') and $sudo = 'y'">
487 <xsl:call-template name="output-root">
488 <xsl:with-param name="out-string"
489 select="substring-before($out-string,'\')"/>
490 </xsl:call-template>
491 <xsl:text>\\</xsl:text>
492 <xsl:call-template name="output-root">
493 <xsl:with-param name="out-string"
494 select="substring-after($out-string,'\')"/>
495 </xsl:call-template>
496 </xsl:when>
497 <xsl:otherwise>
498 <xsl:value-of select="$out-string"/>
499 </xsl:otherwise>
500 </xsl:choose>
501 </xsl:template>
502
503 <xsl:template match="replaceable">
504 <xsl:text>**EDITME</xsl:text>
505 <xsl:apply-templates/>
506 <xsl:text>EDITME**</xsl:text>
507 </xsl:template>
508
509 <xsl:template match="replaceable" mode="root">
510 <xsl:text>**EDITME</xsl:text>
511 <xsl:apply-templates/>
512 <xsl:text>EDITME**</xsl:text>
513 </xsl:template>
514
515</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.