]>
Commit | Line | Data |
---|---|---|
235217d2 MT |
1 | #!/bin/bash |
2 | ||
3 | # A function that finds needed libraries and interpreters. | |
4 | # | |
5 | function find_requires() { | |
6 | local dir | |
7 | local dirs=$@ | |
8 | ||
9 | # Find interpreters of all files in the dirs and skip those we provide | |
10 | # ourself. | |
11 | local interpreter | |
12 | local interpreters | |
13 | for interpreter in $(find_interpreters ${dirs}); do | |
14 | local found=0 | |
15 | for dir in ${dirs}; do | |
16 | if [ -e "${dir}/${interpreter}" ]; then | |
17 | found=1 | |
18 | break | |
19 | fi | |
20 | done | |
21 | ||
22 | [ "${found}" = "0" ] && interpreters="${interpreters} ${interpreter}" | |
23 | done | |
24 | ||
25 | # Find NEEDED libs and add them to a list if they are not provided by any | |
26 | # other file in dirs. | |
27 | local neededs | |
28 | for file in $(find_elf_files ${dirs}); do | |
29 | for needed in $(file_get_needed ${file}); do | |
30 | neededs="${neededs} ${needed}" | |
31 | done | |
32 | done | |
33 | ||
34 | # Find all symlink destinations | |
35 | local links=$(find_symlink_destinations ${dirs}) | |
36 | ||
37 | # Others | |
38 | local others=$(find_python_requires ${dirs}) | |
39 | others="${others} $(find_weak_symbols_requires ${dirs})" | |
40 | others="${others} $(find_perl_requires ${dirs})" | |
8852b4d8 | 41 | others="${others} $(find_pkgconfig_requires ${dirs})" |
235217d2 MT |
42 | |
43 | # Get provides, because packages should not depend on features they provide | |
44 | # by themselves. | |
45 | local provides=$(find_provides ${dirs}) | |
46 | ||
47 | # Return a sorted and unique(!) list | |
48 | local require | |
49 | local requires | |
a045948d | 50 | for require in $(listsort ${PKG_DEPS} ${interpreters} ${neededs} ${links} ${others}); do |
235217d2 | 51 | [ "${require:0:3}" = "ld-" ] && continue |
0c9e602e MT |
52 | |
53 | if [ -n "${PKG_REQUIRES_FILTER}" ]; then | |
54 | grep -qE "${PKG_REQUIRES_FILTER}" <<< "${require}" && continue | |
55 | fi | |
56 | ||
235217d2 MT |
57 | listmatch ${require} ${provides} || requires="${requires} ${require}" |
58 | done | |
59 | ||
60 | echo ${requires} | |
61 | } | |
62 | ||
63 | function find_provides() { | |
64 | local dirs=$@ | |
65 | ||
66 | local file | |
67 | local sonames | |
68 | for file in $(find_elf_files ${dirs}); do | |
69 | sonames="${sonames} $(file_get_soname ${file})" | |
70 | done | |
71 | sonames=$(listsort ${sonames}) | |
72 | ||
73 | # Others | |
74 | local others=$(find_python_provides ${dirs}) | |
75 | others="${others} $(find_weak_symbols_provides ${dirs})" | |
76 | others="${others} $(find_perl_provides ${dirs})" | |
8852b4d8 | 77 | others="${others} $(find_pkgconfig_provides ${dirs})" |
235217d2 | 78 | |
0c9e602e MT |
79 | local provide |
80 | local provides | |
81 | for provide in $(listsort ${PKG_PROVIDES} ${sonames} ${others}); do | |
82 | if [ -n "${PKG_PROVIDES_FILTER}" ]; then | |
83 | grep -qE "${PKG_PROVIDES_FILTER}" <<< "${provide}" && continue | |
84 | fi | |
85 | ||
86 | provides="${provides} ${provide}" | |
87 | done | |
88 | ||
89 | echo ${provides} | |
235217d2 MT |
90 | } |
91 | ||
92 | function find_interpreters() { | |
93 | local dirs=$@ | |
94 | ||
95 | log DEBUG "Searching for interpreters in ${dirs}" | |
96 | ||
97 | local file | |
98 | local interpreter | |
99 | local interpreters | |
100 | for file in $(find ${dirs} -type f 2>/dev/null); do | |
101 | # Get interpreter information from file. | |
102 | interpreter=$(file_get_interpreter ${file}) | |
103 | ||
104 | # Skip the file silently if the result was empty. | |
105 | [ -z "${interpreter}" ] && continue | |
106 | ||
107 | # Skip invalid interpreters that don't start with a slash. | |
108 | if [ "${interpreter:0:1}" != "/" ]; then | |
109 | log WARNING "Skipping invalid interpreter \"${interpreter}\" from \"${file}\"." | |
110 | continue | |
111 | fi | |
112 | ||
113 | if ! listmatch ${interpreter} ${INTERPRETERS_TO_BE_SKIPPED}; then | |
114 | interpreters="${interpreters} ${interpreter}" | |
115 | fi | |
116 | done | |
117 | ||
118 | interpreters=$(listsort ${interpreters}) | |
119 | ||
120 | log DEBUG "find_interpreters ${dirs}: ${interpreters}" | |
121 | ||
122 | echo "${interpreters}" | |
123 | } | |
124 | ||
125 | # Find the destinations of all symlinks and adds a dependency for that. | |
126 | # | |
127 | function find_symlink_destinations() { | |
128 | local dir=$@ | |
129 | ||
130 | local link | |
131 | local links | |
132 | for link in $(find ${dir} -type l 2>/dev/null); do | |
133 | link="$(readlink -m ${link})" | |
134 | [ -e "${link}" ] && continue | |
135 | ||
136 | link="${link#${dir}}" | |
137 | links="${links} ${link}" | |
138 | done | |
139 | ||
140 | echo ${links} | |
141 | } | |
142 | ||
143 | function find_python_provides() { | |
144 | local dir=${1} | |
145 | ||
146 | local file | |
147 | for file in $(find ${dir}/usr/bin/python* 2>/dev/null); do | |
148 | file=$(basename ${file}) | |
149 | file=${file#python} | |
150 | ||
151 | if [ -n "${file}" ]; then | |
152 | echo "python-api=${file}" | |
153 | fi | |
154 | done | |
155 | } | |
156 | ||
157 | function find_python_requires() { | |
158 | local dir=${1} | |
159 | ||
160 | local file | |
161 | for file in $(find ${dir}/usr/lib -maxdepth 1 2>/dev/null); do | |
162 | file=$(basename ${file}) | |
163 | ||
164 | if [ "${file:0:6}" = "python" ]; then | |
165 | file=${file#python} | |
166 | ||
167 | if [ -n "${file}" ]; then | |
168 | echo "python-api=${file}" | |
169 | fi | |
170 | fi | |
171 | done | |
172 | } | |
173 | ||
174 | function find_perl_files() { | |
175 | local extension | |
176 | for extension in pm pl; do | |
177 | find $@ -name "*.${extension}" 2>/dev/null | |
178 | done | |
179 | } | |
180 | ||
181 | function find_perl_provides() { | |
182 | [ -x "/usr/bin/perl" ] || return 0 | |
c10853e2 | 183 | perl ${BASEDIR}/perl.prov $(find_perl_files $@) | sort -u |
235217d2 MT |
184 | } |
185 | ||
186 | function find_perl_requires() { | |
187 | [ -x "/usr/bin/perl" ] || return 0 | |
c10853e2 | 188 | perl ${BASEDIR}/perl.req $(find_perl_files $@) | sort -u |
235217d2 MT |
189 | } |
190 | ||
8852b4d8 MT |
191 | function find_pkgconfig_provides() { |
192 | [ -x "/usr/bin/pkg-config" ] || return 0 | |
193 | find $@ | ${BASEDIR}/pkg-config.prov | |
194 | } | |
195 | ||
196 | function find_pkgconfig_requires() { | |
197 | [ -x "/usr/bin/pkg-config" ] || return 0 | |
198 | find $@ | ${BASEDIR}/pkg-config.req | |
199 | } | |
200 | ||
235217d2 MT |
201 | function find_weak_symbols_provides() { |
202 | local dirs=$@ | |
203 | ||
204 | local file | |
205 | local soname | |
206 | local symbol | |
207 | for file in $(find_elf_files ${dirs}); do | |
208 | soname=$(file_get_soname ${file}) | |
209 | [ -z "${soname}" ] && continue | |
210 | ||
211 | for symbol in $(objdump -p ${file} | grep -E "^[0-9]+" | awk '{ print $4 }'); do | |
212 | [ "${symbol}" = "${soname}" ] && continue | |
213 | [ "${symbol}" = "GLIBC_PRIVATE" ] && continue | |
214 | ||
215 | echo "${soname}(${symbol})" | |
216 | done | |
217 | done | sort -u | |
218 | } | |
219 | ||
220 | function find_weak_symbols_requires() { | |
221 | local dirs=$@ | |
222 | ||
223 | local file | |
224 | for file in $(find_elf_files ${dirs}); do | |
225 | objdump -p ${file} | awk 'BEGIN { START=0; LIBNAME=""; } | |
226 | /^$/ { START=0; } | |
227 | /^Dynamic Section:$/ { START=1; } | |
228 | (START==1) && /NEEDED/ { | |
229 | print $2; | |
230 | } | |
231 | (START==2) && /^[A-Za-z]/ { START=3; } | |
232 | /^Version References:$/ { START=2; } | |
233 | (START==2) && /required from/ { | |
234 | sub(/:/, "", $3); | |
235 | LIBNAME=$3; | |
236 | } | |
237 | (START==2) && (LIBNAME!="") && ($4!="") && (($4~/^GLIBC_*/) || ($4~/^GCC_*/)) { | |
238 | print LIBNAME "(" $4 ")"; | |
239 | }' | |
240 | done | grep -v "GLIBC_PRIVATE" | sort -u | |
241 | } |