source: BLFS/gen-special.sh@ 83cfe91

trunk
Last change on this file since 83cfe91 was 83cfe91, checked in by Pierre Labastie <pierre.labastie@…>, 3 days ago

fix building xcb-utilities
Fixes ticket #1741

  • Property mode set to 100755
File size: 12.7 KB
Line 
1#!/bin/bash
2
3#-------------------------------------------------------------------------
4# generates an xsl stylesheet containing a template for special
5# cases in the book:
6# - If the version does not begin with a number, it is impossible to know
7# where the package name ends and where the version begins. We therefore
8# use the ENTITY at the beginning of the validated full-xml.
9# - If a package is part of a group of xorg packages (proto, fonts, etc)
10# there is no easy way to extract it from the xml. We use the ENTITY at
11# the top of each file x7*.xml
12# - Some non-versioned packages are needed as dependencies of others: we
13# attribute version 1.0.0 to them. It is just used to know if the package
14# is installed, by checking inst-version.
15# - If a package is versioned but the version is not mentioned in the book
16# (currently only udev), we retrieve the version by other means
17#-------------------------------------------------------------------------
18# Arguments:
19# $1 contains the name of the validated xml book
20# $2 contains the name of the ouput xsl file
21# $3 contains the name of the book sources directory
22#-------------------------------------------------------------------------
23
24BLFS_XML=$1
25if ! test -f ${BLFS_XML}; then
26 echo File \`${BLFS_XML}\' does not exist
27 exit 1
28fi
29SPECIAL_FILE=$2
30if test -z "${SPECIAL_FILE}"; then SPECIAL_FILE=specialCases.xsl;fi
31BLFS_DIR=$3
32if test -z "${BLFS_DIR}"; then BLFS_DIR=$(cd $(dirname ${BLFS_XML})/.. ; pwd);fi
33
34# Packages whose version does not begin with a number
35EXCEPTIONS=$(grep 'ENTITY.*version[ ]*"[^0-9"&.].*[0-9]' ${BLFS_DIR}/packages.ent |
36 sed 's@^[^"]*"\([^"]*\)".*@\1@')
37
38# Non-versioned packages:
39NV_LIST="postlfs-config-profile postlfs-config-random postlfs-config-vimrc \
40initramfs xorg-env kde-pre-install-config kf5-intro \
41lxqt-pre-install lxqt-post-install ojdk-conf tex-path"
42
43cat >$SPECIAL_FILE << EOF
44<?xml version="1.0" encoding="ISO-8859-1"?>
45
46<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
47 version="1.0">
48
49<xsl:template match='*' mode="special">
50 <xsl:choose>
51<!-- Although versioned, this page is not a package. But
52 the sect2 with id "xorg-env" is referred to at several
53 places in the book. We have added it to the list of non
54 versioned packages. -->
55 <xsl:when test="@id='xorg7'">
56 <xsl:apply-templates select="child::sect2" mode="special"/>
57 </xsl:when>
58EOF
59
60# Non-versionned packages. Add to NV_LIST if you need more.
61for nv_id in $NV_LIST; do
62# Actually, kf5-intro contains some version info, so should be
63# versioned. For other packages, we define version to 1.0.0
64# because the DTD needs a version tag.
65 DUM_VER=1.0.0
66 if [ $nv_id = kf5-intro ]; then
67 DUM_VER=$(grep kf5-version $BLFS_DIR/packages.ent | \
68 sed 's/[^"]*"\([^"]*\).*/\1/')
69 fi
70 cat >>$SPECIAL_FILE << EOF
71 <xsl:when test="@id='$nv_id'">
72 <xsl:text> </xsl:text>
73 <package><xsl:text>&#xA; </xsl:text>
74 <xsl:element name="name">$nv_id</xsl:element>
75 <xsl:text>&#xA; </xsl:text>
76 <xsl:element name="version">$DUM_VER</xsl:element>
77 <xsl:if
78 test="document(\$installed-packages)//package[name=current()/@id]">
79 <xsl:text>&#xA; </xsl:text>
80 <xsl:element name="inst-version">
81 <xsl:value-of
82 select="document(\$installed-packages
83 )//package[name=current()/@id]/version"/>
84 </xsl:element>
85 </xsl:if>
86<!-- Dependencies -->
87 <xsl:apply-templates select=".//para[@role='required' or
88 @role='recommended' or
89 @role='optional']"
90 mode="dependency"/>
91<!-- End dependencies -->
92 <xsl:text>&#xA; </xsl:text>
93 </package><xsl:text>&#xA;</xsl:text>
94 </xsl:when>
95EOF
96done
97
98# Taking packages contained in pages installing several packages (x7* except
99# x7driver, kf5-frameworks, and plasma5-all), as versionned modules.
100# We also write a dependency expansion when a dep is of the form
101# xorg7-something or kf5-frameworks or plasma5-build. Since that is another
102# template, we need a temporary file, which we shall concatenate at the end
103cat >tmpfile << EOF
104 <xsl:template name="expand-deps">
105 <xsl:param name="section"/>
106 <xsl:param name="status"/>
107 <xsl:param name="build"/>
108 <xsl:choose>
109EOF
110for file in $(ls ${BLFS_DIR}/x/installing/x7* | grep -v x7driver) \
111 ${BLFS_DIR}/kde/kf5/kf5-frameworks.xml \
112 ${BLFS_DIR}/kde/plasma5/plasma-all.xml \
113 ${BLFS_DIR}/x/installing/xcb-utilities.xml; do
114 id=$(grep xreflabel $file | sed 's@.*id="\([^"]*\).*@\1@')
115 cat >>$SPECIAL_FILE << EOF
116 <xsl:when test="@id='$id'">
117 <xsl:text> </xsl:text>
118 <package><xsl:text>&#xA; </xsl:text>
119 <xsl:element name="name">$id</xsl:element>
120 <xsl:text>&#xA; </xsl:text>
121EOF
122 cat >> tmpfile << EOF
123 <xsl:when test="\$section='$id'">
124EOF
125# We extract the list of packages for those pages from
126# the "cat" command that creates the md5 file. We assume
127# that the preceding package is a dependency of the following,
128# except the first.
129# note that some pages may have several "cat" command, so we have to
130# make a complex regex for the first line to save. All those lines have
131# .md5 in them except the one for x7legacy that has .dat.
132# we need also to remove lines beginning with #.
133# Note that only xorg pages have '&' in them. So for kde
134# pages, what is extracted it the full tarball name.
135 list_cat="$(sed -n '/>cat.*\.\(md5\|dat\)/,/EOF</p' $file | \
136 grep -v '>cat\|EOF<\|#' | \
137 awk '{ print $NF }' | sed 's/-&.*//')"
138
139 precpack=NONE
140 for pack in $list_cat; do
141 if grep -q -E 'x7|xcb' $file; then # this is an xorg package
142 packname=$pack
143# We extract the version from the ENTITY parts of the .xml file.
144 packversion=$(grep "ENTITY ${pack}-version" $file | \
145 sed 's@[^"]*"\([^"]*\).*@\1@')
146 else
147 packname=${pack%-[[:digit:]]*}
148 packversion=$(echo $pack | sed 's/[^.]*-\([.[:digit:]]*\)\.tar.*/\1/')
149 fi
150 cat >>$SPECIAL_FILE << EOF
151 <module><xsl:text>&#xA; </xsl:text>
152 <xsl:element name="name">$packname</xsl:element>
153 <xsl:element name="version">$packversion</xsl:element>
154 <xsl:if test="document(\$installed-packages)//package[name='$packname']">
155 <xsl:element name="inst-version">
156 <xsl:value-of
157 select="document(\$installed-packages
158 )//package[name='$packname']/version"/>
159 </xsl:element>
160 </xsl:if>
161<!-- Dependencies -->
162EOF
163 if test $precpack != NONE; then
164 cat >>$SPECIAL_FILE << EOF
165 <xsl:element name="dependency">
166 <xsl:attribute name="status">required</xsl:attribute>
167 <xsl:attribute name="build">before</xsl:attribute>
168 <xsl:attribute name="name">$precpack</xsl:attribute>
169 <xsl:attribute name="type">ref</xsl:attribute>
170 </xsl:element>
171EOF
172 else
173 cat >>$SPECIAL_FILE << EOF
174 <xsl:apply-templates select=".//para[@role='required' or
175 @role='recommended' or
176 @role='optional']"
177 mode="dependency"/>
178EOF
179 fi
180 cat >>$SPECIAL_FILE << EOF
181<!-- End dependencies -->
182 </module>
183EOF
184# cat >> tmpfile << EOF
185# <xsl:element name="dependency">
186# <xsl:attribute name="status">
187# <xsl:value-of select="\$status"/>
188# </xsl:attribute>
189# <xsl:attribute name="build">
190# <xsl:value-of select="\$build"/>
191# </xsl:attribute>
192# <xsl:attribute name="name">$packname</xsl:attribute>
193# <xsl:attribute name="type">ref</xsl:attribute>
194# </xsl:element>
195#EOF
196 precpack=$packname
197 done
198# We need a dummy package for plasma post install instructions
199 if [ $(basename $file .xml) = plasma-all ]; then
200 cat >>$SPECIAL_FILE << EOF
201 <module><xsl:text>&#xA; </xsl:text>
202 <xsl:element name="name">plasma-post-install</xsl:element>
203 <xsl:element name="version">1.0.0</xsl:element>
204 <xsl:if test="document(\$installed-packages)//package[name='plasma-post-install']">
205 <xsl:element name="inst-version">
206 <xsl:value-of
207 select="document(\$installed-packages
208 )//package[name='plasma-post-install']/version"/>
209 </xsl:element>
210 </xsl:if>
211<!-- Dependencies -->
212 <xsl:element name="dependency">
213 <xsl:attribute name="status">required</xsl:attribute>
214 <xsl:attribute name="build">before</xsl:attribute>
215 <xsl:attribute name="name">$precpack</xsl:attribute>
216 <xsl:attribute name="type">ref</xsl:attribute>
217 </xsl:element>
218<!-- End dependencies -->
219 </module>
220EOF
221 fi
222
223 cat >>$SPECIAL_FILE << EOF
224 </package>
225 </xsl:when>
226EOF
227 cat >> tmpfile << EOF
228 <xsl:element name="dependency">
229 <xsl:attribute name="status">
230 <xsl:value-of select="\$status"/>
231 </xsl:attribute>
232 <xsl:attribute name="build">
233 <xsl:value-of select="\$build"/>
234 </xsl:attribute>
235 <xsl:attribute name="name">$packname</xsl:attribute>
236 <xsl:attribute name="type">ref</xsl:attribute>
237 </xsl:element>
238 </xsl:when>
239EOF
240done
241
242for ver_ent in $EXCEPTIONS; do
243 id=$(grep 'xreflabel=".*'$ver_ent $BLFS_XML | sed 's@.*id="\([^"]*\)".*@\1@')
244 [[ -z $id ]] && continue
245 cat >>$SPECIAL_FILE << EOF
246 <xsl:when test="@id='$id'">
247<!-- if there is a sect1 ancestor, we have a module -->
248 <xsl:choose>
249 <xsl:when test="ancestor::sect1">
250 <xsl:text> </xsl:text>
251 <module><xsl:text>&#xA; </xsl:text>
252 <xsl:element name="name">$id</xsl:element>
253 <xsl:text>&#xA; </xsl:text>
254 <xsl:element name="version">$ver_ent</xsl:element>
255 <xsl:if
256 test="document(\$installed-packages)//package[name=current()/@id]">
257 <xsl:text>&#xA; </xsl:text>
258 <xsl:element name="inst-version">
259 <xsl:value-of
260 select="document(\$installed-packages
261 )//package[name=current()/@id]/version"/>
262 </xsl:element>
263 </xsl:if>
264<!-- Dependencies -->
265 <xsl:apply-templates select=".//para[@role='required' or
266 @role='recommended' or
267 @role='optional']"
268 mode="dependency"/>
269<!-- End dependencies -->
270 <xsl:text>&#xA; </xsl:text>
271 </module><xsl:text>&#xA;</xsl:text>
272 </xsl:when>
273 <xsl:otherwise>
274 <xsl:text> </xsl:text>
275 <package><xsl:text>&#xA; </xsl:text>
276 <xsl:element name="name">$id</xsl:element>
277 <xsl:text>&#xA; </xsl:text>
278 <xsl:element name="version">$ver_ent</xsl:element>
279 <xsl:if
280 test="document(\$installed-packages)//package[name=current()/@id]">
281 <xsl:text>&#xA; </xsl:text>
282 <xsl:element name="inst-version">
283 <xsl:value-of
284 select="document(\$installed-packages
285 )//package[name=current()/@id]/version"/>
286 </xsl:element>
287 </xsl:if>
288<!-- Dependencies -->
289 <xsl:apply-templates select=".//para[@role='required' or
290 @role='recommended' or
291 @role='optional']"
292 mode="dependency"/>
293<!-- End dependencies -->
294 <xsl:text>&#xA; </xsl:text>
295 </package><xsl:text>&#xA;</xsl:text>
296 </xsl:otherwise>
297 </xsl:choose>
298 </xsl:when>
299EOF
300done
301
302cat >>$SPECIAL_FILE << EOF
303 <xsl:otherwise>
304 <xsl:apply-templates
305 select="self::node()[contains(translate(@xreflabel,
306 '123456789',
307 '000000000'),
308 '-0')
309 ]"
310 mode="normal"/>
311 </xsl:otherwise>
312 </xsl:choose>
313</xsl:template>
314EOF
315cat $SPECIAL_FILE tmpfile > tmpfile1
316mv tmpfile1 $SPECIAL_FILE
317rm tmpfile
318cat >> $SPECIAL_FILE << EOF
319 <xsl:otherwise>
320 <xsl:message>
321 <xsl:text>You should not be seeing this</xsl:text>
322 </xsl:message>
323 </xsl:otherwise>
324 </xsl:choose>
325</xsl:template>
326</xsl:stylesheet>
327EOF
Note: See TracBrowser for help on using the repository browser.