source: BLFS/gen-special.sh@ e86d4cd

ablfs
Last change on this file since e86d4cd was d236bbd, checked in by Pierre Labastie <pierre@…>, 12 years ago

BLFS tools:

  • Separates the groups of xorg package into individual builds
  • Property mode set to 100755
File size: 7.9 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# In the list, the preceding package is a dependency of the following,
101# except the first:
102 precpack=NONE
103# Rationale for the sed below: the following for breaks words at spaces (unless
104# we tweak IFS). So replace spaces with commas in lines so that only newlines
105# are separators.
106 for pack in \
107 $(grep 'ENTITY.*version' $file | sed 's/[ ]\+/,/g'); do
108 packname=$(echo $pack | sed s'@.*ENTITY,\(.*\)-version.*@\1@')
109 packversion=$(echo $pack | sed 's@[^"]*"\([^"]*\).*@\1@')
110 cat >>$SPECIAL_FILE << EOF
111 <module><xsl:text>&#xA; </xsl:text>
112 <xsl:element name="name">$packname</xsl:element>
113 <xsl:element name="version">$packversion</xsl:element>
114 <xsl:if test="document(\$installed-packages)//package[name='$packname']">
115 <xsl:element name="inst-version">
116 <xsl:value-of
117 select="document(\$installed-packages
118 )//package[name='$packname']/version"/>
119 </xsl:element>
120 </xsl:if>
121<!-- Dependencies -->
122EOF
123 if test $precpack != NONE; then
124 cat >>$SPECIAL_FILE << EOF
125 <xsl:element name="dependency">
126 <xsl:attribute name="status">required</xsl:attribute>
127 <xsl:attribute name="name">$precpack</xsl:attribute>
128 <xsl:attribute name="type">ref</xsl:attribute>
129 </xsl:element>
130EOF
131 else
132 cat >>$SPECIAL_FILE << EOF
133 <xsl:apply-templates select=".//para[@role='required' or
134 @role='recommended' or
135 @role='optional']"
136 mode="dependency"/>
137EOF
138 fi
139 cat >>$SPECIAL_FILE << EOF
140<!-- End dependencies -->
141 </module>
142EOF
143 cat >> tmpfile << EOF
144 <xsl:element name="dependency">
145 <xsl:attribute name="status">
146 <xsl:value-of select="\$status"/>
147 </xsl:attribute>
148 <xsl:attribute name="name">$packname</xsl:attribute>
149 <xsl:attribute name="type">ref</xsl:attribute>
150 </xsl:element>
151EOF
152 precpack=$packname
153 done
154 cat >>$SPECIAL_FILE << EOF
155 </package>
156 </xsl:when>
157EOF
158 cat >> tmpfile << EOF
159 </xsl:when>
160EOF
161done
162
163for ver_ent in $EXCEPTIONS; do
164 id=$(grep 'xreflabel=".*'$ver_ent $BLFS_XML | sed 's@.*id="\([^"]*\)".*@\1@')
165 [[ -z $id ]] && continue
166 cat >>$SPECIAL_FILE << EOF
167 <xsl:when test="@id='$id'">
168 <xsl:text> </xsl:text>
169 <package><xsl:text>&#xA; </xsl:text>
170 <xsl:element name="name">$id</xsl:element>
171 <xsl:text>&#xA; </xsl:text>
172 <xsl:element name="version">$ver_ent</xsl:element>
173 <xsl:if
174 test="document(\$installed-packages)//package[name=current()/@id]">
175 <xsl:text>&#xA; </xsl:text>
176 <xsl:element name="inst-version">
177 <xsl:value-of
178 select="document(\$installed-packages
179 )//package[name=current()/@id]/version"/>
180 </xsl:element>
181 </xsl:if>
182<!-- Dependencies -->
183 <xsl:apply-templates select=".//para[@role='required' or
184 @role='recommended' or
185 @role='optional']"
186 mode="dependency"/>
187<!-- End dependencies -->
188 <xsl:text>&#xA; </xsl:text>
189 </package><xsl:text>&#xA;</xsl:text>
190 </xsl:when>
191EOF
192done
193
194cat >>$SPECIAL_FILE << EOF
195 <xsl:otherwise>
196 <xsl:apply-templates
197 select="self::node()[contains(translate(@xreflabel,
198 '123456789',
199 '000000000'),
200 '-0')
201 ]"
202 mode="normal"/>
203 </xsl:otherwise>
204 </xsl:choose>
205</xsl:template>
206EOF
207cat $SPECIAL_FILE tmpfile > tmpfile1
208mv tmpfile1 $SPECIAL_FILE
209rm tmpfile
210cat >> $SPECIAL_FILE << EOF
211 <xsl:otherwise>
212 <xsl:message>
213 <xsl:text>You should not be seeing this</xsl:text>
214 </xsl:message>
215 </xsl:otherwise>
216 </xsl:choose>
217</xsl:template>
218</xsl:stylesheet>
219EOF
Note: See TracBrowser for help on using the repository browser.