-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild-app.sh
executable file
·74 lines (64 loc) · 1.5 KB
/
build-app.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
set -e
apps="cxs"
sandbox=""
profiling=""
only_app=""
usage () {
echo "Usage: $0 [-p] [-o APP]"
echo "Options:"
echo " -p build with profiling turned on"
echo " -o APP only build app APP"
echo " -s use sandbox instead of new-build"
exit $1
}
while getopts "hpo:s" opt; do
case $opt in
h) usage && exit 0;;
p) profiling=1;;
o) only_app=$OPTARG;;
s) sandbox=1;;
*) usage && exit 1;;
esac
done
shift $((OPTIND-1))
if [[ $sandbox ]]; then
build="install"
app_dir=".cabal-sandbox/bin"
if [[ ! -d ".cabal-sandbox" ]]; then
echo "no sandbox! try \"cabal sandbox init\"?"
exit 1
fi
else
build="new-build"
app_dir="dist-newstyle"
fi
if [ $only_app ]; then
if ! perl -E "exit 1 unless \"$apps\" =~ \"$only_app\""; then
echo "error: unknown program \"$only_app\""
echo "supported programs: $apps"
exit 1
fi
apps=$only_app
fi
for app in $apps; do
echo -en '\e[0;32m'
echo "building $app"
echo -en '\e[0m'
if [ $profiling ]; then
cabal $build $app --enable-profiling --profiling-detail=all-functions
else
cabal $build $app
fi
done
for app in $apps; do
exe=$(find dist-newstyle -name $app -type f | head -n1)
if [ ! "$exe" ]; then
echo "error: no binary in build directory ($app_dir)"
exit 1
fi
echo -en '\e[0;32m'
echo "created executable $app"
echo -en '\e[0m'
cp $exe $app
done