source: BLFS/libs/func_dependencies@ 5f14bd3

experimental
Last change on this file since 5f14bd3 was 5f14bd3, checked in by Manuel Canales Esparcia <manuel@…>, 18 years ago

Skip installed packages when processing dependencies instead of when generating the Makefile.
Fixed a bug when TARGET=xorg7

  • Property mode set to 100644
File size: 10.7 KB
RevLine 
[1d2f9d4]1#!/bin/bash
2#
3# $Id$
4#
5set -e
6
[41d4c11]7declare -i cntr=0
8declare -a spaceSTR=" "
9
10#----------------------------#
11generate_dependency_tree() { #
12#----------------------------#
13: <<inline_doc
14 function: Create a dependency tree for the TARGET
15 input vars: none
16 externals: vars: TARGET
17 PKGXML
18 DEP_LEVEL
19 func: do_dependencies
[2a3e0f0]20 modifies: vars: PKGXML
[41d4c11]21 BLFS_XML
22 returns: nothing
23 output: files: $TARGET.dep
24 $TARGET-index.xml.tmp
25 depure.txt
26 on error: nothing
27 on success: nothing
28inline_doc
29
30 local ENTRY_START
31 local ENTRY_END
[2a3e0f0]32
[41d4c11]33 #---------------------
34 # Create the working directory and cd into it
[6f0f0ed]35 if [[ -d $TARGET ]] ; then
36 echo -e "\tERROR: Looks like $TARGET has been already processed."
37 echo -e "\tPlease delete or rename the $TARGET directory.\n"
38 exit 1
39 else
40 mkdir $TARGET && cd $TARGET
41 fi
[41d4c11]42
43 #---------------------
44 # XML file of the target package
45 PKGXML=`grep "^$TARGET[[:space:]]" ../packages | cut -f2`
46
47 #---------------------
48 # The BLFS sources directory.
49 BLFS_XML=`echo $PKGXML | sed -e 's,/.*,,'`
50
51 if [[ ! -d ../$BLFS_XML ]] ; then
52 echo -e "\tThe BLFS book sources directory is missing.\n"
53 echo -e "\tExecution aborted.\n"
54 cd .. && rmdir $TARGET
55 exit 1
56 fi
57
58 #---------------------
59 # XInclude stuff
60 ENTRY_START="<xi:include xmlns:xi=\"http://www.w3.org/2003/XInclude\" href=\"../"
61 ENTRY_END="\"/>"
62
[d0d9e90]63 echo -e "\tGenerating $TARGET dependencies tree ..."
[41d4c11]64
[ad3bf2c]65 mkdir dependencies
66
[41d4c11]67 #---------------------
68 # Create target package dependencies list
69 case $TARGET in
[f1fadeb]70 # Skip the creation when all dependencies are circular.
71 alsa-lib | cracklib | libexif | unixodbc ) ;;
[ad3bf2c]72
[41d4c11]73 # Meta-packages at target level
[ad3bf2c]74 alsa )
[323f805]75 cp ../libs/alsa.dep dependencies/
[ad3bf2c]76 ;;
77 gnome-core )
78 cp ../libs/gnome-core.dep dependencies/
79 ;;
80 gnome-full )
81 cp ../libs/gnome-{core,full}.dep dependencies/
82 ;;
83 kde-core )
84 cp ../libs/kde-core.dep dependencies/
85 ;;
86 kde-full )
87 cp ../libs/kde-{core,full}.dep dependencies/
88 ;;
89 kde-koffice )
[323f805]90 cp ../libs/kde-{core,full,koffice}.dep dependencies/
[41d4c11]91 ;;
[f2a45d9]92 xorg7 )
[323f805]93 cp ../libs/xorg7.dep dependencies/
[6f0f0ed]94 ;;
[41d4c11]95 * ) # Default
96 xsltproc --stringparam dependencies $DEP_LEVEL \
97 -o dependencies/$TARGET.dep \
[2ca2992]98 ../libs/dependencies.xsl ../$PKGXML
[41d4c11]99 ;;
100 esac
101
102 #---------------------
103 # Start with a clean $TARGET-index.xml.tmp file
104 > $TARGET-index.xml.tmp
105
106 #---------------------
107 # Write the XInclude
[f1fadeb]108 case $TARGET in
109 # If there is no usefull XML page, skip it.
[5f14bd3]110 alsa | gnome-core | gnome-full | kde-core | kde-full | kde-koffice | xorg7) ;;
[f1fadeb]111 * )
112 echo -e " $ENTRY_START$PKGXML$ENTRY_END" >> $TARGET-index.xml.tmp
113 ;;
114 esac
[41d4c11]115
116 #---------------------
117 # If have dependencies, write its XInclude and find sub-dependencies
118 if [[ -f dependencies/$TARGET.dep ]]; then
119 mkdir xincludes && do_dependencies $TARGET
120 fi
121
[d0d9e90]122 echo -e "\n\t... done"
[41d4c11]123}
124
125
126
[1d2f9d4]127#-----------------------#
[41d4c11]128do_dependencies() { # Loop to find sub-dependencies :::WARNING::: THIS IS A RECURVISE FUNCTION
[1d2f9d4]129#-----------------------#
[41d4c11]130: <<inline_doc
131 function: Loop through all the packages and create a sub-dependency tree
132 input vars: $1, package name
133 externals: vars: $DEP_LEVEL
134 $TARGET
135 $PRINT_SERVER
136 $KBR5
137 $GHOSTSCRIPT
138 $MAILSERVER
139 file: depure.txt
140 $TARGET-index.xml.tmp
141 $PKG.dep
[2a3e0f0]142 $PKG.inc
[41d4c11]143 modifies: files
144 returns: nothing
145 output: file: $PKG-xinc.tmp
146 depure.txt
147 $TARGET-index.xml.tmp
148 on error: exit
[2a3e0f0]149 on success:
[41d4c11]150inline_doc
151
[1d2f9d4]152 set -e
153 local PKG=$1
154 local saveIFS=$IFS
155 local DEP_LV=$DEP_LEVEL
[5f14bd3]156 local line line2 DEP pkg_ver
157 local TRACKING_DIR=/var/lib/jhalfs/BLFS
[1d2f9d4]158
[41d4c11]159 #------------------
160 # If a premade xinclude file exists, use it. If not, create one
[1d2f9d4]161 if [[ -f xincludes/$PKG.xinc ]] ; then
162 IFS=$'\x0A'
163 for line in `cat xincludes/$PKG.xinc` ; do
164 IFS=$saveIFS
165 # Remove the Xinclude entry if found. We want the most newer one.
166 # Using double quotes to let bash expand variables.
167 # Remove also the empty line created. Can not be done in one step
168 # due that d requires the pattner between /, but we have a lot of /
169 # inside the pattner.
170 sed -e "s,^[[:space:]]*$line,," -e '/./!d' -i $TARGET-index.xml.tmp
171 # Write the XInclude
172 echo -e "$line" >> $TARGET-index.xml.tmp
173 done
[41d4c11]174 return
175 fi
[2a3e0f0]176
[41d4c11]177 #------------------
178 # Start with a clean $PKG.xinc.tmp file
179 > xincludes/$PKG.xinc.tmp
180 for DEP in `cat dependencies/$PKG.dep`; do
[5f14bd3]181 # If DEP has been previouly installed, skip it
182 pkg_ver=$(grep "^${DEP}[[:space:]]" ../packages | cut -f3)
183 [ -e $TRACKING_DIR/${DEP}-$pkg_ver ] && continue
[41d4c11]184 # Special packages (a lot of hacks)
185 case $DEP in
[2a3e0f0]186
[4fe29a2]187 db ) continue ;; # The proper version of DB is installed in LFS
[4761b5a]188
189 # Don't have their own XML file
[4fe29a2]190 hal-requirements | hal-runtime-dependencies ) continue ;;
191 perl-* | tk-perl ) DEP=perl-modules ;;
[41d4c11]192
[1d2f9d4]193 # Orphan links (proper link must be created when generating the book)
[4761b5a]194 arts ) DEP=aRts ;;
195 kde ) DEP=kde-core ;;
[4fe29a2]196
[1d2f9d4]197 # Set values for alternative packages
198 # X is a meta-package, thus handled in another way.
[4fe29a2]199 LPRng | cups ) DEP=$PRINT_SERVER ;;
200 mitkrb | heimdal ) DEP=$KBR5 ;;
201 gs | espgs ) DEP=$GHOSTSCRIPT ;;
202 server-mail ) DEP=$MAIL_SERVER ;;
[41d4c11]203 esac
204
205 #------------------
[f1fadeb]206 # Prevent circular dependencies
207 # If all dependencies are circular, the creation of the *.dep file
208 # must be skipped, not placed here, to avoid that the script will bomb
209 # due empty *.xinc files
[41d4c11]210 case $DEP in
[2a3e0f0]211 jadetex | perl-* | lynx | Links | w3m )
212 # Optional dependencies are runtime only
213 [[ "$PKG" = "docbook-utils" ]] && continue
214 ;;
215 libxslt )
216 # libxml2-->libxslt-->libxml2
217 [[ "$PKG" = "libxml2" ]] && continue
218 ;;
219 openldap | postgresql | $KBR5 )
220 # cyrus-sasl-->several-->cyrus-sasl
221 [[ "$PKG" = "cyrus-sasl" ]] && continue
222 ;;
223 espgs )
224 # sendmail-->espgs-->cups-->php-->sendmail
[da8017e]225 [[ "$PKG" = "$MAIL_SERVER" ]] && continue
[2a3e0f0]226 ;;
227 aRts )
228 # esound-->aRts-->esound
229 [[ "$PKG" = "esound" ]] && continue
230 ;;
[f1fadeb]231 gimp | sane )
232 # imagemagick-->{sane}-->gimp-->imagemagick
[2a3e0f0]233 [[ "$PKG" = "imagemagick" ]] && continue
[41d4c11]234 ;;
[f1fadeb]235 ffmpeg )
236 # alsa-plugins-->ffmpeg-->several-->alsa-plugins
237 [[ "$PKG" = "alsa-plugins" ]] && continue
238 ;;
[ad3bf2c]239 akode )
240 # Both are in the same page
241 [[ "$PKG" = "kdemultimedia" ]] && continue
242 ;;
[41d4c11]243 esac
244
245 #------------------
246 # XML file of dependency package
247 DEP_XML=`grep "^$DEP[[:space:]]" ../packages | cut -f2`
248 case $DEP in
[f1fadeb]249 x-window-system | alsa ) ;; # No page for that (proper link must be created when generating the book)
[41d4c11]250 xorg7 ) ;; # This page will be dump in the xorg7.xinc file
[ad3bf2c]251 gnome-core | kde-core | kde-full ) ;; # Invented packages
[41d4c11]252 * )
253 # Remove the Xinclude entry if found
254 sed -e "s,^[[:space:]]*$ENTRY_START$DEP_XML$ENTRY_END,," \
255 -e '/./!d' -i xincludes/$PKG.xinc.tmp
256 # Write the XInclude
257 echo -e " $ENTRY_START$DEP_XML$ENTRY_END" >> xincludes/$PKG.xinc.tmp
258 ;;
259 esac
260
261 #------------------
262 # If not already created, create its dependencies list
263 if [[ ! -f dependencies/$DEP.dep ]] ; then
[1d2f9d4]264 case $DEP in
[f1fadeb]265 # Skip the creation when all dependencies are circular.
266 alsa-lib | cracklib | libexif | unixodbc ) ;;
[addb529]267 # Meta-packages at dependency level
[323f805]268 alsa )
269 cp ../libs/alsa.dep dependencies/
[41d4c11]270 ;;
[6a49a38]271 kde-core )
272 cp ../libs/kde-core.dep dependencies/
273 ;;
[41d4c11]274 x-window-system ) # X11 alternatives
[ad3bf2c]275 echo -e "x-config\nx-setup\n$X11" > dependencies/x-window-system.dep
[41d4c11]276 ;;
[323f805]277 xorg7 ) # At dependencies level, remove x-config and x-setup
278 cp ../libs/xorg7.dep dependencies/
279 sed -i '/x-config/d;/x-setup/d' dependencies/xorg7.dep
[41d4c11]280 ;;
281 * ) xsltproc --stringparam dependencies $DEP_LV \
[2ca2992]282 -o dependencies/$DEP.dep ../libs/dependencies.xsl ../$DEP_XML
[1d2f9d4]283 ;;
284 esac
[41d4c11]285 fi
286
287 #------------------
288 # If needed, process its dependencies
289 if [[ -f dependencies/$DEP.dep ]] ; then
290 # If a premade xinclude file esist, include it
291 if [[ -f xincludes/$DEP.xinc ]] ; then
292 IFS=$'\x0A'
293 for line2 in `cat xincludes/$DEP.xinc` ; do
294 IFS=$saveIFS
[1d2f9d4]295 # Remove the Xinclude entry if found
[41d4c11]296 sed -e "s,^[[:space:]]*$line2,," -e '/./!d' -i xincludes/$PKG.xinc.tmp
[1d2f9d4]297 # Write the XInclude
[41d4c11]298 echo -e "$line2" >> xincludes/$PKG.xinc.tmp
299 done
300 #------------------
301 # Create the xinclude file
302 else
303 #
304 # >>>>>> THIS IS A RECURSIVE FUNCTION CALL.. BEWARE OF GREMLINS. <<<<<<
305 #
306 # If the recursion depth is not too great this is an acceptable methodology for a script language
307 # However, uncontrolled recursion will cause a seg-fault due to stack issues with local variables.
[2a3e0f0]308 #
[41d4c11]309 set +e
[d0d9e90]310 [[ "${VERBOSITY}" > 0 ]] && echo -ne "\ncall: $((++cntr))${spaceSTR:0:$cntr}${RED}$DEP${OFF}"
[41d4c11]311 do_dependencies $DEP
[d0d9e90]312 [[ "${VERBOSITY}" > 0 ]] && echo -ne "\n ret: $cntr${spaceSTR:0:$((cntr--))}${GREEN}$DEP${OFF} Using $DEP Xinc to solve $PKG"
[41d4c11]313 set -e
[2a3e0f0]314
[41d4c11]315 # Include it when done
316 IFS=$'\x0A'
317 for line2 in `cat xincludes/$DEP.xinc` ; do
318 IFS=$saveIFS
319 # Remove the Xinclude entry if found
320 sed -e "s,^[[:space:]]*$line2,," -e '/./!d' -i xincludes/$PKG.xinc.tmp
321 # Write the XInclude
322 echo -e "$line2" >> xincludes/$PKG.xinc.tmp
323 done
[1d2f9d4]324 fi
325 fi
[41d4c11]326 done
327
328 #------------------
329 if [[ "$PKG" = "xorg7" ]] ; then
330 # Add their XInclude
[addb529]331 PKG_XML=${BLFS_XML}/x/installing/xorg7.xml
[41d4c11]332 echo -e " $ENTRY_START$PKG_XML$ENTRY_END" >> xincludes/$PKG.xinc.tmp
[1d2f9d4]333 fi
334
[41d4c11]335 #------------------
336 mv xincludes/$PKG.xinc.tmp xincludes/$PKG.xinc
337 IFS=$'\x0A'
338 for line in `cat xincludes/$PKG.xinc` ; do
339 IFS=$saveIFS
340 # Remove the Xinclude entry if found.
341 sed -e "s,^[[:space:]]*$line,," -e '/./!d' -i $TARGET-index.xml.tmp
342 # Write the XInclude
343 echo -e "$line" >> $TARGET-index.xml.tmp
344 done
[1d2f9d4]345}
Note: See TracBrowser for help on using the repository browser.