You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ghc/cabal2spec

44 lines
921 B

#!/bin/sh
set -e
[ $# -ne 1 -o ! -r "$1" ] && echo "Usage: $0 hackage-version.tar.gz" && exit 1
HACKAGE=$1
INPUT=$(basename $HACKAGE .tar.gz)
VERSION=$(echo $INPUT | sed -e "s/.*-//")
NAME=$(echo $INPUT | sed -e "s/-$VERSION//")
TMPDIR=$(mktemp -d)
CURRENT_DIR=$PWD
cd $TMPDIR
tar zxf $HACKAGE "*.cabal"
if grep -qi exposed-modules: */*.cabal; then
HAS_LIB=yes
fi
if grep -qi executable */*.cabal; then
HAS_BIN=yes
fi
cd -
rm -rf $TMPDIR
if [ "$HAS_LIB" -a ! "$HAS_BIN" ]; then
PREFIX=ghc-
fi
SPECFILE=$PREFIX$NAME.spec
[ -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})"
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