Skip to content

Instantly share code, notes, and snippets.

@chorn
Created July 8, 2014 11:53
Show Gist options
  • Save chorn/ef38193ad167982ef492 to your computer and use it in GitHub Desktop.
Save chorn/ef38193ad167982ef492 to your computer and use it in GitHub Desktop.
OS X Homebrew Formula compatible with Yosemite (10.10) and Xcode6 Beta as of 2014-07-08
require 'formula'
class Gcc49 < Formula
def arch
if Hardware::CPU.type == :intel
if MacOS.prefer_64_bit?
'x86_64'
else
'i686'
end
elsif Hardware::CPU.type == :ppc
if MacOS.prefer_64_bit?
'ppc64'
else
'ppc'
end
end
end
def osmajor
`uname -r`.chomp
end
homepage 'http://gcc.gnu.org'
url 'http://ftpmirror.gnu.org/gcc/gcc-4.9.0/gcc-4.9.0.tar.bz2'
mirror 'ftp://gcc.gnu.org/pub/gcc/releases/gcc-4.9.0/gcc-4.9.0.tar.bz2'
sha1 'fbde8eb49f2b9e6961a870887cf7337d31cd4917'
# head 'svn://gcc.gnu.org/svn/gcc/branches/gcc-4_9-branch'
head 'svn://gcc.gnu.org/svn/gcc/trunk', :revision => "{2014-06-17}"
if MacOS.version == '10.10'
patch do
url 'https://gcc.gnu.org/bugzilla/attachment.cgi?id=32949'
sha1 '1d567683f67d58b23fc26ceeb33d5153c665dc8a'
end
end
option 'enable-fortran', 'Build the gfortran compiler'
option 'enable-java', 'Build the gcj compiler'
option 'enable-all-languages', 'Enable all compilers and languages, except Ada'
option 'enable-nls', 'Build with native language support (localization)'
option 'enable-profiled-build', 'Make use of profile guided optimization when bootstrapping GCC'
# enabling multilib on a host that can't run 64-bit results in build failures
option 'disable-multilib', 'Build without multilib support' if MacOS.prefer_64_bit?
depends_on 'gmp4'
depends_on 'libmpc08'
depends_on 'mpfr2'
depends_on 'cloog018'
depends_on 'isl011'
depends_on 'ecj' if build.include? 'enable-java' or build.include? 'enable-all-languages'
def install
# GCC bootstraps itself, so it is OK to have an incompatible C++ stdlib
cxxstdlib_check :skip
# GCC will suffer build errors if forced to use a particular linker.
ENV.delete 'LD'
if build.include? 'enable-all-languages'
# Everything but Ada, which requires a pre-existing GCC Ada compiler
# (gnat) to bootstrap. GCC 4.6.0 add go as a language option, but it is
# currently only compilable on Linux.
languages = %w[c c++ fortran java objc obj-c++]
else
# C, C++, ObjC compilers are always built
languages = %w[c c++ objc obj-c++]
languages << 'fortran' if build.include? 'enable-fortran'
languages << 'java' if build.include? 'enable-java'
end
version_suffix = '4.9'
args = [
"--build=#{arch}-apple-darwin#{osmajor}",
"--prefix=#{prefix}",
"--enable-languages=#{languages.join(',')}",
# Make most executables versioned to avoid conflicts.
"--program-suffix=-#{version_suffix}",
"--with-gmp=#{Formula["gmp4"].opt_prefix}",
"--with-mpfr=#{Formula["mpfr2"].opt_prefix}",
"--with-mpc=#{Formula["libmpc08"].opt_prefix}",
"--with-cloog=#{Formula["cloog018"].opt_prefix}",
"--with-isl=#{Formula["isl011"].opt_prefix}",
"--with-system-zlib",
# This ensures lib, libexec, include are sandboxed so that they
# don't wander around telling little children there is no Santa
# Claus.
"--enable-version-specific-runtime-libs",
"--enable-libstdcxx-time=yes",
"--enable-stage1-checking",
"--enable-checking=release",
"--enable-lto",
# A no-op unless --HEAD is built because in head warnings will
# raise errors. But still a good idea to include.
"--disable-werror",
"--with-pkgversion=Homebrew #{name} #{pkg_version} #{build.used_options*" "}".strip,
"--with-bugurl=https://github.com/Homebrew/homebrew-versions/issues",
]
# "Building GCC with plugin support requires a host that supports
# -fPIC, -shared, -ldl and -rdynamic."
args << "--enable-plugin" if MacOS.version > :tiger
# Otherwise make fails during comparison at stage 3
# See: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45248
args << '--with-dwarf2' if MacOS.version < :leopard
args << '--disable-nls' unless build.include? 'enable-nls'
if build.include? 'enable-java' or build.include? 'enable-all-languages'
args << "--with-ecj-jar=#{Formula["ecj"].opt_prefix}/share/java/ecj.jar"
end
if !MacOS.prefer_64_bit? || build.include?('disable-multilib')
args << '--disable-multilib'
else
args << '--enable-multilib'
end
mkdir 'build' do
unless MacOS::CLT.installed?
# For Xcode-only systems, we need to tell the sysroot path.
# 'native-system-header's will be appended
args << "--with-native-system-header-dir=/usr/include"
args << "--with-sysroot=#{MacOS.sdk_path}"
end
system '../configure', *args
if build.include? 'enable-profiled-build'
# Takes longer to build, may bug out. Provided for those who want to
# optimise all the way to 11.
system 'make profiledbootstrap'
else
system 'make bootstrap'
end
# At this point `make check` could be invoked to run the testsuite. The
# deja-gnu and autogen formulae must be installed in order to do this.
system 'make install'
end
# Handle conflicts between GCC formulae.
# Since GCC 4.8 libffi stuff are no longer shipped.
# Rename libiberty.a.
Dir.glob(prefix/"**/libiberty.*") { |file| add_suffix file, version_suffix }
# Rename man7.
Dir.glob(man7/"*.7") { |file| add_suffix file, version_suffix }
# Even when suffixes are appended, the info pages conflict when
# install-info is run. TODO fix this.
info.rmtree
# Since GCC 4.9 java properties are properly sandboxed.
end
def add_suffix file, suffix
dir = File.dirname(file)
ext = File.extname(file)
base = File.basename(file, ext)
File.rename file, "#{dir}/#{base}-#{suffix}#{ext}"
end
end
@chorn
Copy link
Author

chorn commented Jul 8, 2014

brew install gcc49 --HEAD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment