Elliot Lee 03bb291
#!/bin/bash
Elliot Lee 03bb291
Elliot Lee 03bb291
#
Elliot Lee 03bb291
# Auto-generate requirements for executables (both ELF and a.out) and library
Elliot Lee 03bb291
# sonames, script interpreters, and perl modules.
Elliot Lee 03bb291
#
Elliot Lee 03bb291
Elliot Lee 03bb291
ulimit -c 0
Elliot Lee 03bb291
Elliot Lee 03bb291
#
Elliot Lee 03bb291
# --- Set needed to 0 for traditional find-requires behavior.
Elliot Lee 03bb291
needed=1
Elliot Lee 03bb291
if [ X"$1" = Xldd ]; then
Elliot Lee 03bb291
    needed=0
Elliot Lee 03bb291
elif [ X"$1" = Xobjdump ]; then
Elliot Lee 03bb291
    needed=1
Elliot Lee 03bb291
fi
Elliot Lee dce3663
[ -z "$OBJDUMP" ] && OBJDUMP=objdump
Elliot Lee 03bb291
Elliot Lee 03bb291
#
Elliot Lee 03bb291
# --- Grab the file manifest and classify files.
Elliot Lee f3e0116
#filelist=`sed "s/['\"]/\\\&/g"`
Elliot Lee f3e0116
filelist=`sed "s/[]['\"*?{}]/\\\\\&/g"`
Elliot Lee 03bb291
exelist=`echo $filelist | xargs -r file | egrep -v ":.* (commands|script) " | \
Elliot Lee 03bb291
	grep ":.*executable" | cut -d: -f1`
Elliot Lee 03bb291
scriptlist=`echo $filelist | xargs -r file | \
Elliot Lee 03bb291
	egrep ":.* (commands|script) " | cut -d: -f1`
Elliot Lee 03bb291
liblist=`echo $filelist | xargs -r file | \
Elliot Lee 03bb291
	grep ":.*shared object" | cut -d : -f1`
Elliot Lee 03bb291
Elliot Lee 03bb291
interplist=
Elliot Lee 03bb291
perllist=
Elliot Lee 03bb291
pythonlist=
Elliot Lee 03bb291
tcllist=
Elliot Lee 03bb291
Elliot Lee 03bb291
#
Elliot Lee 03bb291
# --- Alpha does not mark 64bit dependencies
Elliot Lee 03bb291
case `uname -m` in
Elliot Lee 03bb291
  alpha*)	mark64="" ;;
Elliot Lee 03bb291
  *)		mark64="()(64bit)" ;;
Elliot Lee 03bb291
esac
Elliot Lee 03bb291
Elliot Lee 03bb291
if [ "$needed" -eq 0 ]; then
Elliot Lee 03bb291
#
Elliot Lee 03bb291
# --- Executable dependency sonames.
Elliot Lee 03bb291
  for f in $exelist; do
Elliot Lee 03bb291
    [ -r $f -a -x $f ] || continue
Elliot Lee 03bb291
    lib64=`if file -L $f 2>/dev/null | \
Elliot Lee 03bb291
	grep "ELF 64-bit" >/dev/null; then echo "$mark64"; fi`
Elliot Lee 03bb291
    ldd $f | awk '/=>/ {
Elliot Lee 03bb291
	if ($1 !~ /libNoVersion.so/ && $1 !~ /4[um]lib.so/ && $1 !~ /libredhat-kernel.so/) {
Elliot Lee 03bb291
	    gsub(/'\''"/,"\\&",$1);
Elliot Lee 03bb291
	    printf "%s'$lib64'\n", $1
Elliot Lee 03bb291
	}
Elliot Lee 03bb291
    }'
Elliot Lee 03bb291
  done | xargs -r -n 1 basename | sort -u
Elliot Lee 03bb291
Elliot Lee 03bb291
#
Elliot Lee 03bb291
# --- Library dependency sonames.
Elliot Lee 03bb291
  for f in $liblist; do
Elliot Lee 03bb291
    [ -r $f ] || continue
Elliot Lee 03bb291
    lib64=`if file -L $f 2>/dev/null | \
Elliot Lee 03bb291
	grep "ELF 64-bit" >/dev/null; then echo "$mark64"; fi`
Elliot Lee 03bb291
    ldd $f | awk '/=>/ {
Elliot Lee 03bb291
	if ($1 !~ /libNoVersion.so/ && $1 !~ /4[um]lib.so/ && $1 !~ /libredhat-kernel.so/) {
Elliot Lee 03bb291
	    gsub(/'\''"/,"\\&",$1);
Elliot Lee 03bb291
	    printf "%s'$lib64'\n", $1
Elliot Lee 03bb291
	}
Elliot Lee 03bb291
    }'
Elliot Lee 03bb291
  done | xargs -r -n 1 basename | sort -u
Elliot Lee 03bb291
fi
Elliot Lee 03bb291
Elliot Lee 03bb291
#
Elliot Lee 03bb291
# --- Script interpreters.
Elliot Lee 03bb291
for f in $scriptlist; do
Elliot Lee 03bb291
    [ -r $f -a -x $f ] || continue
Elliot Lee 8617b2f
    interp=`head -n 1 $f | sed -e 's/^\#\![ 	]*//' | cut -d" " -f1`
Elliot Lee 03bb291
    interplist="$interplist $interp"
Elliot Lee 03bb291
    case $interp in
Elliot Lee 03bb291
    */perl)	perllist="$perllist $f" ;;
Elliot Lee 03bb291
    esac
Elliot Lee 03bb291
done
Elliot Lee 03bb291
[ -n "$interplist" ] && { echo "$interplist" | tr '[:blank:]' \\n | sort -u ; }
Elliot Lee 03bb291
Elliot Lee 03bb291
#
Elliot Lee 03bb291
# --- Add perl module files to perllist.
Elliot Lee 03bb291
for f in $filelist; do
Elliot Lee 03bb291
    [ -r $f -a "${f%.pm}" != "${f}" ] && perllist="$perllist $f"
Elliot Lee 03bb291
done
Elliot Lee 03bb291
Elliot Lee 03bb291
#
Elliot Lee 03bb291
# --- Weak symbol versions (from glibc).
Elliot Lee 03bb291
[ -n "$mark64" ] && mark64="(64bit)"
Elliot Lee 03bb291
for f in $liblist $exelist ; do
Elliot Lee 03bb291
    [ -r $f ] || continue
Elliot Lee 03bb291
    lib64=`if file -L $f 2>/dev/null | \
Elliot Lee 03bb291
	grep "ELF 64-bit" >/dev/null; then echo "$mark64"; fi`
Elliot Lee dce3663
    $OBJDUMP -p $f | awk 'BEGIN { START=0; LIBNAME=""; needed='$needed'; }
Elliot Lee 03bb291
	/^$/ { START=0; }
Elliot Lee 03bb291
	/^Dynamic Section:$/ { START=1; }
Elliot Lee 03bb291
	(START==1) && /NEEDED/ {
Elliot Lee 03bb291
	    if (needed) {
Elliot Lee 03bb291
		if ("'$lib64'" != "") {
Elliot Lee 03bb291
		    sub(/$/, "()'$lib64'", $2) ;
Elliot Lee 03bb291
		}
Elliot Lee 03bb291
		print $2 ;
Elliot Lee 03bb291
	    }
Elliot Lee 03bb291
	}
635437c
	(START==2) && /^[A-Za-z]/ { START=3; }
Elliot Lee 03bb291
	/^Version References:$/ { START=2; }
Elliot Lee 03bb291
	(START==2) && /required from/ {
Elliot Lee 03bb291
	    sub(/:/, "", $3);
Elliot Lee 03bb291
	    LIBNAME=$3;
Elliot Lee 03bb291
	}
Bill Nottingham 7a4e10b
	(START==2) && (LIBNAME!="") && ($4!="") {
Elliot Lee 03bb291
	    print LIBNAME "(" $4 ")'$lib64'";
Elliot Lee 03bb291
	}
Elliot Lee 03bb291
    '
Elliot Lee 03bb291
done | sort -u
Elliot Lee 03bb291
Elliot Lee 03bb291
#
Elliot Lee 03bb291
# --- Perl modules.
bda00a1
[ -x /usr/lib/rpm/perl.req -a -n "$perllist" ] && \
bda00a1
    echo $perllist | tr '[:blank:]' \\n | /usr/lib/rpm/perl.req | sort -u
Elliot Lee 03bb291
Elliot Lee 03bb291
#
Elliot Lee 03bb291
# --- Python modules.
Elliot Lee 03bb291
[ -x /usr/lib/rpm/redhat/python.req -a -n "$pythonlist" ] && \
Elliot Lee 03bb291
    echo $pythonlist | tr '[:blank:]' \\n | /usr/lib/rpm/redhat/python.req | sort -u
Elliot Lee 03bb291
Elliot Lee 03bb291
#
Elliot Lee 03bb291
# --- Tcl modules.
Elliot Lee 03bb291
[ -x /usr/lib/rpm/redhat/tcl.req -a -n "$tcllist" ] && \
Elliot Lee 03bb291
    echo $tcllist | tr '[:blank:]' \\n | /usr/lib/rpm/redhat/tcl.req | sort -u
Elliot Lee 03bb291
Jon Masters 97a3288
#
Jon Masters 97a3288
# --- Kernel module imported symbols
Jon Masters 97a3288
#
Jon Masters 97a3288
# Since we don't (yet) get passed the name of the package being built, we
Jon Masters 97a3288
# cheat a little here by looking first for a kernel, then for a kmod.
Jon Masters 97a3288
#
Jon Masters 97a3288
Jeremy Katz 48c39c9
unset is_kmod
Jeremy Katz 48c39c9
Jon Masters 97a3288
for f in $filelist; do
Jon Masters 97a3288
    if [ $(echo "$f" | sed -r -ne 's:^.*/lib/modules/(.*)/(.*).ko$:\2:p') ]
Jon Masters 97a3288
    then
Jeremy Katz 48c39c9
        is_kmod=1;
Jeremy Katz 48c39c9
    elif [ $(echo "$f" | sed -r -ne 's:^.*/boot/(.*):\1:p') ]
Jon Masters 97a3288
    then
Jeremy Katz 48c39c9
	unset is_kmod;
Jeremy Katz 48c39c9
	break;
Jon Masters 97a3288
    fi
Jon Masters 97a3288
done
Jon Masters 97a3288
Jon Masters 83405d7
# Disabling for now while the Fedora kernel doesn't produce kABI deps.
Jon Masters 83405d7
#[ -x /usr/lib/rpm/redhat/find-requires.ksyms ] && [ "$is_kmod" ] &&
Jon Masters 83405d7
#    printf "%s\n" "${filelist[@]}" | /usr/lib/rpm/redhat/find-requires.ksyms
Jon Masters 97a3288
Elliot Lee 03bb291
exit 0