Commit ef23ae4e authored by crimsonwoods's avatar crimsonwoods

support 'Cygwin' as build platform.

parent bb63eb04
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
# Build description. # Build description.
# basic build file for mruby # basic build file for mruby
MRUBY_ROOT = File.dirname(File.expand_path(__FILE__)) MRUBY_ROOT = File.dirname(File.expand_path(__FILE__))
MRUBY_BUILD_HOST_IS_CYGWIN = RUBY_PLATFORM.include?('cygwin')
# load build systems # load build systems
load "#{MRUBY_ROOT}/tasks/ruby_ext.rake" load "#{MRUBY_ROOT}/tasks/ruby_ext.rake"
......
...@@ -128,6 +128,14 @@ module MRuby ...@@ -128,6 +128,14 @@ module MRuby
end end
end end
def cygwin_filename(name)
if name.is_a?(Array)
name.flatten.map { |n| cyg_filename(n) }
else
'"%s"' % `cygpath -w "#{filename(name)}"`.strip
end
end
def exefile(name) def exefile(name)
if name.is_a?(Array) if name.is_a?(Array)
name.flatten.map { |n| exefile(n) } name.flatten.map { |n| exefile(n) }
......
...@@ -4,7 +4,7 @@ module MRuby ...@@ -4,7 +4,7 @@ module MRuby
class Command class Command
include Rake::DSL include Rake::DSL
extend Forwardable extend Forwardable
def_delegators :@build, :filename, :objfile, :libfile, :exefile def_delegators :@build, :filename, :objfile, :libfile, :exefile, :cygwin_filename
attr_accessor :build, :command attr_accessor :build, :command
def initialize(build) def initialize(build)
...@@ -49,8 +49,12 @@ module MRuby ...@@ -49,8 +49,12 @@ module MRuby
def all_flags(_defineds=[], _include_paths=[], _flags=[]) def all_flags(_defineds=[], _include_paths=[], _flags=[])
define_flags = [defines, _defineds].flatten.map{ |d| option_define % d } define_flags = [defines, _defineds].flatten.map{ |d| option_define % d }
include_path_flags = [include_paths, _include_paths].flatten.map do |f| include_path_flags = [include_paths, _include_paths].flatten.map do |f|
if MRUBY_BUILD_HOST_IS_CYGWIN
option_include_path % cygwin_filename(f)
else
option_include_path % filename(f) option_include_path % filename(f)
end end
end
[flags, define_flags, include_path_flags, _flags].flatten.join(' ') [flags, define_flags, include_path_flags, _flags].flatten.join(' ')
end end
...@@ -61,9 +65,14 @@ module MRuby ...@@ -61,9 +65,14 @@ module MRuby
option_include_path % filename(f) option_include_path % filename(f)
end end
_pp "CC", infile.relative_path, outfile.relative_path _pp "CC", infile.relative_path, outfile.relative_path
if MRUBY_BUILD_HOST_IS_CYGWIN
_run compile_options, { :flags => all_flags(_defineds, _include_paths, _flags),
:infile => cygwin_filename(infile), :outfile => cygwin_filename(outfile) }
else
_run compile_options, { :flags => all_flags(_defineds, _include_paths, _flags), _run compile_options, { :flags => all_flags(_defineds, _include_paths, _flags),
:infile => filename(infile), :outfile => filename(outfile) } :infile => filename(infile), :outfile => filename(outfile) }
end end
end
def define_rules(build_dir, source_dir='') def define_rules(build_dir, source_dir='')
@out_ext = build.exts.object @out_ext = build.exts.object
...@@ -127,8 +136,12 @@ module MRuby ...@@ -127,8 +136,12 @@ module MRuby
def all_flags(_library_paths=[], _flags=[]) def all_flags(_library_paths=[], _flags=[])
library_path_flags = [library_paths, _library_paths].flatten.map do |f| library_path_flags = [library_paths, _library_paths].flatten.map do |f|
if MRUBY_BUILD_HOST_IS_CYGWIN
option_library_path % cygwin_filename(f)
else
option_library_path % filename(f) option_library_path % filename(f)
end end
end
[flags, library_path_flags, _flags].flatten.join(' ') [flags, library_path_flags, _flags].flatten.join(' ')
end end
...@@ -142,6 +155,13 @@ module MRuby ...@@ -142,6 +155,13 @@ module MRuby
library_path_flags = [library_paths, _library_paths].flatten.map { |f| option_library_path % filename(f) } library_path_flags = [library_paths, _library_paths].flatten.map { |f| option_library_path % filename(f) }
_pp "LD", outfile.relative_path _pp "LD", outfile.relative_path
if MRUBY_BUILD_HOST_IS_CYGWIN
_run link_options, { :flags => all_flags(_library_paths, _flags),
:outfile => cygwin_filename(outfile) , :objs => cygwin_filename(objfiles).join(' '),
:flags_before_libraries => [flags_before_libraries, _flags_before_libraries].flatten.join(' '),
:flags_after_libraries => [flags_after_libraries, _flags_after_libraries].flatten.join(' '),
:libs => library_flags.join(' ') }
else
_run link_options, { :flags => all_flags(_library_paths, _flags), _run link_options, { :flags => all_flags(_library_paths, _flags),
:outfile => filename(outfile) , :objs => filename(objfiles).join(' '), :outfile => filename(outfile) , :objs => filename(objfiles).join(' '),
:flags_before_libraries => [flags_before_libraries, _flags_before_libraries].flatten.join(' '), :flags_before_libraries => [flags_before_libraries, _flags_before_libraries].flatten.join(' '),
...@@ -149,6 +169,7 @@ module MRuby ...@@ -149,6 +169,7 @@ module MRuby
:libs => library_flags.join(' ') } :libs => library_flags.join(' ') }
end end
end end
end
class Command::Archiver < Command class Command::Archiver < Command
attr_accessor :archive_options attr_accessor :archive_options
...@@ -162,9 +183,13 @@ module MRuby ...@@ -162,9 +183,13 @@ module MRuby
def run(outfile, objfiles) def run(outfile, objfiles)
FileUtils.mkdir_p File.dirname(outfile) FileUtils.mkdir_p File.dirname(outfile)
_pp "AR", outfile.relative_path _pp "AR", outfile.relative_path
if MRUBY_BUILD_HOST_IS_CYGWIN
_run archive_options, { :outfile => cygwin_filename(outfile), :objs => cygwin_filename(objfiles).join(' ') }
else
_run archive_options, { :outfile => filename(outfile), :objs => filename(objfiles).join(' ') } _run archive_options, { :outfile => filename(outfile), :objs => filename(objfiles).join(' ') }
end end
end end
end
class Command::Yacc < Command class Command::Yacc < Command
attr_accessor :compile_options attr_accessor :compile_options
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment