Use NEEDED from objdump, not ldd, to auto-generate Requires:.
[platform/upstream/rpm.git] / autodeps / linux.req
1 #!/bin/bash
2
3 #
4 # Auto-generate requirements for executables (both ELF and a.out) and library
5 # sonames, script interpreters, and perl modules.
6 #
7
8 ulimit -c 0
9
10 #
11 # --- Set needed to 0 for traditional find-requires behavior.
12 if [ X"$1" = Xldd ]; then
13     needed=0
14 else
15     needed=1
16 fi
17
18 #
19 # --- Grab the file manifest and classify files.
20 filelist=`sed "s/['\"]/\\\&/g"`
21 exelist=`echo $filelist | xargs -r file | egrep -v ":.* (commands|script) " | \
22         grep ":.*executable" | cut -d: -f1`
23 scriptlist=`echo $filelist | xargs -r file | \
24         egrep ":.* (commands|script) " | cut -d: -f1`
25 liblist=`echo $filelist | xargs -r file | \
26         grep ":.*shared object" | cut -d : -f1`
27
28 interplist=
29 perllist=
30 pythonlist=
31 tcllist=
32
33 #
34 # --- Alpha does not mark 64bit dependencies
35 case `uname -m` in
36   alpha*)       mark64="" ;;
37   *)            mark64="()(64bit)" ;;
38 esac
39
40 if [ "$needed" -eq 0 ]; then
41 #
42 # --- Executable dependency sonames.
43   for f in $exelist; do
44     [ -r $f -a -x $f ] || continue
45     lib64=`if file -L $f 2>/dev/null | \
46         grep "ELF 64-bit" >/dev/null; then echo "$mark64"; fi`
47     ldd $f | awk '/=>/ {
48         if ($1 !~ /libNoVersion.so/ && $1 !~ /4[um]lib.so/ && $1 !~ /libredhat-kernel.so/) {
49             gsub(/'\''"/,"\\&",$1);
50             printf "%s'$lib64'\n", $1
51         }
52     }'
53   done | xargs -r -n 1 basename | sort -u
54
55 #
56 # --- Library dependency sonames.
57   for f in $liblist; do
58     [ -r $f ] || continue
59     lib64=`if file -L $f 2>/dev/null | \
60         grep "ELF 64-bit" >/dev/null; then echo "$mark64"; fi`
61     ldd $f | awk '/=>/ {
62         if ($1 !~ /libNoVersion.so/ && $1 !~ /4[um]lib.so/ && $1 !~ /libredhat-kernel.so/) {
63             gsub(/'\''"/,"\\&",$1);
64             printf "%s'$lib64'\n", $1
65         }
66     }'
67   done | xargs -r -n 1 basename | sort -u
68 fi
69
70 #
71 # --- Script interpreters.
72 for f in $scriptlist; do
73     [ -r $f -a -x $f ] || continue
74     interp=`head -1 $f | sed -e 's/^\#\![       ]*//' | cut -d" " -f1`
75     interplist="$interplist $interp"
76     case $interp in
77     */perl)     perllist="$perllist $f" ;;
78     esac
79 done
80 [ -n "$interplist" ] && { echo "$interplist" | tr '[:blank:]' \\n | sort -u ; }
81
82 #
83 # --- Add perl module files to perllist.
84 for f in $filelist; do
85     [ -r $f -a "${f%.pm}" != "${f}" ] && perllist="$perllist $f"
86 done
87
88 #
89 # --- Weak symbol versions (from glibc).
90 [ -n "$mark64" ] && mark64="(64bit)"
91 for f in $liblist $exelist ; do
92     [ -r $f ] || continue
93     lib64=`if file -L $f 2>/dev/null | \
94         grep "ELF 64-bit" >/dev/null; then echo "$mark64"; fi`
95     objdump -p $f | awk 'BEGIN { START=0; LIBNAME=""; needed='$needed'; }
96         /^$/ { START=0; }
97         /^Dynamic Section:$/ { START=1; }
98         (START==1) && /NEEDED/ {
99             if (needed) { print $2 ; }
100         }
101         /^Version References:$/ { START=2; }
102         (START==2) && /required from/ {
103             sub(/:/, "", $3);
104             LIBNAME=$3;
105         }
106         (START==2) && (LIBNAME!="") && ($4!="") && (($4~/^GLIBC_*/) || ($4~/^GCC_*/)) {
107             print LIBNAME "(" $4 ")'$lib64'";
108         }
109     '
110 done | sort -u
111
112 #
113 # --- Perl modules.
114 [ -x /usr/lib/rpm/perl.req -a -n "$perllist" ] && \
115     echo $perllist | tr '[:blank:]' \\n | /usr/lib/rpm/perl.req | sort -u
116
117 #
118 # --- Python modules.
119 [ -x /usr/lib/rpm/python.req -a -n "$pythonlist" ] && \
120     echo $pythonlist | tr '[:blank:]' \\n | /usr/lib/rpm/python.req | sort -u
121
122 #
123 # --- Tcl modules.
124 [ -x /usr/lib/rpm/tcl.req -a -n "$tcllist" ] && \
125     echo $tcllist | tr '[:blank:]' \\n | /usr/lib/rpm/tcl.req | sort -u
126
127 exit 0