Skip to content

Commit

Permalink
ghc: cleanup/decruft.
Browse files Browse the repository at this point in the history
- Fix static GMP
- Remove --32-bit option (ghc 7.6 or newer is needed to build).
- Building with llvm-gcc and 7.6.3 works on Snow Leopard and Lion.

Closes Homebrew/legacy-homebrew#39134.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
  • Loading branch information
geoff-nixon authored and MikeMcQuaid committed May 13, 2015
1 parent 74fe38b commit 2bcd427
Showing 1 changed file with 58 additions and 122 deletions.
180 changes: 58 additions & 122 deletions Formula/ghc.rb
Expand Up @@ -3,170 +3,106 @@ class Ghc < Formula
url "https://downloads.haskell.org/~ghc/7.10.1/ghc-7.10.1-src.tar.xz"
sha256 "92f3e3d67a637c587c49b61c704a670953509eb4b17a93c0c2ac153da4cd3aa0"

revision 1

bottle do
revision 1
sha256 "c2ec277a5445ece878b940838a93feed7a0c7733273ddcb26c07ec434f6ad800" => :yosemite
sha256 "1107ca8344e4bf2229d78cee7b3ee7a86f06d950f4a3b6c5c58d66675922935b" => :mavericks
sha256 "ad654abb4c2459b6cc764f275d5b6b141669e366f5051c58d871e54cb71a250c" => :mountain_lion
end

option "32-bit"
option "with-tests", "Verify the build using the testsuite."

deprecated_option "tests" => "with-tests"

# http://hackage.haskell.org/trac/ghc/ticket/6009
depends_on :macos => :snow_leopard
depends_on "gcc" if MacOS.version == :mountain_lion

resource "gmp" do
url "http://ftpmirror.gnu.org/gmp/gmp-6.0.0a.tar.bz2"
mirror "ftp://ftp.gmplib.org/pub/gmp/gmp-6.0.0a.tar.bz2"
mirror "https://ftp.gnu.org/gnu/gmp/gmp-6.0.0a.tar.bz2"
mirror "ftp://ftp.gnu.org/gnu/gmp/gmp-6.0.0a.tar.bz2"
sha256 "7f8e9a804b9c6d07164cf754207be838ece1219425d64e28cfa3e70d5c759aaf"
end

if build.build_32_bit? || !MacOS.prefer_64_bit?
resource "binary" do
url "https://downloads.haskell.org/~ghc/7.4.2/ghc-7.4.2-i386-apple-darwin.tar.bz2"
sha256 "80c946e6d66e46ca5d40755f3fbe3100e24c0f8036b850fd8767c4f9efd02bef"
end
elsif MacOS.version <= :lion
# https://ghc.haskell.org/trac/ghc/ticket/9257
resource "binary" do
url "https://downloads.haskell.org/~ghc/7.6.3/ghc-7.6.3-x86_64-apple-darwin.tar.bz2"
sha256 "f7a35bea69b6cae798c5f603471a53b43c4cc5feeeeb71733815db6e0a280945"
end
else
# there is currently no 7.10.1 binary download for darwin,
# so we use the one for 7.8.4 instead
resource "binary" do
url "https://downloads.haskell.org/~ghc/7.8.4/ghc-7.8.4-x86_64-apple-darwin.tar.xz"
sha256 "ebb6b0294534abda05af91798b43e2ea02481edacbf3d845a1e5925a211c67e3"
if MacOS.version <= :lion
fails_with :clang do
cause <<-EOS.undent
Fails to bootstrap ghc-cabal. Error is:
libraries/Cabal/Cabal/Distribution/Compat/Binary/Class.hs:398:14:
The last statement in a 'do' block must be an expression
n <- get :: Get Int getMany n
EOS
end
end

stable do
resource "testsuite" do
url "https://downloads.haskell.org/~ghc/7.10.1/ghc-7.10.1-testsuite.tar.xz"
sha256 "33bbdfcfa50363526ea9671c8c1f01b7c5dec01372604d45cbb53bb2515298cb"
resource "binary" do
if MacOS.version <= :lion
url "https://downloads.haskell.org/~ghc/7.6.3/ghc-7.6.3-x86_64-apple-darwin.tar.bz2"
sha256 "f7a35bea69b6cae798c5f603471a53b43c4cc5feeeeb71733815db6e0a280945"
else
url "https://downloads.haskell.org/~ghc/7.10.1/ghc-7.10.1-x86_64-apple-darwin.tar.xz"
sha256 "bc45de19efc831f7d5a3fe608ba4ebcd24cc0f414cac4bc40ef88a04640583f6"
end
end

fails_with :llvm do
cause <<-EOS.undent
cc1: error: unrecognized command line option "-Wno-invalid-pp-token"
cc1: error: unrecognized command line option "-Wno-unicode"
EOS
end

if build.build_32_bit? || !MacOS.prefer_64_bit? || MacOS.version < :mavericks
fails_with :clang do
cause <<-EOS.undent
Building with Clang configures GHC to use Clang as its preprocessor,
which causes subsequent GHC-based builds to fail.
EOS
end
resource "testsuite" do
url "https://downloads.haskell.org/~ghc/7.10.1/ghc-7.10.1-testsuite.tar.xz"
sha256 "33bbdfcfa50363526ea9671c8c1f01b7c5dec01372604d45cbb53bb2515298cb"
end

def install
ENV.m32 if build.build_32_bit?

# Build a static gmp (to avoid dynamic linking to ghc)
gmp_prefix = buildpath/"gmp-static"
resource("gmp").stage do
gmp_args = ["--prefix=#{gmp_prefix}", "--enable-cxx", "--enable-shared=no"]
gmp_args << "ABI=32" if build.build_32_bit?
# Build a static gmp rather than in-tree gmp, otherwise it links to brew's.
gmp = libexec/"integer-gmp"

# https://github.com/Homebrew/homebrew/issues/20693
gmp_args << "--disable-assembly" if build.build_32_bit? || build.bottle?
# MPN_PATH: The lowest common denomenator asm paths that work on Darwin,
# corresponding to Yonah and Merom. Obviates --disable-assembly.
ENV["MPN_PATH"] = "x86_64/fastsse x86_64/core2 x86_64 generic" if build.bottle?

system "./configure", *gmp_args
# GMP *does not* use PIC by default without shared libs so --with-pic
# is mandatory or else you'll get "illegal text relocs" errors.
resource("gmp").stage do
system "./configure", "--prefix=#{gmp}", "--with-pic", "--disable-shared"
system "make"
system "make", "check"
ENV.deparallelize
system "make", "install"
ENV.deparallelize { system "make", "install" }
end

# Move the main tarball contents into a subdirectory
(buildpath+"Ghcsource").install Dir["*"]
args = ["--with-gmp-includes=#{gmp}/include",
"--with-gmp-libraries=#{gmp}/lib",
"--with-ld=ld", # Avoid hardcoding superenv's ld.
# The offending -Wno-[unicode] flags get appended here, so set:
"--with-hs-cpp-flags=-E -undef -traditional",
"--with-gcc=#{ENV.cc}"] # Always.

if ENV.compiler == :clang
args << "--with-clang=#{ENV.cc}"
elsif ENV.compiler == :llvm
args << "--with-gcc-4.2=#{ENV.cc}"
end

resource("binary").stage do
# Define where the subformula will temporarily install itself
subprefix = buildpath+"subfo"
binary = buildpath/"binary"

# ensure configure does not use Xcode 5 "gcc" which is actually clang
system "./configure", "--prefix=#{subprefix}", "--with-gcc=#{ENV.cc}"

if MacOS.version <= :lion
# __thread is not supported on Lion but configure enables it anyway.
File.open("mk/config.h", "a") do |file|
file.write("#undef CC_SUPPORTS_TLS")
end
end
system "./configure", "--prefix=#{binary}", *args
ENV.deparallelize { system "make", "install" }

# -j1 fixes an intermittent race condition
system "make", "-j1", "install"
ENV.prepend_path "PATH", subprefix/"bin"
ENV.prepend_path "PATH", binary/"bin"
end

cd "Ghcsource" do
# Fix an assertion when linking ghc with llvm-gcc
# https://github.com/Homebrew/homebrew/issues/13650
ENV["LD"] = "ld"
system "./configure", "--prefix=#{prefix}", *args
system "make"

if build.build_32_bit? || !MacOS.prefer_64_bit?
arch = "i386"
else
arch = "x86_64"
if build.with? "tests"
resource("testsuite").stage { buildpath.install Dir["*"] }
cd "testsuite" do
system "make", "clean"
system "make", "CLEANUP=1", "THREADS=#{ENV.make_jobs}", "fast"
end

# These will find their way into ghc's settings file, ensuring
# that ghc will look in the Homebrew lib dir for native libs
# (e.g., libgmp) even if the prefix is not /usr/local. Both are
# necessary to avoid problems on systems with custom prefixes:
# ghci fails without the first, compiling packages that depend
# on native libs fails without the second.
ENV["CONF_CC_OPTS_STAGE2"] = "-B#{HOMEBREW_PREFIX}/lib"
ENV["CONF_GCC_LINKER_OPTS_STAGE2"] = "-L#{HOMEBREW_PREFIX}/lib"

# ensure configure does not use Xcode 5 "gcc" which is actually clang
system "./configure", "--prefix=#{prefix}",
"--build=#{arch}-apple-darwin",
"--with-gcc=#{ENV.cc}",
"--with-gmp-includes=#{gmp_prefix}",
"--with-gmp-libraries=#{gmp_prefix}"
system "make"

if build.with? "tests"
resource("testsuite").stage do
cd "testsuite" do
(buildpath+"Ghcsource/config").install Dir["config/*"]
(buildpath+"Ghcsource/driver").install Dir["driver/*"]
(buildpath+"Ghcsource/mk").install Dir["mk/*"]
(buildpath+"Ghcsource/tests").install Dir["tests/*"]
(buildpath+"Ghcsource/timeout").install Dir["timeout/*"]
end
cd (buildpath+"Ghcsource/tests") do
system "make", "CLEANUP=1", "THREADS=#{ENV.make_jobs}", "fast"
end
end
end

system "make"
# -j1 fixes an intermittent race condition
system "make", "-j1", "install"
# use clang, even when gcc was used to build ghc
settings = Dir[lib/"ghc-*/settings"][0]
inreplace settings, "\"#{ENV.cc}\"", "\"clang\""
end

ENV.deparallelize { system "make", "install" }
end

test do
hello = (testpath/"hello.hs")
hello.write('main = putStrLn "Hello Homebrew"')
output = `echo "main" | '#{bin}/ghci' #{hello}`
assert $?.success?
assert_match /Hello Homebrew/i, output
(testpath/"hello.hs").write('main = putStrLn "Hello Homebrew"')
system "runghc", testpath/"hello.hs"
end
end

0 comments on commit 2bcd427

Please sign in to comment.