source: BLFS/libs/func_dependencies@ 00f4966

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

Merged r2925:2931 from trunk

  • Property mode set to 100644
File size: 11.5 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
[d0d9e90]65 echo -e "\tGenerating $TARGET dependencies tree ..."
[41d4c11]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 #---------------------
124 # If have dependencies, write its XInclude and find sub-dependencies
125 if [[ -f dependencies/$TARGET.dep ]]; then
126 mkdir xincludes && do_dependencies $TARGET
127 fi
128
[d0d9e90]129 echo -e "\n\t... done"
[41d4c11]130}
131
132
133
[1d2f9d4]134#-----------------------#
[41d4c11]135do_dependencies() { # Loop to find sub-dependencies :::WARNING::: THIS IS A RECURVISE FUNCTION
[1d2f9d4]136#-----------------------#
[41d4c11]137: <<inline_doc
138 function: Loop through all the packages and create a sub-dependency tree
139 input vars: $1, package name
140 externals: vars: $DEP_LEVEL
141 $TARGET
142 $PRINT_SERVER
143 $KBR5
144 $GHOSTSCRIPT
145 $MAILSERVER
146 file: depure.txt
147 $TARGET-index.xml.tmp
148 $PKG.dep
[2a3e0f0]149 $PKG.inc
[41d4c11]150 modifies: files
151 returns: nothing
152 output: file: $PKG-xinc.tmp
153 depure.txt
154 $TARGET-index.xml.tmp
155 on error: exit
[2a3e0f0]156 on success:
[41d4c11]157inline_doc
158
[1d2f9d4]159 set -e
160 local PKG=$1
161 local saveIFS=$IFS
162 local DEP_LV=$DEP_LEVEL
163 local line line2 DEP
164
[41d4c11]165 #------------------
166 # If a premade xinclude file exists, use it. If not, create one
[1d2f9d4]167 if [[ -f xincludes/$PKG.xinc ]] ; then
168 IFS=$'\x0A'
169 for line in `cat xincludes/$PKG.xinc` ; do
170 IFS=$saveIFS
171 # Remove the Xinclude entry if found. We want the most newer one.
172 # Using double quotes to let bash expand variables.
173 # Remove also the empty line created. Can not be done in one step
174 # due that d requires the pattner between /, but we have a lot of /
175 # inside the pattner.
176 sed -e "s,^[[:space:]]*$line,," -e '/./!d' -i $TARGET-index.xml.tmp
177 # Write the XInclude
178 echo -e "$line" >> $TARGET-index.xml.tmp
179 done
[41d4c11]180 return
181 fi
[2a3e0f0]182
[41d4c11]183 #------------------
184 # Start with a clean $PKG.xinc.tmp file
185 > xincludes/$PKG.xinc.tmp
186 for DEP in `cat dependencies/$PKG.dep`; do
187 # Special packages (a lot of hacks)
188 case $DEP in
[2a3e0f0]189
[4fe29a2]190 db ) continue ;; # The proper version of DB is installed in LFS
[4761b5a]191
192 # Don't have their own XML file
[4fe29a2]193 hal-requirements | hal-runtime-dependencies ) continue ;;
194 perl-* | tk-perl ) DEP=perl-modules ;;
[41d4c11]195
[1d2f9d4]196 # Orphan links (proper link must be created when generating the book)
[4761b5a]197 arts ) DEP=aRts ;;
198 kde ) DEP=kde-core ;;
[4fe29a2]199
200 # Dummy gnome-core pages
[4761b5a]201 GNOME-desktop-file-utils ) DEP=desktop-file-utils ;;
202 GNOME-shared-mime-info ) DEP=shared-mime-info ;;
203
[1d2f9d4]204 # Set values for alternative packages
205 # X is a meta-package, thus handled in another way.
[4fe29a2]206 LPRng | cups ) DEP=$PRINT_SERVER ;;
207 mitkrb | heimdal ) DEP=$KBR5 ;;
208 gs | espgs ) DEP=$GHOSTSCRIPT ;;
209 server-mail ) DEP=$MAIL_SERVER ;;
[41d4c11]210 esac
211
212 #------------------
[f1fadeb]213 # Prevent circular dependencies
214 # If all dependencies are circular, the creation of the *.dep file
215 # must be skipped, not placed here, to avoid that the script will bomb
216 # due empty *.xinc files
[41d4c11]217 case $DEP in
[2a3e0f0]218 jadetex | perl-* | lynx | Links | w3m )
219 # Optional dependencies are runtime only
220 [[ "$PKG" = "docbook-utils" ]] && continue
221 ;;
222 libxslt )
223 # libxml2-->libxslt-->libxml2
224 [[ "$PKG" = "libxml2" ]] && continue
225 ;;
226 openldap | postgresql | $KBR5 )
227 # cyrus-sasl-->several-->cyrus-sasl
228 [[ "$PKG" = "cyrus-sasl" ]] && continue
229 ;;
230 espgs )
231 # sendmail-->espgs-->cups-->php-->sendmail
[da8017e]232 [[ "$PKG" = "$MAIL_SERVER" ]] && continue
[2a3e0f0]233 ;;
234 aRts )
235 # esound-->aRts-->esound
236 [[ "$PKG" = "esound" ]] && continue
237 ;;
[f1fadeb]238 gimp | sane )
239 # imagemagick-->{sane}-->gimp-->imagemagick
[2a3e0f0]240 [[ "$PKG" = "imagemagick" ]] && continue
[41d4c11]241 ;;
[f1fadeb]242 ffmpeg )
243 # alsa-plugins-->ffmpeg-->several-->alsa-plugins
244 [[ "$PKG" = "alsa-plugins" ]] && continue
245 ;;
[ad3bf2c]246 akode )
247 # Both are in the same page
248 [[ "$PKG" = "kdemultimedia" ]] && continue
249 ;;
[41d4c11]250 esac
251
252 #------------------
253 # XML file of dependency package
254 DEP_XML=`grep "^$DEP[[:space:]]" ../packages | cut -f2`
255 case $DEP in
[f1fadeb]256 x-window-system | alsa ) ;; # No page for that (proper link must be created when generating the book)
[41d4c11]257 xorg7 ) ;; # This page will be dump in the xorg7.xinc file
[ad3bf2c]258 gnome-core | kde-core | kde-full ) ;; # Invented packages
[41d4c11]259 * )
260 # Remove the Xinclude entry if found
261 sed -e "s,^[[:space:]]*$ENTRY_START$DEP_XML$ENTRY_END,," \
262 -e '/./!d' -i xincludes/$PKG.xinc.tmp
263 # Write the XInclude
264 echo -e " $ENTRY_START$DEP_XML$ENTRY_END" >> xincludes/$PKG.xinc.tmp
265 ;;
266 esac
267
268 #------------------
269 # If not already created, create its dependencies list
270 if [[ ! -f dependencies/$DEP.dep ]] ; then
[1d2f9d4]271 case $DEP in
[f1fadeb]272 # Skip the creation when all dependencies are circular.
273 alsa-lib | cracklib | libexif | unixodbc ) ;;
[41d4c11]274 # Meta-packages at dependency level (ugly *.dep files, but work for now)
275 alsa ) # When dependency "alsa", use all alsa-* packages
276 echo -e "alsa-oss\nalsa-firmware\nalsa-tools\nalsa-utils\n \
[ad3bf2c]277 alsa-plugins\nalsa-lib" > dependencies/alsa.dep
[41d4c11]278 ;;
[6a49a38]279 kde-core )
280 cp ../libs/kde-core.dep dependencies/
281 ;;
[41d4c11]282 x-window-system ) # X11 alternatives
[ad3bf2c]283 echo -e "x-config\nx-setup\n$X11" > dependencies/x-window-system.dep
[41d4c11]284 ;;
[6f0f0ed]285 xorg7 )
286 echo -e "rman\nxterm2\nxorg7-driver\nxorg7-server\nluit\nxorg7-font\n \
[41d4c11]287 xorg7-data\nxorg7-app\nxbitmaps\nmesalib\nlibdrm\n \
[ad3bf2c]288 xorg7-lib\nxorg7-util\nxorg7-proto" > dependencies/xorg7.dep
[41d4c11]289 ;;
290 * ) xsltproc --stringparam dependencies $DEP_LV \
[2ca2992]291 -o dependencies/$DEP.dep ../libs/dependencies.xsl ../$DEP_XML
[1d2f9d4]292 ;;
293 esac
[41d4c11]294 fi
295
296 #------------------
297 # If needed, process its dependencies
298 if [[ -f dependencies/$DEP.dep ]] ; then
299 # If a premade xinclude file esist, include it
300 if [[ -f xincludes/$DEP.xinc ]] ; then
301 IFS=$'\x0A'
302 for line2 in `cat xincludes/$DEP.xinc` ; do
303 IFS=$saveIFS
[1d2f9d4]304 # Remove the Xinclude entry if found
[41d4c11]305 sed -e "s,^[[:space:]]*$line2,," -e '/./!d' -i xincludes/$PKG.xinc.tmp
[1d2f9d4]306 # Write the XInclude
[41d4c11]307 echo -e "$line2" >> xincludes/$PKG.xinc.tmp
308 done
309 #------------------
310 # Create the xinclude file
311 else
312 #
313 # >>>>>> THIS IS A RECURSIVE FUNCTION CALL.. BEWARE OF GREMLINS. <<<<<<
314 #
315 # If the recursion depth is not too great this is an acceptable methodology for a script language
316 # However, uncontrolled recursion will cause a seg-fault due to stack issues with local variables.
[2a3e0f0]317 #
[41d4c11]318 set +e
[d0d9e90]319 [[ "${VERBOSITY}" > 0 ]] && echo -ne "\ncall: $((++cntr))${spaceSTR:0:$cntr}${RED}$DEP${OFF}"
[41d4c11]320 do_dependencies $DEP
[d0d9e90]321 [[ "${VERBOSITY}" > 0 ]] && echo -ne "\n ret: $cntr${spaceSTR:0:$((cntr--))}${GREEN}$DEP${OFF} Using $DEP Xinc to solve $PKG"
[41d4c11]322 set -e
[2a3e0f0]323
[41d4c11]324 # Include it when done
325 IFS=$'\x0A'
326 for line2 in `cat xincludes/$DEP.xinc` ; do
327 IFS=$saveIFS
328 # Remove the Xinclude entry if found
329 sed -e "s,^[[:space:]]*$line2,," -e '/./!d' -i xincludes/$PKG.xinc.tmp
330 # Write the XInclude
331 echo -e "$line2" >> xincludes/$PKG.xinc.tmp
332 done
[1d2f9d4]333 fi
334 fi
[41d4c11]335 done
336
337 #------------------
338 if [[ "$PKG" = "xorg7" ]] ; then
339 # Add their XInclude
340 PKG_XML=`grep "^$PKG[[:space:]]" ../packages | cut -f2`
341 echo -e " $ENTRY_START$PKG_XML$ENTRY_END" >> xincludes/$PKG.xinc.tmp
[1d2f9d4]342 fi
343
[41d4c11]344 #------------------
345 mv xincludes/$PKG.xinc.tmp xincludes/$PKG.xinc
346 IFS=$'\x0A'
347 for line in `cat xincludes/$PKG.xinc` ; do
348 IFS=$saveIFS
349 # Remove the Xinclude entry if found.
350 sed -e "s,^[[:space:]]*$line,," -e '/./!d' -i $TARGET-index.xml.tmp
351 # Write the XInclude
352 echo -e "$line" >> $TARGET-index.xml.tmp
353 done
[1d2f9d4]354}
Note: See TracBrowser for help on using the repository browser.