cookutils view modules/deps @ rev 939

modules/deps (tiny edits)
author Paul Issott <paul@slitaz.org>
date Tue Jun 20 19:02:35 2017 +0100 (2017-06-20)
parents 5ae6788158f0
children 81f33cdb5a66
line source
1 #!/bin/sh
2 #
3 # deps - module of the SliTaz Cook
4 # Copyright (C) SliTaz GNU/Linux - GNU GPL v3
5 #
7 . /usr/lib/slitaz/libcook.sh
10 # Maintain databases
12 fl="$cache/tp.files.db" # combined list of all files
13 db_so="$cache/tp.so.db" # database with *.so files
14 db_a="$cache/tp.a.db" # database with *.a files
15 db_la="$cache/tp.la.db" # database with *.la files
16 db_pc="$cache/tp.pc.db" # database with *.pc files
18 fl_mirrorz='/var/lib/tazpkg/files.list.lzma' # mirror files list
19 fl_local='/home/slitaz/cache/files.list' # local files list
21 # recreate "combined list of all files" in the cases:
22 # * if absent
23 # * mirror files list has been updated
24 # * local files list has been updated
26 case $(hostname) in
27 # Do we need to use mirror files list?
28 # It's useful on casual development on local host, but useless on cooker server
29 # (and slows down list creation a lot).
30 tank)
31 if [ ! -s $fl -o $fl_mirrorz -nt $fl -o $fl_local -nt $fl ]; then
32 # unpack mirror files list
33 fl_mirror="$(mktemp)"
34 lzcat $fl_mirrorz > $fl_mirror
36 # remove packages that exist in local list
37 cut -d: -f1 $fl_local | uniq | \
38 while read package; do
39 sed -i "/^$package: /d" $fl_mirror
40 done
42 # combine lists
43 cat $fl_mirror $fl_local > $fl
45 # clean
46 rm $fl_mirror
47 fi
48 ;;
49 *)
50 [ ! -s $fl -o $fl_local -nt $fl ] && cp $fl_local $fl
51 ;;
52 esac
54 # recreate "database with *.so files" in the cases:
55 # * if absent
56 # * combined list of all files has been updated
58 if [ ! -s $db_so -o $fl -nt $db_so ]; then
59 fgrep '/lib/' $fl | fgrep '.so' | \
60 sed 's|^\([^:]*\):.*/\([^/]*\)$|\2\t\1|' | \
61 awk -F$'\t' '{if ($2 !~ "uclibc") print}' | \
62 sort > $db_so
63 fi
65 # recreate "database with *.a files" in the cases:
66 # * if absent
67 # * combined list of all files has been updated
69 if [ ! -s $db_a -o $fl -nt $db_a ]; then
70 fgrep '/usr/lib/lib' $fl | fgrep '.a' | \
71 sed 's|^\([^:]*\):.*/\([^/]*\)$|\2\t\1|' | \
72 sort > $db_a
73 fi
75 # recreate "database with *.la files" in the cases:
76 # * if absent
77 # * combined list of all files has been updated
79 if [ ! -s $db_la -o $fl -nt $db_la ]; then
80 fgrep '/usr/lib/' $fl | fgrep '.la' | \
81 sed 's|^\([^:]*\): \(.*\)$|\2\t\1|' | \
82 sort > $db_la
83 fi
85 # recreate "database with *.pc files" in the cases:
86 # * if absent
87 # * combined list of all files has been updated
89 if [ ! -s $db_pc -o $fl -nt $db_pc ]; then
90 grep '\.pc$' $fl | \
91 sed -e 's|^\([^:]*\):.*/\([^/]*\)$|\2\t\1|' -e '/\tbuildroot$/d' | \
92 sort > $db_pc
93 fi
98 # Auxiliary function that deals with "not found" packages as well as with "repeatedly found" packages
100 outpkg() {
101 pkgs="$1"
102 case $pkgs in
103 *ld-linux.so*);;
104 *linux-gate.so*);;
105 *)
106 echo "$pkgs" | awk '
107 # if both packages exist in list, return the first one only
108 function s(pkg1, pkg2) {
109 if (index(" "$0" ", " "pkg1" ") && index(" "$0" ", " " pkg2 " "))
110 $0 = pkg1;
111 }
112 {
113 s("wine", "wine-rt");
114 s("samba", "samba-pam");
115 s("mesa", "mesa-wayland");
116 s("mysql", "mariadb");
117 s("perl", "perl-thread");
118 s("xorg-server", "xorg-server-light");
119 s("cairo", "cairo-gl");
120 s("freetype", "freetype-infinality");
121 s("freetype", "freetype-without-harfbuzz");
122 s("harfbuzz", "harfbuzz-icu");
123 s("openbox", "openbox-imlib2");
124 s("gcc-lib-base", "gcc49-lib-base"); # also gcc54-lib-base and gcc61-lib-base
125 s("polkit", "polkit-pam");
126 s("libgudev", "eudev"); # also systemd
127 s("xz-dev", "liblzma-dev");
129 if (! index($0, "glibc-base") &&
130 ! index($0, "gcc-lib-base") &&
131 ! index($0, "glibc-dev") &&
132 $0 != "gcc")
133 print gensub(" ", "|", "g");
134 }';;
135 esac >>$tmptmp
136 }
139 # Search for item $1 in db $2
141 indb() {
142 local res="$(awk -vi="$1" '
143 {
144 if ($1 == i)
145 { print $2; found = 1; }
146 }
147 END {
148 if (found != 1) {
149 if (index(i, "statically linked"))
150 print gensub(" ", "_", "g", i);
151 else
152 printf("[%s]\n", i);
153 }
154 }
155 ' $2 | tr '\n' ' ')"
156 outpkg "${res% }"
157 }
160 # Like `ldd` function but returns packages names where dependency exists.
161 # Also can process some development files
163 tp_ldd() {
164 unset IFS
165 tmptmp=$(mktemp)
167 case $1 in
168 *.la)
169 # found dependencies in the *.la files
170 libs=$(. $1; echo $dependency_libs)
171 for i in $libs; do
172 case $i in
173 -l*) indb "lib${i#-l}.so" $db_so;; # FIXME: I'm not sure it's about a *.so, but *.a often absent
174 *.la) indb "$i" $db_la;;
175 esac
176 done
177 ;;
178 *.pc)
179 # found dependencies in the *.pc files
180 # Syntax examples:
181 # Requires: glib-2.0 gobject-2.0
182 # Requires.private: gmodule-no-export-2.0
183 # Requires: gobject-2.0,gio-2.0
184 # Requires.private: nspr >= 4.9.2
185 pcs=$(grep '^Requires' $1 | cut -d: -f2 | tr ',' ' ' | tr '\n' ' ')
186 for i in $pcs; do
187 isitlib=$(echo $i | tr -d '<=>0-9.')
188 # if it contains only comparisons, numbers, dot - it is not lib, skip
189 [ -n "$isitlib" ] || continue
190 indb "$i.pc" $db_pc
191 done
192 # Syntax examples:
193 # Libs: -L${libdir} -lgio-2.0
194 # Libs.private: -lz -lresolv
195 libs=$(grep '^Libs' $1 | cut -d: -f2 | tr '\n' ' ')
196 for i in $libs; do
197 case $i in
198 -l*) indb "lib${i#-l}.so" $db_so;;
199 esac
200 done
201 ;;
202 */lib/modules/*)
203 echo 'linux'
204 ;;
205 *.pl|*.pm)
206 echo 'perl'
207 ;;
208 *.py)
209 echo 'python'
210 ;;
211 *)
212 LD_PRELOAD= LD_TRACE_LOADED_OBJECTS=1 /lib/ld-linux* "$1" 2>/dev/null | \
213 sed 's| =>.*||; s| (.*||; s|\t||' | \
214 while read i; do
215 indb "$i" $db_so
216 done
217 ;;
218 esac
220 sort -u $tmptmp
221 rm $tmptmp
222 }
225 # Return all the names of packages bundled in this receipt
227 all_names() {
228 local split=" $SPLIT "
229 if [ "${split/ $PACKAGE /}" != "$split" ]; then
230 # $PACKAGE included somewhere in $SPLIT (probably in the end).
231 # We should build packages in the order defined in the $SPLIT.
232 echo $SPLIT
233 else
234 # We'll build the $PACKAGE, then all defined in the $SPLIT.
235 echo $PACKAGE $SPLIT
236 fi
237 }
242 unset IFS
243 . $WOK/$1/receipt
245 for pkg in $(all_names); do
246 title 'Dependencies for "%s"' "$pkg"
247 IFS=$'\n'
248 while read file; do
249 tp_ldd "$WOK/$1/taz/$pkg-$VERSION/fs$file"
250 done < $WOK/$1/taz/$pkg-$VERSION/files.list | sort -u | grep -v "^$pkg$"
251 done
253 newline