Created
December 7, 2010 01:57
-
-
Save jonforums/731350 to your computer and use it in GitHub Desktop.
Ruby build helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ostruct' | |
require 'rake/clean' | |
# remove CLEAN defaults since this is a "global" Rakefile which means | |
# the defaults could recursively delete from other peer project dirs | |
CLEAN.clear | |
FLAVORS = [ | |
"TRUNK", | |
"TRUNKP", | |
"TRUNKOPT", | |
"RUBY192", | |
"RUBY187" | |
] | |
module BuildUtils | |
@@src_dir = 'ruby-git' | |
@@build_dir = '%s/build' % @@src_dir | |
@@install_dir = '%s/pkg' % @@build_dir | |
def self.src_dir | |
@@src_dir | |
end | |
def self.build_dir | |
@@build_dir | |
end | |
def self.install_dir | |
@@install_dir | |
end | |
MSYS = OpenStruct.new( | |
:base => 'c:/DevKit', | |
:shell => 'c:/DevKit/bin/bash.exe' | |
) | |
# TODO add libyaml include and library paths | |
DEPS = OpenStruct.new( | |
:lib_options => [ | |
"LDFLAGS='-Lc:/gnuwin32/zlib/lib -Lc:/gnuwin32/iconv/lib'" | |
], | |
:inc_options => [ | |
"CPPFLAGS='-Ic:/gnuwin32/zlib/include -Ic:/gnuwin32/iconv/include'" | |
] | |
) | |
TRUNK = OpenStruct.new( | |
:repo => 'http://svn.ruby-lang.org/repos/ruby/trunk', | |
:configure_options => [ | |
"--enable-shared", | |
"--disable-install-doc" | |
], | |
:configure_vars => [ | |
"optflags='-O0 -pipe'", | |
"debugflags='-g3 -ggdb'" | |
] | |
) | |
TRUNKP = OpenStruct.new( | |
:configure_options => [ | |
"--enable-shared", | |
"--disable-install-doc" | |
], | |
:configure_vars => [ | |
"optflags='-O -pipe -pg'", | |
"debugflags='-ggdb3'", | |
"LIBS='-lgmon'" | |
] | |
) | |
TRUNKOPT = OpenStruct.new( | |
:configure_options => [ | |
"--enable-shared", | |
"--disable-install-doc" | |
], | |
:configure_vars => [ | |
"optflags='-O3 -pipe -march=native -mtune=native'", | |
"debugflags=''" | |
] | |
) | |
RUBY192 = OpenStruct.new( | |
:repo => 'http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_9_2', | |
:configure_options => [ | |
"--enable-shared", | |
"--disable-install-doc" | |
], | |
:configure_vars => [ | |
"optflags='-O3 -pipe -march=native -mtune=native'", | |
"debugflags=''" | |
] | |
) | |
RUBY187 = OpenStruct.new( | |
:repo => 'http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8_7', | |
:configure_options => [ | |
"--enable-shared", | |
"--with-winsock2", | |
"--disable-install-doc" | |
], | |
:configure_vars => [ | |
"optflags='-O3 -pipe -march=native -mtune=native -DFD_SETSIZE=256'", | |
"debugflags=''" | |
] | |
) | |
def self.msys_sh(cmd, options={}) | |
cd_dir = "cd '#{File.expand_path(options[:dir])}' &&" if options[:dir] | |
sh "\"#{BuildUtils::MSYS.shell}\" --login -c \"#{cd_dir} #{cmd}\"" | |
end | |
def self.prepare(roob) | |
rm_rf '%s/autom4te.cache' % @@src_dir | |
rm_f %W( #{@@src_dir}/configure #{@@src_dir}/revision.h ) | |
msys_sh "autoconf", :dir => "#{@@src_dir}" | |
end | |
end # module BuildUtils | |
desc "update repositories" | |
task :rup do |t| | |
repo_dirs = Dir.glob('*-git').sort | |
repo_dirs.each do |d| | |
Dir.chdir(d) do |wd| | |
# TODO cleverness with `git ls-remote` and `git show-ref` comparisons | |
`git st` | |
if $?.exitstatus != 0 | |
puts 'need to do something' | |
end | |
end | |
end | |
end | |
CLOBBER << BuildUtils.build_dir | |
namespace :bld do | |
directory "#{BuildUtils.build_dir}" | |
directory "#{BuildUtils.install_dir}" | |
desc "configure Ruby interpreter [CC]" | |
task :configure, [:flavor] => [ "#{BuildUtils.build_dir}" ] do |t, args| | |
args.with_defaults :flavor => 'TRUNK' | |
abort "[ERROR] unknown Ruby flavor '#{args.flavor}'" unless FLAVORS.include? args.flavor.upcase | |
puts "configuring Ruby '#{args.flavor}' flavor..." | |
roob = BuildUtils.class_eval "#{args.flavor.upcase}" | |
BuildUtils.prepare(roob) | |
args = "#{roob.configure_options.join(' ')} " | |
args << "--prefix='#{File.expand_path(BuildUtils.install_dir)}' " | |
args << "#{roob.configure_vars.join(' ')} " | |
args << "#{roob.custom_options.join(' ')} " if roob.custom_options | |
args << "#{BuildUtils::DEPS.lib_options.join(' ')} #{BuildUtils::DEPS.inc_options.join(' ')} " | |
args << "CC='#{ENV['CC']}'" if ENV['CC'] | |
BuildUtils.msys_sh "../configure #{args}", :dir => "#{BuildUtils.build_dir}" | |
end # task :configure | |
desc "build Ruby targets [CC] [OPTFLAGS] [DEBUGFLAGS]" | |
task :make, [:target] do |t, args| | |
env = [] | |
env << "CC='#{ENV['CC']}'" if ENV['CC'] | |
env << "optflags='#{ENV['optflags']}'" if ENV['optflags'] | |
env << "debugflags='#{ENV['debugflags']}'" if ENV['debugflags'] | |
if env.empty? | |
BuildUtils.msys_sh "make #{args.target}", :dir => "#{BuildUtils.build_dir}" | |
else | |
BuildUtils.msys_sh "make #{args.target} #{env.join(' ')}", :dir => "#{BuildUtils.build_dir}" | |
end | |
end # task :make | |
# TODO implement | |
desc "install a previously built Ruby" | |
task :install, [:dir] => [ "#{BuildUtils.install_dir}" ] do |t, args| | |
abort '[ERROR] must provide an installation directory' unless args.dir | |
end | |
end # namespace :bld |
not so far. i don't always consistently use them when building other things, and i rarely use this gist anymore...caveat emptor.
are you seeing segfaults?
I think I did once upon a time (like mingw gcc 4.2 or something) when
I used both -O3 and -march=native. I "think" (hope) that those
segfaults have since been fixed, but it's been awhile so I'm not sure.
if yes, what are you trying to build and what toolchain are you using? i've recently started looking at http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/ as i understand their header support is better than the standard mingw headers...also, their automated builds have gcc 4.7.0
I was actually building on linux but trying to remember if it bugged
out or not.
Thanks!
-r
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
not so far. i don't always consistently use them when building other things, and i rarely use this gist anymore...caveat emptor.
are you seeing segfaults? if yes, what are you trying to build and what toolchain are you using? i've recently started looking at http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/ as i understand their header support is better than the standard mingw headers...also, their automated builds have gcc 4.7.0