]> git.ipfire.org Git - people/stevee/pakfire.git/blob - tools/find-requires
Speedup searching for requires (esp. in the kernel).
[people/stevee/pakfire.git] / tools / find-requires
1 #!/bin/bash
2
3 # Include functions.
4 BASEDIR=$(dirname ${0})
5 source ${BASEDIR}/find-common
6
7 # BUILDROOT is the first argument.
8 BUILDROOT=${1}
9 FILELIST=${2}
10
11 # Determine libdir.
12 if [ "$(uname -m)" = "x86_64" ]; then
13 libdir=/usr/lib64
14 else
15 libdir=/usr/lib
16 fi
17
18 binary_files=
19 perl_files=
20 script_files=
21 pkgconfig_files=
22
23 # Walk through all file files and see what we have got here.
24 while read file; do
25 case "${file}" in
26 */usr/lib/debug/*|*/usr/src/debug/*)
27 # Skip all debuginfo files.
28 ;;
29 *.ko)
30 # Skip all kernel modules because they do not
31 # require anything at all.
32 continue
33 ;;
34 *.pc)
35 # Find all pkg-config files.
36 pkgconfig_files="${pkgconfig_files} ${file}"
37 continue
38 ;;
39 *.pm)
40 # Find all perl modules.
41 if [ -r "${file}" ]; then
42 perl_files="${perl_files} ${file}"
43 continue
44 fi
45 ;;
46
47 # Python
48 */usr/lib*/python*/*)
49 # Sort out all python files.
50 ;;
51 */usr/lib/python*|*/usr/lib64/python*)
52 # This will only get the python directory.
53 file=$(basename ${file})
54
55 # Strip the python version from the string.
56 python_version="${file#python}"
57
58 if [ -n "${python_version}" ]; then
59 echo "python-abi = ${python_version}"
60 fi
61 continue
62 ;;
63 esac
64
65 # Unresolved symlinks.
66 if [ -L "${file}" ]; then
67 # Get destination.
68 link=$(readlink -m ${file})
69
70 # If destination does not exist, make
71 # a dependency for it.
72 if ! [ -e "${link}" ]; then
73 echo "${link#${BUILDROOT}}"
74 fi
75
76 # Don't search for anything else, because
77 # symlinks do not require anything but the target file.
78 continue
79 fi
80
81 # Search for all binary files.
82 if file_is_elf ${file}; then
83 binary_files="${binary_files} ${file}"
84 continue
85 fi
86
87 # Search for script files.
88 if file_is_script ${file}; then
89 script_files="${script_files} ${file}"
90 continue
91 fi
92 done < ${FILELIST}
93
94 # Process script files.
95 interpreters=
96 for file in ${script_files}; do
97 [ -r ${file} -a -x ${file} ] || continue
98
99 interp=$(file_get_script_interpreter ${file})
100 interpreters="${interpreters} ${interp}"
101
102 # Collect all perl files.
103 case "${interp}" in
104 */perl)
105 perl_files="${perl_files} ${file}"
106 ;;
107 esac
108 done
109
110 # Output the list of needed interpreters.
111 [ -n "${interpreters}" ] && { echo ${interpreters} | tr '[:blank:]' \\n | sort -u ; }
112
113 # Search for binary interpreters.
114 for file in ${binary_files}; do
115 # Just print the interpreter.
116 file_get_elf_interpreter ${file}
117 done | sort -u
118
119 # Weak symbol versions (from glibc).
120 [ -n "${mark64}" ] && mark64="(64bit)"
121 for file in ${binary_files}; do
122 [ -r ${file} ] || continue
123
124 lib64=$(if file_is_64bit ${file}; then echo "${mark64}"; fi)
125 objdump -p ${file} 2>/dev/null | awk 'BEGIN { START=0; LIBNAME=""; }
126 /^$/ { START=0; }
127 /^Dynamic Section:$/ { START=1; }
128 (START==1) && /NEEDED/ {
129 if ("'${lib64}'" != "") {
130 sub(/$/, "()'${lib64}'", $2);
131 }
132 print $2;
133 }
134 (START==2) && /^[A-Za-z]/ { START=3; }
135 /^Version References:$/ { START=2; }
136 (START==2) && /required from/ {
137 sub(/:/, "", $3);
138 LIBNAME=$3;
139 }
140 (START==2) && (LIBNAME!="") && ($4!="") {
141 print LIBNAME "(" $4 ")'${lib64}'";
142 }'
143 done | sort -u
144
145 # Search for perl requires.
146 if [ -n "${perl_files}" ] && [ -x /usr/bin/perl ]; then
147 perl ${BASEDIR}/perl.req ${perl_files} | sort -u
148 fi
149
150 # Search for pkg-config requires.
151 pkgconfig=$(which pkg-config)
152 if [ -n "${pkgconfig}" -a -x "${pkgconfig}" ]; then
153 for file in ${pkgconfig_files}; do
154 # The dependency for the pkgconfig package itself.
155 echo "pkgconfig"
156
157 ${pkgconfig} --print-requires --print-requires-private "${file}" 2> /dev/null | while read n r v ; do
158 echo "pkgconfig(${n})" "${r}" "${v}"
159 done
160 done
161 fi
162
163 exit 0