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
RevLine 
[8aba69a]1<?xml version="1.0"?>
[d6be7ea]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
[3d888ef]10<!-- XSLT stylesheet to create shell scripts from "linear build" BLFS books. -->
[d6be7ea]11
[00f4966]12 <!-- Build as user (y) or as root (n)? -->
13 <xsl:param name="sudo" select="y"/>
14
[d6be7ea]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']))">
[3d888ef]26
[d6be7ea]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')"/>
[3d888ef]31
[a4ccd54]32 <!-- Package name (use "Download FTP" by default. If empty, use "Download HTTP" -->
[3d888ef]33 <xsl:param name="package">
[a4ccd54]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>
[3d888ef]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
[d6be7ea]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>
[3d888ef]76
[37ac06a]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
[3d888ef]88 <!-- Creating the scripts -->
[d0d9e90]89 <exsl:document href="{$order}-z-{$filename}" method="text">
[d6be7ea]90 <xsl:text>#!/bin/sh&#xA;set -e&#xA;&#xA;</xsl:text>
[838b61a]91 <xsl:choose>
[d3d90e7]92 <!-- Package page -->
[838b61a]93 <xsl:when test="sect2[@role='package']">
[d3d90e7]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"/>
[2fedf49]100 <xsl:text>&#xA;SRC_DIR=$SRC_DIR&#xA;&#xA;</xsl:text>
[d3d90e7]101 <!-- Download code and build commands -->
[838b61a]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>
[d3d90e7]106 <!-- Clean-up -->
[2fedf49]107 <xsl:text>cd $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
[d0d9e90]108 <xsl:text>rm -rf $UNPACKDIR unpacked&#xA;&#xA;</xsl:text>
[838b61a]109 </xsl:when>
[d3d90e7]110 <!-- Non-package page -->
[838b61a]111 <xsl:otherwise>
112 <xsl:apply-templates select=".//screen"/>
113 </xsl:otherwise>
114 </xsl:choose>
[d6be7ea]115 <xsl:text>exit</xsl:text>
116 </exsl:document>
[3d888ef]117
[d6be7ea]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'">
[2fedf49]128 <xsl:text>mkdir -p $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
129 <xsl:text>cd $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
[d6be7ea]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'">
[d0d9e90]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@/.*@@'`
[59f096b]144cd $UNPACKDIR&#xA;</xsl:text>
[d6be7ea]145 <xsl:apply-templates select=".//screen | .//para/command"/>
[9d158f9]146 <xsl:if test="$sudo = 'y'">
147 <xsl:text>sudo </xsl:text>
148 </xsl:if>
149 <xsl:text>ldconfig&#xA;&#xA;</xsl:text>
[d6be7ea]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
[3d888ef]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>
[07eac51]174 <xsl:when test="contains($sub-url,'.patch')"/>
[3d888ef]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"/>
[edf7e4c]185 <!-- A lot of hardcoded dir names. Not full revised yet. -->
[37ac06a]186 <xsl:choose>
187 <!-- cdparanoia -->
188 <xsl:when test="contains($package, '-III')">
189 <xsl:text>cdparanoia</xsl:text>
[edf7e4c]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>
[37ac06a]218 </xsl:when>
219 <!-- Open Office -->
220 <xsl:when test="contains($package, 'OOo')">
221 <xsl:text>OOo</xsl:text>
222 </xsl:when>
[edf7e4c]223 <!-- pine -->
224 <xsl:when test="contains($package, 'pine')">
225 <xsl:text>pine</xsl:text>
[a4ccd54]226 </xsl:when>
227 <!-- portmap -->
228 <xsl:when test="contains($package, 'portmap')">
229 <xsl:text>portmap</xsl:text>
[edf7e4c]230 </xsl:when>
231 <!-- psutils -->
232 <xsl:when test="contains($package, 'psutils')">
233 <xsl:text>psutils</xsl:text>
[a4ccd54]234 </xsl:when>
235 <!-- qpopper -->
236 <xsl:when test="contains($package, 'qpopper')">
237 <xsl:text>qpopper</xsl:text>
[8aba69a]238 </xsl:when>
239 <!-- QT -->
240 <xsl:when test="contains($package, 'qt-x')">
241 <xsl:text>qt-x11-free</xsl:text>
[edf7e4c]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 -->
[8aba69a]268 <xsl:when test="contains($package, 'tk8')">
[edf7e4c]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>
[37ac06a]282 </xsl:when>
283 <!-- XOrg -->
284 <xsl:when test="contains($package, 'X11R6')">
[edf7e4c]285 <xsl:text>Xorg</xsl:text>
286 </xsl:when>
287 <!-- zip -->
288 <xsl:when test="contains($package, 'zip2')">
289 <xsl:text>zip</xsl:text>
[37ac06a]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>
[3d888ef]303 </xsl:template>
304
[d6be7ea]305 <xsl:template match="itemizedlist/listitem/para">
306 <xsl:param name="package" select="foo"/>
307 <xsl:param name="ftpdir" select="foo"/>
308 <xsl:choose>
[d3d90e7]309 <!-- This depend on all package pages having both "Download HTTP" and "Download FTP" lines -->
[d6be7ea]310 <xsl:when test="contains(string(),'HTTP')">
[d3d90e7]311 <xsl:text>if [[ ! -f $PACKAGE ]] ; then&#xA;</xsl:text>
[6e4e0dd]312 <!-- SRC_ARCHIVE may have subdirectories or not -->
[d3d90e7]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>
[d6be7ea]317 <!-- The FTP_SERVER mirror -->
[d0d9e90]318 <xsl:text> wget ${FTP_SERVER}conglomeration/$PKG_DIR/$PACKAGE</xsl:text>
[d6be7ea]319 <!-- Upstream HTTP URL -->
[40d4ca7]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>
[a4ccd54]323 <xsl:value-of select="ulink/@url"/>
324 </xsl:if>
[d6be7ea]325 </xsl:when>
326 <xsl:when test="contains(string(),'FTP')">
327 <!-- Upstream FTP URL -->
[a4ccd54]328 <xsl:if test="string-length(ulink/@url) &gt; '10'">
[40d4ca7]329 <xsl:text> || \&#xA; wget </xsl:text>
[a4ccd54]330 <xsl:value-of select="ulink/@url"/>
331 </xsl:if>
[40d4ca7]332 <xsl:text>&#xA; fi&#xA;fi&#xA;</xsl:text>
[d6be7ea]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: ')"/>
[d3d90e7]337 <xsl:text>&#x20;&#x20;$PACKAGE" | md5sum -c -&#xA;</xsl:text>
[d6be7ea]338 </xsl:when>
[40d4ca7]339 <!-- Patches -->
[e52ffe5]340 <xsl:when test="contains(string(ulink/@url),'.patch')">
[d6be7ea]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">
[1504208]351 <xsl:if test="child::* = userinput and not(@role = 'nodump')">
[00f4966]352 <xsl:if test="@role = 'root' and $sudo = 'y'">
[1504208]353 <xsl:text>sudo sh -c "</xsl:text>
354 </xsl:if>
355 <xsl:apply-templates select="userinput"/>
[00f4966]356 <xsl:if test="@role = 'root' and $sudo = 'y'">
[1504208]357 <xsl:text>"</xsl:text>
358 </xsl:if>
359 <xsl:text>&#xA;</xsl:text>
[d6be7ea]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
[1504208]374 <xsl:template match="userinput">
[d6be7ea]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.