348 lines
7.6 KiB
Bash
Executable File
348 lines
7.6 KiB
Bash
Executable File
#!/bin/sh -ef
|
|
#
|
|
# $Id$
|
|
# Copyright (C) 2000-2005 Dmitry V. Levin <ldv@altlinux.org>
|
|
#
|
|
# find-requires - generate list of linux-specific package requires.
|
|
# Inspired by tool with same name from RPM distribution.
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, write to the Free Software
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
#
|
|
|
|
[ -z "$RPM_SCRIPTS_DEBUG" ] || set -x
|
|
|
|
PROG="${0##*/}"
|
|
|
|
exit_handler()
|
|
{
|
|
local rc=$?
|
|
trap - EXIT
|
|
cat >/dev/null 2>&1
|
|
exit $rc
|
|
}
|
|
|
|
trap exit_handler EXIT
|
|
|
|
# If using normal root, avoid changing anything.
|
|
if [ -z "$(printf %s "$RPM_BUILD_ROOT" |tr -d ' /.')" ]; then
|
|
echo "$PROG: non-/ RPM_BUILD_ROOT expected" >&2
|
|
exit 1
|
|
fi
|
|
|
|
FIND_FILES=
|
|
FIND_LIBS=
|
|
FIND_PAM=
|
|
FIND_PERL=
|
|
FIND_PYTHON=
|
|
FIND_LIBPERL=
|
|
FIND_SHELL=
|
|
FIND_TCL=
|
|
libperl_so=
|
|
|
|
ParseMethod()
|
|
{
|
|
local t
|
|
for t in "$@"; do
|
|
case "${t/%,}" in
|
|
no|none|off|false)
|
|
FIND_FILES=
|
|
FIND_LIBS=
|
|
FIND_PAM=
|
|
FIND_PERL=
|
|
FIND_PYTHON=
|
|
FIND_LIBPERL=
|
|
FIND_SHELL=
|
|
FIND_TCL=
|
|
;;
|
|
lib|library)
|
|
FIND_LIBS=1
|
|
;;
|
|
libperl)
|
|
FIND_LIBPERL=1
|
|
;;
|
|
nolib|nolibrary)
|
|
FIND_LIBS=
|
|
;;
|
|
nolibperl)
|
|
FIND_LIBPERL=
|
|
;;
|
|
files)
|
|
FIND_FILES=1
|
|
;;
|
|
nofiles)
|
|
FIND_FILES=
|
|
;;
|
|
pam)
|
|
FIND_PAM=1
|
|
;;
|
|
nopam)
|
|
FIND_PAM=
|
|
;;
|
|
perl)
|
|
FIND_PERL=1
|
|
FIND_LIBPERL=1
|
|
;;
|
|
noperl)
|
|
FIND_PERL=
|
|
FIND_LIBPERL=
|
|
;;
|
|
python)
|
|
FIND_PYTHON=1
|
|
;;
|
|
nopython)
|
|
FIND_PYTHON=
|
|
;;
|
|
sh|shell)
|
|
FIND_SHELL=1
|
|
;;
|
|
nosh|noshell)
|
|
FIND_SHELL=
|
|
;;
|
|
tcl)
|
|
FIND_TCL=1
|
|
;;
|
|
notcl)
|
|
FIND_TCL=
|
|
;;
|
|
all)
|
|
FIND_FILES=1
|
|
FIND_LIBS=1
|
|
FIND_PAM=1
|
|
FIND_PYTHON=1
|
|
FIND_PERL=1
|
|
FIND_LIBPERL=1
|
|
FIND_SHELL=1
|
|
FIND_TCL=1
|
|
;;
|
|
default|yes|true)
|
|
ParseMethod $RPM_FINDREQ_DEFAULT_METHOD
|
|
;;
|
|
*)
|
|
echo "Unrecognized find-requires method: $t" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
}
|
|
ParseMethod $RPM_FINDREQ_METHOD
|
|
|
|
FIND_SCRIPT=
|
|
if [ -n "$FIND_PAM" -o -n "$FIND_PERL" -o -n "$FIND_SHELL" -o -n "$FIND_TCL" ]; then
|
|
FIND_SCRIPT=1
|
|
fi
|
|
|
|
if [ -z "$FIND_LIBS" -a -z "$FIND_SCRIPT" -a -z "$FIND_FILES" ]; then
|
|
# Nothing to do
|
|
exit
|
|
fi
|
|
|
|
if [ -n "$*" ]; then
|
|
# We do not handle arguments yet...
|
|
exit
|
|
fi
|
|
|
|
. @RPMCONFIGDIR@/find-package
|
|
|
|
ulimit -c 0
|
|
|
|
case "$LD_PRELOAD" in
|
|
*libfakeroot*)
|
|
unset LD_PRELOAD
|
|
;;
|
|
*libbuildreq.so*)
|
|
unset LD_PRELOAD
|
|
;;
|
|
esac
|
|
|
|
FOUND_REQS=
|
|
LIST_PERL=
|
|
LIST_PYTHON=
|
|
LIST_TCL=
|
|
|
|
ListScriptReqs()
|
|
{
|
|
[ -n "$FIND_SCRIPT" ] || return 0
|
|
|
|
local f t
|
|
f="$1"
|
|
t="$2"
|
|
if [ -x "$f" ]; then
|
|
local r
|
|
r="$(FindPackage "$f" "$(head -1 "$f" |sed -n 's|^#![[:space:]]*\(/[^[:space:]]\+\).*|\1|p')")" || return 1
|
|
[ -z "$FOUND_REQS" ] && FOUND_REQS="$r" || FOUND_REQS="$FOUND_REQS
|
|
$r"
|
|
fi
|
|
if [ -z "${t##*Bourne* shell script text*}" ]; then
|
|
if [ -n "$FIND_SHELL" -a -x "$f" ]; then
|
|
local r
|
|
r="$(@RPMCONFIGDIR@/shell.req "$f")" || return 1
|
|
[ -z "$FOUND_REQS" ] && FOUND_REQS="$r" || FOUND_REQS="$FOUND_REQS
|
|
$r"
|
|
fi
|
|
elif [ -z "${t##ASCII *text*}" -a -z "${f%%$RPM_BUILD_ROOT/etc/pam.d/*}" ]; then
|
|
if [ -n "$FIND_PAM" ]; then
|
|
local r
|
|
r="$(@RPMCONFIGDIR@/pam.req "$f")" || return 1
|
|
[ -z "$FOUND_REQS" ] && FOUND_REQS="$r" || FOUND_REQS="$FOUND_REQS
|
|
$r"
|
|
fi
|
|
elif [ -z "${t##*perl script text*}" -o -z "${f%%*.p[lmh]}" ]; then
|
|
if [ -n "$FIND_PERL" ]; then
|
|
[ -z "$LIST_PERL" ] && LIST_PERL="$f" || LIST_PERL="$LIST_PERL
|
|
$f"
|
|
fi
|
|
elif [ -z "${f%%*.py}" ]; then
|
|
if [ -n "$FIND_PYTHON" ]; then
|
|
[ -z "$LIST_PYTHON" ] && LIST_PYTHON="$f" || LIST_PYTHON="$LIST_PYTHON
|
|
$f"
|
|
fi
|
|
elif [ -z "${f%%*.tcl}" ]; then
|
|
if [ -n "$FIND_TCL" ]; then
|
|
[ -z "$LIST_TCL" ] && LIST_TCL="$f" || LIST_TCL="$LIST_TCL
|
|
$f"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
FindPerlReqs()
|
|
{
|
|
[ -n "$LIST_PERL" ] || return 0
|
|
|
|
local r
|
|
r="$(printf %s\\n "$LIST_PERL" |@RPMCONFIGDIR@/perl.req)" || return 1
|
|
[ -z "$FOUND_REQS" ] && FOUND_REQS="$r" || FOUND_REQS="$FOUND_REQS
|
|
$r"
|
|
}
|
|
|
|
FindPythonReqs()
|
|
{
|
|
[ -n "$LIST_PYTHON" ] || return 0
|
|
[ -x "$RPM_PYTHON" ] || return 0
|
|
|
|
local r
|
|
r="$(printf %s\\n "$LIST_PYTHON" |"$RPM_PYTHON" @RPMCONFIGDIR@/python.req.py)" || return 1
|
|
[ -z "$FOUND_REQS" ] && FOUND_REQS="$r" || FOUND_REQS="$FOUND_REQS
|
|
$r"
|
|
}
|
|
|
|
FindTclReqs()
|
|
{
|
|
[ -n "$LIST_TCL" ] || return 0
|
|
[ -x "$RPM_TCLSH" ] || return 0
|
|
|
|
local r
|
|
r="$(printf %s\\n "$LIST_TCL" |@RPMCONFIGDIR@/tcl.req)" || return 1
|
|
[ -z "$FOUND_REQS" ] && FOUND_REQS="$r" || FOUND_REQS="$FOUND_REQS
|
|
$r"
|
|
}
|
|
|
|
# Note this works for both a.out and ELF executables.
|
|
# It also auto-generates requirements for scripts.
|
|
|
|
FindLibReqs()
|
|
{
|
|
[ -n "$FIND_LIBS" ] || return 0
|
|
|
|
local f d braces= suffix=
|
|
f="$1"
|
|
|
|
if d="$(objdump -p "$f")"; then
|
|
# Shared library dependencies, glibc version references.
|
|
suffix="$(printf %s\\n "$d" |sed -ne 's/^.*file format \(elf64\).*$/(64bit)/p')" || return 1
|
|
[ -z "$suffix" ] || braces='()'
|
|
printf %s\\n "$d" |awk "-vsuffix=$suffix" "-vbraces=$braces" '
|
|
BEGIN {start_shared=0; start_version=0; lib_name="";}
|
|
/^($)/ {start_shared=0; start_version=0; lib_name=""; next;}
|
|
/^private/ {start_shared=0; start_version=0; lib_name=""; next;}
|
|
/^Dynamic Section:$/ {start_shared=1; next;}
|
|
/^Version References:$/ {start_version=1; next;}
|
|
(start_version==1) && /^ *required from/ {sub(/:/, "", $3); lib_name=$3; next;}
|
|
(start_shared==1) && /^ *NEEDED/ {print $2 braces suffix; next;}
|
|
(start_version==1) && (lib_name!="") && ($4!="") {print lib_name "(" $4 ")" suffix;}
|
|
'
|
|
if [ -n "$FIND_LIBPERL" -a -z "$libperl_so" -a -z "${f##*/usr/lib/perl?/*/auto/*.so}" ]; then
|
|
libperl_so=`perl -MConfig -e 'print "$Config{libperl}\n"'`
|
|
printf %s\\n "$libperl_so$braces$suffix"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
FindExeReqs()
|
|
{
|
|
if [ -x "$1" ]; then
|
|
FindLibReqs "$1"
|
|
fi
|
|
}
|
|
|
|
if [ -n "$RPM_SUBPACKAGE_NAME" ]; then
|
|
if [ -n "${RPM_SUBPACKAGE_NAME%%glibc*}" -a -z "${RPM_SUBPACKAGE_NAME##*-devel-static}" ]; then
|
|
FOUND_REQS=glibc-devel-static
|
|
fi
|
|
fi
|
|
|
|
: ${RPM_FINDREQ_TOPDIR:=}
|
|
: ${RPM_FINDREQ_SKIPLIST:=}
|
|
|
|
while IFS= read -r f; do
|
|
fname="${f#$RPM_BUILD_ROOT}"
|
|
fname="${fname#.}"
|
|
|
|
if [ -n "$RPM_FINDREQ_TOPDIR" ] && [ -z "${fname%%$RPM_FINDREQ_TOPDIR/*}" ]; then
|
|
continue;
|
|
fi
|
|
if [ -n "$RPM_FINDREQ_SKIPLIST" ]; then
|
|
for skip in $RPM_FINDREQ_SKIPLIST; do
|
|
if [ -z "${fname##$skip}" ]; then
|
|
continue 2
|
|
fi
|
|
done
|
|
fi
|
|
if [ -n "$FIND_FILES" ]; then
|
|
for p in $(grep '^[^#]' @RPMCONFIGDIR@/files.req.list); do
|
|
if [ -z "${fname%%$p/*}" ]; then
|
|
[ -z "$FOUND_REQS" ] && FOUND_REQS="$p" || FOUND_REQS="$FOUND_REQS
|
|
$p"
|
|
break
|
|
fi
|
|
done
|
|
fi
|
|
t="$(file -b "$f")"
|
|
if [ -z "${t##* text*}" ]; then
|
|
ListScriptReqs "$f" "$t"
|
|
elif [ -z "${t##* executable*}" ]; then
|
|
r="$(FindExeReqs "$f")"
|
|
[ -z "$FOUND_REQS" ] && FOUND_REQS="$r" || FOUND_REQS="$FOUND_REQS
|
|
$r"
|
|
elif [ -z "${t##* shared object*}" ]; then
|
|
r="$(FindLibReqs "$f")"
|
|
[ -z "$FOUND_REQS" ] && FOUND_REQS="$r" || FOUND_REQS="$FOUND_REQS
|
|
$r"
|
|
[ -z "$LIST_PYTHON" ] && LIST_PYTHON="$f" || LIST_PYTHON="$LIST_PYTHON
|
|
$f"
|
|
fi
|
|
done
|
|
|
|
# Find requires in listed perl scripts, if any
|
|
FindPerlReqs
|
|
|
|
# Find requires in listed python scripts, if any
|
|
FindPythonReqs
|
|
|
|
# Find requires in listed tcl scripts, if any
|
|
FindTclReqs
|
|
|
|
# Finally sort and print them.
|
|
printf %s "$FOUND_REQS" |LC_COLLATE=C sort -u
|