[63fc514] | 1 | #!/bin/bash
|
---|
| 2 |
|
---|
| 3 | # $Id: gen-special.sh 21 2012-02-16 15:06:19Z labastie $
|
---|
| 4 |
|
---|
[d236bbd] | 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 |
|
---|
[63fc514] | 23 | BLFS_XML=$1
|
---|
| 24 | if ! test -f ${BLFS_XML}; then
|
---|
[d236bbd] | 25 | echo File \`${BLFS_XML}\' does not exist
|
---|
[63fc514] | 26 | exit 1
|
---|
| 27 | fi
|
---|
| 28 | SPECIAL_FILE=$2
|
---|
| 29 | if test -z "${SPECIAL_FILE}"; then SPECIAL_FILE=specialCases.xsl;fi
|
---|
[d236bbd] | 30 | BLFS_DIR=$3
|
---|
| 31 | if test -z "${BLFS_DIR}"; then BLFS_DIR=$(cd $(dirname ${BLFS_XML})/.. ; pwd);fi
|
---|
| 32 |
|
---|
[63fc514] | 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@')
|
---|
[d236bbd] | 36 |
|
---|
[63fc514] | 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>
|
---|
[d236bbd] | 50 | <xsl:when test="contains(@id,'udev')">
|
---|
[63fc514] | 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>
|
---|
[d236bbd] | 74 | <!-- Although versioned, this page is not a package -->
|
---|
[63fc514] | 75 | <xsl:when test="@id='xorg7'"/>
|
---|
[d236bbd] | 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'">
|
---|
[63fc514] | 92 | <xsl:text> </xsl:text>
|
---|
| 93 | <package><xsl:text>
 </xsl:text>
|
---|
[d236bbd] | 94 | <xsl:element name="name">$id</xsl:element>
|
---|
[63fc514] | 95 | <xsl:text>
 </xsl:text>
|
---|
[d236bbd] | 96 | EOF
|
---|
| 97 | cat >> tmpfile << EOF
|
---|
| 98 | <xsl:when test="\$section='$id'">
|
---|
| 99 | EOF
|
---|
[14a3e90] | 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 |
|
---|
[d236bbd] | 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@')
|
---|
[14a3e90] | 116 | precpack=NONE
|
---|
| 117 | for i in $list_cat; do
|
---|
| 118 | if [ "$i" = "$packname" ]; then break; fi
|
---|
| 119 | precpack=$i
|
---|
| 120 | done
|
---|
| 121 |
|
---|
[d236bbd] | 122 | cat >>$SPECIAL_FILE << EOF
|
---|
| 123 | <module><xsl:text>
 </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>
|
---|
[63fc514] | 133 | <!-- Dependencies -->
|
---|
[d236bbd] | 134 | EOF
|
---|
| 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>
|
---|
| 142 | EOF
|
---|
| 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"/>
|
---|
| 149 | EOF
|
---|
| 150 | fi
|
---|
| 151 | cat >>$SPECIAL_FILE << EOF
|
---|
| 152 | <!-- End dependencies -->
|
---|
| 153 | </module>
|
---|
| 154 | EOF
|
---|
| 155 | cat >> tmpfile << EOF
|
---|
[96a30c7] | 156 | <xsl:element name="dependency">
|
---|
[d236bbd] | 157 | <xsl:attribute name="status">
|
---|
| 158 | <xsl:value-of select="\$status"/>
|
---|
[96a30c7] | 159 | </xsl:attribute>
|
---|
[d236bbd] | 160 | <xsl:attribute name="name">$packname</xsl:attribute>
|
---|
[96a30c7] | 161 | <xsl:attribute name="type">ref</xsl:attribute>
|
---|
| 162 | </xsl:element>
|
---|
[63fc514] | 163 | EOF
|
---|
[d236bbd] | 164 | done
|
---|
| 165 | cat >>$SPECIAL_FILE << EOF
|
---|
| 166 | </package>
|
---|
| 167 | </xsl:when>
|
---|
| 168 | EOF
|
---|
| 169 | cat >> tmpfile << EOF
|
---|
| 170 | </xsl:when>
|
---|
| 171 | EOF
|
---|
| 172 | done
|
---|
[63fc514] | 173 |
|
---|
| 174 | for 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>
 </xsl:text>
|
---|
| 181 | <xsl:element name="name">$id</xsl:element>
|
---|
| 182 | <xsl:text>
 </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>
 </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>
 </xsl:text>
|
---|
| 200 | </package><xsl:text>
</xsl:text>
|
---|
| 201 | </xsl:when>
|
---|
| 202 | EOF
|
---|
| 203 | done
|
---|
| 204 |
|
---|
| 205 | cat >>$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>
|
---|
[d236bbd] | 217 | EOF
|
---|
| 218 | cat $SPECIAL_FILE tmpfile > tmpfile1
|
---|
| 219 | mv tmpfile1 $SPECIAL_FILE
|
---|
| 220 | rm tmpfile
|
---|
| 221 | cat >> $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>
|
---|
[63fc514] | 229 | </xsl:stylesheet>
|
---|
| 230 | EOF
|
---|