source: BLFS/libs/scripts.xsl@ 59f096b

experimental
Last change on this file since 59f096b was 59f096b, checked in by Manuel Canales Esparcia <manuel@…>, 18 years ago

Fixed a build scripts look issue

  • Property mode set to 100644
File size: 13.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$ -->
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 <xsl:if test="@id != 'locale-issues' and
23 (count(descendant::screen/userinput) &gt; 0 and
24 count(descendant::screen/userinput) &gt;
25 count(descendant::screen[@role='nodump']))">
26
27 <!-- The file names -->
28 <xsl:variable name="pi-file" select="processing-instruction('dbhtml')"/>
29 <xsl:variable name="pi-file-value" select="substring-after($pi-file,'filename=')"/>
30 <xsl:variable name="filename" select="substring-before(substring($pi-file-value,2),'.html')"/>
31
32 <!-- Package name (use "Download FTP" by default. If empty, use "Download HTTP" -->
33 <xsl:param name="package">
34 <xsl:choose>
35 <xsl:when
36 test="string-length(sect2[@role='package']/itemizedlist/listitem[2]/para/ulink/@url)
37 &gt; '10'">
38 <xsl:call-template name="package_name">
39 <xsl:with-param name="url"
40 select="sect2[@role='package']/itemizedlist/listitem[2]/para/ulink/@url"/>
41 </xsl:call-template>
42 </xsl:when>
43 <xsl:otherwise>
44 <xsl:call-template name="package_name">
45 <xsl:with-param name="url"
46 select="sect2[@role='package']/itemizedlist/listitem[1]/para/ulink/@url"/>
47 </xsl:call-template>
48 </xsl:otherwise>
49 </xsl:choose>
50 </xsl:param>
51
52 <!-- FTP dir name -->
53 <xsl:param name="ftpdir">
54 <xsl:call-template name="ftp_dir">
55 <xsl:with-param name="package" select="$package"/>
56 </xsl:call-template>
57 </xsl:param>
58
59 <!-- The build order -->
60 <xsl:variable name="position" select="position()"/>
61 <xsl:variable name="order">
62 <xsl:choose>
63 <xsl:when test="string-length($position) = 1">
64 <xsl:text>00</xsl:text>
65 <xsl:value-of select="$position"/>
66 </xsl:when>
67 <xsl:when test="string-length($position) = 2">
68 <xsl:text>0</xsl:text>
69 <xsl:value-of select="$position"/>
70 </xsl:when>
71 <xsl:otherwise>
72 <xsl:value-of select="$position"/>
73 </xsl:otherwise>
74 </xsl:choose>
75 </xsl:variable>
76
77 <!-- Depuration code -->
78 <xsl:message>
79 <xsl:text>SCRIPT is </xsl:text>
80 <xsl:value-of select="concat($order,'-',$filename)"/>
81 <xsl:text>&#xA; PACKAGE is </xsl:text>
82 <xsl:value-of select="$package"/>
83 <xsl:text>&#xA; FTPDIR is </xsl:text>
84 <xsl:value-of select="$ftpdir"/>
85 <xsl:text>&#xA;&#xA;</xsl:text>
86 </xsl:message>
87
88 <!-- Creating the scripts -->
89 <exsl:document href="{$order}-z-{$filename}" method="text">
90 <xsl:text>#!/bin/sh&#xA;set -e&#xA;&#xA;</xsl:text>
91 <xsl:choose>
92 <!-- Package page -->
93 <xsl:when test="sect2[@role='package']">
94 <!-- Variables -->
95 <xsl:text>SRC_ARCHIVE=$SRC_ARCHIVE&#xA;</xsl:text>
96 <xsl:text>FTP_SERVER=$FTP_SERVER&#xA;&#xA;PACKAGE=</xsl:text>
97 <xsl:value-of select="$package"/>
98 <xsl:text>&#xA;PKG_DIR=</xsl:text>
99 <xsl:value-of select="$ftpdir"/>
100 <xsl:text>&#xA;SRC_DIR=$SRC_DIR&#xA;&#xA;</xsl:text>
101 <!-- Download code and build commands -->
102 <xsl:apply-templates select="sect2">
103 <xsl:with-param name="package" select="$package"/>
104 <xsl:with-param name="ftpdir" select="$ftpdir"/>
105 </xsl:apply-templates>
106 <!-- Clean-up -->
107 <xsl:text>cd $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
108 <xsl:text>rm -rf $UNPACKDIR unpacked&#xA;&#xA;</xsl:text>
109 </xsl:when>
110 <!-- Non-package page -->
111 <xsl:otherwise>
112 <xsl:apply-templates select=".//screen"/>
113 </xsl:otherwise>
114 </xsl:choose>
115 <xsl:text>exit</xsl:text>
116 </exsl:document>
117
118 </xsl:if>
119 </xsl:template>
120
121<!--======================= Sub-sections code =======================-->
122
123 <xsl:template match="sect2">
124 <xsl:param name="package" select="foo"/>
125 <xsl:param name="ftpdir" select="foo"/>
126 <xsl:choose>
127 <xsl:when test="@role = 'package'">
128 <xsl:text>mkdir -p $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
129 <xsl:text>cd $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
130 <xsl:apply-templates select="itemizedlist/listitem/para">
131 <xsl:with-param name="package" select="$package"/>
132 <xsl:with-param name="ftpdir" select="$ftpdir"/>
133 </xsl:apply-templates>
134 <xsl:text>&#xA;</xsl:text>
135 </xsl:when>
136 <xsl:when test="@role = 'installation'">
137 <xsl:text>
138if [[ -e unpacked ]] ; then
139 UNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
140 rm -rf $UNPACKDIR
141fi
142tar -xvf $PACKAGE > unpacked
143UNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
144cd $UNPACKDIR&#xA;</xsl:text>
145 <xsl:apply-templates select=".//screen | .//para/command"/>
146 <xsl:if test="$sudo = 'y'">
147 <xsl:text>sudo </xsl:text>
148 </xsl:if>
149 <xsl:text>ldconfig&#xA;&#xA;</xsl:text>
150 </xsl:when>
151 <xsl:when test="@role = 'configuration'">
152 <xsl:apply-templates select=".//screen"/>
153 <xsl:text>&#xA;</xsl:text>
154 </xsl:when>
155 </xsl:choose>
156 </xsl:template>
157
158<!--==================== Download code =======================-->
159
160 <xsl:template name="package_name">
161 <xsl:param name="url" select="foo"/>
162 <xsl:param name="sub-url" select="substring-after($url,'/')"/>
163 <xsl:choose>
164 <xsl:when test="contains($sub-url,'/')">
165 <xsl:call-template name="package_name">
166 <xsl:with-param name="url" select="$sub-url"/>
167 </xsl:call-template>
168 </xsl:when>
169 <xsl:otherwise>
170 <xsl:choose>
171 <xsl:when test="contains($sub-url,'?')">
172 <xsl:value-of select="substring-before($sub-url,'?')"/>
173 </xsl:when>
174 <xsl:when test="contains($sub-url,'.patch')"/>
175 <xsl:otherwise>
176 <xsl:value-of select="$sub-url"/>
177 </xsl:otherwise>
178 </xsl:choose>
179 </xsl:otherwise>
180 </xsl:choose>
181 </xsl:template>
182
183 <xsl:template name="ftp_dir">
184 <xsl:param name="package" select="foo"/>
185 <!-- A lot of hardcoded dir names. Not full revised yet. -->
186 <xsl:choose>
187 <!-- cdparanoia -->
188 <xsl:when test="contains($package, '-III')">
189 <xsl:text>cdparanoia</xsl:text>
190 </xsl:when>
191 <!-- DobBook 3.1 -->
192 <xsl:when test="contains($package, 'docbk31')">
193 <xsl:text>docbk</xsl:text>
194 </xsl:when>
195 <!-- gc -->
196 <xsl:when test="contains($package, 'gc6')">
197 <xsl:text>gc</xsl:text>
198 </xsl:when>
199 <!-- ISO-codes -->
200 <xsl:when test="contains($package, 'iso-codes')">
201 <xsl:text>iso-codes</xsl:text>
202 </xsl:when>
203 <!-- JPEG -->
204 <xsl:when test="contains($package, 'jpegsrc')">
205 <xsl:text>jpeg</xsl:text>
206 </xsl:when>
207 <!-- lynx -->
208 <xsl:when test="contains($package, 'lynx')">
209 <xsl:text>lynx</xsl:text>
210 </xsl:when>
211 <!-- ntp -->
212 <xsl:when test="contains($package, 'ntp')">
213 <xsl:text>ntp</xsl:text>
214 </xsl:when>
215 <!-- OpenLDAP -->
216 <xsl:when test="contains($package, 'openldap')">
217 <xsl:text>openldap</xsl:text>
218 </xsl:when>
219 <!-- Open Office -->
220 <xsl:when test="contains($package, 'OOo')">
221 <xsl:text>OOo</xsl:text>
222 </xsl:when>
223 <!-- pine -->
224 <xsl:when test="contains($package, 'pine')">
225 <xsl:text>pine</xsl:text>
226 </xsl:when>
227 <!-- portmap -->
228 <xsl:when test="contains($package, 'portmap')">
229 <xsl:text>portmap</xsl:text>
230 </xsl:when>
231 <!-- psutils -->
232 <xsl:when test="contains($package, 'psutils')">
233 <xsl:text>psutils</xsl:text>
234 </xsl:when>
235 <!-- qpopper -->
236 <xsl:when test="contains($package, 'qpopper')">
237 <xsl:text>qpopper</xsl:text>
238 </xsl:when>
239 <!-- QT -->
240 <xsl:when test="contains($package, 'qt-x')">
241 <xsl:text>qt-x11-free</xsl:text>
242 </xsl:when>
243 <!-- sendmail -->
244 <xsl:when test="contains($package, 'sendmail')">
245 <xsl:text>sendmail</xsl:text>
246 </xsl:when>
247 <!-- Slib -->
248 <xsl:when test="contains($package, 'slib')">
249 <xsl:text>slib</xsl:text>
250 </xsl:when>
251 <!-- TCL -->
252 <xsl:when test="contains($package, 'tcl')">
253 <xsl:text>tcl</xsl:text>
254 </xsl:when>
255 <!-- tcpwrappers -->
256 <xsl:when test="contains($package, 'tcp_wrappers')">
257 <xsl:text>tcp_wrappers</xsl:text>
258 </xsl:when>
259 <!-- TeTeX -->
260 <xsl:when test="contains($package, 'tetex')">
261 <xsl:text>tetex</xsl:text>
262 </xsl:when>
263 <!-- Tidy -->
264 <xsl:when test="contains($package, 'tidy')">
265 <xsl:text>tidy</xsl:text>
266 </xsl:when>
267 <!-- Tk -->
268 <xsl:when test="contains($package, 'tk8')">
269 <xsl:text>tk</xsl:text>
270 </xsl:when>
271 <!-- unzip -->
272 <xsl:when test="contains($package, 'unzip')">
273 <xsl:text>unzip</xsl:text>
274 </xsl:when>
275 <!-- wireless_tools -->
276 <xsl:when test="contains($package, 'wireless_tools')">
277 <xsl:text>wireless_tools</xsl:text>
278 </xsl:when>
279 <!-- whois -->
280 <xsl:when test="contains($package, 'whois')">
281 <xsl:text>whois</xsl:text>
282 </xsl:when>
283 <!-- XOrg -->
284 <xsl:when test="contains($package, 'X11R6')">
285 <xsl:text>Xorg</xsl:text>
286 </xsl:when>
287 <!-- zip -->
288 <xsl:when test="contains($package, 'zip2')">
289 <xsl:text>zip</xsl:text>
290 </xsl:when>
291 <!-- General rule -->
292 <xsl:otherwise>
293 <xsl:variable name="cut"
294 select="translate(substring-after($package, '-'), '0123456789', '0000000000')"/>
295 <xsl:variable name="package2">
296 <xsl:value-of select="substring-before($package, '-')"/>
297 <xsl:text>-</xsl:text>
298 <xsl:value-of select="$cut"/>
299 </xsl:variable>
300 <xsl:value-of select="substring-before($package2, '-0')"/>
301 </xsl:otherwise>
302 </xsl:choose>
303 </xsl:template>
304
305 <xsl:template match="itemizedlist/listitem/para">
306 <xsl:param name="package" select="foo"/>
307 <xsl:param name="ftpdir" select="foo"/>
308 <xsl:choose>
309 <!-- This depend on all package pages having both "Download HTTP" and "Download FTP" lines -->
310 <xsl:when test="contains(string(),'HTTP')">
311 <xsl:text>if [[ ! -f $PACKAGE ]] ; then&#xA;</xsl:text>
312 <!-- SRC_ARCHIVE may have subdirectories or not -->
313 <xsl:text> if [[ -f $SRC_ARCHIVE/$PKG_DIR/$PACKAGE ]] ; then&#xA;</xsl:text>
314 <xsl:text> cp $SRC_ARCHIVE/$PKG_DIR/$PACKAGE $PACKAGE&#xA;</xsl:text>
315 <xsl:text> elif [[ -f $SRC_ARCHIVE/$PACKAGE ]] ; then&#xA;</xsl:text>
316 <xsl:text> cp $SRC_ARCHIVE/$PACKAGE $PACKAGE&#xA; else&#xA;</xsl:text>
317 <!-- The FTP_SERVER mirror -->
318 <xsl:text> wget ${FTP_SERVER}conglomeration/$PKG_DIR/$PACKAGE</xsl:text>
319 <!-- Upstream HTTP URL -->
320 <xsl:if test="string-length(ulink/@url) &gt; '10' and
321 not(contains(string(ulink/@url),'sourceforge'))">
322 <xsl:text> || \&#xA; wget </xsl:text>
323 <xsl:value-of select="ulink/@url"/>
324 </xsl:if>
325 </xsl:when>
326 <xsl:when test="contains(string(),'FTP')">
327 <!-- Upstream FTP URL -->
328 <xsl:if test="string-length(ulink/@url) &gt; '10'">
329 <xsl:text> || \&#xA; wget </xsl:text>
330 <xsl:value-of select="ulink/@url"/>
331 </xsl:if>
332 <xsl:text>&#xA; fi&#xA;fi&#xA;</xsl:text>
333 </xsl:when>
334 <xsl:when test="contains(string(),'MD5')">
335 <xsl:text>echo "</xsl:text>
336 <xsl:value-of select="substring-after(string(),'sum: ')"/>
337 <xsl:text>&#x20;&#x20;$PACKAGE" | md5sum -c -&#xA;</xsl:text>
338 </xsl:when>
339 <!-- Patches -->
340 <xsl:when test="contains(string(ulink/@url),'.patch')">
341 <xsl:text>wget </xsl:text>
342 <xsl:value-of select="ulink/@url"/>
343 <xsl:text>&#xA;</xsl:text>
344 </xsl:when>
345 </xsl:choose>
346 </xsl:template>
347
348<!--======================== Commands code ==========================-->
349
350 <xsl:template match="screen">
351 <xsl:if test="child::* = userinput and not(@role = 'nodump')">
352 <xsl:if test="@role = 'root' and $sudo = 'y'">
353 <xsl:text>sudo sh -c "</xsl:text>
354 </xsl:if>
355 <xsl:apply-templates select="userinput"/>
356 <xsl:if test="@role = 'root' and $sudo = 'y'">
357 <xsl:text>"</xsl:text>
358 </xsl:if>
359 <xsl:text>&#xA;</xsl:text>
360 </xsl:if>
361 </xsl:template>
362
363 <xsl:template match="para/command">
364 <xsl:if test="(contains(string(),'test') or
365 contains(string(),'check'))">
366 <xsl:text>#</xsl:text>
367 <xsl:value-of select="substring-before(string(),'make')"/>
368 <xsl:text>make -k</xsl:text>
369 <xsl:value-of select="substring-after(string(),'make')"/>
370 <xsl:text> || true&#xA;</xsl:text>
371 </xsl:if>
372 </xsl:template>
373
374 <xsl:template match="userinput">
375 <xsl:apply-templates/>
376 </xsl:template>
377
378 <xsl:template match="replaceable">
379 <xsl:text>**EDITME</xsl:text>
380 <xsl:apply-templates/>
381 <xsl:text>EDITME**</xsl:text>
382 </xsl:template>
383
384</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.