source: BLFS/libs/func_dependencies@ f1fadeb

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

More circular dependencies fixes.

  • Property mode set to 100644
File size: 11.4 KB
Line 
1#!/bin/bash
2#
3# $Id$
4#
5set -e
6
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
20 modifies: vars: PKGXML
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
32
33 #---------------------
34 # Create the working directory and cd into it
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
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
63 echo -en "\tGenerating $TARGET dependencies tree ..."
64
65 #---------------------
66 # Create target package dependencies list
67 case $TARGET in
68 # Skip the creation when all dependencies are circular.
69 alsa-lib | cracklib | libexif | unixodbc ) ;;
70 # Meta-packages at target level
71 # KDE and Gnome-{core,full} could be made via packages.sh, but not sure yet how.
72 alsa ) # When target "alsa", use all alsa-* packages
73 mkdir dependencies
74 echo -e "alsa-oss\nalsa-firmware\nalsa-tools\nalsa-utils\n \
75 alsa-plugins\nalsa-lib" > dependencies/$TARGET.dep
76 ;;
77 xorg7 ) # At atarget level, add also x-config and x-setup
78 mkdir dependencies
79 echo -e "x-config\nx-setup\nrman\nxterm2\nxorg7-driver\nxorg7-server\nluit\n \
80 xorg7-font\nxorg7-data\nxorg7-app\nxbitmaps\nmesalib\nlibdrm\n \
81 xorg7-lib\nxorg7-util\nxorg7-proto" > dependencies/$TARGET.dep
82 ;;
83 * ) # Default
84 xsltproc --stringparam dependencies $DEP_LEVEL \
85 -o dependencies/$TARGET.dep \
86 ../libs/dependencies.xsl ../$PKGXML
87 ;;
88 esac
89
90 #---------------------
91 # Start with a clean $TARGET-index.xml.tmp file
92 > $TARGET-index.xml.tmp
93
94 #---------------------
95 # Write the XInclude
96 case $TARGET in
97 # If there is no usefull XML page, skip it.
98 alsa | arts | gnome-core | gnome-full | kde-core | kde-full | kde-koffice ) ;;
99 * )
100 echo -e " $ENTRY_START$PKGXML$ENTRY_END" >> $TARGET-index.xml.tmp
101 ;;
102 esac
103
104 #------------------P---
105 # Start with a clean depure.txt file
106 > depure.txt
107
108 #---------------------
109 # If have dependencies, write its XInclude and find sub-dependencies
110 if [[ -f dependencies/$TARGET.dep ]]; then
111 echo -e "Start loop for PKG $TARGET\n" >> depure.txt
112 mkdir xincludes && do_dependencies $TARGET
113 fi
114
115 echo "done"
116}
117
118
119
120#-----------------------#
121do_dependencies() { # Loop to find sub-dependencies :::WARNING::: THIS IS A RECURVISE FUNCTION
122#-----------------------#
123: <<inline_doc
124 function: Loop through all the packages and create a sub-dependency tree
125 input vars: $1, package name
126 externals: vars: $DEP_LEVEL
127 $TARGET
128 $PRINT_SERVER
129 $KBR5
130 $GHOSTSCRIPT
131 $MAILSERVER
132 file: depure.txt
133 $TARGET-index.xml.tmp
134 $PKG.dep
135 $PKG.inc
136 modifies: files
137 returns: nothing
138 output: file: $PKG-xinc.tmp
139 depure.txt
140 $TARGET-index.xml.tmp
141 on error: exit
142 on success:
143inline_doc
144
145 set -e
146 local PKG=$1
147 local saveIFS=$IFS
148 local DEP_LV=$DEP_LEVEL
149 local line line2 DEP
150 echo -e "\tPKG is $PKG" >> depure.txt
151 echo -e "\tDEP_LEVEL for $PKG is $DEP_LV\n" >> depure.txt
152
153 #------------------
154 # If a premade xinclude file exists, use it. If not, create one
155 if [[ -f xincludes/$PKG.xinc ]] ; then
156 echo -e "\tReusing xinclude file for PKG $PKG" >> depure.txt
157 IFS=$'\x0A'
158 for line in `cat xincludes/$PKG.xinc` ; do
159 IFS=$saveIFS
160 # Remove the Xinclude entry if found. We want the most newer one.
161 # Using double quotes to let bash expand variables.
162 # Remove also the empty line created. Can not be done in one step
163 # due that d requires the pattner between /, but we have a lot of /
164 # inside the pattner.
165 sed -e "s,^[[:space:]]*$line,," -e '/./!d' -i $TARGET-index.xml.tmp
166 # Write the XInclude
167 echo -e "$line" >> $TARGET-index.xml.tmp
168 done
169 return
170 fi
171
172 #------------------
173 # Start with a clean $PKG.xinc.tmp file
174 > xincludes/$PKG.xinc.tmp
175 for DEP in `cat dependencies/$PKG.dep`; do
176 # Special packages (a lot of hacks)
177 case $DEP in
178
179 db ) # The proper version of DB is installed in LFS
180 continue ;;
181 hal-requirements ) # ID value don't have their own XML package file
182 continue ;;
183 perl-* | tk-perl ) DEP=perl-modules ;;
184
185 # Orphan links (proper link must be created when generating the book)
186 arts ) DEP=aRts ;;
187 # Set values for alternative packages
188 # X is a meta-package, thus handled in another way.
189 LPRng | cups ) DEP=$PRINT_SERVER ;;
190 mitkrb | heimdal ) DEP=$KBR5 ;;
191 gs | espgs ) DEP=$GHOSTSCRIPT ;;
192 server-mail ) DEP=$MAIL_SERVER ;;
193 esac
194
195 #------------------
196 echo -e "\tDEP for $PKG is $DEP" >> depure.txt
197 # Prevent circular dependencies
198 # If all dependencies are circular, the creation of the *.dep file
199 # must be skipped, not placed here, to avoid that the script will bomb
200 # due empty *.xinc files
201 case $DEP in
202 jadetex | perl-* | lynx | Links | w3m )
203 # Optional dependencies are runtime only
204 [[ "$PKG" = "docbook-utils" ]] && continue
205 ;;
206 libxslt )
207 # libxml2-->libxslt-->libxml2
208 [[ "$PKG" = "libxml2" ]] && continue
209 ;;
210 openldap | postgresql | $KBR5 )
211 # cyrus-sasl-->several-->cyrus-sasl
212 [[ "$PKG" = "cyrus-sasl" ]] && continue
213 ;;
214 espgs )
215 # sendmail-->espgs-->cups-->php-->sendmail
216 [[ "$PKG" = "$MAIL_SERVER" ]] && continue
217 ;;
218 aRts )
219 # esound-->aRts-->esound
220 [[ "$PKG" = "esound" ]] && continue
221 ;;
222 gimp | sane )
223 # imagemagick-->{sane}-->gimp-->imagemagick
224 [[ "$PKG" = "imagemagick" ]] && continue
225 ;;
226 ffmpeg )
227 # alsa-plugins-->ffmpeg-->several-->alsa-plugins
228 [[ "$PKG" = "alsa-plugins" ]] && continue
229 ;;
230 esac
231
232 #------------------
233 echo -e "\tDEP_LEVEL for $DEP is $DEP_LV" >> depure.txt
234 # XML file of dependency package
235 DEP_XML=`grep "^$DEP[[:space:]]" ../packages | cut -f2`
236 echo -e "\t\tDEP_XML is $DEP_XML\n" >> depure.txt
237 case $DEP in
238 x-window-system | alsa ) ;; # No page for that (proper link must be created when generating the book)
239 xorg7 ) ;; # This page will be dump in the xorg7.xinc file
240 * )
241 # Remove the Xinclude entry if found
242 sed -e "s,^[[:space:]]*$ENTRY_START$DEP_XML$ENTRY_END,," \
243 -e '/./!d' -i xincludes/$PKG.xinc.tmp
244 # Write the XInclude
245 echo -e " $ENTRY_START$DEP_XML$ENTRY_END" >> xincludes/$PKG.xinc.tmp
246 ;;
247 esac
248
249 #------------------
250 # If not already created, create its dependencies list
251 if [[ ! -f dependencies/$DEP.dep ]] ; then
252 case $DEP in
253 # Skip the creation when all dependencies are circular.
254 alsa-lib | cracklib | libexif | unixodbc ) ;;
255 # Meta-packages at dependency level (ugly *.dep files, but work for now)
256 alsa ) # When dependency "alsa", use all alsa-* packages
257 echo -e "alsa-oss\nalsa-firmware\nalsa-tools\nalsa-utils\n \
258 alsa-plugins\nalsa-lib" > dependencies/$DEP.dep
259 ;;
260 x-window-system ) # X11 alternatives
261 echo -e "x-config\nx-setup\n$X11" > dependencies/$DEP.dep
262 ;;
263 xorg7 )
264 echo -e "rman\nxterm2\nxorg7-driver\nxorg7-server\nluit\nxorg7-font\n \
265 xorg7-data\nxorg7-app\nxbitmaps\nmesalib\nlibdrm\n \
266 xorg7-lib\nxorg7-util\nxorg7-proto" > dependencies/$DEP.dep
267 ;;
268 * ) xsltproc --stringparam dependencies $DEP_LV \
269 -o dependencies/$DEP.dep ../libs/dependencies.xsl ../$DEP_XML
270 ;;
271 esac
272 fi
273
274 #------------------
275 # If needed, process its dependencies
276 if [[ -f dependencies/$DEP.dep ]] ; then
277 # If a premade xinclude file esist, include it
278 if [[ -f xincludes/$DEP.xinc ]] ; then
279 echo -e "\tReusing xinclude file for PKG $DEP (to solve $PKG)\n" >> depure.txt
280 IFS=$'\x0A'
281 for line2 in `cat xincludes/$DEP.xinc` ; do
282 IFS=$saveIFS
283 # Remove the Xinclude entry if found
284 sed -e "s,^[[:space:]]*$line2,," -e '/./!d' -i xincludes/$PKG.xinc.tmp
285 # Write the XInclude
286 echo -e "$line2" >> xincludes/$PKG.xinc.tmp
287 done
288 #------------------
289 # Create the xinclude file
290 else
291 echo -e "\nStart new loop for PKG $DEP (to solve $PKG)\n" >> depure.txt
292 #
293 # >>>>>> THIS IS A RECURSIVE FUNCTION CALL.. BEWARE OF GREMLINS. <<<<<<
294 #
295 # If the recursion depth is not too great this is an acceptable methodology for a script language
296 # However, uncontrolled recursion will cause a seg-fault due to stack issues with local variables.
297 #
298 set +e
299 [[ "${VERBOSITY}" > 0 ]] && echo -ne "\nrecursive call: $((++cntr)) ${spaceSTR:0:$cntr} ${RED}$DEP${OFF}"
300 do_dependencies $DEP
301 [[ "${VERBOSITY}" > 0 ]] && echo -ne "\nrecursive ret: $cntr ${spaceSTR:0:$((cntr--))} ${GREEN}$DEP${OFF}\tUsing the new xinclude file for PKG $DEP (to solve $PKG)"
302 set -e
303
304 # Include it when done
305 echo -e "\tUsing the new xinclude file for PKG $DEP (to solve $PKG)\n" >> depure.txt
306 IFS=$'\x0A'
307 for line2 in `cat xincludes/$DEP.xinc` ; do
308 IFS=$saveIFS
309 # Remove the Xinclude entry if found
310 sed -e "s,^[[:space:]]*$line2,," -e '/./!d' -i xincludes/$PKG.xinc.tmp
311 # Write the XInclude
312 echo -e "$line2" >> xincludes/$PKG.xinc.tmp
313 done
314 fi
315 fi
316 done
317
318 #------------------
319 if [[ "$PKG" = "xorg7" ]] ; then
320 # Add their XInclude
321 PKG_XML=`grep "^$PKG[[:space:]]" ../packages | cut -f2`
322 echo -e " $ENTRY_START$PKG_XML$ENTRY_END" >> xincludes/$PKG.xinc.tmp
323 fi
324
325 #------------------
326 mv xincludes/$PKG.xinc.tmp xincludes/$PKG.xinc
327 echo -e "Using the new xinclude file for PKG $PKG" >> depure.txt
328 IFS=$'\x0A'
329 for line in `cat xincludes/$PKG.xinc` ; do
330 IFS=$saveIFS
331 # Remove the Xinclude entry if found.
332 sed -e "s,^[[:space:]]*$line,," -e '/./!d' -i $TARGET-index.xml.tmp
333 # Write the XInclude
334 echo -e "$line" >> $TARGET-index.xml.tmp
335 done
336
337 echo -e "\nEnd loop for PKG $PKG\n" >> depure.txt
338}
Note: See TracBrowser for help on using the repository browser.