aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Formula/ghc.rb
blob: 0c7feb9610e742b32b859b83e4d5b8b26a757989 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'formula'

class Ghc <Formula
  homepage 'http://haskell.org/ghc/'
  url "http://darcs.haskell.org/download/dist/6.12.3/GHC-6.12.3-i386.pkg"
  version '6.12.3'
  md5 '58399e3af68f50a23a847bdfe3de5aca'

  # Avoid stripping the Haskell binaries & libraries.
  # See: http://hackage.haskell.org/trac/ghc/ticket/2458
  skip_clean ['bin', 'lib']

  def replace_all foo, bar
    # Find all text files containing foo and replace it with bar
    files = `/usr/bin/grep -lsIR #{foo} .`.split
    inreplace files, foo, bar
  end

  def install
    short_version = version.split('.').first(2).join('')

    # Extract files from .pax.gz
    system '/bin/pax -f ghc.pkg/Payload -p p -rz'
    cd "GHC.framework/Versions/#{short_version}/usr"

    # Fix paths
    replace_all "/Library/Frameworks/GHC.framework/Versions/#{short_version}/usr/lib/ghc-#{version}", "#{lib}/ghc"
    replace_all "/Library/Frameworks/GHC.framework/Versions/#{short_version}/usr", prefix

    prefix.install ['bin', 'share']

    # Remove version from lib folder
    lib.install "lib/ghc-#{version}" => 'ghc'

    # Fix ghc-asm Perl reference
    inreplace "#{lib}/ghc/ghc-asm", "#!/opt/local/bin/perl", "#!/usr/bin/env perl"

    # Regenerate GHC package cache
    rm "#{lib}/ghc/package.conf.d/package.cache"
    system "#{bin}/ghc-pkg", 'recache', '--package-conf', "#{lib}/ghc/package.conf.d"
  end
end