source: BLFS/gen-special.sh@ b9c3497

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

Merge ablfs branch. Normally, jhalfs should not perform differently
for building LFS

  • Property mode set to 100755
File size: 8.3 KB
Line 
1#!/bin/bash
2
3# $Id: gen-special.sh 21 2012-02-16 15:06:19Z labastie $
4
5#-------------------------------------------------------------------------
6# generates an xsl stylesheet containing a template for special
7# cases in the book:
8# - If the version does not begin with a number, it is impossible to know
9# where the package name ends and where the version begins. We therefore
10# use the ENTITY at the beginning of the validated full-xml.
11# - If a package is part of a group of xorg packages (proto, fonts, etc)
12# there is no easy way to extract it from the xml. We use the ENTITY at
13# the top of each file x7*.xml
14# - If a pacakge is versioned but the version is not mentioned in the book
15# (currently only udev), we retrieve the version by other means
16#-------------------------------------------------------------------------
17# Arguments:
18# $1 contains the name of the validated xml book
19# $2 contains the name of the ouput xsl file
20# $3 contains the name of the book sources directory
21#-------------------------------------------------------------------------
22
23BLFS_XML=$1
24if ! test -f ${BLFS_XML}; then
25 echo File \`${BLFS_XML}\' does not exist
26 exit 1
27fi
28SPECIAL_FILE=$2
29if test -z "${SPECIAL_FILE}"; then SPECIAL_FILE=specialCases.xsl;fi
30BLFS_DIR=$3
31if test -z "${BLFS_DIR}"; then BLFS_DIR=$(cd $(dirname ${BLFS_XML})/.. ; pwd);fi
32
33# Packages whose version does not begin with a number
34EXCEPTIONS=$(grep 'ENTITY.*version[ ]*"[^0-9"&.].*[0-9]' $BLFS_XML |
35 sed 's@^[^"]*"\([^"]*\)".*@\1@')
36
37# Set PATH to be sure to find udevadm
38SAVPATH=$PATH
39PATH=/bin:/sbin:/usr/bin:/usr/sbin
40UDEVVERSION=$(udevadm --version)
41
42cat >$SPECIAL_FILE << EOF
43<?xml version="1.0" encoding="ISO-8859-1"?>
44
45<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
46 version="1.0">
47
48<xsl:template match='*' mode="special">
49 <xsl:choose>
50 <xsl:when test="contains(@id,'udev')">
51 <xsl:text> </xsl:text>
52 <package><xsl:text>&#xA; </xsl:text>
53 <xsl:element name="name"><xsl:value-of select="@id"/></xsl:element>
54 <xsl:text>&#xA; </xsl:text>
55 <xsl:element name="version">$UDEVVERSION</xsl:element>
56 <xsl:if
57 test="document(\$installed-packages)//package[name=current()/@id]">
58 <xsl:text>&#xA; </xsl:text>
59 <xsl:element name="inst-version">
60 <xsl:value-of
61 select="document(\$installed-packages
62 )//package[name=current()/@id]/version"/>
63 </xsl:element>
64 </xsl:if>
65<!-- Dependencies -->
66 <xsl:apply-templates select=".//para[@role='required' or
67 @role='recommended' or
68 @role='optional']"
69 mode="dependency"/>
70<!-- End dependencies -->
71 <xsl:text>&#xA; </xsl:text>
72 </package><xsl:text>&#xA;</xsl:text>
73 </xsl:when>
74<!-- Although versioned, this page is not a package -->
75 <xsl:when test="@id='xorg7'"/>
76EOF
77
78# Taking packages inside x7proto etc, as versionned modules.
79# We also write a dependency expansion when a dep is of the form
80# xorg7-something. Since that is another template, we need
81# a temporary file, which we shall concatenate at the end
82cat >tmpfile << EOF
83 <xsl:template name="expand-deps">
84 <xsl:param name="section"/>
85 <xsl:param name="status"/>
86 <xsl:choose>
87EOF
88for file in $(ls ${BLFS_DIR}/x/installing/x7* | grep -v x7driver); do
89 id=$(grep xreflabel $file | sed 's@.*id="\([^"]*\).*@\1@')
90 cat >>$SPECIAL_FILE << EOF
91 <xsl:when test="@id='$id'">
92 <xsl:text> </xsl:text>
93 <package><xsl:text>&#xA; </xsl:text>
94 <xsl:element name="name">$id</xsl:element>
95 <xsl:text>&#xA; </xsl:text>
96EOF
97 cat >> tmpfile << EOF
98 <xsl:when test="\$section='$id'">
99EOF
100# We extract the list of packages for an xorg page from
101# the version part of the .xml file. Seems that
102# the order is not always the same as in the "cat" command.
103# So we have to read that command too, since it may be assumed
104# that the preceding package is a dependency of the following,
105# except the first.
106 list_cat="$(sed -n '/>cat/,/EOF</p' $file | grep -v 'cat\|EOF' |
107 sed 's/^[^ ]*\ *\([^&]*\).*/\1/' | sed 's/-$//')"
108
109# Rationale for the sed below: the following for breaks words at spaces (unless
110# we tweak IFS). So replace spaces with commas in lines so that only newlines
111# are separators.
112 for pack in \
113 $(grep 'ENTITY.*version' $file | sed 's/[ ]\+/,/g'); do
114 packname=$(echo $pack | sed s'@.*ENTITY,\(.*\)-version.*@\1@')
115 packversion=$(echo $pack | sed 's@[^"]*"\([^"]*\).*@\1@')
116 precpack=NONE
117 for i in $list_cat; do
118 if [ "$i" = "$packname" ]; then break; fi
119 precpack=$i
120 done
121
122 cat >>$SPECIAL_FILE << EOF
123 <module><xsl:text>&#xA; </xsl:text>
124 <xsl:element name="name">$packname</xsl:element>
125 <xsl:element name="version">$packversion</xsl:element>
126 <xsl:if test="document(\$installed-packages)//package[name='$packname']">
127 <xsl:element name="inst-version">
128 <xsl:value-of
129 select="document(\$installed-packages
130 )//package[name='$packname']/version"/>
131 </xsl:element>
132 </xsl:if>
133<!-- Dependencies -->
134EOF
135 if test $precpack != NONE; then
136 cat >>$SPECIAL_FILE << EOF
137 <xsl:element name="dependency">
138 <xsl:attribute name="status">required</xsl:attribute>
139 <xsl:attribute name="name">$precpack</xsl:attribute>
140 <xsl:attribute name="type">ref</xsl:attribute>
141 </xsl:element>
142EOF
143 else
144 cat >>$SPECIAL_FILE << EOF
145 <xsl:apply-templates select=".//para[@role='required' or
146 @role='recommended' or
147 @role='optional']"
148 mode="dependency"/>
149EOF
150 fi
151 cat >>$SPECIAL_FILE << EOF
152<!-- End dependencies -->
153 </module>
154EOF
155 cat >> tmpfile << EOF
156 <xsl:element name="dependency">
157 <xsl:attribute name="status">
158 <xsl:value-of select="\$status"/>
159 </xsl:attribute>
160 <xsl:attribute name="name">$packname</xsl:attribute>
161 <xsl:attribute name="type">ref</xsl:attribute>
162 </xsl:element>
163EOF
164 done
165 cat >>$SPECIAL_FILE << EOF
166 </package>
167 </xsl:when>
168EOF
169 cat >> tmpfile << EOF
170 </xsl:when>
171EOF
172done
173
174for ver_ent in $EXCEPTIONS; do
175 id=$(grep 'xreflabel=".*'$ver_ent $BLFS_XML | sed 's@.*id="\([^"]*\)".*@\1@')
176 [[ -z $id ]] && continue
177 cat >>$SPECIAL_FILE << EOF
178 <xsl:when test="@id='$id'">
179 <xsl:text> </xsl:text>
180 <package><xsl:text>&#xA; </xsl:text>
181 <xsl:element name="name">$id</xsl:element>
182 <xsl:text>&#xA; </xsl:text>
183 <xsl:element name="version">$ver_ent</xsl:element>
184 <xsl:if
185 test="document(\$installed-packages)//package[name=current()/@id]">
186 <xsl:text>&#xA; </xsl:text>
187 <xsl:element name="inst-version">
188 <xsl:value-of
189 select="document(\$installed-packages
190 )//package[name=current()/@id]/version"/>
191 </xsl:element>
192 </xsl:if>
193<!-- Dependencies -->
194 <xsl:apply-templates select=".//para[@role='required' or
195 @role='recommended' or
196 @role='optional']"
197 mode="dependency"/>
198<!-- End dependencies -->
199 <xsl:text>&#xA; </xsl:text>
200 </package><xsl:text>&#xA;</xsl:text>
201 </xsl:when>
202EOF
203done
204
205cat >>$SPECIAL_FILE << EOF
206 <xsl:otherwise>
207 <xsl:apply-templates
208 select="self::node()[contains(translate(@xreflabel,
209 '123456789',
210 '000000000'),
211 '-0')
212 ]"
213 mode="normal"/>
214 </xsl:otherwise>
215 </xsl:choose>
216</xsl:template>
217EOF
218cat $SPECIAL_FILE tmpfile > tmpfile1
219mv tmpfile1 $SPECIAL_FILE
220rm tmpfile
221cat >> $SPECIAL_FILE << EOF
222 <xsl:otherwise>
223 <xsl:message>
224 <xsl:text>You should not be seeing this</xsl:text>
225 </xsl:message>
226 </xsl:otherwise>
227 </xsl:choose>
228</xsl:template>
229</xsl:stylesheet>
230EOF
Note: See TracBrowser for help on using the repository browser.