ghc/cabal2spec

62 lines
1.6 KiB
Plaintext
Raw Normal View History

#!/bin/sh
set -e
[ $# -ne 1 -o ! -r "$1" ] && echo "Usage: $(basename $0) [hackage.tar.gz|hackage.cabal]" && exit 1
FILE=$1
case $FILE in
*.tar.gz)
TARNAME_VER=$(basename $FILE .tar.gz)
TARVERSION=$(echo $TARNAME_VER | sed -e "s/.*-//")
TARNAME=$(echo $TARNAME_VER | sed -e "s/-$TARVERSION//")
WORKDIR=$(mktemp -d)
tar zxf $FILE -C $WORKDIR "*.cabal"
CABAL="$WORKDIR/*/*.cabal" ;;
*.cabal)
CABAL=$FILE ;;
esac
NAME=$(grep -i ^name: $CABAL | sed -e "s/[Nn]ame:[ \t]*//")
if [ -n "$TARNAME" -a "$TARNAME" != "$NAME" ]; then
echo "Warning: tarball name ($TARNAME) and cabal name ($NAME) differ!"
fi
VERSION=$(grep -i ^version: $CABAL | sed -e "s/[Vv]ersion:[ \t]*//")
if [ -n "$TARVERSION" -a "$TARVERSION" != "$VERSION" ]; then
echo "Warning: tarball version ($TARVERSION) and cabal version ($VERSION) differ!"
fi
CABALFILENAME=$(basename $CABAL .cabal)
if [ "$CABALFILENAME" != "$NAME" ]; then
echo "Warning: .cabal filename ($CABALFILENAME) and cabal Name field ($NAME) differ!"
fi
if grep -qi exposed-modules: $CABAL; then
HAS_LIB=yes
fi
if grep -qi executable $CABAL; then
HAS_BIN=yes
fi
[ -d "$WORKDIR" ] && rm -r $WORKDIR
if [ "$HAS_LIB" -a ! "$HAS_BIN" ]; then
PREFIX=ghc-
fi
SPECFILE=$PREFIX$NAME.spec
2008-11-25 15:40:11 +00:00
[ -r "$SPECFILE" ] && echo "$SPECFILE already exists!" && exit 1
cp /usr/share/ghc/cabal-${HAS_BIN:+bin}${HAS_LIB:+lib}-template.spec.in $SPECFILE
echo "created $SPECFILE (${HAS_BIN:+bin}${HAS_LIB:+lib}) for $NAME-$VERSION"
DATE=$(env LANG=C date +"%a %b %e %Y")
sed -i -e "s/@PACKAGE@/$NAME/" -e "s/@GHC_VERSION@/$(ghc --numeric-version)/" -e "s/@VERSION@/$VERSION/" -e "s/@DATE@/$DATE/" $SPECFILE