-
Notifications
You must be signed in to change notification settings - Fork 80
/
node-build
executable file
·1123 lines (951 loc) · 26.7 KB
/
node-build
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
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
#
# Usage: node-build [-kpv] <definition> <prefix>
# node-build --definitions
# node-build --version
#
# -c/--compile Force compilation even if a matching binary exists
# -k/--keep Do not remove source tree after installation
# -p/--patch Apply a patch from stdin before building
# -v/--verbose Verbose mode: print compilation status to stdout
# -4/--ipv4 Resolve names to IPv4 addresses only
# -6/--ipv6 Resolve names to IPv6 addresses only
# --definitions List all local definitions
# -l/--list List latest stable releases for each Node
# --version Show version of node-build
#
NODE_BUILD_VERSION=5.3.0
OLDIFS="$IFS"
set -E
exec 3<&2 # preserve original stderr at fd 3
lib() {
parse_options() {
OPTIONS=()
ARGUMENTS=()
EXTRA_ARGUMENTS=()
local arg option index
while [ $# -gt 0 ]; do
arg="$1"
if [ "$arg" == "--" ]; then
shift 1
break
elif [ "${arg:0:1}" = "-" ]; then
if [ "${arg:1:1}" = "-" ]; then
OPTIONS[${#OPTIONS[*]}]="${arg:2}"
else
index=1
while option="${arg:$index:1}"; do
[ -n "$option" ] || break
OPTIONS[${#OPTIONS[*]}]="$option"
index=$((index+1))
done
fi
shift 1
else
ARGUMENTS[${#ARGUMENTS[*]}]="$arg"
shift 1
fi
done
EXTRA_ARGUMENTS=("$@")
}
if [ "$1" == "--${FUNCNAME[0]}" ]; then
declare -f "${FUNCNAME[0]}"
echo "${FUNCNAME[0]} \"\$1\";"
exit
fi
}
lib "$1"
resolve_link() {
$(type -p greadlink readlink | head -1) "$1"
}
abs_dirname() {
local path="$1"
local cwd
cwd="$(pwd || true)"
while [ -n "$path" ]; do
cd "${path%/*}" || return 1
local name="${path##*/}"
path="$(resolve_link "$name" || true)"
done
pwd
cd "$cwd" || return 1
}
capitalize() {
# shellcheck disable=SC2018,SC2019
printf "%s" "$1" | tr 'a-z' 'A-Z'
}
sanitize() {
printf "%s" "$1" | sed "s/[^A-Za-z0-9.-]/_/g; s/__*/_/g"
}
colorize() {
if [ -t 1 ]; then printf "\e[%sm%s\e[m" "$1" "$2"
else echo -n "$2"
fi
}
os_information() {
if type -p lsb_release >/dev/null; then
lsb_release -sir | xargs echo
elif type -p sw_vers >/dev/null; then
echo "$(sw_vers -productName) $(sw_vers -productVersion)"
elif [ -r /etc/os-release ]; then
# shellcheck disable=SC1091
source /etc/os-release
# shellcheck disable=SC2153
echo "$NAME $VERSION_ID"
else
local os
os="$(cat /etc/{centos,redhat,fedora,system}-release /etc/debian_version 2>/dev/null | head -1)"
echo "${os:-$(uname -sr)}"
fi
}
is_mac() {
[ "$(uname -s)" = "Darwin" ] || return 1
[ $# -eq 0 ] || [ "$(osx_version)" -ge "$1" ]
}
is_freebsd() {
[ "$(uname -s)" = "FreeBSD" ]
}
freebsd_package_prefix() {
local package="$1"
pkg info --prefix "$package" 2>/dev/null | cut -wf2
}
# 9.1 -> 901
# 10.9 -> 1009
# 10.10 -> 1010
osx_version() {
local ver
IFS=. read -d "" -r -a ver <<<"$(sw_vers -productVersion)" || true
IFS="$OLDIFS"
echo $(( ver[0]*100 + ver[1] ))
}
build_failed() {
{ echo
colorize 1 "BUILD FAILED"
echo " ($(os_information) using $(version))"
echo
if [ -n "$BINARY_ATTEMPT" ]; then
printf "Binary installation failed; try compiling from source with \`--compile\` flag\\n\\n"
fi
if ! rmdir "${BUILD_PATH}" 2>/dev/null; then
echo "Inspect or clean up the working tree at ${BUILD_PATH}"
if [ -n "$(head -1 "$LOG_PATH" 2>/dev/null)" ]; then
colorize 33 "Results logged to ${LOG_PATH}"
printf "\n\n"
echo "Last 10 log lines:"
tail -n 10 "$LOG_PATH"
fi
fi
} >&3
exit 1
}
num_cpu_cores() {
local num
case "$(uname -s)" in
Darwin | *BSD )
num="$(sysctl -n hw.ncpu 2>/dev/null || true)"
;;
SunOS )
num="$(getconf NPROCESSORS_ONLN 2>/dev/null || true)"
;;
* )
num="$({ getconf _NPROCESSORS_ONLN ||
grep -c ^processor /proc/cpuinfo; } 2>/dev/null)"
num="${num#0}"
;;
esac
echo "${num:-2}"
}
platform() {
local arch os distro
arch="$(uname -m)"
case "$arch" in
arm64 | aarch64 ) arch=arm64 ;;
x86_64 | amd64 | i686-64 ) arch=x64 ;;
i[36]86* | [ix]86pc ) arch=x86 ;;
esac
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
if type -p lsb_release >/dev/null; then
case "$(lsb_release -sir)" in
*Ubuntu* ) distro=ubuntu ;;
*Debian* ) distro=debian ;;
*SUSE* ) distro=suse ;;
*"Red Hat"* ) distro=redhat ;;
*Gentoo* ) distro=gentoo ;;
esac
elif [ "$os" = freebsd ]; then
distro="$os$(uname -r | sed 's/[^[:digit:]].*//')"
fi
echo "${arch}:${os}:${distro}"
}
matches_platform() {
local match="$1"
local -a platform
IFS=: platform=( $(platform) )
IFS="$OLDIFS"
[ "${platform[1]}-${platform[0]}" = "$match" ] ||
[ "${platform[2]}-${platform[0]}" = "$match" ]
}
mirror() {
local package_url="$1"
local checksum="$2"
if [ -n "$NODE_BUILD_MIRROR_URL" ]; then
echo "${package_url/https:\/\/nodejs.org\/dist/$NODE_BUILD_MIRROR_URL}"
elif [ -n "$NODE_BUILD_MIRROR_PACKAGE_URL" ]; then
echo "$NODE_BUILD_MIRROR_PACKAGE_URL"
fi
}
try_binary(){
[ -n "$BINARY_URL" ] && [ -z "$SKIP_BINARY" ] && [ -z "$BINARY_ATTEMPT" ]
}
binary() {
local platform="$1"
local url="$2"
# return if already set
[ -n "$BINARY_URL" ] && return 0
if matches_platform "$platform"; then
BINARY_URL="$url"
fi
}
install_binary() {
local url name
url="$1"
name="$(basename "$url")"
name="${name%.tar.gz*}"
name="${name%.zip*}"
install_package "$name" "$url" copy "${@:2}"
}
install_package() {
install_package_using "tarball" 1 "$@"
}
install_git() {
install_package_using "git" 2 "$@"
}
install_package_using() {
local package_type="$1"
local package_type_nargs="$2"
local package_name="$3"
shift 3
local fetch_args=( "$package_name" "${@:1:$package_type_nargs}" )
local make_args=( "$package_name" )
local arg last_arg
for arg in "${@:$(( package_type_nargs + 1 ))}"; do
if [ "$last_arg" = "--if" ]; then
"$arg" || return 0
elif [ "$arg" != "--if" ]; then
make_args["${#make_args[@]}"]="$arg"
fi
last_arg="$arg"
done
if try_binary; then
BINARY_ATTEMPT=true # skip binary on recursive pass
install_binary "$BINARY_URL" "${make_args[@]:1}"
BINARY_ATTEMPT=
SKIP_BINARY=true # skip binary for subsequent packages
return 0
fi
# shellcheck disable=SC2164
pushd "$BUILD_PATH" >&4
"fetch_${package_type}" "${fetch_args[@]}"
make_package "${make_args[@]}"
# shellcheck disable=SC2164
popd >&4
{ echo "Installed ${package_name} to ${PREFIX_PATH}"
echo
} >&2
}
make_package() {
local package_name="$1"
shift
# shellcheck disable=SC2164
pushd "$package_name" >&4
before_install_package "$package_name"
build_package "$package_name" "$@"
after_install_package "$package_name"
# shellcheck disable=SC2164
popd >&4
}
compute_sha2() {
local output
if type shasum &>/dev/null; then
output="$(shasum -a 256 -b)" || return 1
echo "${output% *}"
elif type openssl &>/dev/null; then
local openssl
openssl="$(command -v "$(brew --prefix openssl 2>/dev/null || true)"/bin/openssl openssl | head -1)"
output="$("$openssl" dgst -sha256 2>/dev/null)" || return 1
echo "${output##* }"
elif type sha256sum &>/dev/null; then
output="$(sha256sum -b)" || return 1
echo "${output%% *}"
else
return 1
fi
}
compute_sha1() {
local output
if type sha1 &>/dev/null; then
sha1 -q
elif type openssl &>/dev/null; then
output="$(openssl sha1)" || return 1
echo "${output##* }"
elif type sha1sum &>/dev/null; then
output="$(sha1sum -b)" || return 1
echo "${output%% *}"
else
return 1
fi
}
compute_md5() {
local output
if type md5 &>/dev/null; then
md5 -q
elif type openssl &>/dev/null; then
output="$(openssl md5)" || return 1
echo "${output##* }"
elif type md5sum &>/dev/null; then
output="$(md5sum -b)" || return 1
echo "${output%% *}"
else
return 1
fi
}
has_checksum_support() {
local checksum_command="$1"
local has_checksum_var="HAS_CHECKSUM_SUPPORT_${checksum_command}"
if [ -z "${!has_checksum_var+defined}" ]; then
if "$checksum_command" <<<"test" >/dev/null; then
printf -v "$has_checksum_var" 0 # success
else
printf -v "$has_checksum_var" 1 # error
fi
fi
return "${!has_checksum_var}"
}
verify_checksum() {
local checksum_command
local filename="$1"
local expected_checksum
expected_checksum="$(tr 'A-F' 'a-f' <<<"$2")"
# If the specified filename doesn't exist, return success
[ -e "$filename" ] || return 0
case "${#expected_checksum}" in
0) return 0 ;; # empty checksum; return success
32) checksum_command="compute_md5" ;;
40) checksum_command="compute_sha1" ;;
64) checksum_command="compute_sha2" ;;
*)
{ echo
echo "unexpected checksum length: ${#expected_checksum} (${expected_checksum})"
echo "expected 0 (no checksum), 32 (MD5), 40 (SHA-1), or 64 (SHA2-256)"
echo
} >&4
return 1 ;;
esac
# If chosen provided checksum algorithm isn't supported, return success
has_checksum_support "$checksum_command" || return 0
# If the computed checksum is empty, return failure
local computed_checksum
computed_checksum="$("$checksum_command" < "$filename" | tr 'A-F' 'a-f')"
[ -n "$computed_checksum" ] || return 1
if [ "$expected_checksum" != "$computed_checksum" ]; then
{ echo
echo "checksum mismatch: ${filename} (file is corrupt)"
echo "expected $expected_checksum, got $computed_checksum"
echo
} >&4
return 1
fi
}
http() {
local method="$1"
[ -n "$2" ] || return 1
shift 1
NODE_BUILD_HTTP_CLIENT="${NODE_BUILD_HTTP_CLIENT:-$(detect_http_client 2>&3)}"
[ -n "$NODE_BUILD_HTTP_CLIENT" ] || return 1
"http_${method}_${NODE_BUILD_HTTP_CLIENT}" "$@"
}
detect_http_client() {
local client
for client in aria2c curl wget; do
if type "$client" &>/dev/null; then
echo "$client"
return
fi
done
echo "error: install \`curl\`, \`wget\`, or \`aria2c\` to download packages" >&2
return 1
}
http_head_aria2c() {
# shellcheck disable=SC2086
aria2c --dry-run --no-conf=true ${ARIA2_OPTS} "$1" >&4 2>&1
}
http_get_aria2c() {
local out="${2:-$(mktemp "out.XXXXXX")}"
# shellcheck disable=SC2086
if aria2c --allow-overwrite=true --no-conf=true -o "${out}" ${ARIA2_OPTS} "$1" >&4; then
[ -n "$2" ] || cat "${out}"
else
false
fi
}
http_head_curl() {
# shellcheck disable=SC2086
curl -qsILf ${CURL_OPTS} "$1" >&4 2>&1
}
http_get_curl() {
# shellcheck disable=SC2086
curl -q -o "${2:--}" -sSLf ${CURL_OPTS} "$1"
}
http_head_wget() {
# shellcheck disable=SC2086
wget -q --spider ${WGET_OPTS} "$1" >&4 2>&1
}
http_get_wget() {
# shellcheck disable=SC2086
wget -nv ${WGET_OPTS} -O "${2:--}" "$1"
}
fetch_tarball() {
local package_name="$1"
local package_url="$2"
local mirror_url
local checksum
local extracted_dir
if [ -z "$package_url" ]; then
echo "error: failed to download $package_name (missing package url)" >&2
return 1
fi
if [ "$package_url" != "${package_url/\#}" ]; then
checksum="${package_url#*#}"
package_url="${package_url%%#*}"
if [ -z "$NODE_BUILD_SKIP_MIRROR" ]; then
mirror_url="$("${NODE_BUILD_MIRROR_CMD:-mirror}" $package_url $checksum 2>&4)" || unset mirror_url
fi
fi
local tar="tar"
local tar_args="xzf"
local package_filename="${package_name}.tar.gz"
if [ "$package_url" != "${package_url%bz2}" ]; then
if ! type -p bzip2 >/dev/null; then
echo "warning: bzip2 not found; consider installing \`bzip2\` package" >&4
fi
package_filename="${package_filename%.gz}.bz2"
tar_args="${tar_args/z/j}"
fi
if [ "$package_url" != "${package_url%zip}" ]; then
tar="unzip"
tar_args="-oq"
fi
if ! reuse_existing_tarball "$package_filename" "$checksum"; then
local tarball_filename
tarball_filename="$(basename "$package_url")"
echo "Downloading ${tarball_filename}..." >&2
# shellcheck disable=SC2015
http head "$mirror_url" &&
download_tarball "$mirror_url" "$package_filename" "$checksum" ||
download_tarball "$package_url" "$package_filename" "$checksum"
fi
{ if $tar "$tar_args" "$package_filename"; then
if [ ! -d "$package_name" ]; then
extracted_dir="$(find_extracted_directory)"
mv "$extracted_dir" "$package_name"
fi
if [ -z "$KEEP_BUILD_PATH" ]; then
rm -f "$package_filename"
else
true
fi
fi
} >&4 2>&1
}
find_extracted_directory() {
for f in *; do
if [ -d "$f" ]; then
echo "$f"
return
fi
done
echo "Extracted directory not found" >&2
return 1
}
reuse_existing_tarball() {
local package_filename="$1"
local checksum="$2"
# Reuse existing file in build location
if [ -e "$package_filename" ] && verify_checksum "$package_filename" "$checksum"; then
return 0
fi
# Reuse previously downloaded file in cache location
[ -n "$NODE_BUILD_CACHE_PATH" ] || return 1
local cached_package_filename="${NODE_BUILD_CACHE_PATH}/$package_filename"
[ -e "$cached_package_filename" ] || return 1
verify_checksum "$cached_package_filename" "$checksum" >&4 2>&1 || return 1
ln -s "$cached_package_filename" "$package_filename" >&4 2>&1 || return 1
}
download_tarball() {
local package_url="$1"
[ -n "$package_url" ] || return 1
local package_filename="$2"
local checksum="$3"
echo "-> $package_url" >&2
if http get "$package_url" "$package_filename" >&4 2>&1; then
verify_checksum "$package_filename" "$checksum" >&4 2>&1 || return 1
else
echo "error: failed to download $package_filename" >&2
return 1
fi
if [ -n "$NODE_BUILD_CACHE_PATH" ]; then
local cached_package_filename="${NODE_BUILD_CACHE_PATH}/$package_filename"
{ mv "$package_filename" "$cached_package_filename"
ln -s "$cached_package_filename" "$package_filename"
} >&4 2>&1 || return 1
fi
}
fetch_git() {
local package_name="$1"
local git_url="$2"
local git_ref="$3"
echo "Cloning ${git_url}..." >&2
if type git &>/dev/null; then
if [ -n "$NODE_BUILD_CACHE_PATH" ]; then
# shellcheck disable=SC2164
pushd "$NODE_BUILD_CACHE_PATH" >&4
local clone_name
clone_name="$(sanitize "$git_url")"
if [ -e "$clone_name" ]; then
{ # shellcheck disable=SC2164
cd "$clone_name"
git fetch --force "$git_url" "+${git_ref}:${git_ref}"
} >&4 2>&1
else
git clone --bare --branch "$git_ref" "$git_url" "${clone_name}" >&4 2>&1
fi
git_url="$NODE_BUILD_CACHE_PATH/${clone_name}"
# shellcheck disable=SC2164
popd >&4
fi
if [ -e "${package_name}" ]; then
( # shellcheck disable=SC2164
cd "${package_name}"
git fetch --depth 1 origin "+${git_ref}"
git checkout -q -B "$git_ref" "origin/${git_ref}"
) >&4 2>&1
else
git clone --depth 1 --branch "$git_ref" "$git_url" "${package_name}" >&4 2>&1
fi
else
echo "error: please install \`git\` and try again" >&2
exit 1
fi
}
build_package() {
local package_name="$1"
shift
if [ "$#" -eq 0 ]; then
local commands="standard"
else
local commands="$*"
fi
echo "Installing ${package_name}..." >&2
[ -n "$HAS_PATCH" ] && apply_node_patch "$package_name"
for command in $commands; do
"build_package_${command}" "$package_name"
done
}
package_option() {
local package_name="$1"
local command_name="$2"
local variable
# e.g. NODE_CONFIGURE_OPTS_ARRAY, OPENSSL_MAKE_OPTS_ARRAY
variable="$(capitalize "${package_name}_${command_name}")_OPTS_ARRAY"
local array="${variable}[@]"
shift 2
# shellcheck disable=SC2034
local value=( "${!array}" "$@" )
eval "$variable=( \"\${value[@]}\" )"
}
build_package_warn_eol() {
local package_name="$1"
{ echo
echo "WARNING: $package_name is past its end of life and is now unsupported."
echo "It no longer receives bug fixes or security updates."
echo
} >&3
}
build_package_warn_lts_maintenance() {
local package_name="$1"
{ echo
echo "WARNING: $package_name is in LTS Maintenance mode and nearing its end of life."
echo "It only receives *critical* security updates, *critical* bug fixes and documentation updates."
echo
} >&3
}
build_package_standard_build() {
local package_name="$1"
if [ "${MAKEOPTS+defined}" ]; then
MAKE_OPTS="$MAKEOPTS"
elif [ -z "${MAKE_OPTS+defined}" ]; then
MAKE_OPTS="-j $(num_cpu_cores)"
fi
# Support YAML_CONFIGURE_OPTS, NODE_CONFIGURE_OPTS, etc.
local package_var_name
package_var_name="$(capitalize "${package_name%%-*}")"
local PACKAGE_CONFIGURE="${package_var_name}_CONFIGURE"
local PACKAGE_PREFIX_PATH="${package_var_name}_PREFIX_PATH"
local PACKAGE_CONFIGURE_OPTS="${package_var_name}_CONFIGURE_OPTS"
local PACKAGE_CONFIGURE_OPTS_ARRAY="${package_var_name}_CONFIGURE_OPTS_ARRAY[@]"
local PACKAGE_MAKE_OPTS="${package_var_name}_MAKE_OPTS"
local PACKAGE_MAKE_OPTS_ARRAY="${package_var_name}_MAKE_OPTS_ARRAY[@]"
local PACKAGE_CFLAGS="${package_var_name}_CFLAGS"
( if [ "${CFLAGS+defined}" ] || [ "${!PACKAGE_CFLAGS+defined}" ]; then
export CFLAGS="$CFLAGS ${!PACKAGE_CFLAGS}"
fi
if [ -z "$CC" ] && is_mac 1010; then
export CC=clang
fi
# shellcheck disable=SC2086,SC2153
${!PACKAGE_CONFIGURE:-./configure} --prefix="${!PACKAGE_PREFIX_PATH:-$PREFIX_PATH}" \
"${!PACKAGE_CONFIGURE_OPTS_ARRAY}" $CONFIGURE_OPTS ${!PACKAGE_CONFIGURE_OPTS} || return 1
) >&4 2>&1
# shellcheck disable=SC2086
{ "$MAKE" "${!PACKAGE_MAKE_OPTS_ARRAY}" $MAKE_OPTS ${!PACKAGE_MAKE_OPTS}
} >&4 2>&1
}
build_package_standard_install() {
local package_name="$1"
local package_var_name
package_var_name="$(capitalize "${package_name%%-*}")"
local PACKAGE_MAKE_INSTALL_OPTS="${package_var_name}_MAKE_INSTALL_OPTS"
local PACKAGE_MAKE_INSTALL_OPTS_ARRAY="${package_var_name}_MAKE_INSTALL_OPTS_ARRAY[@]"
# shellcheck disable=SC2086
{ "$MAKE" ${MAKE_INSTALL_TARGET:-install} "${!PACKAGE_MAKE_INSTALL_OPTS_ARRAY}" $MAKE_INSTALL_OPTS ${!PACKAGE_MAKE_INSTALL_OPTS}
} >&4 2>&1
}
build_package_standard() {
build_package_standard_build "$@"
build_package_standard_install "$@"
}
build_package_autoconf() {
{ autoreconf -i
} >&4 2>&1
}
build_package_copy_to() {
to="$1"
mkdir -p "$to"
cp -fR . "$to"
}
build_package_copy() {
build_package_copy_to "$PREFIX_PATH"
}
build_package_jxcore_v8_328() {
CONFIGURE_OPTS="--engine-v8-3-28 $CONFIGURE_OPTS"
}
build_package_jxcore_spidermonkey() {
CONFIGURE_OPTS="--engine-mozilla $CONFIGURE_OPTS"
}
build_package_jxcore_npm() {
local npmjxpath="$PREFIX_PATH/libexec"
local oldprefix="$PREFIX_PATH"
PREFIX_PATH="$npmjxpath/.jx/npm"
build_package_copy
PREFIX_PATH="$oldprefix"
# jx needs this version lock file of sorts
echo 1 > "$npmjxpath/.jx/$("$PREFIX_PATH/bin/jx" -jxv)"
# configure jx to use this local npm and not install to ~/.jx
cat > "$PREFIX_PATH/bin/jx.config" <<JX
{
"npmjxPath": "$npmjxpath"
}
JX
}
build_package_graal() {
cd "$PREFIX_PATH" || return 1
if [ -d Contents/Home ]; then
mv -f Contents/Home/* .
rm -rf Contents
fi
rm -rf demo sample src
}
before_install_package() {
:
}
after_install_package() {
:
}
fix_jxcore_directory_structure() {
{
mkdir -p "$PREFIX_PATH/bin"
pushd "$PREFIX_PATH/bin"
if [ -x ../jx ]; then
mv -f ../jx .
fi
ln -sf jx node
ln -sf ../libexec/.jx/npm/bin/npm-cli.js npm
popd
} >&4
}
# Kept for backward compatibility
require_java7() {
require_java 7
}
# Kept for backward compatibility
require_gcc() {
:
}
# Kept for backward compatibility
require_llvm() {
:
}
# Ensure that directories listed in LDFLAGS exist
build_package_ldflags_dirs() {
local ldflags
read -d '' -r -a ldflags <<<"$LDFLAGS" || true
local index=0
local dir
while [ "$index" -lt "${#ldflags[@]}" ]; do
dir=""
case "${ldflags[index]}" in
-L ) dir="${ldflags[index+1]}" ;;
-L* ) dir="${ldflags[index]#-L}" ;;
esac
[ -z "$dir" ] || mkdir -p "$dir"
index=$((index+1))
done
}
build_package_enable_shared() {
if [[ " ${NODE_CONFIGURE_OPTS} " != *" --disable-shared"* ]]; then
package_option node configure --enable-shared
fi
}
apply_node_patch() {
local patchfile
case "$1" in
node-* | iojs-* )
patchfile="$(mktemp "${TMP}/node-patch.XXXXXX")"
cat "${2:--}" >"$patchfile"
local striplevel=0
grep -q '^--- a/' "$patchfile" && striplevel=1
patch -p$striplevel --force -i "$patchfile"
;;
esac
}
version() {
local git_revision
# Read the revision from git if the remote points to "node-build" repository
if GIT_DIR="$NODE_BUILD_INSTALL_PREFIX/.git" git remote -v 2>/dev/null | grep -q /node-build; then
git_revision="$(GIT_DIR="$NODE_BUILD_INSTALL_PREFIX/.git" git describe --tags HEAD 2>/dev/null || true)"
git_revision="${git_revision#v}"
fi
echo "node-build ${git_revision:-$NODE_BUILD_VERSION}"
}
usage() {
sed -ne '/^#/!q;s/.\{1,2\}//;1,2d;p' < "$0"
[ -z "$1" ] || exit "$1"
}
# list all versions
list_definitions() {
{ for DEFINITION_DIR in "${NODE_BUILD_DEFINITIONS[@]}"; do
[ -d "$DEFINITION_DIR" ] && ls "$DEFINITION_DIR"
done
} | sort_versions | uniq
}
# list only latest stable versions excluding RC, preview, dev and EoL'ed
list_maintained_versions() {
{ for DEFINITION_DIR in "${NODE_BUILD_DEFINITIONS[@]}"; do
[ -d "$DEFINITION_DIR" ] && \
grep -L -e warn_eol "$DEFINITION_DIR"/* 2>/dev/null | \
sed 's|.*/||'
done
} | exclude_prereleases | extract_latest_versions | sort_versions | uniq
}
exclude_prereleases() {
grep -vE -e'-(dev|next|rc|nightly)'
}
extract_latest_versions() {
sort_versions |
sed -E 'h; s/$/.z/; G; s/\n/ /' | # create 'index' for each major version
sed -E 's/([0-9]+).*z/\1/' | # truncate to major from first column
awk '{ latest[$1] =$2 } END{ for(key in latest) { print latest[key] } }'
}
sort_versions() {
sed -E 'h; s/[~^<>=[:space:]]//g; s/^([[:digit:]])/a.\1/g; s/[+-]/./g; s/$/.0.0.0.0/; G; s/\n/ /' \
| LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n \
| cut -d' ' -f 2-
}
unset VERBOSE
unset SKIP_BINARY
unset KEEP_BUILD_PATH
unset HAS_PATCH
unset IPV4
unset IPV6
unset EARLY_EXIT
NODE_BUILD_INSTALL_PREFIX="$(abs_dirname "$0")/.."
# shellcheck disable=SC2206
IFS=: NODE_BUILD_DEFINITIONS=($NODE_BUILD_DEFINITIONS ${NODE_BUILD_ROOT:-$NODE_BUILD_INSTALL_PREFIX}/share/node-build)
IFS="$OLDIFS"
parse_options "$@"
for option in "${OPTIONS[@]}"; do
case "$option" in
"h" | "help" )
EARLY_EXIT=help
;;
"definitions" )
EARLY_EXIT=list_definitions
;;
"c" | "compile" )
SKIP_BINARY=true
;;
"l" | "list")
EARLY_EXIT=list_maintained_versions
;;
"k" | "keep" )
KEEP_BUILD_PATH=true
;;
"v" | "verbose" )
VERBOSE=true
;;
"p" | "patch" )
HAS_PATCH=true
;;
"4" | "ipv4")
IPV4=true
;;
"6" | "ipv6")
IPV6=true
;;
"version" )
EARLY_EXIT=version
;;
* )
printf "node-build: invalid flag '%s'\n" "$option" >&2
EARLY_EXIT=usage_error
;;
esac
done
DEFINITION_PATH="${ARGUMENTS[0]}"
PREFIX_PATH="${ARGUMENTS[1]}"
if [ -z "$EARLY_EXIT" ] && [ -z "$DEFINITION_PATH" ]; then
echo "node-build: missing definition argument" >&2
EARLY_EXIT=usage_error
fi
if [ -z "$EARLY_EXIT" ] && [ -z "$PREFIX_PATH" ]; then
echo "node-build: missing prefix argument" >&2
EARLY_EXIT=usage_error
fi
if [ "${#ARGUMENTS[@]}" -gt 2 ]; then
echo "node-build: expected at most 2 arguments, got [${ARGUMENTS[*]}]" >&2
EARLY_EXIT=usage_error
fi
if [ "${#EXTRA_ARGUMENTS[@]}" -gt 0 ]; then
NODE_CONFIGURE_OPTS_ARRAY=("${EXTRA_ARGUMENTS[@]}")
fi
case "$EARLY_EXIT" in
help )
version
echo