3 # A function that finds needed libraries and interpreters.
5 function find_requires
() {
9 # Find interpreters of all files in the dirs and skip those we provide
13 for interpreter
in $
(find_interpreters
${dirs}); do
15 for dir
in ${dirs}; do
16 if [ -e "${dir}/${interpreter}" ]; then
22 [ "${found}" = "0" ] && interpreters="${interpreters} ${interpreter}"
25 # Find NEEDED libs and add them to a list if they are not provided by any
28 for file in $
(find_elf_files
${dirs}); do
29 for needed
in $
(file_get_needed
${file}); do
30 neededs
="${neededs} ${needed}"
34 # Find all symlink destinations
35 local links
=$
(find_symlink_destinations
${dirs})
38 local others
=$
(find_python_requires
${dirs})
39 others
="${others} $(find_weak_symbols_requires ${dirs})"
40 others
="${others} $(find_perl_requires ${dirs})"
41 others
="${others} $(find_pkgconfig_requires ${dirs})"
43 # Return a sorted and unique(!) list
46 for require
in $
(listsort
${PKG_DEPS} ${interpreters} ${neededs} ${links} ${others}); do
47 [ "${require:0:3}" = "ld-" ] && continue
49 if [ -n "${PKG_REQUIRES_FILTER}" ]; then
50 grep -qE "${PKG_REQUIRES_FILTER}" <<< "${require}" && continue
53 requires
="${requires} ${require}"
59 function find_provides
() {
64 for file in $
(find_elf_files
${dirs}); do
65 sonames
="${sonames} $(file_get_soname ${file})"
67 sonames
=$
(listsort
${sonames})
70 local others
=$
(find_python_provides
${dirs})
71 others
="${others} $(find_weak_symbols_provides ${dirs})"
72 others
="${others} $(find_perl_provides ${dirs})"
73 others
="${others} $(find_pkgconfig_provides ${dirs})"
77 for provide
in $
(listsort
${PKG_PROVIDES} ${sonames} ${others}); do
78 if [ -n "${PKG_PROVIDES_FILTER}" ]; then
79 grep -qE "${PKG_PROVIDES_FILTER}" <<< "${provide}" && continue
82 provides
="${provides} ${provide}"
88 function find_interpreters
() {
91 log DEBUG
"Searching for interpreters in ${dirs}"
96 for file in $
(find ${dirs} -type f
2>/dev
/null
); do
97 # Get interpreter information from file.
98 interpreter
=$
(file_get_interpreter
${file})
100 # Skip the file silently if the result was empty.
101 [ -z "${interpreter}" ] && continue
103 # Skip invalid interpreters that don't start with a slash.
104 if [ "${interpreter:0:1}" != "/" ]; then
105 log WARNING
"Skipping invalid interpreter \"${interpreter}\" from \"${file}\"."
109 if ! listmatch
${interpreter} ${INTERPRETERS_TO_BE_SKIPPED}; then
110 interpreters
="${interpreters} ${interpreter}"
114 interpreters
=$
(listsort
${interpreters})
116 log DEBUG
"find_interpreters ${dirs}: ${interpreters}"
118 echo "${interpreters}"
121 # Find the destinations of all symlinks and adds a dependency for that.
123 function find_symlink_destinations
() {
128 for link
in $
(find ${dir} -type l
2>/dev
/null
); do
129 link
="$(readlink -m ${link})"
130 [ -e "${link}" ] && continue
132 link
="${link#${dir}}"
133 links
="${links} ${link}"
139 function find_python_provides
() {
143 for file in $
(find ${dir}/usr
/bin
/python
* 2>/dev
/null
); do
144 file=$
(basename ${file})
147 if [ -n "${file}" ]; then
148 echo "python-api=${file}"
153 function find_python_requires
() {
157 for file in $
(find ${dir}/usr
/lib
-maxdepth 1 2>/dev
/null
); do
158 file=$
(basename ${file})
160 if [ "${file:0:6}" = "python" ]; then
163 if [ -n "${file}" ]; then
164 echo "python-api=${file}"
170 function find_perl_files
() {
172 for extension
in pm pl
; do
173 find $@
-name "*.${extension}" 2>/dev
/null
177 function find_perl_provides
() {
178 [ -x "/usr/bin/perl" ] ||
return 0
179 perl
${BASEDIR}/perl.prov $
(find_perl_files $@
) |
sort -u
182 function find_perl_requires
() {
183 [ -x "/usr/bin/perl" ] ||
return 0
184 perl
${BASEDIR}/perl.req $
(find_perl_files $@
) |
sort -u
187 function find_pkgconfig_provides
() {
188 [ -x "/usr/bin/pkg-config" ] ||
return 0
189 find $@ |
${BASEDIR}/pkg-config.prov
192 function find_pkgconfig_requires
() {
193 [ -x "/usr/bin/pkg-config" ] ||
return 0
194 find $@ |
${BASEDIR}/pkg-config.req
197 function find_weak_symbols_provides
() {
203 for file in $
(find_elf_files
${dirs}); do
204 soname
=$
(file_get_soname
${file})
205 [ -z "${soname}" ] && continue
207 for symbol
in $
(objdump
-p ${file} |
grep -E "^[0-9]+" |
awk '{ print $4 }'); do
208 [ "${symbol}" = "${soname}" ] && continue
209 [ "${symbol}" = "GLIBC_PRIVATE" ] && continue
211 echo "${soname}(${symbol})"
216 function find_weak_symbols_requires
() {
220 for file in $
(find_elf_files
${dirs}); do
221 objdump
-p ${file} |
awk 'BEGIN { START=0; LIBNAME=""; }
223 /^Dynamic Section:$/ { START=1; }
224 (START==1) && /NEEDED/ {
227 (START==2) && /^[A-Za-z]/ { START=3; }
228 /^Version References:$/ { START=2; }
229 (START==2) && /required from/ {
233 (START==2) && (LIBNAME!="") && ($4!="") && (($4~/^GLIBC_*/) || ($4~/^GCC_*/)) {
234 print LIBNAME "(" $4 ")";
236 done |
grep -v "GLIBC_PRIVATE" |
sort -u