-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·175 lines (157 loc) · 4.79 KB
/
build.sh
File metadata and controls
executable file
·175 lines (157 loc) · 4.79 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/env bash
set -o errexit -o pipefail -o noclobber -o nounset
PWD="$(pwd)"
PROJECT_DIR_NAME="flow"
# Ensure we work from the project base dir to avoid
# weird mounting behaviour when running container
case "$(basename "$PWD")" in
"$PROJECT_DIR_NAME") ;;
*)
echo "[ERROR] This script must be run from the $PROJECT_DIR_NAME directory, not $PWD"
exit 1
;;
esac
# Ignore errexit with `&& true`
getopt --test > /dev/null && true
if [[ $? -ne 4 ]]; then
echo '[ERROR] getopt invocation failed.'
exit 1
fi
function printHelp() {
echo "Usage: ./build.sh [<options>]"
echo "Options:"
echo " -h | --help Print this help message"
echo " -r | --rebuild Build dependencies and executable (default: false)"
}
# Note that options with a ':' require an argument
LONGOPTS=help,rebuild
OPTIONS=hr
# 1. Temporarily store output to be able to check for errors
# 2. Activate quoting/enhanced mode (e.g. by writing out “--options”)
# 3. Pass arguments only via -- "$@" to separate them correctly
# 4. If getopt fails, it complains itself to stdout
PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@") || exit 2
# Read getopt’s output this way to handle the quoting right:
eval set -- "$PARSED"
rebuild=0
# Handle options in order and nicely split until we see --
while true; do
case "$1" in
-h|--help)
printHelp
exit 1
;;
-r|--rebuild)
rebuild=1
shift
;;
--)
shift
break
;;
*)
echo "[ERROR] Unknown option encountered: $1"
exit 3
;;
esac
done
static_lib_extension="a"
case "$OSTYPE" in
darwin*)
static_lib_extension="a"
;;
linux*|mysys*|cygwin*|bsd*)
static_lib_extension="a"
;;
*)
echo "[ERROR] Unsupported OS: $OSTYPE"
exit 1
;;
esac
libs_dir="$(pwd)/lib"
include_dir="$(pwd)/include"
# TODO: Stop building these libs, and make them Zig modules
function build_piece_chain() {
pushd external/PieceChain
echo "[INFO] Initialising cmake"
cmake .
echo "[INFO] Building PieceChain static library"
make
echo "[INFO] Installing libraries and headers into project"
local __libs_dir="$libs_dir/piece_chain"
local __include_dir="$include_dir/PieceChain"
mkdir -p "$__libs_dir"
mkdir -p "$__include_dir"
cp "libPieceChain.$static_lib_extension" "$__libs_dir/."
cp "include/PieceChain/PieceChain.h" "$__include_dir/."
popd
}
function build_librope() {
pushd external/librope
echo "[INFO] Removing forced x86_64 build in Makefile"
if [[ "$OSTYPE" == darwin* ]]; then
gsed -i -z -E 's/ifeq \(\$\(UNAME\), Darwin\)\nCFLAGS := \$\(CFLAGS\) \-arch x86_64\nendif\n//g' Makefile
else
sed -i -z -E 's/ifeq \(\$\(UNAME\), Darwin\)\nCFLAGS := \$\(CFLAGS\) \-arch x86_64\nendif\n//g' Makefile
fi
echo "[INFO] Building static library"
make clean all
echo "[INFO] Installing libraries and header into project"
local __libs_dir="$libs_dir/rope"
local __include_dir="$include_dir/rope"
mkdir -p "$__libs_dir"
mkdir -p "$__include_dir"
cp "librope.$static_lib_extension" "$__libs_dir/."
cp "rope.h" "$__include_dir/."
popd
}
function build_notcurses() {
pushd external/notcurses
echo "[INFO] Creating build output directory"
rm -rf build
mkdir -p build
pushd build
echo "[INFO] Initialising cmake"
cmake -DCMAKE_BUILD_TYPE=Release \
-DBUILD_TESTING=OFF \
-DBUILD_EXECUTABLES=OFF \
-DBUILD_FFI_LIBRARY=ON \
-DUSE_DOCTEST=OFF \
-DUSE_PANDOC=OFF \
-DUSE_CXX=OFF \
-DUSE_POC=OFF \
-DUSE_DOXYGEN=OFF \
-DUSE_MULTIMEDIA=none \
..
echo "[INFO] Building notcurses libraries"
make notcurses-core-static notcurses-static
echo "[INFO] Installing libraries and headers into project"
local __libs_dir="$libs_dir/notcurses"
local __include_dir="$include_dir/notcurses"
mkdir -p "$__libs_dir"
mkdir -p "$__include_dir"
cp *.a "$__libs_dir/."
cp -r ../include/notcurses/ "$__include_dir/."
cp include/version.h "$__include_dir/."
popd
popd
}
function build_tree_sitter {
pushd external/tree-sitter
echo "[INFO] Building static library"
make "libtree-sitter.$static_lib_extension"
echo "[INFO] Install libraries and headers into project"
local __libs_dir="$libs_dir/tree_sitter"
mkdir -p "$__libs_dir"
cp "libtree-sitter.$static_lib_extension" "$__libs_dir/."
cp -r lib/include/tree_sitter "$include_dir/."
popd
}
if [ $rebuild -eq 1 ]; then
build_piece_chain
build_librope
build_notcurses
build_tree_sitter
fi
echo "[INFO] Building executable"
zig build