source: BLFS/xsl/scripts.xsl@ d8add36

ablfs
Last change on this file since d8add36 was 5e9076f, checked in by Pierre Labastie <pierre@…>, 13 years ago

Add sudo to generation of rm-rf when cleanning the build tree
because some files may be ownded by root (python2 e.g.)

  • Property mode set to 100644
File size: 18.0 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'] and not(@id = 'xorg7-app' or
60 @id = 'xorg7-data' or @id = 'xorg7-driver' or
61 @id = 'xorg7-font' or @id = 'xorg7-lib' or
62 @id = 'xorg7-proto' or @id = 'xorg7-util')">
63 <!-- Variables -->
64 <!-- These three lines could be important if SRC_ARCHIVE,
65 FTP_SERVER and SRCDIR were not set in the environment.
66 But they are not tested for length or anything later,
67 so not needed
68 <xsl:text>SRC_ARCHIVE=$SRC_ARCHIVE&#xA;</xsl:text>
69 <xsl:text>FTP_SERVER=$FTP_SERVER&#xA;</xsl:text>
70 <xsl:text>SRC_DIR=$SRC_DIR&#xA;&#xA;</xsl:text>-->
71 <xsl:text>&#xA;PKG_DIR=</xsl:text>
72 <xsl:value-of select="$filename"/>
73 <xsl:text>&#xA;</xsl:text>
74 <!-- Download code and build commands -->
75 <xsl:apply-templates select="sect2"/>
76 <!-- Clean-up -->
77 <!-- xorg7-server used to require mesalib tree being present.
78 That is no more true
79 <xsl:if test="not(@id='mesalib')"> -->
80 <xsl:text>cd $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
81 <!-- In some case, some files in the build tree are owned
82 by root -->
83 <xsl:if test="$sudo='y'">
84 <xsl:text>sudo </xsl:text>
85 </xsl:if>
86 <xsl:text>rm -rf $UNPACKDIR unpacked&#xA;&#xA;</xsl:text>
87 <!-- Same reason as preceding comment
88 </xsl:if>
89 <xsl:if test="@id='xorg7-server'">
90 <xsl:text>cd $SRC_DIR/MesaLib
91UNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
92rm -rf $UNPACKDIR unpacked&#xA;&#xA;</xsl:text>
93 </xsl:if> -->
94 </xsl:when>
95 <!-- Xorg7 pseudo-packages -->
96 <xsl:when test="contains(@id,'xorg7') and not(@id = 'xorg7-server')">
97 <xsl:text># Useless SRC_DIR=$SRC_DIR
98
99cd $SRC_DIR
100mkdir -p xc
101cd xc&#xA;</xsl:text>
102 <xsl:apply-templates select="sect2" mode="xorg7"/>
103 </xsl:when>
104 <!-- Non-package page -->
105 <xsl:otherwise>
106 <xsl:apply-templates select=".//screen"/>
107 </xsl:otherwise>
108 </xsl:choose>
109 <xsl:text>exit</xsl:text>
110 </exsl:document>
111 </xsl:if>
112 </xsl:template>
113
114<!--======================= Sub-sections code =======================-->
115
116 <xsl:template match="sect2">
117 <xsl:choose>
118 <xsl:when test="@role = 'package'">
119 <xsl:text>mkdir -p $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
120 <xsl:text>cd $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
121 <xsl:apply-templates select="bridgehead[@renderas='sect3']"/>
122 <xsl:text>&#xA;</xsl:text>
123 </xsl:when>
124 <xsl:when test="@role = 'installation'">
125 <xsl:text>
126if [[ -e unpacked ]] ; then
127 UNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
128 [[ -n $UNPACKDIR ]] &amp;&amp; [[ -d $UNPACKDIR ]] &amp;&amp; rm -rf $UNPACKDIR
129fi
130tar -xvf $PACKAGE > unpacked
131UNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
132cd $UNPACKDIR&#xA;</xsl:text>
133 <xsl:apply-templates select=".//screen | .//para/command"/>
134 <xsl:if test="$sudo = 'y'">
135 <xsl:text>sudo /sbin/</xsl:text>
136 </xsl:if>
137 <xsl:text>ldconfig&#xA;&#xA;</xsl:text>
138 </xsl:when>
139 <xsl:when test="@role = 'configuration'">
140 <xsl:apply-templates select=".//screen" mode="config"/>
141 </xsl:when>
142 </xsl:choose>
143 </xsl:template>
144
145 <xsl:template match="sect2" mode="xorg7">
146 <xsl:choose>
147 <xsl:when test="@role = 'package'">
148 <xsl:apply-templates select="itemizedlist/listitem/para" mode="xorg7"/>
149 </xsl:when>
150 <xsl:when test="not(@role)">
151<!-- Useless <xsl:text>SRC_ARCHIVE=$SRC_ARCHIVE
152FTP_SERVER=$FTP_SERVER&#xA;</xsl:text> -->
153 <xsl:apply-templates select=".//screen" mode="sect-ver"/>
154 <xsl:text>mkdir -p ${section}&#xA;cd ${section}&#xA;</xsl:text>
155 <xsl:apply-templates select="../sect2[@role='package']/itemizedlist/listitem/para" mode="xorg7-patch"/>
156 <xsl:text>for line in $(grep -v '^#' ../${sect_ver}.wget) ; do
157 if [[ ! -f ${line} ]] ; then
158 if [[ -f $SRC_ARCHIVE/Xorg/${section}/${line} ]] ; then
159 cp $SRC_ARCHIVE/Xorg/${section}/${line} ${line}
160 elif [[ -f $SRC_ARCHIVE/Xorg/${line} ]] ; then
161 cp $SRC_ARCHIVE/Xorg/${line} ${line}
162 elif [[ -f $SRC_ARCHIVE/${section}/${line} ]] ; then
163 cp $SRC_ARCHIVE/${section}/${line} ${line}
164 elif [[ -f $SRC_ARCHIVE/${line} ]] ; then
165 cp $SRC_ARCHIVE/${line} ${line}
166 else
167 wget -T 30 -t 5 ${FTP_X_SERVER}pub/individual/${section}/${line} || \
168 wget -T 30 -t 5 http://xorg.freedesktop.org/releases/individual/${section}/${line}
169 fi
170 fi
171done
172md5sum -c ../${sect_ver}.md5
173cp ../${sect_ver}.wget ../${sect_ver}.wget.orig
174cp ../${sect_ver}.md5 ../${sect_ver}.md5.orig&#xA;</xsl:text>
175 </xsl:when>
176 <xsl:when test="@role = 'installation'">
177 <xsl:text>for package in $(grep -v '^#' ../${sect_ver}.wget) ; do
178 packagedir=$(echo $package | sed 's/.tar.bz2//')
179 tar -xf ${package}
180 cd ${packagedir}&#xA;</xsl:text>
181 <xsl:apply-templates select=".//screen | .//para/command"/>
182 <xsl:text> cd ..
183 rm -rf ${packagedir}
184 sed -i "/${package}/d" ../${sect_ver}.wget
185 sed -i "/${package}/d" ../${sect_ver}.md5
186done
187mv ../${sect_ver}.wget.orig ../${sect_ver}.wget
188mv ../${sect_ver}.md5.orig ../${sect_ver}.md5&#xA;</xsl:text>
189 <xsl:if test="$sudo = 'y'">
190 <xsl:text>sudo /sbin/</xsl:text>
191 </xsl:if>
192 <xsl:text>ldconfig&#xA;&#xA;</xsl:text>
193 </xsl:when>
194 <xsl:when test="@role = 'configuration'">
195 <xsl:apply-templates select=".//screen"/>
196 <xsl:text>&#xA;</xsl:text>
197 </xsl:when>
198 </xsl:choose>
199 </xsl:template>
200
201<!--==================== Download code =======================-->
202
203 <xsl:template name="package_name">
204 <xsl:param name="url" select="foo"/>
205 <xsl:param name="sub-url" select="substring-after($url,'/')"/>
206 <xsl:choose>
207 <xsl:when test="contains($sub-url,'/')">
208 <xsl:call-template name="package_name">
209 <xsl:with-param name="url" select="$sub-url"/>
210 </xsl:call-template>
211 </xsl:when>
212 <xsl:otherwise>
213 <xsl:choose>
214 <xsl:when test="contains($sub-url,'?')">
215 <xsl:value-of select="substring-before($sub-url,'?')"/>
216 </xsl:when>
217<!-- Should never happen
218 <xsl:when test="contains($sub-url,'.patch')"/> -->
219 <xsl:otherwise>
220 <xsl:value-of select="$sub-url"/>
221 </xsl:otherwise>
222 </xsl:choose>
223 </xsl:otherwise>
224 </xsl:choose>
225 </xsl:template>
226
227 <xsl:template match="bridgehead">
228 <xsl:choose>
229 <xsl:when test="string()='Package Information'">
230 <xsl:variable name="url">
231 <xsl:choose>
232 <xsl:when
233 test="string-length(
234 following-sibling::itemizedlist[1]/listitem[1]/para/ulink/@url)
235 &gt; 10">
236 <xsl:value-of select=
237 "following-sibling::itemizedlist[1]/listitem[1]/para/ulink/@url"/>
238 </xsl:when>
239 <xsl:otherwise>
240 <xsl:value-of select=
241 "following-sibling::itemizedlist[1]/listitem[2]/para/ulink/@url"/>
242 </xsl:otherwise>
243 </xsl:choose>
244 </xsl:variable>
245 <xsl:variable name="package">
246 <xsl:call-template name="package_name">
247 <xsl:with-param name="url" select="$url"/>
248 </xsl:call-template>
249 </xsl:variable>
250 <xsl:variable
251 name="first_letter"
252 select="translate(substring($package,1,1),
253 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
254 'abcdefghijklmnopqrstuvwxyz')"/>
255 <xsl:text>PACKAGE=</xsl:text>
256 <xsl:value-of select="$package"/>
257 <xsl:text>&#xA;if [[ ! -f $PACKAGE ]] ; then&#xA;</xsl:text>
258 <!-- SRC_ARCHIVE may have subdirectories or not -->
259 <xsl:text> if [[ -f $SRC_ARCHIVE/$PKG_DIR/$PACKAGE ]] ; then&#xA;</xsl:text>
260 <xsl:text> cp $SRC_ARCHIVE/$PKG_DIR/$PACKAGE $PACKAGE&#xA;</xsl:text>
261 <xsl:text> elif [[ -f $SRC_ARCHIVE/$PACKAGE ]] ; then&#xA;</xsl:text>
262 <xsl:text> cp $SRC_ARCHIVE/$PACKAGE $PACKAGE&#xA; else&#xA;</xsl:text>
263 <!-- The FTP_SERVER mirror -->
264 <xsl:text> wget -T 30 -t 5 ${FTP_SERVER}svn/</xsl:text>
265 <xsl:value-of select="$first_letter"/>
266 <xsl:text>/$PACKAGE</xsl:text>
267 <xsl:apply-templates
268 select="following-sibling::itemizedlist[1]/listitem/para"
269 mode="package"/>
270 </xsl:when>
271 <xsl:when test="string()='Additional Downloads'">
272 <xsl:apply-templates
273 select="following-sibling::itemizedlist[1]/listitem/para"
274 mode="additional"/>
275 </xsl:when>
276 <xsl:otherwise/>
277 </xsl:choose>
278 </xsl:template>
279
280 <xsl:template match="para" mode="package">
281 <xsl:choose>
282 <xsl:when test="contains(string(),'HTTP')">
283 <!-- Upstream HTTP URL -->
284 <xsl:if test="string-length(ulink/@url) &gt; '10'">
285 <xsl:text> || \&#xA; wget -T 30 -t 5 </xsl:text>
286 <xsl:choose>
287 <xsl:when test="contains(ulink/@url,'?')">
288 <xsl:value-of select="substring-before(ulink/@url,'?')"/>
289 </xsl:when>
290 <xsl:otherwise>
291 <xsl:value-of select="ulink/@url"/>
292 </xsl:otherwise>
293 </xsl:choose>
294 <xsl:if test="not(contains(string(parent::listitem/following-sibling::listitem[1]/para),'FTP'))">
295 <xsl:text>&#xA; fi&#xA;fi&#xA;</xsl:text>
296 </xsl:if>
297 </xsl:if>
298 </xsl:when>
299 <xsl:when test="contains(string(),'FTP')">
300 <!-- Upstream FTP URL -->
301 <xsl:if test="string-length(ulink/@url) &gt; '10'">
302 <xsl:text> || \&#xA; wget -T 30 -t 5 </xsl:text>
303 <xsl:value-of select="ulink/@url"/>
304 </xsl:if>
305 <xsl:text>&#xA; fi&#xA;fi&#xA;</xsl:text>
306 </xsl:when>
307 <xsl:when test="contains(string(),'MD5')">
308 <xsl:text>echo "</xsl:text>
309 <xsl:value-of select="substring-after(string(),'sum: ')"/>
310 <xsl:text>&#x20;&#x20;$PACKAGE" | md5sum -c -&#xA;</xsl:text>
311 </xsl:when>
312 </xsl:choose>
313 </xsl:template>
314
315 <xsl:template match="para" mode="additional">
316 <xsl:choose>
317 <xsl:when test="contains(string(ulink/@url),'.patch')">
318 <xsl:text>wget -T 30 -t 5 </xsl:text>
319 <xsl:value-of select="ulink/@url"/>
320 <xsl:text>&#xA;</xsl:text>
321 </xsl:when>
322 <xsl:when test="ulink">
323 <xsl:if test="string-length(ulink/@url) &gt; '10'">
324 <xsl:variable name="package">
325 <xsl:call-template name="package_name">
326 <xsl:with-param name="url" select="ulink/@url"/>
327 </xsl:call-template>
328 </xsl:variable>
329 <xsl:variable
330 name="first_letter"
331 select="translate(substring($package,1,1),
332 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
333 'abcdefghijklmnopqrstuvwxyz')"/>
334 <xsl:text>PACKAGE1=</xsl:text>
335 <xsl:value-of select="$package"/>
336 <xsl:text>&#xA;if [[ ! -f $PACKAGE1 ]] ; then&#xA;</xsl:text>
337 <!-- SRC_ARCHIVE may have subdirectories or not -->
338 <xsl:text> if [[ -f $SRC_ARCHIVE/$PKG_DIR/$PACKAGE1 ]] ; then&#xA;</xsl:text>
339 <xsl:text> cp $SRC_ARCHIVE/$PKG_DIR/$PACKAGE1 $PACKAGE1&#xA;</xsl:text>
340 <xsl:text> elif [[ -f $SRC_ARCHIVE/$PACKAGE1 ]] ; then&#xA;</xsl:text>
341 <xsl:text> cp $SRC_ARCHIVE/$PACKAGE1 $PACKAGE1&#xA; else&#xA;</xsl:text>
342 <!-- The FTP_SERVER mirror -->
343 <xsl:text> wget -T 30 -t 5 ${FTP_SERVER}blfs/svn/</xsl:text>
344 <xsl:value-of select="$first_letter"/>
345 <xsl:text>/$PACKAGE1</xsl:text>
346 <xsl:text> || \&#xA; wget -T 30 -t 5 </xsl:text>
347 <xsl:value-of select="ulink/@url"/>
348 <xsl:text>&#xA; fi&#xA;fi&#xA;</xsl:text>
349 </xsl:if>
350 </xsl:when>
351 <xsl:when test="contains(string(),'MD5')">
352 <xsl:text>echo "</xsl:text>
353 <xsl:value-of select="substring-after(string(),'sum: ')"/>
354 <xsl:text>&#x20;&#x20;$PACKAGE1" | md5sum -c -&#xA;</xsl:text>
355 </xsl:when>
356 </xsl:choose>
357 </xsl:template>
358
359 <xsl:template match="itemizedlist/listitem/para" mode="xorg7">
360 <xsl:if test="contains(string(ulink/@url),'.md5') or
361 contains(string(ulink/@url),'.wget')">
362 <xsl:text>wget -T 30 -t 5 </xsl:text>
363 <xsl:value-of select="ulink/@url"/>
364 <xsl:text>&#xA;</xsl:text>
365 </xsl:if>
366 </xsl:template>
367
368 <xsl:template match="itemizedlist/listitem/para" mode="xorg7-patch">
369 <xsl:if test="contains(string(ulink/@url),'.patch')">
370 <xsl:text>wget -T 30 -t 5 </xsl:text>
371 <xsl:value-of select="ulink/@url"/>
372 <xsl:text>&#xA;</xsl:text>
373 </xsl:if>
374 </xsl:template>
375
376<!--======================== Commands code ==========================-->
377
378 <xsl:template match="screen">
379 <xsl:if test="child::* = userinput and not(@role = 'nodump')">
380 <xsl:choose>
381 <xsl:when test="@role = 'root'">
382 <xsl:if test="$sudo = 'y'">
383 <xsl:text>sudo sh -c '</xsl:text>
384 </xsl:if>
385 <xsl:apply-templates select="userinput" mode="root"/>
386 <xsl:if test="$sudo = 'y'">
387 <xsl:text>'</xsl:text>
388 </xsl:if>
389 </xsl:when>
390 <xsl:otherwise>
391 <xsl:apply-templates select="userinput"/>
392 </xsl:otherwise>
393 </xsl:choose>
394 <xsl:text>&#xA;</xsl:text>
395 </xsl:if>
396 </xsl:template>
397
398 <xsl:template match="screen" mode="config">
399 <xsl:if test="preceding-sibling::para[1]/xref[@linkend='bootscripts']">
400 <xsl:text>[[ ! -d $SRC_DIR/blfs-bootscripts ]] &amp;&amp; mkdir $SRC_DIR/blfs-bootscripts
401pushd $SRC_DIR/blfs-bootscripts
402URL=</xsl:text>
403 <xsl:value-of select="id('bootscripts')//itemizedlist//ulink/@url"/><xsl:text>
404BOOTPACKG=$(basename $URL)
405[[ ! -f "$BOOTPACKG" ]] &amp;&amp; { wget -T 30 -t 5 $URL; rm -f unpacked; }
406if [[ -e unpacked ]] ; then
407 UNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
408 if ! [[ -d $UNPACKDIR ]]; then
409 rm unpacked
410 tar -xvf $BOOTPACKG > unpacked
411 UNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
412 fi
413else
414 tar -xvf $BOOTPACKG > unpacked
415 UNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
416fi
417cd $UNPACKDIR
418</xsl:text>
419 </xsl:if>
420 <xsl:apply-templates select='.'/>
421 <xsl:if test="preceding-sibling::para[1]/xref[@linkend='bootscripts']">
422 <xsl:text>
423popd</xsl:text>
424 </xsl:if>
425 <xsl:text>&#xA;</xsl:text>
426 </xsl:template>
427
428 <xsl:template match="screen" mode="sect-ver">
429 <xsl:text>section=</xsl:text>
430 <xsl:value-of select="substring-before(substring-after(string(),'mkdir '),' &amp;')"/>
431 <xsl:text>&#xA;sect_ver=</xsl:text>
432 <xsl:value-of select="substring-before(substring-after(string(),'-c ../'),'.md5')"/>
433 <xsl:text>&#xA;</xsl:text>
434 </xsl:template>
435
436 <xsl:template match="para/command">
437 <xsl:if test="(contains(string(),'test') or
438 contains(string(),'check'))">
439 <xsl:text>#</xsl:text>
440 <xsl:value-of select="substring-before(string(),'make')"/>
441 <xsl:text>make -k</xsl:text>
442 <xsl:value-of select="substring-after(string(),'make')"/>
443 <xsl:text> || true&#xA;</xsl:text>
444 </xsl:if>
445 </xsl:template>
446
447 <xsl:template match="userinput">
448 <xsl:apply-templates/>
449 </xsl:template>
450
451 <xsl:template match="userinput" mode="root">
452 <xsl:for-each select="child::node()">
453 <xsl:choose>
454 <xsl:when test="self::text() and contains(string(),'make')">
455 <xsl:value-of select="substring-before(string(),'make')"/>
456 <xsl:text>make -j1</xsl:text>
457 <xsl:value-of select="substring-after(string(),'make')"/>
458 </xsl:when>
459 <xsl:otherwise>
460 <xsl:apply-templates select="self::node()"/>
461 </xsl:otherwise>
462 </xsl:choose>
463 </xsl:for-each>
464 </xsl:template>
465
466 <xsl:template match="replaceable">
467<!-- Not needed anymore
468 <xsl:choose>
469 <xsl:when test="ancestor::sect1[@id='xorg7-server']">
470 <xsl:text>$SRC_DIR/MesaLib</xsl:text>
471 </xsl:when>
472 <xsl:otherwise> -->
473 <xsl:text>**EDITME</xsl:text>
474 <xsl:apply-templates/>
475 <xsl:text>EDITME**</xsl:text>
476<!-- </xsl:otherwise>
477 </xsl:choose> -->
478 </xsl:template>
479
480</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.