source: BLFS/libs/func_dependencies@ 37ac06a

experimental
Last change on this file since 37ac06a was 4fe29a2, checked in by Manuel Canales Esparcia <manuel@…>, 19 years ago

Solved wrong and dead cross-references.

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