mxcl/homebrew — pull request #22674 by darinmorrison (2013-09-19 03:55:34+00:00)
Title: ghc: fix building with Xcode 5 (again)

After #21960 I thought the `ghc` formula was building on Xcode 5. However, I just tested it again and it's not. Here's what I found after a little bit of digging:

The final commit I made in that thread included a change to the `configure`, specifically to pass the `--with-gcc` argument. Without this, the `configure` will choose `clang` even when `fails_with` is being used. See the line in question here:

https://github.com/darinmorrison/homebrew/blob/7e9f31a391ad52c5b8a1383f13c11ebe7dcf60bb/Library/Formula/ghc.rb#L80

At the time I didn't realize that Xcode 5 was also available for 10.8, hence the check for 10.9 (where Xcode 5, and thus `clang` are the default). @mikemcquaid made a change to my commit which should have generalized the solution to also work on 10.8 with Xcode 5. See here:

https://github.com/mxcl/homebrew/blob/93fe0378e7fbecf6ac9d0890cac2c1714c613a97/Library/Formula/ghc.rb#L60

Unfortunately, this change doesn't work and now causes _all_ Xcode 5 builds to fail (10.8 and 10.9). The reason why is because the condition is never true: specifically, `ENV.compiler` is not equal to `:gcc` even when `fails_with :clang` causes `apple-gcc42` to be selected.

To demonstrate, I added the following lines to the `ghc.rb`:

```ruby
puts ":clang - #{:clang}"
puts ":gcc - #{:gcc}"
puts ":gcc_4_0 - #{:gcc_4_0}"
puts ":gcc_4_0_1 - #{:gcc_4_0_1}"
puts ":gcc_4_2 - #{:gcc_4_2}"
puts ":llvm - #{:llvm}"
puts "MacOS.default_compiler - #{MacOS.default_compiler}"
puts "ENV.cc - #{ENV.cc}"
puts "ENV.compiler - #{ENV.compiler}"
puts "args - #{args}"
```

Here's the output (on 10.8.5 with Xcode 5 GM):

```
:clang - clang
:gcc - gcc
:gcc_4_0 - gcc_4_0
:gcc_4_0_1 - gcc_4_0_1
:gcc_4_2 - gcc_4_2
:llvm - llvm
MacOS.default_compiler - clang
ENV.cc - /usr/local/bin/gcc-4.2
ENV.compiler - clang
args - --prefix=/private/tmp/default-EdOK/ghc-7.6.3/subfo
```

Here's the output of `brew --config`:

```
HOMEBREW_VERSION: 0.9.4
ORIGIN: https://github.com/mxcl/homebrew
HEAD: eeebe553919372efcb2a90f8d2b3f0fac9900c9a
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
CPU: 6-core 64-bit ivybridge
OS X: 10.8.5-x86_64
Xcode: 5.0
CLT: 5.0.0.0.1.1377666378
GCC-4.2: build 5666
LLVM-GCC: N/A
Clang: 5.0 build 500
X11: N/A
System Ruby: 1.8.7-358
Perl: /usr/bin/perl
Python: /usr/bin/python
Ruby: /usr/bin/ruby => /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
```

The solution is simply to remove the conditional and always pass `--with-gcc`. This seems to work fine in both cases (with Xcode 5 or with earlier versions). It's also the same approach used by the MacPorts folk:

https://trac.macports.org/browser/trunk/dports/lang/ghc/Portfile?order=name

I missed this because I was using a modified version of the original commit I made in the thread and of course the build bots didn't catch it because they aren't using Xcode 5 yet (AFAIK).