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