Avoid common shell scripting pitfalls
authorDavid Luposchainsky <dluposchainsky@gmail.com>
Mon, 21 Dec 2015 12:46:03 +0000 (13:46 +0100)
committerDavid Luposchainsky <dluposchainsky@gmail.com>
Wed, 23 Dec 2015 14:03:49 +0000 (15:03 +0100)
- Get bash from $PATH instead of reading it from /bin/bash (useful for e.g. NixOS)
- set -euo pipefail: "strict bash mode"
- Quote all paths to be whitespace compatible
- GHC uses --make mode automatically

build.sh

index d350779..1918cdd 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -1,6 +1,22 @@
-#!/bin/bash -e
+#!/usr/bin/env bash
 
-root=`dirname $0`
-mkdir -p $root/.shake
-ghc --make -Wall $root/src/Main.hs -i$root/src -rtsopts -with-rtsopts=-I0 -outputdir=$root/.shake -o $root/.shake/build
-$root/.shake/build --lint --directory $root/.. $@
+set -euo pipefail
+
+root="$(dirname "$0")"
+
+mkdir -p "$root/.shake"
+
+ghc                           \
+    "$root/src/Main.hs"       \
+    -Wall                     \
+    -i"$root/src"             \
+    -rtsopts                  \
+    -with-rtsopts=-I0         \
+    -outputdir="$root/.shake" \
+    -o "$root/.shake/build"
+
+"$root/.shake/build"       \
+    --lint                 \
+    --directory "$root/.." \
+    --colour               \
+    "$@"