cookutils view modules/deps @ rev 937
modules/deps (tiny edits)
author | Paul Issott <paul@slitaz.org> |
---|---|
date | Mon Jun 19 19:00:28 2017 +0100 (2017-06-19) |
parents | 9a70c8fdc40c |
children | 5ae6788158f0 |
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 if [ ! -s $fl -o $fl_mirrorz -nt $fl -o $fl_local -nt $fl ]; then
27 # unpack mirror files list
28 fl_mirror="$(mktemp)"
29 lzcat $fl_mirrorz > $fl_mirror
31 # remove packages that exist in local list
32 cut -d: -f1 $fl_local | uniq | \
33 while read package; do
34 sed -i "/^$package: /d" $fl_mirror
35 done
37 # combine lists
38 cat $fl_mirror $fl_local > $fl
40 # clean
41 rm $fl_mirror
42 fi
44 # recreate "database with *.so files" in the cases:
45 # * if absent
46 # * combined list of all files has been updated
48 if [ ! -s $db_so -o $fl -nt $db_so ]; then
49 fgrep '/lib/' $fl | fgrep '.so' | \
50 sed 's|^\([^:]*\):.*/\([^/]*\)$|\2\t\1|' | \
51 awk -F$'\t' '{if ($2 !~ "uclibc") print}' | \
52 sort > $db_so
53 fi
55 # recreate "database with *.a files" in the cases:
56 # * if absent
57 # * combined list of all files has been updated
59 if [ ! -s $db_a -o $fl -nt $db_a ]; then
60 fgrep '/usr/lib/lib' $fl | fgrep '.a' | \
61 sed 's|^\([^:]*\):.*/\([^/]*\)$|\2\t\1|' | \
62 sort > $db_a
63 fi
65 # recreate "database with *.la files" in the cases:
66 # * if absent
67 # * combined list of all files has been updated
69 if [ ! -s $db_la -o $fl -nt $db_la ]; then
70 fgrep '/usr/lib/' $fl | fgrep '.la' | \
71 sed 's|^\([^:]*\): \(.*\)$|\2\t\1|' | \
72 sort > $db_la
73 fi
75 # recreate "database with *.pc files" in the cases:
76 # * if absent
77 # * combined list of all files has been updated
79 if [ ! -s $db_pc -o $fl -nt $db_pc ]; then
80 grep '\.pc$' $fl | \
81 sed -e 's|^\([^:]*\):.*/\([^/]*\)$|\2\t\1|' -e '/\tbuildroot$/d' | \
82 sort > $db_pc
83 fi
88 # Auxiliary function that deals with "not found" packages as well as with "repeatedly found" packages
90 outpkg() {
91 pkgs="$1"
92 case $pkgs in
93 *ld-linux.so*);;
94 *linux-gate.so*);;
95 *)
96 echo "$pkgs" | awk '
97 # if both packages exist in list, return the first one only
98 function s(pkg1, pkg2) {
99 if (index(" "$0" ", " "pkg1" ") && index(" "$0" ", " " pkg2 " "))
100 $0 = pkg1;
101 }
102 {
103 s("wine", "wine-rt");
104 s("samba", "samba-pam");
105 s("mesa", "mesa-wayland");
106 s("mysql", "mariadb");
107 s("perl", "perl-thread");
108 s("xorg-server", "xorg-server-light");
109 s("cairo", "cairo-gl");
110 s("freetype", "freetype-infinality");
111 s("freetype", "freetype-without-harfbuzz");
112 s("harfbuzz", "harfbuzz-icu");
113 s("openbox", "openbox-imlib2");
114 s("gcc-lib-base", "gcc49-lib-base"); # also gcc54-lib-base and gcc61-lib-base
115 s("polkit", "polkit-pam");
116 s("libgudev", "eudev"); # also systemd
117 s("xz-dev", "liblzma-dev");
119 if (! index($0, "glibc-base") &&
120 ! index($0, "gcc-lib-base") &&
121 ! index($0, "glibc-dev") &&
122 $0 != "gcc")
123 print gensub(" ", "|", "g");
124 }';;
125 esac >>$tmptmp
126 }
129 # Search for item $1 in db $2
131 indb() {
132 local res="$(awk -vi="$1" '
133 {
134 if ($1 == i)
135 { print $2; found = 1; }
136 }
137 END {
138 if (found != 1) {
139 if (index(i, "statically linked"))
140 print gensub(" ", "_", "g", i);
141 else
142 printf("[%s]\n", i);
143 }
144 }
145 ' $2 | tr '\n' ' ')"
146 outpkg "${res% }"
147 }
150 # Like `ldd` function but returns packages names where dependency exists.
151 # Also can process some development files
153 tp_ldd() {
154 unset IFS
155 tmptmp=$(mktemp)
157 case $1 in
158 *.la)
159 # found dependencies in the *.la files
160 libs=$(. $1; echo $dependency_libs)
161 for i in $libs; do
162 case $i in
163 -l*) indb "lib${i#-l}.so" $db_so;; # FIXME: I'm not sure it's about a *.so, but *.a often absent
164 *.la) indb "$i" $db_la;;
165 esac
166 done
167 ;;
168 *.pc)
169 # found dependencies in the *.pc files
170 # Syntax examples:
171 # Requires: glib-2.0 gobject-2.0
172 # Requires.private: gmodule-no-export-2.0
173 # Requires: gobject-2.0,gio-2.0
174 pcs=$(grep '^Requires' $1 | cut -d: -f2 | tr ',' ' ' | tr '\n' ' ')
175 for i in $pcs; do
176 indb "$i.pc" $db_pc
177 done
178 # Syntax examples:
179 # Libs: -L${libdir} -lgio-2.0
180 # Libs.private: -lz -lresolv
181 libs=$(grep '^Libs' $1 | cut -d: -f2 | tr '\n' ' ')
182 for i in $libs; do
183 case $i in
184 -l*) indb "lib${i#-l}.so" $db_so;;
185 esac
186 done
187 ;;
188 */lib/modules/*)
189 echo 'linux'
190 ;;
191 *.pl|*.pm)
192 echo 'perl'
193 ;;
194 *.py)
195 echo 'python'
196 ;;
197 *)
198 LD_PRELOAD= LD_TRACE_LOADED_OBJECTS=1 /lib/ld-linux* "$1" 2>/dev/null | \
199 sed 's| =>.*||; s| (.*||; s|\t||' | \
200 while read i; do
201 indb "$i" $db_so
202 done
203 ;;
204 esac
206 sort -u $tmptmp
207 rm $tmptmp
208 }
211 # Return all the names of packages bundled in this receipt
213 all_names() {
214 local split=" $SPLIT "
215 if [ "${split/ $PACKAGE /}" != "$split" ]; then
216 # $PACKAGE included somewhere in $SPLIT (probably in the end).
217 # We should build packages in the order defined in the $SPLIT.
218 echo $SPLIT
219 else
220 # We'll build the $PACKAGE, then all defined in the $SPLIT.
221 echo $PACKAGE $SPLIT
222 fi
223 }
228 unset IFS
229 . $WOK/$1/receipt
231 for pkg in $(all_names); do
232 title 'Dependencies for "%s"' "$pkg"
233 IFS=$'\n'
234 while read file; do
235 tp_ldd "$WOK/$1/taz/$pkg-$VERSION/fs$file"
236 done < $WOK/$1/taz/$pkg-$VERSION/files.list | sort -u | grep -v "^$pkg$"
237 done
239 newline