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 |
|
---|
23 | BLFS_XML=$1
|
---|
24 | if ! test -f ${BLFS_XML}; then
|
---|
25 | echo File \`${BLFS_XML}\' does not exist
|
---|
26 | exit 1
|
---|
27 | fi
|
---|
28 | SPECIAL_FILE=$2
|
---|
29 | if test -z "${SPECIAL_FILE}"; then SPECIAL_FILE=specialCases.xsl;fi
|
---|
30 | BLFS_DIR=$3
|
---|
31 | if test -z "${BLFS_DIR}"; then BLFS_DIR=$(cd $(dirname ${BLFS_XML})/.. ; pwd);fi
|
---|
32 |
|
---|
33 | # Packages whose version does not begin with a number
|
---|
34 | EXCEPTIONS=$(grep 'ENTITY.*version[ ]*"[^0-9"&.].*[0-9]' $BLFS_XML |
|
---|
35 | sed 's@^[^"]*"\([^"]*\)".*@\1@')
|
---|
36 |
|
---|
37 | # Set PATH to be sure to find udevadm
|
---|
38 | SAVPATH=$PATH
|
---|
39 | PATH=/bin:/sbin:/usr/bin:/usr/sbin
|
---|
40 | UDEVVERSION=$(udevadm --version)
|
---|
41 |
|
---|
42 | cat >$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>
 </xsl:text>
|
---|
53 | <xsl:element name="name"><xsl:value-of select="@id"/></xsl:element>
|
---|
54 | <xsl:text>
 </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>
 </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>
 </xsl:text>
|
---|
72 | </package><xsl:text>
</xsl:text>
|
---|
73 | </xsl:when>
|
---|
74 | <!-- Although versioned, this page is not a package -->
|
---|
75 | <xsl:when test="@id='xorg7'"/>
|
---|
76 | EOF
|
---|
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
|
---|
82 | cat >tmpfile << EOF
|
---|
83 | <xsl:template name="expand-deps">
|
---|
84 | <xsl:param name="section"/>
|
---|
85 | <xsl:param name="status"/>
|
---|
86 | <xsl:choose>
|
---|
87 | EOF
|
---|
88 | for 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>
 </xsl:text>
|
---|
94 | <xsl:element name="name">$id</xsl:element>
|
---|
95 | <xsl:text>
 </xsl:text>
|
---|
96 | EOF
|
---|
97 | cat >> tmpfile << EOF
|
---|
98 | <xsl:when test="\$section='$id'">
|
---|
99 | EOF
|
---|
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>
 </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 -->
|
---|
122 | EOF
|
---|
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>
|
---|
130 | EOF
|
---|
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"/>
|
---|
137 | EOF
|
---|
138 | fi
|
---|
139 | cat >>$SPECIAL_FILE << EOF
|
---|
140 | <!-- End dependencies -->
|
---|
141 | </module>
|
---|
142 | EOF
|
---|
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>
|
---|
151 | EOF
|
---|
152 | precpack=$packname
|
---|
153 | done
|
---|
154 | cat >>$SPECIAL_FILE << EOF
|
---|
155 | </package>
|
---|
156 | </xsl:when>
|
---|
157 | EOF
|
---|
158 | cat >> tmpfile << EOF
|
---|
159 | </xsl:when>
|
---|
160 | EOF
|
---|
161 | done
|
---|
162 |
|
---|
163 | for 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>
 </xsl:text>
|
---|
170 | <xsl:element name="name">$id</xsl:element>
|
---|
171 | <xsl:text>
 </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>
 </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>
 </xsl:text>
|
---|
189 | </package><xsl:text>
</xsl:text>
|
---|
190 | </xsl:when>
|
---|
191 | EOF
|
---|
192 | done
|
---|
193 |
|
---|
194 | cat >>$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>
|
---|
206 | EOF
|
---|
207 | cat $SPECIAL_FILE tmpfile > tmpfile1
|
---|
208 | mv tmpfile1 $SPECIAL_FILE
|
---|
209 | rm tmpfile
|
---|
210 | cat >> $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>
|
---|
219 | EOF
|
---|