aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Formula/spidermonkey.rb
blob: 5b172b6172846595ccc3b135b121b5f74dc5694b (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
require 'formula'

class Spidermonkey <Formula
  # There are no proper releases of spidermonkey, so pick a version that's known
  # to work (especially with CouchDB), revision r35345.
  url 'http://hg.mozilla.org/tracemonkey/archive/57a6ad20eae9.tar.gz'
  homepage 'https://developer.mozilla.org/en/SpiderMonkey'
  md5 '2d8cf22da82b30c36f47675a8486a3f3'
  version '1.8.5'

  depends_on 'readline'
  depends_on 'nspr'

  def patches
    # Export date functions needed by manually-compiled MongoDB.
    # Is it just me or is the version-to-version stable API of SpiderMonkey kind of a mess?
    "http://gist.github.com/raw/426476/a98a15a94ca4efd3aeafb3b5cd943491b53cbf81/001-Properly-export-js_DateClass-and-js_RegExpClass.patch"
  end

  def install
    if MACOS_VERSION == 10.5
      # aparently this flag causes the build to fail for ivanvc on 10.5 with a
      # penryn (core 2 duo) CPU. So lets be cautious here and remove it.
      # It might not be need with newer spidermonkeys anymore tho.
      ENV['CFLAGS'] = ENV['CFLAGS'].gsub(/-msse[^\s]+/, '')
    end

    # For some reason SpiderMonkey requires Autoconf-2.13
    ac213_prefix = Pathname.pwd.join('ac213')
    Autoconf213.new.brew do |f|
      # probably no longer required, see issue #751
      inreplace 'configure', 'for ac_prog in mawk gawk nawk awk', 'for ac_prog in awk'

      system "./configure", "--disable-debug",
                            "--program-suffix=213",
                            "--prefix=#{ac213_prefix}"
      system "make install"
    end

    Dir.chdir "js/src" do
      # Fixes a bug with linking against CoreFoundation. Tests all pass after
      # building like this. See: http://openradar.appspot.com/7209349
      inreplace "configure.in", "LDFLAGS=\"$LDFLAGS -framework Cocoa\"", ""
      system "#{ac213_prefix}/bin/autoconf213"
      # Remove the broken *(for anyone but FF) install_name
      inreplace "config/rules.mk", "-install_name @executable_path/$(SHARED_LIBRARY) ", ""
    end

    FileUtils.mkdir "brew-build"

    Dir.chdir "brew-build" do
      system "../js/src/configure", "--prefix=#{prefix}",
                                    "--enable-readline",
                                    "--enable-threadsafe",
                                    "--with-system-nspr"

      inreplace "js-config", /JS_CONFIG_LIBS=.*?$/, "JS_CONFIG_LIBS=''"
      # Can't do `make install` right off the bat sadly
      system "make"
      system "make install"

      # The `js` binary ins't installed. Lets do that too, eh?
      bin.install "shell/js"
    end
  end
end


class Autoconf213 <Formula
  url 'http://ftp.gnu.org/pub/gnu/autoconf/autoconf-2.13.tar.gz'
  md5 '9de56d4a161a723228220b0f425dc711'
  homepage 'http://www.gnu.org/software/autoconf/'
end