Skip to content

Instantly share code, notes, and snippets.

@hvr
Last active December 21, 2017 08:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hvr/c77c54d682555b7dd4fe1248732fe978 to your computer and use it in GitHub Desktop.
Save hvr/c77c54d682555b7dd4fe1248732fe978 to your computer and use it in GitHub Desktop.
simple shell script emulating "cabal new-install-exe"
#!/bin/bash
set -e
PKG=$1
EXE=$2
DIR="$3"
if [ "$#" != 3 ]; then
echo "usage: $0 <pkg-name> <exe-name> <bin-target-folder>"
echo ""
echo "(example invocation: $0 hlint hlint ~/bin )"
exit 1
fi
if [ ! -d "$DIR" ]; then
echo "target folder '$DIR' not found"
exit 1
fi
if [ -e "$DIR/$EXE" ]; then
echo "'$DIR/$EXE' exists already - remove it and then call me again"
echo ""
ls -l "$DIR/$EXE"
exit 1
fi
# this needs `cabal-plan:exe:cabal-plan` in PATH
type cabal-plan
type cabal
TMPDIR=$(mktemp -d)
cd $TMPDIR
# todo: add support for version constraints?
cat > dummypkg.cabal <<EOF
name: dummypkg
version: 0
build-type: Simple
cabal-version: >=2.0
library
default-language: Haskell2010
build-tool-depends: ${PKG}:${EXE}
--
EOF
cabal new-build lib:dummypkg
EXEBIN=$(cabal-plan list-bin | awk "\$1 == \"${PKG}:exe:${EXE}\" { print \$2 }")
if [ -x "$EXEBIN" ]; then
cp -sfv "$EXEBIN" "$DIR"
else
echo "*ERROR* couldn't find ${PKG}:exe:${EXE}"
echo ""
cabal-plan list-bin
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment