Skip to content

Instantly share code, notes, and snippets.

@ttilley
Created June 25, 2012 17:45
Show Gist options
  • Save ttilley/2990121 to your computer and use it in GitHub Desktop.
Save ttilley/2990121 to your computer and use it in GitHub Desktop.
updated homebrew formula for Boehm-Demers-Weiser GC supporting building from head and passing in various options to the build
require 'formula'
class Formula
def configure_path_args(choices={})
vars = {
:prefix => self.prefix,
:'exec-prefix' => self.prefix,
:bindir => self.bin,
:sbindir => self.sbin,
:libexecdir => self.libexec,
:sysconfdir => self.etc,
:localstatedir => self.var,
:libdir => self.lib,
:includedir => self.include,
:datarootdir => self.share,
:datadir => self.share,
:infodir => self.info,
:localedir => self.share+'locale',
:mandir => self.man,
:docdir => self.doc,
:htmldir => self.doc,
:dvidir => self.doc,
:pdfdir => self.doc,
:psdir => self.doc,
}.merge(choices)
vars.map {|option, value| "--#{option}=#{value}" }
end
# can be used with a block:
# configure_flag('cow') { foo.can_moo? }
# => "--enable-cow"
# the enable/disable strings can be customized:
# configure_flag('sparkles', 'with', 'without') { false }
# => "--without-sparkles"
# you can also just pass in the flag and the state string you want:
# configure_flag('cupcakes', 'fuck-yeah')
# => "--fuck-yeah-cupcakes"
def configure_flag(flag, enable='enable', disable='disable')
if block_given?
"--#{!!yield ? enable : disable}-#{flag}"
else
"--#{enable}-#{flag}"
end
end
end
class SubRepoStrategy < GitDownloadStrategy
def initialize url, name, version, specs
super
@main_url = @url
@main_clone = @clone
@subrepo_url = specs[:subrepo]
@subrepo_name = File.basename(@subrepo_url, '.git')
@subrepo_clone = @clone+@subrepo_name
end
def fetch
begin
super
@url = @subrepo_url
@clone = @subrepo_clone
super
ensure
@url = @main_url
@clone = @main_clone
end
end
def stage
begin
super
@url = @subrepo_url
@clone = @subrepo_clone
super
ensure
@url = @main_url
@clone = @main_clone
end
end
end
class BdwGc < Formula
homepage 'http://www.hpl.hp.com/personal/Hans_Boehm/gc/'
url 'http://www.hpl.hp.com/personal/Hans_Boehm/gc/gc_source/gc-7.2.tar.gz'
md5 'd17aecedef3d73e75387fb63558fa4eb'
head 'git://github.com/ivmai/bdwgc.git',
:branch => 'master',
:subrepo => 'git://github.com/ivmai/libatomic_ops.git',
:using => SubRepoStrategy
depends_on('autoconf' => :build) if ARGV.build_head?
def options
[
["--parallel-mark", "parallelize marking and free list construction"],
["--disable-cplusplus", "disable C++ support"],
["--gc-debug", "include full support for pointer backtracing etc"],
["--gc-assertions", "collector-internal assertion checking"],
["--redirect-malloc", "redirect malloc and friends to GC routines"],
["--large-config", "optimize for large (> 100MB) heap or root set"],
["--handle-fork", "attempt to ensure a usable collector after fork()" \
" in multi-threaded programs"]
]
end
def install
darwin_release = `uname -r`.to_f.floor
ENV.append_to_cflags("-D_XOPEN_SOURCE=600 -D_DARWIN_C_SOURCE")
ENV.remove_from_cflags('-D_XOPEN_SOURCE=600') if 8 >= darwin_release
ENV.Og unless ARGV.build_stable?
system "./autogen.sh" if ARGV.build_head?
args = '--disable-dependency-tracking',
'--with-threads=posix',
'--with-pic',
'--with-libatomic-ops=check'
args << configure_flag('parallel-mark') {ARGV.flag? '--parallel-mark'}
args << configure_flag('cplusplus') {!ARGV.flag? '--disable-cplusplus'}
args << configure_flag('gc-debug') {ARGV.flag? '--gc-debug'}
args << configure_flag('redirect-malloc') {ARGV.flag? '--redirect-malloc'}
args << configure_flag('handle-fork') {ARGV.flag? '--handle-fork'}
args << configure_flag('gc-assertions') {ARGV.flag? '--gc-assertions'}
system "./configure", *(self.configure_path_args + args)
system "make"
system "make check"
system "make install"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment