-
Notifications
You must be signed in to change notification settings - Fork 0
/
_build_ruby.sh
executable file
·50 lines (41 loc) · 1.6 KB
/
_build_ruby.sh
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
#!/bin/bash
set -xe
_SC_DIR="$(cd "`dirname "$0"`"; pwd)"
_VER="${3:-2.7.5}"
_PKG="ruby-$_VER"
_PREFIX="$1"
_SCRATCH_DIR="$2"
_EXTRA_ARGS="$4"
_NO_TESTS="$5"
cd "$_SCRATCH_DIR"
[[ -s "$_PKG.tar.xz" ]] || \
curl -OkfSL "https://cache.ruby-lang.org/pub/ruby/${_VER%.*}/$_PKG.tar.xz"
rm -rf "$_PKG"
tar -xf "$_PKG.tar.xz"
cd "$_PKG"
./configure "--prefix=$_PREFIX" --enable-shared "--with-opt-dir=$_PREFIX" \
--without-gmp $_EXTRA_ARGS CFLAGS=-O2 CXXFLAGS=-O2
# Optimize .pc file
sed -i- -e "s:$_PREFIX/lib :\${libdir} :;s:$_PREFIX/lib\$:\${libdir}:" ruby-*.pc
make -j2 V=1
make install
# Correct rpath for dynamic libraries
if [[ "$_EXTRA_ARGS" == *--enable-rpath* ]]; then
"$_SC_DIR/change_to_rpath.sh" "$_PREFIX/bin/ruby" "$_PREFIX/lib"
"$_SC_DIR/change_to_rpath.sh" "$_PREFIX/lib/libruby.dylib"
for f in $(cd "$_PREFIX/lib"; find ruby -name '*.bundle'); do
"$_SC_DIR/change_to_rpath.sh" "$_PREFIX/lib/$f" "$_PREFIX/lib" \
"@loader_path/$(dirname "$f" | sed 's:[^/]*:..:g')"
done
fi
# Cleanup & fix permissions
rmdir "$_PREFIX"/lib/ruby/{site_ruby,vendor_ruby}/*/*-darwin*/ \
"$_PREFIX"/lib/ruby/{site_ruby,vendor_ruby}/*/ \
"$_PREFIX"/include/ruby-*/ruby-*/*-darwin*/ "$_PREFIX"/include/ruby-*/ruby-*/ || true
chmod g+w "$_PREFIX"/bin "$_PREFIX"/lib/ruby/*/*-darwin*/rbconfig.rb
chmod -R g+w "$_PREFIX"/lib/ruby/{site_ruby,vendor_ruby} "$_PREFIX"/lib/ruby/gems/*/*
chmod -R g-w "$_PREFIX"/lib/ruby/gems/*/specifications/default || true
if [[ "$_NO_TESTS" == 0 ]]; then
sed -i- 's:^\(MINIRUBY *= *\)\./miniruby:\1$(prefix)/bin/ruby:' Makefile
touch -r Makefile- Makefile && make test test-all
fi