-
Notifications
You must be signed in to change notification settings - Fork 7
/
build-and-install
executable file
·121 lines (97 loc) · 2.95 KB
/
build-and-install
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env bash
set -u -o pipefail
function usage {
echo "usage: ${BASH_SOURCE[0]} [-s] [-v] [-j <JOBS>]"
echo " -h, --help Display this help"
echo " -s, --sudo Install with sudo"
echo " -v, --verbose Log to the terminal"
echo " -j N Run at most N jobs in parallel"
echo " -u Don't install, uninstall"
}
opts=
if getopt -V | grep -q enhanced; then
opts=$(getopt -n ${BASH_SOURCE[0]} -o "j:uhsv" \
-l "jobs:,help,sudo,verbose" -- "$@")
else
opts=$(getopt "j:uhsv" $*)
fi
if [[ $? != 0 ]]; then usage; exit 1; fi
eval set -- "$opts"
makeflags=""
uninstall=false
use_sudo=false
verbose=false
while true; do
case "$1" in
-h|--help) usage; exit 0;;
-j|--jobs) makeflags="$makeflags -j $2"; shift 2;;
-u) uninstall=true; shift ;;
-s|--sudo) use_sudo=true; shift ;;
-v|--verbose) verbose=true ; shift ;;
--) shift; break ;;
*) echo "unexpected flag '$1'"; usage; exit 1 ;;
esac
done
if [[ $# -gt 0 ]]; then echo "unexpected arguments $@"; usage; exit 1; fi
source $(dirname -- "$0")/build-common.sh
root="$HERE";
cd "$root"
if $uninstall; then
rev_build_order=( )
for ((i=${#build_order[@]}-1; i>=0; i--)); do
rev_build_order+=( "${build_order[$i]}" )
done
build_order=( "${rev_build_order[@]}" )
fi
function maybe_sudo {
if $use_sudo; then sudo "$@"; else "$@"; fi
}
function maybe_verbose {
if $verbose; then "$@"; else
local ret=0
local output=''
output=$("$@" 2>&1)
ret=$?
if [[ $ret -ne 0 ]]; then
echo "$output"
return $ret
fi
fi
}
function findlibname {
local oasis=$1
local output=''
(grep 'FindlibParent:' "$oasis" \
|| grep 'FindlibName:' "$oasis") | head -1 | awk '{print $2}'
}
function die { echo "*** ERROR: $1"; exit 1; }
for dir in "${build_order[@]}"; do
echo "=> $dir"
pushd $dir >/dev/null
case $dir in
*-$core_version) ;; # no need to do anything for released packages
*) maybe_verbose ./oasis.sh || die "Error generating $dir/_oasis";;
esac
lib=$(findlibname '_oasis')
if [[ $? -ne 0 ]]; then
die "Couldn't figure out the library name from $dir/_oasis"
fi
if ocamlfind query "$lib" 2>/dev/null >/dev/null; then
echo " * uninstalling"
maybe_verbose maybe_sudo ocamlfind remove "$lib" \
|| die "Couldn't uninstall $lib"
fi
if ! $uninstall; then
echo " * configuring"
maybe_verbose ./configure \
|| die "Couldn't configure $lib"
echo " * compiling"
maybe_verbose make build BUILDFLAGS="$makeflags" \
|| die "Couldn't compile $lib"
echo " * installing"
maybe_verbose maybe_sudo make install \
|| die "Couldn't install $lib"
fi
popd >/dev/null
done
echo "All finished!"