aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Formula/gfortran.rb
blob: 8f9c65dcca67264b30d6e075a265600fcd606b39 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
require 'formula'

class GfortranPkgDownloadStrategy < CurlDownloadStrategy
  def stage
    # The 4.2.4 compiler is distributed as a OS X 10.5
    # package- a single flat xar archive instead of a
    # bundle.
    safe_system '/usr/bin/xar', '-xf', @tarball_path
    chdir

    # Clean up.
    safe_system "mv *.pkg/Payload Payload.gz"
    safe_system "ls | grep -v Payload | xargs rm -r"
  end
end

class Gfortran < Formula
  if MacOS.leopard?
    url 'http://r.research.att.com/gfortran-42-5577.pkg'
    md5 '30fb495c93cf514003cdfcb7846dc701'
    version "4.2.4-5577"
  elsif MACOS_VERSION == 10.6
    # Snow Leopard
    case gcc_42_build
    when 5659
      url 'http://r.research.att.com/gfortran-42-5659.pkg'
      md5 '71bd546baa45c9c0fb4943cdd72ee274'
      version "4.2.4-5659"
    else
      # This version works for XCode 3.2.3-4.0 on Snow Leopard.
      url 'http://r.research.att.com/gfortran-42-5664.pkg'
      md5 'eb64ba9f8507da22e582814a69fbb7ca'
      version "4.2.4-5664"
    end
  else
    # Lion
    if MacOS.xcode_version >= '4.2'
      # This version contains an entire Apple-GCC 4.2 (i386/x86_64) build for
      # Lion. After installation, we will remove all compilers other than
      # GFortran.
      url 'http://r.research.att.com/tools/gcc-42-5666.3-darwin11.pkg'
      md5 '3ccf46da27aaba17706b420711fb997e'
      version '4.2.4-5666.3'
    else
      url 'http://r.research.att.com/gfortran-lion-5666-3.pkg'
      md5 '7eb140822c89bec17db5666859868b3b'
      version "4.2.4-5666.3"
    end
  end

  homepage 'http://r.research.att.com/tools/'

  def download_strategy
    GfortranPkgDownloadStrategy
  end

  # Shouldn't strip compiler binaries.
  skip_clean :all

  def install
    # The version of pax jumped 16 years in development between OS X 10.5
    # and OS X 10.6. In that time it became security conscious. Additionally,
    # there are some slight variations in the packaging- because of this
    # installation is broken down by GCC version.
    case gcc_42_build
    when 5577
      ohai "Installing gfortran 4.2.4 for XCode 3.1.4 (build 5577)"
      safe_system "pax -rz -f Payload.gz -s ',./usr,#{prefix},'"
      # The 5577 package does not contain the gfortran->gfortran-4.2 symlink
      safe_system "ln -sf #{bin}/gfortran-4.2 #{bin}/gfortran"
      safe_system "ln -sf #{man1}/gfortran-4.2.1 #{man1}/gfortran.1"
    when 5659
      ohai "Installing gfortran 4.2.4 for XCode 3.2.2 (build 5659)"
      safe_system "pax --insecure -rz -f Payload.gz -s ',./usr,#{prefix},'"
      safe_system "ln -sf #{man1}/gfortran-4.2.1 #{man1}/gfortran.1"
    when 5664
      ohai "Installing gfortran 4.2.4 for XCode 3.2.3 (build 5664)"
      safe_system "pax --insecure -rz -f Payload.gz -s ',./usr,#{prefix},'"
      safe_system "ln -sf #{man1}/gfortran-4.2.1 #{man1}/gfortran.1"
    when 5666
      ohai "Installing gfortran 4.2.4 for XCode 3.2.6--4.1 (build 5666)"
      safe_system "pax --insecure -rz -f Payload.gz -s ',./usr,#{prefix},'"
      safe_system "ln -sf #{man1}/gfortran-4.2.1 #{man1}/gfortran.1"
    else
      if MacOS.xcode_version >= '4.2'
          ohai "Installing gfortran 4.2.4 for XCode 4.2 (build 5666)"
          safe_system "pax --insecure -rz -f Payload.gz -s ',./usr,#{prefix},'"

          safe_system "ln -sf #{man1}/gfortran-4.2.1 #{man1}/gfortran.1"
          # This package installs a whole GCC suite. Remove non-fortran
          # components.
          bin.children.reject{|p| p.basename.to_s.match /gfortran/}.each{|p| rm p}
          man1.children.reject{|p| p.basename.to_s.match /gfortran/}.each{|p| rm p}
          (include + 'gcc').rmtree
          # This package does not contain the gfortran->gfortran-4.2 symlink
          safe_system "ln -sf #{bin}/gfortran-4.2 #{bin}/gfortran"
      else
        onoe <<-EOS.undent
            Currently the gfortran compiler provided by this brew is only supported
            for:

              - XCode 3.1.4 on OS X 10.5.x
              - XCode 3.2.2/3.2.3 -- 4.0 on OS X 10.6.x
              - XCode 4.1/4.2 on OS X 10.7.x

            The AppStore and Software Update can help upgrade your copy of XCode.
            The latest version of XCode is also available from:

                http://developer.apple.com/technologies/xcode.html
        EOS
        exit
      end
    end
  end

  def caveats; <<-EOS.undent
    Brews that require a Fortran compiler should not use:
      depends_on 'gfortran'

    The preferred method of declaring Fortran support is to use:
      def install
        ...
        ENV.fortran
        ...
      end

    EOS
  end
end