-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinstall-tree-sitter-lib
executable file
·84 lines (72 loc) · 2.26 KB
/
install-tree-sitter-lib
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
#! /usr/bin/env bash
#
# Install the libtree-sitter runtime library.
#
set -eu -o pipefail
prog_name=$(basename "$0")
# Installation root for the tree-sitter executable and runtime library
default_prefix=$(pwd)/tree-sitter
error() {
echo "Current directory: $(pwd)" >&2
echo "Error: $@" >&2
exit 1
}
usage() {
cat <<EOF
Compile the tree-sitter library and install it.
Usage: $prog_name [OPTIONS]
Options:
--help
Show this message and exit.
--prefix PATH
Global installation directory for tree-sitter executables and libraries.
Default: $default_prefix
EOF
}
prefix="$default_prefix"
while [[ $# -gt 0 ]]; do
case "$1" in
--help)
usage
exit 0
;;
--prefix)
prefix="$2"
shift
;;
*)
error "Invalid argument passed to '${prog_name}': '$1'"
esac
shift
done
libdir="$prefix"/lib
dir_name=$(dirname "$BASH_SOURCE")
"$dir_name"/update-version-symlinks
"$dir_name"/download-tree-sitter --lazy
# We use tree-sitter's Makefile to build the tree-sitter library. It
# uses the $(CC), $(AR), and $(STRIP) Make variables to find
# (respectfully) the C compiler, ar, and strip tools. These tools may
# be prefixed by the target triplet in case of cross-compilation, as
# in x86_64-w64-mingw32-gcc. The Makefile cannot discover these
# prefixed tools, they have to be passed as variables or through the
# environment. As we're building an OCaml library, and opam is likely
# installed, ask opam which C compiler is used by the OCaml toolchain
# installed in the current opam switch. Guess the complete name of the
# ar and strip tool from the C compiler name. Users invoking this
# script can always set $CC, $AR, and $STRIP as environment variables.
if [[ -z "${CC:-}" ]]; then
CC=$(opam var sys-ocaml-cc 2>/dev/null || \
opam exec -- ocamlc -config-var c_compiler 2>/dev/null || \
opam exec -- ocamlopt -config-var c_compiler 2>/dev/null)
fi
: ${AR:=${CC:+$(printf "%s" "$CC" | sed -E 's/(-?)[^-]*$/\1ar/')}}
: ${STRIP:=${CC:+$(printf "%s" "$CC" | sed -E 's/(-?)[^-]*$/\1strip/')}}
(
cd downloads/tree-sitter
make PREFIX="$prefix" ${CC:+CC=$CC} ${AR:+AR=$AR} ${STRIP:+STRIP=$STRIP}
make install PREFIX="$prefix" ${CC:+CC=$CC}
)
cat <<EOF
tree-sitter libraries were installed in:
$prefix/lib/
EOF