2010-09-30 02:21:16 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# find rpm provides and requires for Haskell GHC libraries
|
|
|
|
|
|
|
|
# To use add the following lines to spec file:
|
|
|
|
# %define _use_internal_dependency_generator 0
|
2011-05-09 04:59:58 +00:00
|
|
|
# %define __find_requires /usr/lib/rpm/ghc-deps.sh --requires %{buildroot}%{ghclibdir}
|
|
|
|
# %define __find_provides /usr/lib/rpm/ghc-deps.sh --provides %{buildroot}%{ghclibdir}
|
2010-09-30 02:21:16 +00:00
|
|
|
|
2011-05-09 04:59:58 +00:00
|
|
|
[ $# -ne 2 ] && echo "Usage: `basename $0` [--provides|--requires] %{buildroot}%{ghclibdir}" && exit 1
|
2010-09-30 02:21:16 +00:00
|
|
|
|
|
|
|
MODE=$1
|
2010-11-23 05:01:27 +00:00
|
|
|
PKGBASEDIR=$2
|
|
|
|
PKGCONFDIR=$PKGBASEDIR/package.conf.d
|
2011-10-18 08:43:47 +00:00
|
|
|
GHC_VER=$(basename $PKGBASEDIR | sed -e s/ghc-//)
|
|
|
|
|
|
|
|
if [ ! -x "/usr/bin/ghc-pkg-${GHC_VER}" -a -x "$PKGBASEDIR/ghc-pkg" ]; then
|
|
|
|
GHC_PKG="$PKGBASEDIR/ghc-pkg --global-conf=$PKGCONFDIR"
|
|
|
|
else
|
2012-06-08 05:00:43 +00:00
|
|
|
GHC_PKG="/usr/bin/ghc-pkg"
|
2011-10-18 08:43:47 +00:00
|
|
|
fi
|
2010-09-30 02:21:16 +00:00
|
|
|
|
2010-11-23 13:48:16 +00:00
|
|
|
case $MODE in
|
|
|
|
--provides) FIELD=id ;;
|
|
|
|
--requires) FIELD=depends ;;
|
|
|
|
*) echo "`basename $0`: Need --provides or --requires" ; exit 1
|
|
|
|
esac
|
|
|
|
|
2011-03-28 06:57:59 +00:00
|
|
|
if [ -d "$PKGBASEDIR" ]; then
|
|
|
|
SHARED=$(find $PKGBASEDIR -type f -name '*.so')
|
|
|
|
fi
|
2011-02-10 12:11:02 +00:00
|
|
|
|
2011-01-23 05:05:38 +00:00
|
|
|
GHCVERSION=$(ghc --numeric-version)
|
|
|
|
|
2010-09-30 02:21:16 +00:00
|
|
|
files=$(cat)
|
|
|
|
|
2010-11-23 05:01:27 +00:00
|
|
|
#set -x
|
2010-09-30 02:21:16 +00:00
|
|
|
|
2011-01-23 05:05:38 +00:00
|
|
|
for i in $files; do
|
2011-02-10 12:11:02 +00:00
|
|
|
LIB_FILE=$(echo $i | grep /libHS | egrep -v "$PKGBASEDIR/libHS")
|
2011-05-08 14:09:07 +00:00
|
|
|
if [ "$LIB_FILE" ]; then
|
2011-02-10 12:11:02 +00:00
|
|
|
if [ -d "$PKGCONFDIR" ]; then
|
|
|
|
META=""
|
|
|
|
SELF=""
|
|
|
|
case $LIB_FILE in
|
|
|
|
*.so) META=ghc ;;
|
|
|
|
*.a) META=ghc-devel
|
2011-05-08 14:09:07 +00:00
|
|
|
if [ "$SHARED" ]; then
|
2011-02-10 12:11:02 +00:00
|
|
|
SELF=ghc
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
2011-05-08 14:09:07 +00:00
|
|
|
if [ "$META" ]; then
|
2011-02-10 12:11:02 +00:00
|
|
|
PKGVER=$(echo $LIB_FILE | sed -e "s%$PKGBASEDIR/\([^/]\+\)/libHS.*%\1%")
|
2011-10-18 08:43:47 +00:00
|
|
|
HASHS=$(${GHC_PKG} -f $PKGCONFDIR field $PKGVER $FIELD | sed -e "s/^$FIELD: \+//")
|
2011-02-10 12:11:02 +00:00
|
|
|
for i in $HASHS; do
|
|
|
|
case $i in
|
2012-03-21 08:41:59 +00:00
|
|
|
*-*) echo "$META($i)" ;;
|
2011-02-10 12:11:02 +00:00
|
|
|
*) ;;
|
|
|
|
esac
|
|
|
|
done
|
2011-05-08 14:09:07 +00:00
|
|
|
if [ "$MODE" = "--requires" -a "$SELF" ]; then
|
2011-10-18 08:43:47 +00:00
|
|
|
HASHS=$(${GHC_PKG} -f $PKGCONFDIR field $PKGVER id | sed -e "s/^id: \+//")
|
2011-02-10 12:11:02 +00:00
|
|
|
for i in $HASHS; do
|
2012-03-21 08:41:59 +00:00
|
|
|
echo "$SELF($i)"
|
2011-02-10 12:11:02 +00:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
elif [ "$MODE" = "--requires" ]; then
|
|
|
|
if file $i | grep -q 'executable, .* dynamically linked'; then
|
|
|
|
BIN_DEPS=$(ldd $i | grep libHS | grep -v libHSrts | sed -e "s%^\\tlibHS\(.*\)-ghc${GHCVERSION}.so =.*%\1%")
|
2012-06-09 13:00:32 +00:00
|
|
|
if [ -d "$PKGCONFDIR" ]; then
|
|
|
|
PACKAGE_CONF_OPT="--package-conf=$PKGCONFDIR"
|
|
|
|
fi
|
2011-02-10 12:11:02 +00:00
|
|
|
for p in ${BIN_DEPS}; do
|
2012-09-20 03:10:07 +00:00
|
|
|
HASH=$(${GHC_PKG} --global $PACKAGE_CONF_OPT field $p id | sed -e "s/^id: \+//" | uniq)
|
2012-03-21 08:41:59 +00:00
|
|
|
echo "ghc($HASH)"
|
2011-02-10 12:11:02 +00:00
|
|
|
done
|
|
|
|
fi
|
2010-11-23 05:01:27 +00:00
|
|
|
fi
|
2011-01-23 05:05:38 +00:00
|
|
|
done
|
2010-09-30 02:21:16 +00:00
|
|
|
|
|
|
|
echo $files | tr [:blank:] '\n' | /usr/lib/rpm/rpmdeps $MODE
|