-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfigure
More file actions
executable file
·226 lines (188 loc) · 6.54 KB
/
configure
File metadata and controls
executable file
·226 lines (188 loc) · 6.54 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/bin/sh
set -eu # to debug this script add '-x'
###############################################################################
# Prelude
###############################################################################
# The goal of this script is to automate the configuration and installation
# of packages that are needed to then compile and install syncweb itself.
# coupling: adapted from ~/github/codegraph/configure
SYNCWEB_ONLY=false
for arg in "$@"; do
case "$arg" in
--syncweb-only) SYNCWEB_ONLY=true ;;
--help|-h)
echo "Usage: ./configure [--syncweb-only]"
echo ""
echo " --syncweb-only Build only syncweb (no lpizer/indexer)."
echo " Skips semgrep-pfff-langs and tree-sitter setup."
exit 0 ;;
*) echo "Unknown option: $arg"; exit 1 ;;
esac
done
###############################################################################
# Helper functions
###############################################################################
ok() { echo " [OK] $1"; }
warn() { echo " [WARN] $1"; }
err() { echo " [ERR] $1" >&2; }
errors=0
need_command() {
if command -v "$1" >/dev/null 2>&1; then
ok "$1 ($(command -v "$1"))"
else
err "$1 not found in PATH"
errors=$((errors + 1))
fi
}
want_command() {
if command -v "$1" >/dev/null 2>&1; then
ok "$1 ($(command -v "$1"))"
else
warn "$1 not found — $2"
fi
}
check_c_lib() {
local name pkg header search_dirs dir
name="$1"
pkg="$2"
header="$3"
if command -v pkg-config >/dev/null 2>&1 \
&& pkg-config --exists "$pkg" 2>/dev/null; then
ok "$name (pkg-config: $pkg)"
return 0
fi
search_dirs="/usr/include /usr/local/include"
if command -v brew >/dev/null 2>&1; then
search_dirs="$search_dirs $(brew --prefix 2>/dev/null)/include"
fi
for dir in $search_dirs; do
if [ -f "$dir/$header" ]; then
ok "$name (header: $dir/$header)"
return 0
fi
done
err "$name not found (pkg-config module '$pkg', header '$header')"
errors=$((errors + 1))
}
# On macOS, extend PKG_CONFIG_PATH for Homebrew
if command -v brew >/dev/null 2>&1; then
_brew_prefix="$(brew --prefix 2>/dev/null || true)"
if [ -n "$_brew_prefix" ]; then
PKG_CONFIG_PATH="${_brew_prefix}/lib/pkgconfig:${PKG_CONFIG_PATH:-}"
export PKG_CONFIG_PATH
fi
fi
###############################################################################
# Check required tools
###############################################################################
echo "Checking required tools..."
need_command ocaml
need_command opam
need_command make
need_command git
_cc_found=false
for _cc_candidate in ${CC:-} cc gcc clang; do
if command -v "$_cc_candidate" >/dev/null 2>&1; then
ok "C compiler ($_cc_candidate -> $(command -v "$_cc_candidate"))"
_cc_found=true
break
fi
done
if ! $_cc_found; then
err "No C compiler found (tried cc, gcc, clang). Install one or set \$CC."
errors=$((errors + 1))
fi
if ! $SYNCWEB_ONLY; then
need_command curl
want_command pkg-config "tree-sitter will be built from source"
# Detect system tree-sitter early
_ts_required="0.20"
_ts_found=false
if command -v pkg-config >/dev/null 2>&1 \
&& pkg-config --exists tree-sitter 2>/dev/null \
&& pkg-config --atleast-version="$_ts_required" tree-sitter 2>/dev/null; then
_ts_found=true
fi
if ! $_ts_found; then
want_command autoconf "required to build tree-sitter from source"
want_command automake "required to build tree-sitter from source"
fi
fi
echo ""
###############################################################################
# Check git submodules
###############################################################################
echo "Checking git submodules..."
if [ -d "semgrep-pfff-libs/TCB" ]; then
ok "semgrep-pfff-libs (initialized)"
else
err "semgrep-pfff-libs is empty; run: git submodule update --init --recursive"
errors=$((errors + 1))
fi
if ! $SYNCWEB_ONLY; then
if [ -f "semgrep-pfff-langs/parsing_infra/ocaml-tree-sitter-core/configure" ]; then
ok "semgrep-pfff-langs (initialized, including ocaml-tree-sitter-core)"
else
err "semgrep-pfff-langs is empty or ocaml-tree-sitter-core not initialized; run: git submodule update --init --recursive"
errors=$((errors + 1))
fi
fi
echo ""
if [ "$errors" -ne 0 ]; then
echo "$errors error(s) found. Please fix the issues above and re-run ./configure."
exit 1
fi
###############################################################################
# Setup
###############################################################################
# Initialize submodules. Skipped when not in a git repo (e.g., Docker COPY).
if git rev-parse --git-dir >/dev/null 2>&1; then
echo "Initializing git submodules..."
if $SYNCWEB_ONLY; then
git submodule update --init semgrep-pfff-libs
else
git submodule update --init --recursive
fi
fi
if ! $SYNCWEB_ONLY; then
# Configure tree-sitter C library (uses system lib if available, else builds from source)
echo "Setting up tree-sitter..."
./semgrep-pfff-langs/scripts/setup-tree-sitter.sh
fi
# Install OCaml dependencies.
echo "Installing opam dependencies..."
if $SYNCWEB_ONLY; then
opam install --confirm-level=unsafe-yes --deps-only -y ./syncweb.opam
else
opam install --confirm-level=unsafe-yes --deps-only -y ./syncweb.opam ./lpizer.opam
fi
echo ""
###############################################################################
# Verify C libraries
###############################################################################
if ! $SYNCWEB_ONLY; then
echo "Verifying C libraries..."
check_c_lib "PCRE" "libpcre" "pcre.h"
check_c_lib "PCRE2" "libpcre2-8" "pcre2.h"
check_c_lib "GMP" "gmp" "gmp.h"
check_c_lib "libev" "libev" "ev.h"
check_c_lib "libcurl" "libcurl" "curl/curl.h"
if $_ts_found; then
ok "tree-sitter (pkg-config: $(pkg-config --modversion tree-sitter))"
else
warn "tree-sitter >= $_ts_required not found — will be compiled from source"
fi
if [ "$errors" -ne 0 ]; then
echo "$errors C librar(ies) missing after setup. Please install them."
exit 1
fi
fi
echo ''
echo 'Everything looks fine. You can now run: '
echo ''
if $SYNCWEB_ONLY; then
echo ' $ make syncweb-only'
else
echo ' $ make'
echo ' $ make install'
fi