-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
58 lines (49 loc) · 1.38 KB
/
install.sh
File metadata and controls
58 lines (49 loc) · 1.38 KB
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
#!/usr/bin/env bash
# Script for system-wide coffee installation
export COFFEE_ROOT=${COFFEE_ROOT:-$HOME/.coffee}
ROOT=$(dirname $0)
SRC_DIR="$ROOT/src/"
# Feel free to customize c compiler at your needs
CC="${CC:-cc}"
C_FLAGS="${C_FLAGS:- -Wall -O2}"
install-lib() {
echo " . Installing standard libraries"
pushd "$SRC_DIR" >/dev/null
# Cleanup std directory
rm -rf "${COFFEE_ROOT}/lib/"*
find std -name '*.bn' -not -name '*.test.bn' \
-exec bash -c 'mkdir -p $(dirname "${COFFEE_ROOT}/lib/{}") && cp "{}" "${COFFEE_ROOT}/lib/{}"' \;
popd >/dev/null
return 0
}
install-coffee() {
echo " . Building coffee"
llc "$SRC_DIR/coffee.ll" -o coffee.s || return 1
cc $CFLAGS coffee.s -o coffee || return 1
rm coffee.s
mv coffee "$COFFEE_ROOT/bin"
return 0
}
_main() {
# Create installation directory structure
mkdir -p "$COFFEE_ROOT/bin" "$COFFEE_ROOT/lib"
install-lib
install-coffee || warn-installation-failure
[[ -z "$(which coffee)" ]] && warn-coffee-not-in-path
echo " ☕ coffee is ready!"
}
warn-coffee-not-in-path() {
echo ""
echo ""
echo "WARNING: seems like '$COFFEE_ROOT/bin' is not in \$PATH. Add the following to your shell init file:"
echo ""
echo " export PATH=\"\$PATH:$COFFEE_ROOT/bin\""
echo ""
echo "Thanks <3"
echo ""
}
warn-installation-failure() {
echo "Installation interrupted"
exit 1
}
_main