summaryrefslogtreecommitdiffstats
path: root/tools/ghc-rpm-macros/cabal-tweak-flag
diff options
context:
space:
mode:
authorJens Petersen <petersen@redhat.com>2014-02-11 22:06:01 +0900
committerJens Petersen <petersen@redhat.com>2014-02-11 22:06:01 +0900
commit3f80e38a43b3cfb328490259c15418ab51c774c1 (patch)
tree083d6cb556f41b64308d1b4a9a1f904590af8302 /tools/ghc-rpm-macros/cabal-tweak-flag
parent02714f7f0c6fc2abc45fa4332c69f0645e327502 (diff)
downloadpandoc-standalone-3f80e38a43b3cfb328490259c15418ab51c774c1.tar.gz
pandoc-standalone-3f80e38a43b3cfb328490259c15418ab51c774c1.tar.xz
pandoc-standalone-3f80e38a43b3cfb328490259c15418ab51c774c1.zip
tools: import spec files of all packages needed to build pandoc
Diffstat (limited to 'tools/ghc-rpm-macros/cabal-tweak-flag')
-rwxr-xr-xtools/ghc-rpm-macros/cabal-tweak-flag50
1 files changed, 50 insertions, 0 deletions
diff --git a/tools/ghc-rpm-macros/cabal-tweak-flag b/tools/ghc-rpm-macros/cabal-tweak-flag
new file mode 100755
index 0000000..2db3a72
--- /dev/null
+++ b/tools/ghc-rpm-macros/cabal-tweak-flag
@@ -0,0 +1,50 @@
+#!/bin/sh
+
+# TODO:
+# support setting flag when no upstream default
+
+set -e +x
+
+USAGE="Usage: $0 FLAG [True|False]"
+
+if [ $# -ne 2 ]; then
+ echo "$USAGE"
+ exit 1
+fi
+
+FLAG=$1
+
+NEW=$2
+case $NEW in
+ True) OLD=False ;;
+ False) OLD=True ;;
+ *) echo "Flag value can only be set to True or False" ; exit 1 ;;
+esac
+
+CABALFILE=$(ls *.cabal)
+
+if [ $(echo $CABALFILE | wc -w) -ne 1 ]; then
+ echo "There needs to be one .cabal file in the current dir!"
+ exit 1
+fi
+
+if ! grep -q -i "^flag *$FLAG" $CABALFILE; then
+ echo "$CABALFILE does have flag $FLAG"
+ exit 1
+fi
+
+if ! grep -A3 -i "^flag *$FLAG" $CABALFILE | grep -q -i "default:"; then
+ echo "$CABALFILE: $FLAG flag might not have a default"
+ exit 1
+fi
+
+if ! grep -A3 -i "^flag *$FLAG" $CABALFILE | grep -q -i "default: *$OLD"; then
+ echo "$CABALFILE: $FLAG flag already defaults to $NEW"
+ exit 1
+fi
+
+if [ ! -f $CABALFILE.orig ]; then
+ BACKUP=.orig
+fi
+
+sed -i$BACKUP -e "/[Ff]lag *$FLAG/,/[Dd]efault: *$OLD/ s/\([Dd]efault: *\)$OLD/\1$NEW/" $CABALFILE