ghc/cabal2spec
Jens Petersen b17255a641 - add support for bin and binlib packages to cabal2spec script and only
grep .cabal files for exposed-module/executable
- output bin and/or lib status too
2008-11-25 09:15:17 +00:00

44 lines
917 B
Bash
Executable File

#!/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