2010-09-30 02:21:16 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# find rpm provides and requires for Haskell GHC libraries
|
|
|
|
|
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
|
|
|
|
2013-09-10 03:42:26 +00:00
|
|
|
set +x
|
2013-09-09 14:17:35 +00:00
|
|
|
|
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-//)
|
|
|
|
|
2014-10-23 06:48:27 +00:00
|
|
|
# for a ghc build use the new ghc-pkg
|
|
|
|
INPLACE_GHCPKG=$PKGBASEDIR/../../bin/ghc-pkg-$GHC_VER
|
|
|
|
|
|
|
|
if [ -x "$INPLACE_GHCPKG" ]; then
|
|
|
|
case $GHC_VER in
|
|
|
|
7.8.*)
|
|
|
|
GHC_PKG="$PKGBASEDIR/bin/ghc-pkg --global-package-db=$PKGCONFDIR"
|
|
|
|
;;
|
|
|
|
7.6.*)
|
|
|
|
GHC_PKG="$PKGBASEDIR/ghc-pkg --global-package-db=$PKGCONFDIR"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
GHC_PKG="$PKGBASEDIR/ghc-pkg --global-conf=$PKGCONFDIR"
|
|
|
|
;;
|
|
|
|
esac
|
2011-10-18 08:43:47 +00:00
|
|
|
else
|
2013-09-10 03:42:26 +00:00
|
|
|
GHC_PKG="/usr/bin/ghc-pkg-${GHC_VER}"
|
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
|
|
|
|
2010-09-30 02:21:16 +00:00
|
|
|
files=$(cat)
|
|
|
|
|
2011-01-23 05:05:38 +00:00
|
|
|
for i in $files; do
|
2013-09-07 13:08:03 +00:00
|
|
|
LIB_FILE=$(echo $i | grep /libHS | egrep -v "/libHSrts")
|
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
|
2013-09-09 14:17:35 +00:00
|
|
|
BIN_DEPS=$(objdump -p $i | grep NEEDED | grep libHS | grep -v libHSrts | sed -e "s%^ *NEEDED *libHS\(.*\)-ghc${GHC_VER}.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-19 11:00:54 +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
|