From 8c22911c861c13cf53510d7e713cb12d042599f3 Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Sun, 20 Jan 2019 19:47:58 +0900 Subject: Rename `mruby-bin-mruby-config` mrbgem to `mruby-bin-config` For brevity and consistency (e.g. `mruby-bin-strip` doesn't have `mruby-` after `bin-`). --- mrbgems/mruby-bin-config/mrbgem.rake | 31 +++++++++++++++++++++++ mrbgems/mruby-bin-config/mruby-config | 20 +++++++++++++++ mrbgems/mruby-bin-config/mruby-config.bat | 42 +++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 mrbgems/mruby-bin-config/mrbgem.rake create mode 100644 mrbgems/mruby-bin-config/mruby-config create mode 100644 mrbgems/mruby-bin-config/mruby-config.bat (limited to 'mrbgems/mruby-bin-config') diff --git a/mrbgems/mruby-bin-config/mrbgem.rake b/mrbgems/mruby-bin-config/mrbgem.rake new file mode 100644 index 000000000..cca7423ac --- /dev/null +++ b/mrbgems/mruby-bin-config/mrbgem.rake @@ -0,0 +1,31 @@ +module MRuby + class Build + def exefile(name) + if name.is_a?(Array) + name.flatten.map { |n| exefile(n) } + elsif name !~ /\./ + "#{name}#{exts.executable}" + else + name + end + end + end +end + +MRuby.each_target do + next if kind_of? MRuby::CrossBuild + + mruby_config = 'mruby-config' + (ENV['OS'] == 'Windows_NT' ? '.bat' : '') + mruby_config_path = "#{build_dir}/bin/#{mruby_config}" + @bins << mruby_config + + make_cfg = "#{build_dir}/lib/libmruby.flags.mak" + file mruby_config_path => [libmruby_static, make_cfg] do |t| + FileUtils.copy "#{File.dirname(__FILE__)}/#{mruby_config}", t.name + config = Hash[open(make_cfg).read.split("\n").map {|x| a = x.split(/\s*=\s*/, 2); [a[0], a[1].gsub('\\"', '"') ]}] + IO.write(t.name, File.open(t.name) {|f| + f.read.gsub (/echo (MRUBY_CFLAGS|MRUBY_LIBS|MRUBY_LDFLAGS_BEFORE_LIBS|MRUBY_LDFLAGS|MRUBY_LIBMRUBY_PATH)/) {|x| config[$1].empty? ? '' : "echo #{config[$1]}"} + }) + FileUtils.chmod(0755, t.name) + end +end diff --git a/mrbgems/mruby-bin-config/mruby-config b/mrbgems/mruby-bin-config/mruby-config new file mode 100644 index 000000000..57346c03f --- /dev/null +++ b/mrbgems/mruby-bin-config/mruby-config @@ -0,0 +1,20 @@ +#!/bin/sh + +while [ $# -gt 0 ]; do + case $1 in + --cflags) echo MRUBY_CFLAGS;; + --ldflags) echo MRUBY_LDFLAGS;; + --ldflags-before-libs) echo MRUBY_LDFLAGS_BEFORE_LIBS;; + --libs) echo MRUBY_LIBS;; + --libmruby-path) echo MRUBY_LIBMRUBY_PATH;; + --help) echo "Usage: mruby-config [switches]" + echo " switches:" + echo " --cflags print flags passed to compiler" + echo " --ldflags print flags passed to linker" + echo " --ldflags-before-libs print flags passed to linker before linked libraries" + echo " --libs print linked libraries" + echo " --libmruby-path print libmruby path" + exit 0;; + esac + shift +done diff --git a/mrbgems/mruby-bin-config/mruby-config.bat b/mrbgems/mruby-bin-config/mruby-config.bat new file mode 100644 index 000000000..a1f7bfdd1 --- /dev/null +++ b/mrbgems/mruby-bin-config/mruby-config.bat @@ -0,0 +1,42 @@ +@echo off + +:top +shift +if "%0" equ "" goto :eof +if "%0" equ "--cflags" goto cflags +if "%0" equ "--ldflags" goto ldflags +if "%0" equ "--ldflags-before-libs" goto ldflagsbeforelibs +if "%0" equ "--libs" goto libs +if "%0" equ "--libmruby-path" goto libmrubypath +if "%0" equ "--help" goto showhelp +echo Invalid Option +goto :eof + +:cflags +echo MRUBY_CFLAGS +goto top + +:libs +echo MRUBY_LIBS +goto top + +:ldflags +echo MRUBY_LDFLAGS +goto top + +:ldflagsbeforelibs +echo MRUBY_LDFLAGS_BEFORE_LIBS +goto top + +:libmrubypath +echo MRUBY_LIBMRUBY_PATH +goto top + +:showhelp +echo Usage: mruby-config [switches] +echo switches: +echo --cflags print flags passed to compiler +echo --ldflags print flags passed to linker +echo --ldflags-before-libs print flags passed to linker before linked libraries +echo --libs print linked libraries +echo --libmruby-path print libmruby path -- cgit v1.2.3 From c592c093aa654be121a8c7884c32b80c1d6f058f Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Tue, 12 Feb 2019 21:32:39 +0900 Subject: Refine `mrbgems/mruby-bin-config/mrbgem.rake` - Use `MRuby::Gem::Specification` - Fix a binary name is added to `MRuby::Build#bins` multiple times - Close file immediately (avoid using `open(...).read`) - Simplify --- mrbgems/mruby-bin-config/mrbgem.rake | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'mrbgems/mruby-bin-config') diff --git a/mrbgems/mruby-bin-config/mrbgem.rake b/mrbgems/mruby-bin-config/mrbgem.rake index b9ba0e42c..f293c1b9b 100644 --- a/mrbgems/mruby-bin-config/mrbgem.rake +++ b/mrbgems/mruby-bin-config/mrbgem.rake @@ -1,17 +1,22 @@ -MRuby.each_target do - next if kind_of? MRuby::CrossBuild +unless MRuby::Build.current.kind_of?(MRuby::CrossBuild) + MRuby::Gem::Specification.new('mruby-bin-config') do |spec| + name = 'mruby-config' + spec.license = 'MIT' + spec.author = 'mruby developers' + spec.summary = "#{name} command" - mruby_config = 'mruby-config' + (ENV['OS'] == 'Windows_NT' ? '.bat' : '') - mruby_config_path = "#{build_dir}/bin/#{mruby_config}" - @bins << mruby_config + mruby_config = name + (ENV['OS'] == 'Windows_NT' ? '.bat' : '') + mruby_config_path = "#{build.build_dir}/bin/#{mruby_config}" + make_cfg = "#{build.build_dir}/lib/libmruby.flags.mak" + build.bins << mruby_config - make_cfg = "#{build_dir}/lib/libmruby.flags.mak" - file mruby_config_path => [libmruby_static, make_cfg] do |t| - FileUtils.copy "#{File.dirname(__FILE__)}/#{mruby_config}", t.name - config = Hash[open(make_cfg).read.split("\n").map {|x| a = x.split(/\s*=\s*/, 2); [a[0], a[1].gsub('\\"', '"') ]}] - IO.write(t.name, File.open(t.name) {|f| - f.read.gsub (/echo (MRUBY_CFLAGS|MRUBY_LIBS|MRUBY_LDFLAGS_BEFORE_LIBS|MRUBY_LDFLAGS|MRUBY_LIBMRUBY_PATH)/) {|x| config[$1].empty? ? '' : "echo #{config[$1]}"} - }) - FileUtils.chmod(0755, t.name) + file mruby_config_path => [build.libmruby_static, make_cfg] do |t| + config = Hash[File.readlines(make_cfg).map(&:chomp).map {|l| + l.gsub('\\"', '"').split(' = ', 2).map! {|s| s.sub(/^(?=.)/, 'echo ')} + }] + tmplt = File.read("#{__dir__}/#{mruby_config}") + File.write(t.name, tmplt.gsub(/(#{Regexp.union(*config.keys)})\b/, config)) + FileUtils.chmod(0755, t.name) + end end end -- cgit v1.2.3 From b3e0a1398945faa5375809f75fb9727f4982b4dc Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Sun, 17 Feb 2019 15:52:16 +0900 Subject: Refine dependencies for `mruby-config` --- mrbgems/mruby-bin-config/mrbgem.rake | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'mrbgems/mruby-bin-config') diff --git a/mrbgems/mruby-bin-config/mrbgem.rake b/mrbgems/mruby-bin-config/mrbgem.rake index f293c1b9b..3a0a1b897 100644 --- a/mrbgems/mruby-bin-config/mrbgem.rake +++ b/mrbgems/mruby-bin-config/mrbgem.rake @@ -8,13 +8,14 @@ unless MRuby::Build.current.kind_of?(MRuby::CrossBuild) mruby_config = name + (ENV['OS'] == 'Windows_NT' ? '.bat' : '') mruby_config_path = "#{build.build_dir}/bin/#{mruby_config}" make_cfg = "#{build.build_dir}/lib/libmruby.flags.mak" + tmplt_path = "#{__dir__}/#{mruby_config}" build.bins << mruby_config - file mruby_config_path => [build.libmruby_static, make_cfg] do |t| - config = Hash[File.readlines(make_cfg).map(&:chomp).map {|l| + file mruby_config_path => [make_cfg, tmplt_path] do |t| + config = Hash[File.readlines(make_cfg).map!(&:chomp).map! {|l| l.gsub('\\"', '"').split(' = ', 2).map! {|s| s.sub(/^(?=.)/, 'echo ')} }] - tmplt = File.read("#{__dir__}/#{mruby_config}") + tmplt = File.read(tmplt_path) File.write(t.name, tmplt.gsub(/(#{Regexp.union(*config.keys)})\b/, config)) FileUtils.chmod(0755, t.name) end -- cgit v1.2.3