Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 417 lines (337 sloc) 7.942 kb
#!/usr/bin/env bash
RUBY_BUILD_VERSION="20111030"
set -E
exec 3<&2 # preserve original stderr at fd 3
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"
}
build_failed() {
{ echo
echo "BUILD FAILED"
echo
if ! rmdir "${TEMP_PATH}" 2>/dev/null; then
echo "Inspect or clean up the working tree at ${TEMP_PATH}"
if file_is_not_empty "$LOG_PATH"; then
echo "Results logged to ${LOG_PATH}"
echo
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
}
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
pushd "$TEMP_PATH" >&4
"fetch_${package_type}" "$package_name" $*
shift $(($package_type_nargs))
make_package "$package_name" $*
popd >&4
echo "Installed ${package_name} to ${PREFIX_PATH}" >&2
}
make_package() {
local package_name="$1"
shift
pushd "$package_name" >&4
build_package "$package_name" $*
after_install_package "$package_name"
fix_directory_permissions
popd >&4
}
fetch_tarball() {
local package_name="$1"
local package_url="$2"
echo "Downloading ${package_url}..." >&2
{ curl "$package_url" > "${package_name}.tar.gz"
tar xzvf "${package_name}.tar.gz"
} >&4 2>&1
}
fetch_git() {
local package_name="$1"
local git_url="$2"
local git_ref="$3"
echo "Cloning ${git_url}..." >&2
{ git clone --depth 1 --branch "$git_ref" "$git_url" "${package_name}"
} >&4 2>&1
}
build_package() {
local package_name="$1"
shift
if [ "$#" -eq 0 ]; then
local commands="standard"
else
local commands="$*"
fi
echo "Installing ${package_name}..." >&2
for command in $commands; do
"build_package_${command}"
done
}
build_package_standard() {
local package_name="$1"
{ ./configure --prefix="$PREFIX_PATH" $CONFIGURE_OPTS
make -j 2
make install
} >&4 2>&1
}
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() {
local options=""
if [[ "Darwin" = "$(uname)" ]]; then
options="--no-tcmalloc"
fi
# 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"
{ ./configure --prefix="$PREFIX_PATH" --gemsdir="$PREFIX_PATH"
rake install
} >&4 2>&1
}
build_package_jruby() {
build_package_copy
cd "${PREFIX_PATH}/bin"
ln -fs jruby ruby
install_jruby_launcher
remove_windows_files
}
install_jruby_launcher() {
cd "${PREFIX_PATH}/bin"
{ ./ruby gem install jruby-launcher
} >&4 2>&1
}
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 -R . "$PREFIX_PATH"
}
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 -exec chmod go-w {} \;
}
require_cc() {
local cc ccs
ccs="gcc clang"
for cc in $ccs; do
cc="$("locate_$cc" || true)"
[ -n "$cc" ] && break
done
if [ -z "$cc" ]; then
{ echo
echo "ERROR: This package must be compiled from source, and we"
echo "couldn't find a suitable compiler on your system."
echo "Please install any of the following compilers and try again:"
echo
for cc in $ccs; do
echo "- $cc"
done
echo
if [ "$(uname -s)" = "Darwin" ]; then
echo "As of version 4.2, Xcode is LLVM-only and no longer"
echo "includes GCC. You can install GCC with these binary"
echo "packages on Mac OS X:"
echo
echo "https://github.com/kennethreitz/osx-gcc-installer/downloads"
echo
fi
} >&3
return 1
fi
export CC="$cc"
}
require_gcc() {
local gcc="$(locate_gcc || true)"
if [ -z "$gcc" ]; then
{ echo
echo "ERROR: This package must be compiled with GCC, and we"
echo "couldn't find a suitable \`gcc' binary on your system."
echo "Please install GCC and try again."
echo
if [ "$(uname -s)" = "Darwin" ]; then
echo "As of version 4.2, Xcode is LLVM-only and no longer"
echo "includes GCC. You can install GCC with these binary"
echo "packages on Mac OS X:"
echo
echo "https://github.com/kennethreitz/osx-gcc-installer/downloads"
echo
fi
} >&3
return 1
fi
export CC="$gcc"
}
locate_clang() {
local clang
verify_clang "$CC" ||
verify_clang "$(command -v clang || true)"
return 1
}
locate_gcc() {
local gcc gccs
shopt -s nullglob
gccs=( /usr/bin/gcc-* )
shopt -u nullglob
verify_gcc "$CC" ||
verify_gcc "$(command -v gcc || true)" || {
for gcc in "${gccs[@]}"; do
verify_gcc "$gcc" && break || true
done
}
return 1
}
verify_clang() {
local clang="$1"
if [ -z "$clang" ]; then
return 1
fi
local version="$("$clang" --version || true)"
if [ -z "$version" ]; then
return 1
fi
echo "$clang"
}
verify_gcc() {
local gcc="$1"
if [ -z "$gcc" ]; then
return 1
fi
local version="$("$gcc" --version || true)"
if [ -z "$version" ]; then
return 1
fi
if echo "$version" | grep LLVM >/dev/null; then
return 1
fi
echo "$gcc"
}
version() {
echo "ruby-build ${RUBY_BUILD_VERSION}"
}
usage() {
{ version
echo "usage: ruby-build [-v|--verbose] definition prefix"
echo " ruby-build --definitions"
} >&2
if [ -z "$1" ]; then
exit 1
fi
}
list_definitions() {
{ for definition in "${RUBY_BUILD_ROOT}/share/ruby-build/"*; do
echo "${definition##*/}"
done
} | sort
}
unset VERBOSE
RUBY_BUILD_ROOT="$(abs_dirname "$0")/.."
case "$1" in
"-h" | "--help" )
usage without_exiting
{ echo
echo " -v/--verbose Verbose mode: print compilation status to stdout"
echo " --definitions List all built-in definitions"
echo
} >&2
exit 0
;;
"--definitions" )
list_definitions
exit 0
;;
"--version" )
version
exit 0
;;
"-v" | "--verbose" )
VERBOSE=true
shift
;;
esac
DEFINITION_PATH="$1"
if [ -z "$DEFINITION_PATH" ]; then
usage
elif [ ! -e "$DEFINITION_PATH" ]; then
BUILTIN_DEFINITION_PATH="${RUBY_BUILD_ROOT}/share/ruby-build/${DEFINITION_PATH}"
if [ -e "$BUILTIN_DEFINITION_PATH" ]; then
DEFINITION_PATH="$BUILTIN_DEFINITION_PATH"
else
echo "ruby-build: definition not found: ${DEFINITION_PATH}" >&2
exit 1
fi
fi
PREFIX_PATH="$2"
if [ -z "$PREFIX_PATH" ]; then
usage
fi
if [ -z "$TMPDIR" ]; then
TMP="/tmp"
else
TMP="${TMPDIR%/}"
fi
SEED="$(date "+%Y%m%d%H%M%S").$$"
LOG_PATH="${TMP}/ruby-build.${SEED}.log"
TEMP_PATH="${TMP}/ruby-build.${SEED}"
RUBY_BIN="${PREFIX_PATH}/bin/ruby"
CWD="$(pwd)"
exec 4<> "$LOG_PATH" # open the log file at fd 4
if [ -n "$VERBOSE" ]; then
tail -f "$LOG_PATH" &
trap "kill 0" SIGINT SIGTERM EXIT
fi
export LDFLAGS="-L'${PREFIX_PATH}/lib' ${LDFLAGS}"
export CPPFLAGS="-I'${PREFIX_PATH}/include' ${CPPFLAGS}"
unset RUBYOPT
unset RUBYLIB
trap build_failed ERR
mkdir -p "$TEMP_PATH"
source "$DEFINITION_PATH"
rm -fr "$TEMP_PATH"
trap - ERR
Jump to Line
Something went wrong with that request. Please try again.