Skip to content

Commit

Permalink
Multiple compiler support
Browse files Browse the repository at this point in the history
Added clang as fallback for GCC if using require_cc, particularly
useful for Mac OS X and Xcode 4.2. require_gcc still mandates gcc.
  • Loading branch information
lloeki committed Nov 7, 2011
1 parent 495b248 commit a15aa7f
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions bin/ruby-build
Expand Up @@ -200,6 +200,41 @@ fix_directory_permissions() {
find "$PREFIX_PATH" -type d -exec chmod go-w {} \; 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() { require_gcc() {
local gcc="$(locate_gcc || true)" local gcc="$(locate_gcc || true)"
if [ -z "$gcc" ]; then if [ -z "$gcc" ]; then
Expand All @@ -224,6 +259,14 @@ require_gcc() {
export CC="$gcc" export CC="$gcc"
} }


locate_clang() {
local clang
verify_clang "$CC" ||
verify_clang "$(command -v clang || true)"

return 1
}

locate_gcc() { locate_gcc() {
local gcc gccs local gcc gccs
shopt -s nullglob shopt -s nullglob
Expand All @@ -240,6 +283,20 @@ locate_gcc() {
return 1 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() { verify_gcc() {
local gcc="$1" local gcc="$1"
if [ -z "$gcc" ]; then if [ -z "$gcc" ]; then
Expand Down

0 comments on commit a15aa7f

Please sign in to comment.