source: BLFS/xsl/scripts.xsl@ abc8b27

2.4 ablfs-more legacy new_features trunk
Last change on this file since abc8b27 was ba57e61, checked in by Pierre Labastie <pierre@…>, 11 years ago

Add code to download clang in BLFS tools

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