| 1 |
MRuby::Gem::Specification.new('mruby-onig-regexp') do |spec| |
| 2 |
spec.license = 'MIT' |
| 3 |
spec.authors = 'mattn' |
| 4 |
spec.add_dependency 'mruby-string-ext', core: 'mruby-string-ext' |
| 5 |
|
| 6 |
def spec.bundle_onigmo |
| 7 |
return if @onigmo_bundled |
| 8 |
@onigmo_bundled = true |
| 9 |
|
| 10 |
visualcpp = ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR'] |
| 11 |
|
| 12 |
require 'open3' |
| 13 |
|
| 14 |
# remove libonig, instead link directly against pthread |
| 15 |
unless ENV['OS'] == 'Windows_NT' || build.kind_of?(MRuby::CrossBuild) |
| 16 |
linker.libraries = ['pthread'] |
| 17 |
end |
| 18 |
|
| 19 |
version = '6.2.0' |
| 20 |
oniguruma_dir = "#{build_dir}/onigmo-#{version}" |
| 21 |
oniguruma_lib = libfile "#{oniguruma_dir}/.libs/libonigmo" |
| 22 |
unless ENV['OS'] == 'Windows_NT' |
| 23 |
oniguruma_lib = libfile "#{oniguruma_dir}/.libs/libonigmo" |
| 24 |
else |
| 25 |
if ENV['PROCESSOR_ARCHITECTURE'] == 'AMD64' |
| 26 |
oniguruma_lib = libfile "#{oniguruma_dir}/build_x86-64/libonigmo" |
| 27 |
else |
| 28 |
oniguruma_lib = libfile "#{oniguruma_dir}/build_i686/libonigmo" |
| 29 |
end |
| 30 |
end |
| 31 |
header = "#{oniguruma_dir}/onigmo.h" |
| 32 |
|
| 33 |
task :clean do |
| 34 |
FileUtils.rm_rf [oniguruma_dir] |
| 35 |
end |
| 36 |
|
| 37 |
file header do |t| |
| 38 |
FileUtils.mkdir_p oniguruma_dir |
| 39 |
Dir.chdir(build_dir) do |
| 40 |
_pp 'extracting', "onigmo-#{version}" |
| 41 |
`gzip -dc "#{dir}/onigmo-#{version}.tar.gz" | tar xf -` |
| 42 |
end |
| 43 |
end |
| 44 |
|
| 45 |
def run_command(env, command) |
| 46 |
unless system(env, command) |
| 47 |
fail "#{command} failed" |
| 48 |
end |
| 49 |
end |
| 50 |
|
| 51 |
libonig_objs_dir = "#{oniguruma_dir}/libonig_objs" |
| 52 |
libmruby_a = libfile("#{build.build_dir}/lib/libmruby") |
| 53 |
objext = visualcpp ? '.obj' : '.o' |
| 54 |
|
| 55 |
file oniguruma_lib => header do |t| |
| 56 |
Dir.chdir(oniguruma_dir) do |
| 57 |
e = { |
| 58 |
'CC' => "#{build.cc.command} #{build.cc.flags.join(' ')}", |
| 59 |
'CXX' => "#{build.cxx.command} #{build.cxx.flags.join(' ')}", |
| 60 |
'LD' => "#{build.linker.command} #{build.linker.flags.join(' ')}", |
| 61 |
'AR' => build.archiver.command } |
| 62 |
unless ENV['OS'] == 'Windows_NT' |
| 63 |
if build.kind_of? MRuby::CrossBuild |
| 64 |
host = "--host #{build.host_target ? build.host_target : build.name}" |
| 65 |
end |
| 66 |
|
| 67 |
_pp 'autotools', oniguruma_dir |
| 68 |
run_command e, './autogen.sh' if File.exist? 'autogen.sh' |
| 69 |
run_command e, "./configure --disable-shared --enable-static #{host}" |
| 70 |
run_command e, "make -j#{$rake_jobs || 1}" |
| 71 |
else |
| 72 |
run_command e, 'cmd /c "copy /Y win32 > NUL"' |
| 73 |
if visualcpp |
| 74 |
run_command e, 'nmake -f Makefile' |
| 75 |
else |
| 76 |
run_command e, 'make -f Makefile.mingw' |
| 77 |
end |
| 78 |
end |
| 79 |
end |
| 80 |
|
| 81 |
FileUtils.mkdir_p libonig_objs_dir |
| 82 |
Dir.chdir(libonig_objs_dir) do |
| 83 |
unless visualcpp |
| 84 |
`ar x #{oniguruma_lib}` |
| 85 |
else |
| 86 |
winname = oniguruma_lib.gsub(%'/', '\\') |
| 87 |
`lib -nologo -list #{winname}`.each_line do |line| |
| 88 |
line.chomp! |
| 89 |
`lib -nologo -extract:#{line} #{winname}` |
| 90 |
end |
| 91 |
end |
| 92 |
end |
| 93 |
file libmruby_a => Dir.glob("#{libonig_objs_dir}/*#{objext}") |
| 94 |
end |
| 95 |
|
| 96 |
if File.exist? oniguruma_lib |
| 97 |
objs = Dir.glob("#{libonig_objs_dir}/*#{objext}") |
| 98 |
file libmruby_a => objs |
| 99 |
objs.each{|obj| file obj => oniguruma_lib } |
| 100 |
end |
| 101 |
|
| 102 |
task :mruby_onig_regexp_with_compile_option do |
| 103 |
cc.include_paths << oniguruma_dir |
| 104 |
cc.defines += ['HAVE_ONIGMO_H'] |
| 105 |
end |
| 106 |
file "#{dir}/src/mruby_onig_regexp.c" => [:mruby_onig_regexp_with_compile_option, oniguruma_lib] |
| 107 |
end |
| 108 |
|
| 109 |
if spec.respond_to? :search_package and spec.search_package 'onigmo' |
| 110 |
spec.cc.defines += ['HAVE_ONIGMO_H'] |
| 111 |
spec.linker.libraries << 'onigmo' |
| 112 |
elsif spec.respond_to? :search_package and spec.search_package 'oniguruma' |
| 113 |
spec.cc.defines += ['HAVE_ONIGURUMA_H'] |
| 114 |
spec.linker.libraries << 'onig' |
| 115 |
elsif build.cc.respond_to? :search_header_path and build.cc.search_header_path 'onigmo.h' |
| 116 |
spec.cc.defines += ['HAVE_ONIGMO_H'] |
| 117 |
spec.linker.libraries << 'onigmo' |
| 118 |
elsif build.cc.respond_to? :search_header_path and build.cc.search_header_path 'oniguruma.h' |
| 119 |
spec.cc.defines += ['HAVE_ONIGURUMA_H'] |
| 120 |
spec.linker.libraries << 'onig' |
| 121 |
else |
| 122 |
spec.bundle_onigmo |
| 123 |
end |
| 124 |
end |