/
ruby-build
executable file
·1355 lines (1154 loc) · 34.1 KB
/
ruby-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: ruby-build [-kpv] <definition> <prefix>
# ruby-build --definitions
# ruby-build --version
#
# -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 built-in definitions
# --version Show version of ruby-build
#
RUBY_BUILD_VERSION="20180601"
OLDIFS="$IFS"
set -E
exec 3<&2 # preserve original stderr at fd 3
lib() {
parse_options() {
OPTIONS=()
ARGUMENTS=()
local arg option index
for arg in "$@"; do
if [ "${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
else
ARGUMENTS[${#ARGUMENTS[*]}]="$arg"
fi
done
}
if [ "$1" == "--$FUNCNAME" ]; then
declare -f "$FUNCNAME"
echo "$FUNCNAME \"\$1\";"
exit
fi
}
lib "$1"
resolve_link() {
$(type -p greadlink readlink | head -1) "$1"
}
abs_dirname() {
local cwd="$(pwd)"
local path="$1"
while [ -n "$path" ]; do
cd "${path%/*}"
local name="${path##*/}"
path="$(resolve_link "$name" || true)"
done
pwd
cd "$cwd"
}
capitalize() {
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 "OS X $(sw_vers -productVersion)"
elif [ -r /etc/os-release ]; then
source /etc/os-release
echo "$NAME" $VERSION_ID
else
local 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)" "$@" ]
}
# 9.1 -> 901
# 10.9 -> 1009
# 10.10 -> 1010
osx_version() {
local -a ver
IFS=. ver=( `sw_vers -productVersion` )
IFS="$OLDIFS"
echo $(( ${ver[0]}*100 + ${ver[1]} ))
}
build_failed() {
{ echo
colorize 1 "BUILD FAILED"
echo " ($(os_information) using $(version))"
echo
if ! rmdir "${BUILD_PATH}" 2>/dev/null; then
echo "Inspect or clean up the working tree at ${BUILD_PATH}"
if file_is_not_empty "$LOG_PATH"; 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
}
file_is_not_empty() {
local filename="$1"
local line_count="$(wc -l "$filename" 2>/dev/null || true)"
if [ -n "$line_count" ]; then
words=( $line_count )
[ "${words[0]}" -gt 0 ]
else
return 1
fi
}
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}"
}
install_package() {
install_package_using "tarball" 1 "$@"
}
install_git() {
install_package_using "git" 2 "$@"
}
install_svn() {
install_package_using "svn" 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
pushd "$BUILD_PATH" >&4
"fetch_${package_type}" "${fetch_args[@]}"
make_package "${make_args[@]}"
popd >&4
{ echo "Installed ${package_name} to ${PREFIX_PATH}"
echo
} >&2
}
make_package() {
local package_name="$1"
shift
pushd "$package_name" >&4
before_install_package "$package_name"
build_package "$package_name" $*
after_install_package "$package_name"
fix_directory_permissions
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="$(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_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
printf -v "$has_checksum_var" "$(echo test | "$checksum_command" >/dev/null; echo $?)"
fi
return "${!has_checksum_var}"
}
verify_checksum() {
local checksum_command
local filename="$1"
local expected_checksum="$(echo "$2" | tr [A-Z] [a-z])"
# 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" ;;
64) checksum_command="compute_sha2" ;;
*)
{ echo
echo "unexpected checksum length: ${#expected_checksum} (${expected_checksum})"
echo "expected 0 (no checksum), 32 (MD5), 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=`echo "$($checksum_command < "$filename")" | tr [A-Z] [a-z]`
[ -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"
local url="$2"
local file="$3"
[ -n "$url" ] || return 1
if type aria2c &>/dev/null; then
"http_${method}_aria2c" "$url" "$file"
elif type curl &>/dev/null; then
"http_${method}_curl" "$url" "$file"
elif type wget &>/dev/null; then
"http_${method}_wget" "$url" "$file"
else
echo "error: please install \`aria2c\`, \`curl\` or \`wget\` and try again" >&2
exit 1
fi
}
http_head_aria2c() {
aria2c --dry-run --no-conf=true ${ARIA2_OPTS} "$1" >&4 2>&1
}
http_get_aria2c() {
local out="${2:-$(mktemp "out.XXXXXX")}"
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() {
curl -qsILf ${CURL_OPTS} "$1" >&4 2>&1
}
http_get_curl() {
curl -q -o "${2:--}" -sSLf ${CURL_OPTS} "$1"
}
http_head_wget() {
wget -q --spider ${WGET_OPTS} "$1" >&4 2>&1
}
http_get_wget() {
wget -nv ${WGET_OPTS} -O "${2:--}" "$1"
}
fetch_tarball() {
local package_name="$1"
local package_url="$2"
local mirror_url
local checksum
if [ "$package_url" != "${package_url/\#}" ]; then
checksum="${package_url#*#}"
package_url="${package_url%%#*}"
if [ -n "$RUBY_BUILD_MIRROR_URL" ]; then
if [[ -z "$RUBY_BUILD_DEFAULT_MIRROR" || $package_url != */cache.ruby-lang.org/* ]]; then
mirror_url="${RUBY_BUILD_MIRROR_URL}/$checksum"
fi
fi
fi
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 ! reuse_existing_tarball "$package_filename" "$checksum"; then
local tarball_filename=$(basename $package_url)
echo "Downloading ${tarball_filename}..." >&2
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 [ -z "$KEEP_BUILD_PATH" ]; then
rm -f "$package_filename"
else
true
fi
fi
} >&4 2>&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 "$RUBY_BUILD_CACHE_PATH" ] || return 1
local cached_package_filename="${RUBY_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 "$RUBY_BUILD_CACHE_PATH" ]; then
local cached_package_filename="${RUBY_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 "$RUBY_BUILD_CACHE_PATH" ]; then
pushd "$RUBY_BUILD_CACHE_PATH" >&4
local clone_name="$(sanitize "$git_url")"
if [ -e "${clone_name}" ]; then
{ 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="$RUBY_BUILD_CACHE_PATH/${clone_name}"
popd >&4
fi
if [ -e "${package_name}" ]; then
( 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
}
fetch_svn() {
local package_name="$1"
local svn_url="$2"
local svn_rev="$3"
echo "Checking out ${svn_url}..." >&2
if type svn &>/dev/null; then
svn co -r "$svn_rev" "$svn_url" "${package_name}" >&4 2>&1
elif type svnlite &>/dev/null; then
svnlite co -r "$svn_rev" "$svn_url" "${package_name}" >&4 2>&1
else
echo "error: please install Subversion 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_ruby_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="$(capitalize "${package_name}_${command_name}")_OPTS_ARRAY"
local array="$variable[@]"
shift 2
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 critical security updates."
echo
} >&3
}
build_package_warn_unsupported() {
local package_name="$1"
{ echo
echo "WARNING: $package_name is nearing its end of life."
echo "It only receives critical security updates, no bug fixes."
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, RUBY_CONFIGURE_OPTS, etc.
local 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 [ "$package_var_name" = "RUBY" ]; then
use_homebrew_readline || use_freebsd_pkg ||true
fi
( if [ "${CFLAGS+defined}" ] || [ "${!PACKAGE_CFLAGS+defined}" ]; then
export CFLAGS="$CFLAGS ${!PACKAGE_CFLAGS}"
fi
if [ -z "$CC" ] && is_mac -ge 1010; then
export CC=clang
fi
${!PACKAGE_CONFIGURE:-./configure} --prefix="${!PACKAGE_PREFIX_PATH:-$PREFIX_PATH}" \
$CONFIGURE_OPTS ${!PACKAGE_CONFIGURE_OPTS} "${!PACKAGE_CONFIGURE_OPTS_ARRAY}" || return 1
) >&4 2>&1
{ "$MAKE" $MAKE_OPTS ${!PACKAGE_MAKE_OPTS} "${!PACKAGE_MAKE_OPTS_ARRAY}"
} >&4 2>&1
}
build_package_standard_install() {
local package_name="$1"
local 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[@]"
{ "$MAKE" install $MAKE_INSTALL_OPTS ${!PACKAGE_MAKE_INSTALL_OPTS} "${!PACKAGE_MAKE_INSTALL_OPTS_ARRAY}"
} >&4 2>&1
}
build_package_standard_install_with_bundled_gems() {
{ "$MAKE" update-gems
"$MAKE" extract-gems
} >&4 2>&1
build_package_standard_install "$@"
}
# Backword Compatibility for standard function
build_package_standard() {
build_package_standard_build "$@"
build_package_standard_install "$@"
}
build_package_autoconf() {
{ autoconf
} >&4 2>&1
}
build_package_ruby() {
local package_name="$1"
{ "$RUBY_BIN" setup.rb
} >&4 2>&1
}
build_package_ree_installer() {
build_package_auto_tcltk
local options=""
is_mac && options="--no-tcmalloc"
local option
for option in $RUBY_CONFIGURE_OPTS ${RUBY_CONFIGURE_OPTS_ARRAY[@]}; do
options="$options -c $option"
done
# Work around install_useful_libraries crash with --dont-install-useful-gems
mkdir -p "$PREFIX_PATH/lib/ruby/gems/1.8/gems"
{ ./installer --auto "$PREFIX_PATH" --dont-install-useful-gems $options $CONFIGURE_OPTS
} >&4 2>&1
}
build_package_rbx() {
local package_name="$1"
{ [ ! -e "Gemfile" ] || bundle --path=vendor/bundle
if [ -n "$RUBY_BUILD_CACHE_PATH" ]; then
mkdir -p vendor
ln -s "$RUBY_BUILD_CACHE_PATH" vendor/prebuilt
fi
local opt
local -a configure_opts
for opt in "${RUBY_CONFIGURE_OPTS_ARRAY[@]}"; do
if [[ $opt == --with-openssl-dir=* ]]; then
local openssl_dir="${opt#*=}"
configure_opts[${#configure_opts[@]}]="--with-lib-dir=${openssl_dir}/lib"
configure_opts[${#configure_opts[@]}]="--with-include-dir=${openssl_dir}/include"
else
configure_opts[${#configure_opts[@]}]="$opt"
fi
done
RUBYOPT="-rrubygems $RUBYOPT" ./configure --prefix="$PREFIX_PATH" $RUBY_CONFIGURE_OPTS "${configure_opts[@]}"
rake install
fix_rbx_gem_binstubs "$PREFIX_PATH"
fix_rbx_irb "$PREFIX_PATH"
} >&4 2>&1
}
build_package_mruby() {
local package_name="$1"
{ rake
mkdir -p "$PREFIX_PATH"
cp -fR build/host/* "$PREFIX_PATH"
cd "$PREFIX_PATH/bin"
ln -fs mruby ruby
ln -fs mirb irb
} >&4 2>&1
}
build_package_maglev() {
build_package_copy
{ cd "${PREFIX_PATH}"
./install.sh
cd "${PREFIX_PATH}/bin"
echo "Creating symlink for ruby*"
ln -fs maglev-ruby ruby
echo "Creating symlink for irb*"
ln -fs maglev-irb irb
} >&4 2>&1
echo
echo "Run 'maglev start' to start up the stone before using 'ruby' or 'irb'"
}
build_package_topaz() {
build_package_copy
{ cd "${PREFIX_PATH}/bin"
echo "Creating symlink for ruby*"
ln -fs topaz ruby
} >&4 2>&1
}
topaz_architecture() {
case "$(uname -s)" in
"Darwin") echo "osx64";;
"Linux") [[ "$(uname -m)" = "x86_64" ]] && echo "linux64" || echo "linux32";;
*)
echo "no nightly builds available" >&2
exit 1;;
esac
}
build_package_jruby() {
build_package_copy
cd "${PREFIX_PATH}/bin"
ln -fs jruby ruby
chmod +x ruby
install_jruby_launcher
remove_windows_files
fix_jruby_shebangs
}
install_jruby_launcher() {
cd "${PREFIX_PATH}/bin"
{ ./ruby gem install jruby-launcher
} >&4 2>&1
}
fix_jruby_shebangs() {
for file in "${PREFIX_PATH}/bin"/*; do
if [ "$(head -c 20 "$file")" = "#!/usr/bin/env jruby" ]; then
sed -i.bak "1 s:.*:#\!${PREFIX_PATH}\/bin\/jruby:" "$file"
rm "$file".bak
fi
done
}
remove_windows_files() {
cd "$PREFIX_PATH"
rm -f bin/*.exe bin/*.dll bin/*.bat bin/jruby.sh
}
build_package_copy() {
mkdir -p "$PREFIX_PATH"
cp -fR . "$PREFIX_PATH"
}
before_install_package() {
local stub=1
}
after_install_package() {
local stub=1
}
fix_directory_permissions() {
# Ensure installed directories are not world-writable to avoid Bundler warnings
find "$PREFIX_PATH" -type d \( -perm -020 -o -perm -002 \) -exec chmod go-w {} \;
}
fix_rbx_gem_binstubs() {
local prefix="$1"
local gemdir="${prefix}/gems/bin"
local bindir="${prefix}/bin"
local file binstub
# Symlink Rubinius' `gems/bin/` into `bin/`
if [ -d "$gemdir" ] && [ ! -L "$gemdir" ]; then
for file in "$gemdir"/*; do
binstub="${bindir}/${file##*/}"
rm -f "$binstub"
{ echo "#!${bindir}/ruby"
grep -v '^#!' "$file"
} > "$binstub"
chmod +x "$binstub"
done
rm -rf "$gemdir"
ln -s ../bin "$gemdir"
fi
}
fix_rbx_irb() {
local prefix="$1"
"${prefix}/bin/irb" --version &>/dev/null ||
"${prefix}/bin/gem" install rubysl-tracer -v '~> 2.0' --no-rdoc --no-ri &>/dev/null ||
true
}
require_java7() {
local version="$(java -version 2>&1 | grep '\(java\|openjdk\) version' | head -1)"
if [[ $version != *[789]* ]]; then
colorize 1 "ERROR" >&3
echo ": Java 7 required. Please install a 1.7-compatible JRE." >&3
return 1
fi
}
require_gcc() {
local gcc="$(locate_gcc || true)"
if [ -z "$gcc" ]; then
{ echo
colorize 1 "ERROR"
echo ": This package must be compiled with GCC, but ruby-build couldn't"
echo "find a suitable \`gcc\` executable on your system. Please install GCC"
echo "and try again."
echo
if is_mac; then
colorize 1 "DETAILS"
echo ": Apple no longer includes the official GCC compiler with Xcode"
echo "as of version 4.2. Instead, the \`gcc\` executable is a symlink to"
echo "\`llvm-gcc\`, a modified version of GCC which outputs LLVM bytecode."
echo
echo "For most programs the \`llvm-gcc\` compiler works fine. However,"
echo "versions of Ruby older than 1.9.3-p125 are incompatible with"
echo "\`llvm-gcc\`. To build older versions of Ruby you must have the official"
echo "GCC compiler installed on your system."
echo
colorize 1 "TO FIX THE PROBLEM"
if type brew &>/dev/null; then
echo ": Install Homebrew's apple-gcc42 package with this"
echo -n "command: "
colorize 4 "brew tap homebrew/dupes ; brew install apple-gcc42"
else
echo ": Install the official GCC compiler using these"
echo -n "packages: "
colorize 4 "https://github.com/kennethreitz/osx-gcc-installer/downloads"
fi
echo
echo
echo "You will need to install the official GCC compiler to build older"
echo "versions of Ruby even if you have installed Apple's Command Line Tools"
echo "for Xcode package. The Command Line Tools for Xcode package only"
echo "includes \`llvm-gcc\`."
fi
} >&3
return 1
fi
export CC="$gcc"
if is_mac -ge 1010; then
export MACOSX_DEPLOYMENT_TARGET=10.9
fi
}
locate_gcc() {
local gcc gccs
IFS=: gccs=($(gccs_in_path))
IFS="$OLDIFS"
verify_gcc "$CC" ||
verify_gcc "$(command -v gcc || true)" || {
for gcc in "${gccs[@]}"; do
verify_gcc "$gcc" && break || true
done
}
return 1
}
gccs_in_path() {
local gcc path paths
local gccs=()
IFS=: paths=($PATH)
IFS="$OLDIFS"
shopt -s nullglob
for path in "${paths[@]}"; do
for gcc in "$path"/gcc-*; do
gccs["${#gccs[@]}"]="$gcc"
done
done
shopt -u nullglob
printf :%s "${gccs[@]}"
}
verify_gcc() {
local gcc="$1"
if [ -z "$gcc" ]; then
return 1
fi
local version="$("$gcc" --version 2>/dev/null || true)"
if [ -z "$version" ]; then
return 1
fi
if echo "$version" | grep LLVM >/dev/null; then
return 1
fi
echo "$gcc"
}
require_llvm() {
local llvm_version="$1"
if is_mac -ge 1010; then
if [[ "$RUBY_CONFIGURE_OPTS" != *--llvm-* ]]; then
case "$llvm_version" in
3.2 )
package_option ruby configure --prebuilt-name="llvm-3.2-x86_64-apple-darwin13.tar.bz2"
;;
3.[56] )
local llvm_config="$(locate_llvm "$llvm_version")"
if [ -n "$llvm_config" ]; then
package_option ruby configure --llvm-config="$llvm_config"
else
local homebrew_package="llvm@$llvm_version"
{ echo
colorize 1 "ERROR"
echo ": Rubinius will not be able to compile using Apple's LLVM-based "
echo "build tools on OS X. You will need to install LLVM $llvm_version first."
echo
colorize 1 "TO FIX THE PROBLEM"
echo ": Install Homebrew's llvm package with this"
echo -n "command: "
colorize 4 "brew install $homebrew_package"
echo
} >&3
return 1
fi
;;
esac
fi
fi
}
locate_llvm() {
local llvm_version="$1"
local package llvm_config
shopt -s nullglob
for package in `brew list 2>/dev/null | grep "^llvm"`; do
llvm_config="$(echo "$(brew --prefix "$package")/bin/llvm-config"*)"
if [ -n "$llvm_config" ] && [[ "$("$llvm_config" --version)" = "$llvm_version"* ]]; then
echo "$llvm_config"
break
fi
done
shopt -u nullglob
}
needs_yaml() {
[[ "$RUBY_CONFIGURE_OPTS" != *--with-libyaml-dir=* ]] &&
! use_homebrew_yaml
}
use_homebrew_yaml() {
local libdir="$(brew --prefix libyaml 2>/dev/null || true)"
if [ -d "$libdir" ]; then
echo "ruby-build: use libyaml from homebrew"
package_option ruby configure --with-libyaml-dir="$libdir"
else
return 1
fi
}
use_freebsd_pkg() {
# check if FreeBSD
if [ "FreeBSD" = "$(uname -s)" ]; then
# use openssl if installed from Ports Collection
if [ -f /usr/local/include/openssl/ssl.h ]; then
package_option ruby configure --with-openssl-dir="/usr/local"
fi
# check if 11-R or later
release="$(uname -r)"
if [ "${release%%.*}" -ge 11 ]; then
# prefers readline to compile most of ruby versions
if pkg info -e readline > /dev/null; then
# use readline from Ports Collection
package_option ruby configure --with-readline-dir="/usr/local"
elif pkg info -e libedit > /dev/null; then
# use libedit from Ports Collection
package_option ruby configure --enable-libedit
package_option ruby configure --with-libedit-dir="/usr/local"
fi
fi
fi
}
use_homebrew_readline() {
if [[ "$RUBY_CONFIGURE_OPTS" != *--with-readline-dir=* ]]; then
local libdir="$(brew --prefix readline 2>/dev/null || true)"
if [ -d "$libdir" ]; then
echo "ruby-build: use readline from homebrew"
package_option ruby configure --with-readline-dir="$libdir"
else
return 1
fi
fi
}
has_broken_mac_openssl() {
is_mac || return 1
local openssl_version="$(/usr/bin/openssl version 2>/dev/null || true)"
[[ $openssl_version = "OpenSSL 0.9.8"?* || $openssl_version = "LibreSSL"* ]] &&
[[ "$RUBY_CONFIGURE_OPTS" != *--with-openssl-dir=* ]] &&
! use_homebrew_openssl
}
use_homebrew_openssl() {
local ssldir="$(brew --prefix openssl 2>/dev/null || true)"
if [ -d "$ssldir" ]; then
echo "ruby-build: use openssl from homebrew"
package_option ruby configure --with-openssl-dir="$ssldir"
else
return 1