-
Notifications
You must be signed in to change notification settings - Fork 1k
/
configure
executable file
·560 lines (493 loc) · 17.1 KB
/
configure
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
#!/bin/sh -e
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
# next steps:
# try running this, figure out what to do with the vars in the generated files
# in the bottom
# cd into this script’s directory
rootdir="$(cd "${0%/*}" 2>/dev/null; echo "$PWD")"
basename=`basename $0`
PACKAGE_AUTHOR_NAME="The Apache Software Foundation"
REBAR3_BRANCH="3.23.0"
ERLFMT_VERSION="v1.3.0"
# TEST=0
WITH_PROPER="true"
WITH_FAUXTON="true"
WITH_DOCS="true"
WITH_NOUVEAU="false"
WITH_CLOUSEAU="false"
ERLANG_MD5="false"
SKIP_DEPS="false"
WITH_SPIDERMONKEY="true"
run_erlang() {
erl -noshell -eval "$1" -eval "halt()."
}
COUCHDB_USER="$(whoami 2>/dev/null || echo couchdb)"
JS_ENGINE=${JS_ENGINE:-"spidermonkey"}
SM_VSN=${SM_VSN:-"91"}
CLOUSEAU_MTH=${CLOUSEAU_MTH:-"dist"}
CLOUSEAU_URI=${CLOUSEAU_URI:-"https://github.com/cloudant-labs/clouseau/releases/download/%s/clouseau-%s-dist.zip"}
CLOUSEAU_VSN=${CLOUSEAU_VSN:-"2.23.1"}
CLOUSEAU_DIR="$(pwd)"/clouseau
ARCH="$(uname -m)"
ERLANG_VER="$(run_erlang 'io:put_chars(erlang:system_info(otp_release)).')"
ERLANG_OS="$(run_erlang 'case os:type() of {OS, _} -> io:format("~s~n", [OS]) end.')"
display_help () {
cat << EOF
Usage: $basename [OPTION]
The $basename command is responsible for generating the build
system for Apache CouchDB.
Options:
-h | --help display a short help message and exit
-u | --user USER set the username to run as (defaults to $COUCHDB_USER)
--disable-fauxton do not build Fauxton
--disable-docs do not build any documentation or manpages
--with-nouveau build the new experimental search module
--with-clouseau build the Clouseau search module
--erlang-md5 use erlang for md5 hash operations
--dev alias for --disable-docs --disable-fauxton
--spidermonkey-version VSN specify the version of SpiderMonkey to use (defaults to $SM_VSN)
--clouseau-method MTH specify the method for Clouseau to deploy: git or dist (defaults to $CLOUSEAU_MTH)
--clouseau-uri URI specify the location for retrieving Clouseau (defaults $(printf "$CLOUSEAU_URI" "$CLOUSEAU_VSN" "$CLOUSEAU_VSN"))
--clouseau-version VSN specify the version (tag/branch for git) of Clouseau to use (defaults to $CLOUSEAU_VSN)
--skip-deps do not update erlang dependencies
--rebar=PATH use rebar by specified path (version >=2.6.0 && <3.0 required)
--rebar3=PATH use rebar3 by specified path
--erlfmt=PATH use erlfmt by specified path
--js-engine=ENGINE use js engine: spidermonkey or quickjs, defaults to spidermonkey
--disable-spidermonkey disable spidermonkey, don't try to build it
EOF
}
parse_opts() {
while :; do
case $1 in
-h|--help)
display_help
exit
;;
--without-proper)
WITH_PROPER="false"
shift
continue
;;
--disable-fauxton)
WITH_FAUXTON="false"
shift
continue
;;
--disable-docs)
WITH_DOCS="false"
shift
continue
;;
--with-nouveau)
WITH_NOUVEAU="true"
shift
continue
;;
--with-clouseau)
WITH_CLOUSEAU="true"
shift
continue
;;
--erlang-md5)
ERLANG_MD5="true"
shift
continue
;;
--dev)
WITH_DOCS="false"
WITH_FAUXTON="false"
shift
continue
;;
--dev-with-nouveau)
WITH_DOCS="false"
WITH_FAUXTON="false"
WITH_NOUVEAU="true"
shift
continue
;;
--skip-deps)
SKIP_DEPS="true"
shift
continue
;;
--rebar)
if [ -x "$2" ]; then
version=`$2 --version 2> /dev/null | grep -o "2\.[6-9]\.[0-9]"`
if [ $? -ne 0 ]; then
printf 'Rebar >=2.6.0 and <3.0.0 required' >&2
exit 1
fi
eval REBAR=$2
shift 2
continue
else
printf 'ERROR: "--rebar" requires valid path to executable.\n' >&2
exit 1
fi
;;
--rebar3)
if [ -x "$2" ]; then
eval REBAR3=$2
shift 2
continue
else
printf 'ERROR: "--rebar3" requires valid path to executable.\n' >&2
exit 1
fi
;;
--erlfmt)
if [ -x "$2" ]; then
eval ERLFMT=$2
shift 2
continue
else
printf 'ERROR: "--erlfmt" requires valid path to executable.\n' >&2
exit 1
fi
;;
--user|-u)
if [ -n "$2" ]; then
eval COUCHDB_USER=$2
shift 2
continue
else
printf 'ERROR: "--user" requires a non-empty argument.\n' >&2
exit 1
fi
;;
--user=?*)
eval COUCHDB_USER=${1#*=}
;;
--user=)
printf 'ERROR: "--user" requires a non-empty argument.\n' >&2
exit 1
;;
--spidermonkey-version)
if [ -n "$2" ]; then
eval SM_VSN=$2
shift 2
continue
else
printf 'ERROR: "--spidermonkey-version" requires a non-empty argument.\n' >&2
exit 1
fi
;;
--spidermonkey-version=?*)
eval SM_VSN=${1#*=}
;;
--spidermonkey-version=)
printf 'ERROR: "--spidermonkey-version" requires a non-empty argument.\n' >&2
exit 1
;;
--js-engine)
if [ -n "$2" ]; then
eval JS_ENGINE=$2
shift 2
continue
else
printf 'ERROR: "--js-engine" requires a non-empty argument.\n' >&2
exit 1
fi
;;
--js-engine=?*)
eval JS_ENGINE=${1#*=}
;;
--js-engine=)
printf 'ERROR: "--js-engine" requires a non-empty argument.\n' >&2
exit 1
;;
--disable-spidermonkey)
WITH_SPIDERMONKEY="false"
shift
continue
;;
--clouseau-version)
if [ -n "$2" ]; then
eval CLOUSEAU_VSN=$2
shift 2
continue
else
printf 'ERROR: "--clouseau-version" requires a non-empty argument.\n' >&2
exit 1
fi
;;
--clouseau-version=?*)
eval CLOUSEAU_VSN=${1#*=}
;;
--clouseau-version=)
printf 'ERROR: "--clouseau-version" requires a non-empty argument.\n' >&2
exit 1
;;
--clouseau-method)
if [ -n "$2" ]; then
eval CLOUSEAU_MTH=$2
shift 2
continue
else
printf 'ERROR: "--clouseau-method" requires a non-empty argument.\n' >&2
exit 1
fi
;;
--clouseau-method=?*)
eval CLOUSEAU_MTH=${1#*=}
;;
--clouseau-method=)
printf 'ERROR: "--clouseau-method" requires a non-empty argument.\n' >&2
exit 1
;;
--clouseau-uri)
if [ -n "$2" ]; then
eval CLOUSEAU_URI=$2
shift 2
continue
else
printf 'ERROR: "--clouseau-uri" requires a non-empty argument.\n' >&2
exit 1
fi
;;
--clouseau-uri=?*)
eval CLOUSEAU_URI=${1#*=}
;;
--clouseau-uri=)
printf 'ERROR: "--clouseau-uri" requires a non-empty argument.\n' >&2
exit 1
;;
--) # End of options
shift
break
;;
-?*)
echo "WARNING: Unknown option '$1', ignoring" >&2
shift
;;
*) # Done
break
esac
shift
done
}
parse_opts $@
if [ "${WITH_SPIDERMONKEY}" = "true" ] && [ "${ARCH}" = "aarch64" ] && [ "${SM_VSN}" = "60" ]; then
echo "ERROR: SpiderMonkey 60 is known broken on ARM 64 (aarch64). Use another version instead."
exit 1
fi
if [ "${WITH_SPIDERMONKEY}" = "true" ] && [ "${ERLANG_OS}" = "unix" ]; then
case "${SM_VSN}" in
1.8.5)
SM_HEADERS="js"
;;
*) SM_HEADERS="mozjs-${SM_VSN}"
;;
esac
# This list is taken from src/couch/rebar.config.script, please keep them in sync.
if [ ! -d "/usr/include/${SM_HEADERS}" ] && \
[ ! -d "/usr/local/include/${SM_HEADERS}" ] && \
[ ! -d "/opt/homebrew/include/${SM_HEADERS}" ]; then
echo "ERROR: SpiderMonkey ${SM_VSN} is not found. Please specify with --spidermonkey-version."
exit 1
fi
fi
# If spidermonkey was disabled but JS_ENGINE set to "spidermonkey", reset it to "quickjs"
if [ "${WITH_SPIDERMONKEY}" = "false" ] && [ "${JS_ENGINE}" = "spidermonkey" ]; then
echo "NOTICE: Spidermonkey was disabled, but JS_ENGINE=spidermonkey. Setting JS_ENGINE=quickjs"
JS_ENGINE="quickjs"
fi
# If we're in a release tarball and we don't have proper, then mark it as skipped
if [ ! -d .git ] && [ "$WITH_PROPER" = "true" ] && [ ! -d src/proper ]; then
WITH_PROPER="false"
fi
# If we're in a release tarball and we don't have spidermonkey, then mark it as skipped and enable quickjs
if [ ! -d .git ] && [ "$WITH_SPIDERMONKEY" = "true" ] && [ ! -d src/couch/priv/couch_js ]; then
echo "NOTICE: Spidermonkey was disabled in release tarball. Setting JS_ENGINE=quickjs"
WITH_SPIDERMONKEY="false"
JS_ENGINE="quickjs"
fi
echo "==> configuring couchdb in rel/couchdb.config"
cat > rel/couchdb.config << EOF
% Licensed under the Apache License, Version 2.0 (the "License"); you may not
% use this file except in compliance with the License. You may obtain a copy of
% the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
% License for the specific language governing permissions and limitations under
% the License.
%
% The contents of this file are auto-generated by configure
%
{package_author_name, "$PACKAGE_AUTHOR_NAME"}.
{prefix, "."}.
{data_dir, "./data"}.
{view_index_dir, "./data"}.
{nouveau_index_dir, "./data/nouveau"}.
{nouveau_url, "http://127.0.0.1:5987"}.
{nouveau_port, 5987}.
{nouveau_admin_port, 5988}.
{state_dir, "./data"}.
{log_file, "$LOG_FILE"}.
{fauxton_root, "./share/www"}.
{user, "$COUCHDB_USER"}.
{js_engine, "$JS_ENGINE"}.
{spidermonkey_version, "$SM_VSN"}.
{with_spidermonkey, $WITH_SPIDERMONKEY}.
{node_name, "-name [email protected]"}.
{cluster_port, 5984}.
{backend_port, 5986}.
{prometheus_port, 17986}.
EOF
cat > install.mk << EOF
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# The contents of this file are auto-generated by configure
#
package_author_name = $PACKAGE_AUTHOR_NAME
with_fauxton = $WITH_FAUXTON
with_docs = $WITH_DOCS
with_nouveau = $WITH_NOUVEAU
with_clouseau = $WITH_CLOUSEAU
user = $COUCHDB_USER
js_engine = $JS_ENGINE
spidermonkey_version = $SM_VSN
with_spidermonkey = $WITH_SPIDERMONKEY
EOF
cat > $rootdir/config.erl << EOF
{with_proper, $WITH_PROPER}.
{erlang_md5, $ERLANG_MD5}.
{js_engine, "$JS_ENGINE"}.
{spidermonkey_version, "$SM_VSN"}.
{with_spidermonkey, $WITH_SPIDERMONKEY}.
EOF
install_local_rebar() {
if [ ! -x "${rootdir}/bin/rebar" ]; then
if [ ! -d "${rootdir}/src/rebar" ]; then
git clone --depth 1 https://github.com/apache/couchdb-rebar.git ${rootdir}/src/rebar
fi
make -C ${rootdir}/src/rebar
mv ${rootdir}/src/rebar/rebar ${rootdir}/bin/rebar
make -C ${rootdir}/src/rebar clean
fi
}
install_local_rebar3() {
if [ ! -x "${rootdir}/bin/rebar3" ]; then
if [ ! -d "${rootdir}/src/rebar3" ]; then
git clone --depth 1 --branch ${REBAR3_BRANCH} https://github.com/erlang/rebar3.git ${rootdir}/src/rebar3
fi
cd src/rebar3
./bootstrap
mv ${rootdir}/src/rebar3/rebar3 ${rootdir}/bin/rebar3
cd ../..
fi
}
install_local_erlfmt() {
if [ ! -x "${rootdir}/bin/erlfmt" ]; then
if [ ! -d "${rootdir}/src/erlfmt" ]; then
git clone --depth 1 --branch "${ERLFMT_VERSION}" https://github.com/WhatsApp/erlfmt.git ${rootdir}/src/erlfmt
fi
cd "${rootdir}"/src/erlfmt
${REBAR3} as release escriptize
mv ${rootdir}/src/erlfmt/_build/release/bin/erlfmt ${rootdir}/bin/erlfmt
${REBAR3} clean
cd ../..
fi
}
check_local_clouseau_dir() {
_dir="$1"
if [ -e "$_dir" ]; then
printf "ERROR: \"%s\" already exists. Please remove or move it away first.\n" "$_dir" >&2
exit 1
fi
}
fetch_file() {
_file_name="$1"
_file_url="$2"
if ! curl -sSL --max-redirs 1 -o "$_file_name" "$_file_url"; then
printf "ERROR: %s could not be downloaded.\n" "$_file_url" >&2
exit 1
fi
}
install_local_clouseau() {
case "$CLOUSEAU_MTH" in
dist)
_DIST_URL=$(printf "$CLOUSEAU_URI" "$CLOUSEAU_VSN" "$CLOUSEAU_VSN")
_MAVEN_BASE_URI=https://repo1.maven.org/maven2
_LOGBACK_DIST_URL="$_MAVEN_BASE_URI"/ch/qos/logback
: "${LOGBACK_VERSION:=1.2.13}"
_LOGBACK_CORE_JAR=logback-core-"$LOGBACK_VERSION".jar
_LOGBACK_CORE_URL="$_LOGBACK_DIST_URL"/logback-core/"$LOGBACK_VERSION"/"$_LOGBACK_CORE_JAR"
_LOGBACK_CLASSIC_JAR=logback-classic-"$LOGBACK_VERSION".jar
_LOGBACK_CLASSIC_URL="$_LOGBACK_DIST_URL"/logback-classic/"$LOGBACK_VERSION"/"$_LOGBACK_CLASSIC_JAR"
check_local_clouseau_dir "$CLOUSEAU_DIR"
mkdir -p "$CLOUSEAU_DIR"
echo "Fetching Clouseau from $_DIST_URL..."
fetch_file clouseau.zip "$_DIST_URL"
if ! unzip -q -j clouseau.zip -d "$CLOUSEAU_DIR"; then
printf "ERROR: Clouseau distribution package (clouseau.zip) could not be extracted.\n" >&2
exit 1
fi
rm clouseau.zip
echo "Fetching Logback $LOGBACK_VERSION from $_LOGBACK_DIST_URL..."
fetch_file "$CLOUSEAU_DIR"/"$_LOGBACK_CORE_JAR" "$_LOGBACK_CORE_URL"
fetch_file "$CLOUSEAU_DIR"/"$_LOGBACK_CLASSIC_JAR" "$_LOGBACK_CLASSIC_URL"
;;
git)
echo "Cloning Clouseau from $CLOUSEAU_URI ($CLOUSEAU_VSN)..."
check_local_clouseau_dir "$CLOUSEAU_DIR"
git clone --depth 1 --branch "$CLOUSEAU_VSN" "$CLOUSEAU_URI" "$CLOUSEAU_DIR"
;;
*) printf "ERROR: Invalid deployment method for Clouseau. Please use either \`dist\` or \`git\` verbatim.\n" >&2
exit 1
esac
}
if [ -z "${REBAR}" ]; then
install_local_rebar
REBAR=${rootdir}/bin/rebar
fi
if [ -z "${REBAR3}" ]; then
install_local_rebar3
REBAR3=${rootdir}/bin/rebar3
fi
if [ -z "${ERLFMT}" ]; then
install_local_erlfmt
ERLFMT=${rootdir}/bin/erlfmt
fi
if [ "$WITH_CLOUSEAU" = "true" ]; then
install_local_clouseau
fi
# only update dependencies, when we are not in a release tarball
if [ -d .git ] && [ "$SKIP_DEPS" = "false" ]; then
echo "==> updating dependencies"
${REBAR} get-deps update-deps
fi
# External repos frequently become integrated with the primary repo,
# resulting in obsolete .git directories, and possible confusion.
# It is usually a good idea to delete these .git directories.
for path in $(find src -name .git -type d); do
git ls-files --error-unmatch $(dirname $path) > /dev/null 2>&1 && \
echo "WARNING unexpected .git directory $path"
done
echo "You have configured Apache CouchDB, time to relax. Relax."