aboutsummaryrefslogtreecommitdiffstats
path: root/find-requires.in
blob: c56c2e129eb264219a944552103ba599b810479e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash

#
# Auto-generate requirements for ELF executables and library
# sonames, script interpreters, and perl modules.
#

ulimit -c 0

# fix parsing output of objdump when localized (mga#7883):
export LC_ALL=C

#
# --- Set needed to 0 for traditional find-requires behavior.
needed=1
if [ X"$3" = Xldd ]; then
    needed=0
elif [ X"$3" = Xobjdump ]; then
    needed=1
fi

# --- Mageia specific part
case "$LD_PRELOAD" in
    *libfakeroot*)
	unset LD_PRELOAD
	;;
esac

RPM_BUILD_ROOT=$1
RPM_ARCH=$2

if [ -n "$RPM_BUILD_ROOT" ]; then
    lib_path_64=$RPM_BUILD_ROOT/usr/X11R6/lib64:$RPM_BUILD_ROOT/usr/lib64:$RPM_BUILD_ROOT/lib64
    lib_path_32=$RPM_BUILD_ROOT/usr/X11R6/lib:$RPM_BUILD_ROOT/usr/lib:$RPM_BUILD_ROOT/lib
    LD_LIBRARY_PATH=$lib_path_64:$lib_path_32
    export LD_LIBRARY_PATH
fi


#
filelist=`sed "s/[]['\"*?{}]/\\\\\&/g"`

rubygemlist=`echo "$filelist"| egrep "\.gemspec$"`

#
# --- If libperl.so exists and if XS modules are found, depend on perlapi-<version> and libperl.so
if [ -n "$perllist" ]; then
    if perl -V:useshrplib | grep -q true ; then
	if echo $perllist | grep -q `perl -MConfig -e 'print $Config{archname}'` ; then
            version=`perl -MConfig -e 'print $Config{version}'`
            echo perlapi-$version

	    f=`perl -MConfig -e 'print $Config{archlib}'`/CORE/libperl.so
	    lib64=`if file -L $f 2>/dev/null | \
		grep "ELF 64-bit" >/dev/null; then echo "()$mark64"; fi`
	    echo libperl.so$lib64
	fi
    fi
fi

[ -x /usr/lib/rpm/rpmdeps -a -n "$filelist" ] && \
	echo $filelist | tr '[:blank:]' \\n | /usr/lib/rpm/rpmdeps --requires

#
# --- typelib() gobject-introspection bindings
[ -x @RPMVENDORDIR@/gi-find-deps.sh ] &&
    echo "$filelist" | tr '[:blank:]' \\n | @RPMVENDORDIR@/gi-find-deps.sh -R | sort -u \
        && test ${PIPESTATUS[2]} -ne 0 && echo 'error: @RPMVENDORDIR@/gi-find-deps.sh failed' >&2 && exit 1

#
# --- Ruby gems
[ -x /usr/bin/ruby -a -x @RPMVENDORDIR@/rubygems.rb -a -n "$rubygemlist" ] &&
    echo $rubygemlist | tr '[:blank:]' \\n | @RPMVENDORDIR@/rubygems.rb --requires | sort -u \
    	&& test ${PIPESTATUS[2]} -ne 0 && echo 'error: @RPMVENDORDIR@/rubygems.rb failed' >&2 && exit 1

#
# --- .so files.
for i in `echo $filelist | tr '[:blank:]' "\n" | egrep "(/usr(/X11R6)?)?/lib(|64)/[^/]+\.so$"`; do
    objd=`objdump -p ${i} | grep SONAME`
    lib64=`if file -L $i 2>/dev/null | grep "ELF 64-bit" >/dev/null; then echo "(64bit)"; fi` && \
    if [ -h ${i} -a -n "${objd}" ]; then
      if [ "$needed" -eq 0 ]; then
       ldd ${i} \
       | grep -v "statically linked" \
       | grep -v "/\(lib\|lib64\)/\(ld\|ld64\|ld-linux.*\)\.so" \
       | perl -p -e "s/\s+(\S+)\.so.*/devel(\1$lib64)/g"
      else
       objdump -p $i | grep -v "\(ld\|ld64\|ld-linux.*\)\.so" \
                     | awk 'BEGIN { START=0; }
       /^$/ { START=0; }
       /^Dynamic Section:$/ { START=1; }
       (START==1) && /NEEDED/ {
           sub(/^/, "devel(", $2) ;
           sub(/\.so.*$/, "'$lib64')", $2) ;
           print $2 ;
       }
       '
      fi
    fi
done | egrep -v 'devel\(linux-gate|linux-vdso32|linux-vdso64|lib(c|pthread|rt)(\(64bit\))?\)' | sort -u

#
# --- multiarch-utils
echo $filelist |  tr '[:blank:]' '\n' | grep -q '/multiarch-.*-linux/' && echo multiarch-utils

#
# haskell requires
if [ -x /usr/bin/haskell-find-requires ]; then
echo $filelist | tr '[:blank:]' '\n' | /usr/bin/haskell-find-requires \
    	&& test ${PIPESTATUS[2]} -ne 0 && echo 'error: /usr/bin/haskell-find-requires failed' >&2 && exit 1
fi

exit 0