source: BLFS/func_dependencies@ 3d1e5a7

experimental
Last change on this file since 3d1e5a7 was 41d4c11, checked in by George Boudreau <georgeb@…>, 19 years ago

Creation of func_xxx files, TODO list, reorganize internal code

  • Property mode set to 100644
File size: 9.9 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 mkdir $TARGET && cd $TARGET
36
37 #---------------------
38 # XML file of the target package
39 PKGXML=`grep "^$TARGET[[:space:]]" ../packages | cut -f2`
40
41 #---------------------
42 # The BLFS sources directory.
43 BLFS_XML=`echo $PKGXML | sed -e 's,/.*,,'`
44
45 if [[ ! -d ../$BLFS_XML ]] ; then
46 echo -e "\tThe BLFS book sources directory is missing.\n"
47 echo -e "\tExecution aborted.\n"
48 cd .. && rmdir $TARGET
49 exit 1
50 fi
51
52 #---------------------
53 # XInclude stuff
54 ENTRY_START="<xi:include xmlns:xi=\"http://www.w3.org/2003/XInclude\" href=\"../"
55 ENTRY_END="\"/>"
56
57 echo -en "\tGenerating $TARGET dependencies tree ..."
58
59 #---------------------
60 # Create target package dependencies list
61 case $TARGET in
62 # Meta-packages at target level
63 # KDE and Gnome-{core,full} could be made via packages.sh, but not sure yet how.
64 alsa ) # When target "alsa", use all alsa-* packages
65 echo -e "alsa-oss\nalsa-firmware\nalsa-tools\nalsa-utils\n \
66 alsa-plugins\nalsa-lib" > dependencies/$TARGET.dep
67 ;;
68 * ) # Default
69 xsltproc --stringparam dependencies $DEP_LEVEL \
70 -o dependencies/$TARGET.dep \
71 ../dependencies.xsl ../$PKGXML
72 ;;
73 esac
74
75 #---------------------
76 # Start with a clean $TARGET-index.xml.tmp file
77 > $TARGET-index.xml.tmp
78
79 #---------------------
80 # Write the XInclude
81 echo -e " $ENTRY_START$PKGXML$ENTRY_END" >> $TARGET-index.xml.tmp
82
83 #------------------P---
84 # Start with a clean depure.txt file
85 > depure.txt
86
87 #---------------------
88 # If have dependencies, write its XInclude and find sub-dependencies
89 if [[ -f dependencies/$TARGET.dep ]]; then
90 echo -e "Start loop for PKG $TARGET\n" >> depure.txt
91 mkdir xincludes && do_dependencies $TARGET
92 fi
93
94 echo "done"
95}
96
97
98
99#-----------------------#
100do_dependencies() { # Loop to find sub-dependencies :::WARNING::: THIS IS A RECURVISE FUNCTION
101#-----------------------#
102: <<inline_doc
103 function: Loop through all the packages and create a sub-dependency tree
104 input vars: $1, package name
105 externals: vars: $DEP_LEVEL
106 $TARGET
107 $PRINT_SERVER
108 $KBR5
109 $GHOSTSCRIPT
110 $MAILSERVER
111 file: depure.txt
112 $TARGET-index.xml.tmp
113 $PKG.dep
114 $PKG.inc
115 modifies: files
116 returns: nothing
117 output: file: $PKG-xinc.tmp
118 depure.txt
119 $TARGET-index.xml.tmp
120 on error: exit
121 on success:
122inline_doc
123
124 set -e
125 local PKG=$1
126 local saveIFS=$IFS
127 local DEP_LV=$DEP_LEVEL
128 local line line2 DEP
129 echo -e "\tPKG is $PKG" >> depure.txt
130 echo -e "\tDEP_LEVEL for $PKG is $DEP_LV\n" >> depure.txt
131
132 #------------------
133 # If a premade xinclude file exists, use it. If not, create one
134 if [[ -f xincludes/$PKG.xinc ]] ; then
135 echo -e "\tReusing xinclude file for PKG $PKG" >> depure.txt
136 IFS=$'\x0A'
137 for line in `cat xincludes/$PKG.xinc` ; do
138 IFS=$saveIFS
139 # Remove the Xinclude entry if found. We want the most newer one.
140 # Using double quotes to let bash expand variables.
141 # Remove also the empty line created. Can not be done in one step
142 # due that d requires the pattner between /, but we have a lot of /
143 # inside the pattner.
144 sed -e "s,^[[:space:]]*$line,," -e '/./!d' -i $TARGET-index.xml.tmp
145 # Write the XInclude
146 echo -e "$line" >> $TARGET-index.xml.tmp
147 done
148 return
149 fi
150
151 #------------------
152 # Start with a clean $PKG.xinc.tmp file
153 > xincludes/$PKG.xinc.tmp
154 for DEP in `cat dependencies/$PKG.dep`; do
155 # Special packages (a lot of hacks)
156 case $DEP in
157
158 db ) # The proper version of DB is installed in LFS
159 continue ;;
160 hal-requirements ) # ID value don't have their own XML package file
161 continue ;;
162 perl-* | tk-perl ) DEP=perl-modules ;;
163
164 # Orphan links (proper link must be created when generating the book)
165 arts ) DEP=aRts ;; # That should be fixed in the BLFS book
166 # Set values for alternative packages
167 # X is a meta-package, thus handled in another way.
168 LPRng | cups ) DEP=$PRINT_SERVER ;;
169 mitkrb | heimdal ) DEP=$KBR5 ;;
170 gs | espgs ) DEP=$GHOSTSCRIPT ;;
171 MTA ) DEP=$MAIL_SERVER ;; # The BLFS book need be fixed yet for that
172 esac
173
174 #------------------
175 echo -e "\tDEP for $PKG is $DEP" >> depure.txt
176 case $DEP in
177 # Circular dependencies at level 3
178 cracklib | docbook-utils | libxml2 | cyrus-sasl | alsa-lib | \
179 unixodbc | cups | libexif | esound | gimp )
180 [[ "$DEP_LV" = "3" ]] && DEP_LV=2
181 ;;
182 * ) DEP_LV=$DEP_LEVEL ;;
183 esac
184
185 #------------------
186 echo -e "\tDEP_LEVEL for $DEP is $DEP_LV" >> depure.txt
187 # XML file of dependency package
188 DEP_XML=`grep "^$DEP[[:space:]]" ../packages | cut -f2`
189 echo -e "\t\tDEP_XML is $DEP_XML\n" >> depure.txt
190 case $DEP in
191 x-window-system ) ;; # No page for that (proper link must be created when generating the book)
192 xorg7 ) ;; # This page will be dump in the xorg7.xinc file
193 * )
194 # Remove the Xinclude entry if found
195 sed -e "s,^[[:space:]]*$ENTRY_START$DEP_XML$ENTRY_END,," \
196 -e '/./!d' -i xincludes/$PKG.xinc.tmp
197 # Write the XInclude
198 echo -e " $ENTRY_START$DEP_XML$ENTRY_END" >> xincludes/$PKG.xinc.tmp
199 ;;
200 esac
201
202 #------------------
203 # If not already created, create its dependencies list
204 if [[ ! -f dependencies/$DEP.dep ]] ; then
205 case $DEP in
206 # Meta-packages at dependency level (ugly *.dep files, but work for now)
207 alsa ) # When dependency "alsa", use all alsa-* packages
208 echo -e "alsa-oss\nalsa-firmware\nalsa-tools\nalsa-utils\n \
209 alsa-plugins\nalsa-lib" > dependencies/$DEP.dep
210 ;;
211 x-window-system ) # X11 alternatives
212 echo -e "x-config\nx-setup\n$X11" > dependencies/$DEP.dep
213 ;;
214 xorg7 ) # All Xorg7 packages except Xterm (circular dependency)
215 echo -e "rman\nxorg7-driver\nxorg7-server\nluit\nxorg7-font\n \
216 xorg7-data\nxorg7-app\nxbitmaps\nmesalib\nlibdrm\n \
217 xorg7-lib\nxorg7-util\nxorg7-proto" > dependencies/$DEP.dep
218 ;;
219 * ) xsltproc --stringparam dependencies $DEP_LV \
220 -o dependencies/$DEP.dep ../dependencies.xsl ../$DEP_XML
221 ;;
222 esac
223 fi
224
225 #------------------
226 # If needed, process its dependencies
227 if [[ -f dependencies/$DEP.dep ]] ; then
228 # If a premade xinclude file esist, include it
229 if [[ -f xincludes/$DEP.xinc ]] ; then
230 echo -e "\tReusing xinclude file for PKG $DEP (to solve $PKG)\n" >> depure.txt
231 IFS=$'\x0A'
232 for line2 in `cat xincludes/$DEP.xinc` ; do
233 IFS=$saveIFS
234 # Remove the Xinclude entry if found
235 sed -e "s,^[[:space:]]*$line2,," -e '/./!d' -i xincludes/$PKG.xinc.tmp
236 # Write the XInclude
237 echo -e "$line2" >> xincludes/$PKG.xinc.tmp
238 done
239 #------------------
240 # Create the xinclude file
241 else
242 echo -e "\nStart new loop for PKG $DEP (to solve $PKG)\n" >> depure.txt
243 #
244 # >>>>>> THIS IS A RECURSIVE FUNCTION CALL.. BEWARE OF GREMLINS. <<<<<<
245 #
246 # If the recursion depth is not too great this is an acceptable methodology for a script language
247 # However, uncontrolled recursion will cause a seg-fault due to stack issues with local variables.
248 #
249 set +e
250 [[ "${VERBOSITY}" > 0 ]] && echo -ne "\nrecursive call: $((++cntr)) ${spaceSTR:0:$cntr} ${RED}$DEP${OFF}"
251 echo -ne "\nrecursive call: $cntr ${spaceSTR:0:$cntr} $DEP" >>koffice.XX
252 do_dependencies $DEP
253 echo -ne "\nrecursive ret: $cntr ${spaceSTR:0:$cntr} $DEP\t(to solve $PKG)" >>koffice.XX
254 [[ "${VERBOSITY}" > 0 ]] && echo -ne "\nrecursive ret: $cntr ${spaceSTR:0:$((cntr--))} ${GREEN}$DEP${OFF}\tUsing the new xinclude file for PKG $DEP (to solve $PKG)"
255 set -e
256
257 # Include it when done
258 echo -e "\tUsing the new xinclude file for PKG $DEP (to solve $PKG)\n" >> depure.txt
259 IFS=$'\x0A'
260 for line2 in `cat xincludes/$DEP.xinc` ; do
261 IFS=$saveIFS
262 # Remove the Xinclude entry if found
263 sed -e "s,^[[:space:]]*$line2,," -e '/./!d' -i xincludes/$PKG.xinc.tmp
264 # Write the XInclude
265 echo -e "$line2" >> xincludes/$PKG.xinc.tmp
266 done
267 fi
268 fi
269 done
270
271 #------------------
272 if [[ "$PKG" = "xorg7" ]] ; then
273 # Add their XInclude
274 PKG_XML=`grep "^$PKG[[:space:]]" ../packages | cut -f2`
275 echo -e " $ENTRY_START$PKG_XML$ENTRY_END" >> xincludes/$PKG.xinc.tmp
276 fi
277
278 #------------------
279 mv xincludes/$PKG.xinc.tmp xincludes/$PKG.xinc
280 echo -e "Using the new xinclude file for PKG $PKG" >> depure.txt
281 IFS=$'\x0A'
282 for line in `cat xincludes/$PKG.xinc` ; do
283 IFS=$saveIFS
284 # Remove the Xinclude entry if found.
285 sed -e "s,^[[:space:]]*$line,," -e '/./!d' -i $TARGET-index.xml.tmp
286 # Write the XInclude
287 echo -e "$line" >> $TARGET-index.xml.tmp
288 done
289
290 echo -e "\nEnd loop for PKG $PKG\n" >> depure.txt
291}
Note: See TracBrowser for help on using the repository browser.