mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Make bin/mruby-config output a directory based on itself
This commit is contained in:
@@ -11,7 +11,16 @@ MRuby::Gem::Specification.new('mruby-bin-config') do |spec|
|
||||
else
|
||||
mruby_config_dir = "#{build.build_dir}/bin"
|
||||
end
|
||||
mruby_config = name + (ENV['OS'] == 'Windows_NT' ? '.bat' : '')
|
||||
|
||||
if ENV['OS'] == 'Windows_NT'
|
||||
suffix = '.bat'
|
||||
refvar = '%\\1%'
|
||||
else
|
||||
suffix = ''
|
||||
refvar = '${\\1}'
|
||||
end
|
||||
|
||||
mruby_config = name + suffix
|
||||
mruby_config_path = "#{mruby_config_dir}/#{mruby_config}"
|
||||
make_cfg = "#{build.build_dir}/lib/libmruby.flags.mak"
|
||||
tmplt_path = "#{__dir__}/#{mruby_config}"
|
||||
@@ -24,11 +33,16 @@ MRuby::Gem::Specification.new('mruby-bin-config') do |spec|
|
||||
|
||||
directory mruby_config_dir
|
||||
|
||||
file mruby_config_path => [mruby_config_dir, make_cfg, tmplt_path] do |t|
|
||||
file mruby_config_path => [__FILE__, mruby_config_dir, make_cfg, tmplt_path] do |t|
|
||||
config = Hash[File.readlines(make_cfg).map!(&:chomp).map! {|l|
|
||||
l.gsub!(/\$\((\w+)\)/, refvar)
|
||||
l.gsub('\\"', '"').split(' = ', 2).map! {|s| s.sub(/^(?=.)/, 'echo ')}
|
||||
}]
|
||||
tmplt = File.read(tmplt_path)
|
||||
tmplt.sub!(%r((?<=\A#!/bin/sh\n\n)), <<~SETDIR)
|
||||
MRUBY_PACKAGE_DIR=$(dirname "$(dirname "$(readlink -f "$0")")")
|
||||
|
||||
SETDIR
|
||||
File.write(t.name, tmplt.gsub(/(#{Regexp.union(*config.keys)})\b/, config))
|
||||
chmod(0755, t.name)
|
||||
end
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
@echo off
|
||||
|
||||
call :init "%~dp0."
|
||||
goto top
|
||||
|
||||
:init
|
||||
rem call init2 for treatments last directory separator
|
||||
call :init2 "%~dp1."
|
||||
goto :eof
|
||||
|
||||
:init2
|
||||
set MRUBY_PACKAGE_DIR=%~f1
|
||||
goto :eof
|
||||
|
||||
:top
|
||||
shift
|
||||
if "%0" equ "" goto :eof
|
||||
|
||||
+30
-5
@@ -38,16 +38,41 @@ MRuby.each_target do
|
||||
file "#{build_dir}/lib/libmruby.flags.mak" => [__FILE__, libmruby_static] do |t|
|
||||
mkdir_p File.dirname t.name
|
||||
open(t.name, 'w') do |f|
|
||||
gemincs = gems.map { |g| g.export_include_paths.map { |n| g.filename(n) } }.flatten.uniq
|
||||
f.puts "MRUBY_CFLAGS = #{cc.all_flags([], gemincs)}"
|
||||
f.puts <<~FLAGS_MAKE
|
||||
# GNU make is required to use this file.
|
||||
MRUBY_PACKAGE_DIR_GNU := $(shell dirname "$(firstword $(MAKEFILE_LIST))")
|
||||
MRUBY_PACKAGE_DIR != dirname "$(MRUBY_PACKAGE_DIR_GNU)"
|
||||
FLAGS_MAKE
|
||||
|
||||
[
|
||||
[cc, "MRUBY_CC", "MRUBY_CFLAGS"],
|
||||
[cxx, "MRUBY_CXX", "MRUBY_CXXFLAGS"],
|
||||
[asm, "MRUBY_AS", "MRUBY_ASFLAGS"],
|
||||
[objc, "MRUBY_OBJC", "MRUBY_OBJCFLAGS"]
|
||||
].each do |cc, cmd, flags|
|
||||
incpaths = cc.include_paths.dup
|
||||
dirmaps = {
|
||||
MRUBY_ROOT => "$(MRUBY_PACKAGE_DIR)",
|
||||
build_dir => "$(MRUBY_PACKAGE_DIR)"
|
||||
}
|
||||
gems.each do |g|
|
||||
incpaths.concat g.export_include_paths
|
||||
dirmaps[g.dir] = "$(MRUBY_PACKAGE_DIR)/include/mruby/gems/#{g.name}"
|
||||
dirmaps[g.build_dir] = "$(MRUBY_PACKAGE_DIR)/include/mruby/gems/#{g.name}"
|
||||
end
|
||||
modcc = cc.clone
|
||||
modcc.include_paths = incpaths.replace_prefix_by(dirmaps).uniq
|
||||
|
||||
f.puts "#{cmd} = #{cc.command}"
|
||||
f.puts "#{flags} = #{modcc.all_flags}"
|
||||
end
|
||||
|
||||
f.puts "MRUBY_CC = #{cc.command}"
|
||||
f.puts "MRUBY_LD = #{linker.command}"
|
||||
|
||||
libgems = gems.reject{|g| g.bin?}
|
||||
gem_flags = libgems.map {|g| g.linker.flags }
|
||||
gem_library_paths = libgems.map {|g| g.linker.library_paths }
|
||||
f.puts "MRUBY_LDFLAGS = #{linker.all_flags(gem_library_paths, gem_flags)} #{linker.option_library_path % "#{build_dir}/lib"}"
|
||||
f.puts "MRUBY_LDFLAGS = #{linker.all_flags(gem_library_paths, gem_flags)} #{linker.option_library_path % "$(MRUBY_PACKAGE_DIR)/lib"}"
|
||||
|
||||
gem_flags_before_libraries = libgems.map {|g| g.linker.flags_before_libraries }
|
||||
f.puts "MRUBY_LDFLAGS_BEFORE_LIBS = #{[linker.flags_before_libraries, gem_flags_before_libraries].flatten.join(' ')}"
|
||||
@@ -55,7 +80,7 @@ MRuby.each_target do
|
||||
gem_libraries = libgems.map {|g| g.linker.libraries }
|
||||
f.puts "MRUBY_LIBS = #{linker.option_library % 'mruby'} #{linker.library_flags(gem_libraries)}"
|
||||
|
||||
f.puts "MRUBY_LIBMRUBY_PATH = #{libmruby_static}"
|
||||
f.puts "MRUBY_LIBMRUBY_PATH = #{libmruby_static.replace_prefix_by(build_dir => "$(MRUBY_PACKAGE_DIR)")}"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user