From c020d8507e6e7a58a3f6e1fc51ab2a2118a5e673 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sun, 12 Feb 2023 21:02:27 +0900 Subject: [PATCH 1/7] Separate `rake install` related stuff into `tasks/install.rake` --- Rakefile | 29 +---------------------------- lib/mruby/build.rb | 2 ++ tasks/install.rake | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 28 deletions(-) create mode 100644 tasks/install.rake diff --git a/Rakefile b/Rakefile index 2a8e11d43..ef7d536c6 100644 --- a/Rakefile +++ b/Rakefile @@ -31,6 +31,7 @@ load "#{MRUBY_ROOT}/tasks/presym.rake" load "#{MRUBY_ROOT}/tasks/test.rake" load "#{MRUBY_ROOT}/tasks/benchmark.rake" load "#{MRUBY_ROOT}/tasks/doc.rake" +load "#{MRUBY_ROOT}/tasks/install.rake" ############################## # generic build targets, rules @@ -67,34 +68,6 @@ task :deep_clean => %w[clean doc:clean] do puts "Cleaned up mrbgems build folder" end -PREFIX = ENV['PREFIX'] || ENV['INSTALL_PREFIX'] || '/usr/local' - -desc "install compiled products" -task :install => :install_bin do - if host = MRuby.targets['host'] - install_D host.libmruby_static, File.join(PREFIX, "lib", File.basename(host.libmruby_static)) - # install mruby.h and mrbconf.h - Dir.glob(File.join(MRUBY_ROOT, "include", "*.h")) do |src| - install_D src, File.join(PREFIX, "include", File.basename(src)) - end - Dir.glob(File.join(MRUBY_ROOT, "include", "mruby", "*.h")) do |src| - install_D src, File.join(PREFIX, "include", "mruby", File.basename(src)) - end - Dir.glob(File.join(File.join(MRUBY_ROOT, "build", "host", "include", "mruby", "presym", "*.h"))) do |src| - install_D src, File.join(PREFIX, "include", "mruby", "presym", File.basename(src)) - end - end -end - -desc "install compiled executable (on host)" -task :install_bin => :all do - if host = MRuby.targets['host'] - Dir.glob(File.join(MRUBY_ROOT, "bin", "*")) do |src| - install_D src, File.join(PREFIX, "bin", File.basename(src)) - end - end -end - desc "run all pre-commit hooks against all files" task :check do sh "pre-commit run --all-files" diff --git a/lib/mruby/build.rb b/lib/mruby/build.rb index 4925cee33..e6298d71f 100644 --- a/lib/mruby/build.rb +++ b/lib/mruby/build.rb @@ -7,6 +7,8 @@ module MRuby autoload :Lockfile, "mruby/lockfile" autoload :Presym, "mruby/presym" + INSTALL_PREFIX = ENV['PREFIX'] || ENV['INSTALL_PREFIX'] || '/usr/local' + class << self def targets @targets ||= {} diff --git a/tasks/install.rake b/tasks/install.rake new file mode 100644 index 000000000..c83d30a4e --- /dev/null +++ b/tasks/install.rake @@ -0,0 +1,25 @@ +desc "install compiled products" +task :install => :install_bin do + if host = MRuby.targets['host'] + install_D host.libmruby_static, File.join(MRuby::INSTALL_PREFIX, "lib", File.basename(host.libmruby_static)) + # install mruby.h and mrbconf.h + Dir.glob(File.join(MRUBY_ROOT, "include", "*.h")) do |src| + install_D src, File.join(MRuby::INSTALL_PREFIX, "include", File.basename(src)) + end + Dir.glob(File.join(MRUBY_ROOT, "include", "mruby", "*.h")) do |src| + install_D src, File.join(MRuby::INSTALL_PREFIX, "include", "mruby", File.basename(src)) + end + Dir.glob(File.join(File.join(MRUBY_ROOT, "build", "host", "include", "mruby", "presym", "*.h"))) do |src| + install_D src, File.join(MRuby::INSTALL_PREFIX, "include", "mruby", "presym", File.basename(src)) + end + end +end + +desc "install compiled executable (on host)" +task :install_bin => :all do + if host = MRuby.targets['host'] + Dir.glob(File.join(MRUBY_ROOT, "bin", "*")) do |src| + install_D src, File.join(MRuby::INSTALL_PREFIX, "bin", File.basename(src)) + end + end +end From aac2fd70556198cf8005308fcbdbebbff2d273d5 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sun, 12 Feb 2023 21:02:28 +0900 Subject: [PATCH 2/7] Copy header files to the build directory This is so that the build directory can be regarded as a temporary installation directory to work in. Directories set in `MRuby::Gem::Specification#export_include_paths` are used as they are if they are subdirectories placed under `gem.dir`. Files are placed under `/include/mruby/gems//` to separate each GEM. When GEM is compiled by building `libmruby.a`, the same `include_paths` will be set as before, so it is expected that no unintended references will be made. --- lib/mruby/build.rb | 15 +++++++++++++++ lib/mruby/core_ext.rb | 21 +++++++++++++++++++++ lib/mruby/gem.rb | 13 +++++++++++++ tasks/libmruby.rake | 24 ++++++++++++++++++++++++ 4 files changed, 73 insertions(+) diff --git a/lib/mruby/build.rb b/lib/mruby/build.rb index e6298d71f..dfe944d35 100644 --- a/lib/mruby/build.rb +++ b/lib/mruby/build.rb @@ -1,6 +1,7 @@ require "mruby/core_ext" require "mruby/build/load_gems" require "mruby/build/command" +autoload :Find, "find" module MRuby autoload :Gem, "mruby/gem" @@ -487,6 +488,20 @@ EOS @internal end + def each_header_files(&block) + return to_enum(__method__) unless block + + basedir = File.join(MRUBY_ROOT, "include") + Find.find(basedir) do |d| + next unless File.file? d + yield d + end + + @gems.each { |g| g.each_header_files(&block) } + + self + end + protected attr_writer :presym diff --git a/lib/mruby/core_ext.rb b/lib/mruby/core_ext.rb index 1ad528c26..ac2737643 100644 --- a/lib/mruby/core_ext.rb +++ b/lib/mruby/core_ext.rb @@ -22,6 +22,27 @@ class String def remove_leading_parents Pathname.new(".#{Pathname.new("/#{self}").cleanpath}").cleanpath.to_s end + + def replace_prefix_by(dirmap) + [self].replace_prefix_by(dirmap)[0] + end +end + +class Array + # Replace the prefix of each string that is a file path that contains in its own array. + # + # dirmap is a hash whose elements are `{ "path/to/old-prefix" => "path/to/new-prefix", ... }`. + # If it does not match any element of dirmap, the file path is not replaced. + def replace_prefix_by(dirmap) + dirmap = dirmap.map { |older, newer| [File.join(older, "/"), File.join(newer, "/")] } + dirmap.sort! + dirmap.reverse! + self.flatten.map do |e| + map = dirmap.find { |older, newer| e.start_with?(older) } + e = e.sub(map[0], map[1]) if map + e + end + end end def install_D(src, dst) diff --git a/lib/mruby/gem.rb b/lib/mruby/gem.rb index 64c6f3dee..4cbe4e696 100644 --- a/lib/mruby/gem.rb +++ b/lib/mruby/gem.rb @@ -292,6 +292,19 @@ module MRuby end end.all? end + + def each_header_files(&block) + return to_enum(__method__) unless block + + self.export_include_paths.flatten.uniq.compact.each do |dir| + Find.find(dir) do |d| + next unless File.file? d + yield d + end + end + + self + end end # Specification class Version diff --git a/tasks/libmruby.rake b/tasks/libmruby.rake index 1fb3cbc31..3f357c921 100644 --- a/tasks/libmruby.rake +++ b/tasks/libmruby.rake @@ -8,9 +8,33 @@ MRuby.each_target do next unless libmruby_enabled? file libmruby_static => libmruby_objs.flatten do |t| + Rake::Task["expose_header_files"].invoke archiver.run t.name, t.prerequisites end + task "expose_header_files" do |t| + # Since header files may be generated dynamically and it is hard to know all of them, + # the task is executed depending on when libmruby.a is generated. + + gemsbasedir = File.join(build_dir, "include/mruby/gems") + dirmap = { + MRUBY_ROOT => build_dir + } + gems.each { |g| + dirmap[g.dir] = File.join(gemsbasedir, g.name) + dirmap[g.build_dir] = File.join(gemsbasedir, g.name) + } + + dirs = each_header_files.to_a + dirs.uniq! + dirs.replace_prefix_by(dirmap).zip(dirs).each do |dest, src| + if File.mtime(src).to_i > (File.mtime(dest).to_i rescue 0) + mkpath File.dirname(dest) + cp src, dest + end + end + end + file "#{build_dir}/lib/libmruby.flags.mak" => [__FILE__, libmruby_static] do |t| mkdir_p File.dirname t.name open(t.name, 'w') do |f| From 7fd7409bf28964fdc855cf0ef5880ad424d11c99 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sun, 12 Feb 2023 21:02:29 +0900 Subject: [PATCH 3/7] Files copied by `task install` should be from the build directory --- tasks/install.rake | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/tasks/install.rake b/tasks/install.rake index c83d30a4e..5ee6302ad 100644 --- a/tasks/install.rake +++ b/tasks/install.rake @@ -1,16 +1,8 @@ desc "install compiled products" task :install => :install_bin do if host = MRuby.targets['host'] - install_D host.libmruby_static, File.join(MRuby::INSTALL_PREFIX, "lib", File.basename(host.libmruby_static)) - # install mruby.h and mrbconf.h - Dir.glob(File.join(MRUBY_ROOT, "include", "*.h")) do |src| - install_D src, File.join(MRuby::INSTALL_PREFIX, "include", File.basename(src)) - end - Dir.glob(File.join(MRUBY_ROOT, "include", "mruby", "*.h")) do |src| - install_D src, File.join(MRuby::INSTALL_PREFIX, "include", "mruby", File.basename(src)) - end - Dir.glob(File.join(File.join(MRUBY_ROOT, "build", "host", "include", "mruby", "presym", "*.h"))) do |src| - install_D src, File.join(MRuby::INSTALL_PREFIX, "include", "mruby", "presym", File.basename(src)) + Dir.glob(File.join(host.build_dir, "{include,lib}/**/*")) do |path| + install_D path, File.join(MRuby::INSTALL_PREFIX, path.relative_path_from(host.build_dir)) if File.file? path end end end @@ -18,8 +10,8 @@ end desc "install compiled executable (on host)" task :install_bin => :all do if host = MRuby.targets['host'] - Dir.glob(File.join(MRUBY_ROOT, "bin", "*")) do |src| - install_D src, File.join(MRuby::INSTALL_PREFIX, "bin", File.basename(src)) + Dir.glob(File.join(host.build_dir, "bin/**/*")) do |path| + install_D path, File.join(MRuby::INSTALL_PREFIX, path.relative_path_from(host.build_dir)) if File.file? path end end end From 0e9a71e50a15aec21f868190b499978c73c4a84e Mon Sep 17 00:00:00 2001 From: dearblue Date: Sun, 12 Feb 2023 21:02:30 +0900 Subject: [PATCH 4/7] Install other build targets with `rake install:full` Build targets other than "host" will be installed under `/mruby/`. This can be changed with `build.install_prefix = dir`. --- doc/guides/compile.md | 46 +++++++++++++++++++++++++++++++++++++++++++ lib/mruby/build.rb | 10 ++++++++++ tasks/install.rake | 40 ++++++++++++++++++++++++++----------- 3 files changed, 84 insertions(+), 12 deletions(-) diff --git a/doc/guides/compile.md b/doc/guides/compile.md index 4302d1362..03450cd6a 100644 --- a/doc/guides/compile.md +++ b/doc/guides/compile.md @@ -557,6 +557,52 @@ LDFLAGS = `$(MRB_CONFIG) --ldflags` LIBS = `$(MRB_CONFIG) --libs` ``` +## Install + +To install the files in the `bin`, `include` and `lib` directories generated by the "host" build target into a system directory, do the following: + +```console +$ rake install +``` + +If there are multiple build targets in the build configuration file, to install the products of all build targets, do the following: + +```console +$ rake install:full +``` + +To install only one of several build targets, e.g., the "its-mine" build target, do the following: + +```console +$ rake install:full:its-mine +``` + +To install only the executable files, do the following: + +```console +$ rake install_bin # only "host" build target +$ rake install:bin # all build targets +$ rake install:bin:its-mine # only "its-mine" build target +``` + +### Installation Directory + +The installation directory is `/usr/local` for the "host" build target and `/usr/local/mruby/` for the others. +To change them, you can set the environment variable `PREFIX` or use `MRuby::Build#install_prefix = dir` in your build configuration file. + +The `PREFIX` environment variable affects all build targets and changes the `/usr/local` part. + +The `MRuby::Build#install_prefix` can be set for each individual build target. +In this case, the environment variable `PREFIX` is ignored. + +--- + +To summarize: + +- The default value of the environment variable `PREFIX` is `/usr/local`. +- For the "host" build target, the default value of `MRuby::Build#install_prefix` is ``. +- For a build target other than "host", the default value of `MRuby::Build#install_prefix` is `/mruby/`. + ## Tips - If you see compilation troubles, try `rake clean` first. diff --git a/lib/mruby/build.rb b/lib/mruby/build.rb index dfe944d35..cfae8c8a1 100644 --- a/lib/mruby/build.rb +++ b/lib/mruby/build.rb @@ -100,6 +100,7 @@ module MRuby @file_separator = '/' @build_dir = "#{build_dir}/#{@name}" @gem_clone_dir = "#{build_dir}/repos/#{@name}" + @install_prefix = nil @defines = [] @cc = Command::Compiler.new(self, %w(.c), label: "CC") @cxx = Command::Compiler.new(self, %w(.cc .cxx .cpp), label: "CXX") @@ -502,6 +503,15 @@ EOS self end + def install_prefix + @install_prefix || (self.name == "host" ? MRuby::INSTALL_PREFIX : + File.join(MRuby::INSTALL_PREFIX, "mruby/#{self.name}")) + end + + def install_prefix=(dir) + @install_prefix = dir&.to_s + end + protected attr_writer :presym diff --git a/tasks/install.rake b/tasks/install.rake index 5ee6302ad..ccb0c1a3c 100644 --- a/tasks/install.rake +++ b/tasks/install.rake @@ -1,17 +1,33 @@ -desc "install compiled products" -task :install => :install_bin do - if host = MRuby.targets['host'] - Dir.glob(File.join(host.build_dir, "{include,lib}/**/*")) do |path| - install_D path, File.join(MRuby::INSTALL_PREFIX, path.relative_path_from(host.build_dir)) if File.file? path - end - end -end +desc "install compiled products (on host)" +task :install => "install:full:host" desc "install compiled executable (on host)" -task :install_bin => :all do - if host = MRuby.targets['host'] - Dir.glob(File.join(host.build_dir, "bin/**/*")) do |path| - install_D path, File.join(MRuby::INSTALL_PREFIX, path.relative_path_from(host.build_dir)) if File.file? path +task :install_bin => "install:bin:host" + +desc "install compiled products (all build targets)" +task "install:full" + +desc "install compiled executable (all build targets)" +task "install:bin" + +MRuby.each_target do |build| + next if build.internal? + + prefix = build.install_prefix + + task "install:full" => "install:full:#{build.name}" + + task "install:full:#{build.name}" => "install:bin:#{build.name}" do + Dir.glob(File.join(build.build_dir.gsub(/[\[\{\*\?]/, "\\\0"), "{include,lib}/**/*")) do |path| + install_D path, File.join(prefix, path.relative_path_from(build.build_dir)) if File.file? path + end + end + + task "install:bin" => "install:bin:#{build.name}" + + task "install:bin:#{build.name}" => "all" do + Dir.glob(File.join(build.build_dir.gsub(/[\[\{\*\?]/, "\\\0"), "{bin,host-bin}/**/*")) do |path| + install_D path, File.join(prefix, path.relative_path_from(build.build_dir)) if File.file? path end end end From 3d996a84cc754cea106ac490099f3cd24f546be8 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sun, 12 Feb 2023 21:02:31 +0900 Subject: [PATCH 5/7] Takes the environment variable `DESTDIR` in `rake install` If the environment variable `DESTDIR` is set, the writing destination is `//...`. It is assumed to be used for package work. --- doc/guides/compile.md | 4 ++++ lib/mruby/build.rb | 1 + tasks/install.rake | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/doc/guides/compile.md b/doc/guides/compile.md index 03450cd6a..08dedbf9d 100644 --- a/doc/guides/compile.md +++ b/doc/guides/compile.md @@ -595,6 +595,9 @@ The `PREFIX` environment variable affects all build targets and changes the `/us The `MRuby::Build#install_prefix` can be set for each individual build target. In this case, the environment variable `PREFIX` is ignored. +Also, if the environment variable `DESTDIR` is set, it will prepend to the path obtained by `install_prefix` to determine the final write directory. +This is intended for temporary file expansion by the user's package work. + --- To summarize: @@ -602,6 +605,7 @@ To summarize: - The default value of the environment variable `PREFIX` is `/usr/local`. - For the "host" build target, the default value of `MRuby::Build#install_prefix` is ``. - For a build target other than "host", the default value of `MRuby::Build#install_prefix` is `/mruby/`. +- If the environment variable `DESTDIR` is set, the actual write directory is `/`. ## Tips diff --git a/lib/mruby/build.rb b/lib/mruby/build.rb index cfae8c8a1..71aed7667 100644 --- a/lib/mruby/build.rb +++ b/lib/mruby/build.rb @@ -9,6 +9,7 @@ module MRuby autoload :Presym, "mruby/presym" INSTALL_PREFIX = ENV['PREFIX'] || ENV['INSTALL_PREFIX'] || '/usr/local' + INSTALL_DESTDIR = ENV['DESTDIR'] || '' class << self def targets diff --git a/tasks/install.rake b/tasks/install.rake index ccb0c1a3c..234bec8d8 100644 --- a/tasks/install.rake +++ b/tasks/install.rake @@ -13,7 +13,7 @@ task "install:bin" MRuby.each_target do |build| next if build.internal? - prefix = build.install_prefix + prefix = File.join(MRuby::INSTALL_DESTDIR, build.install_prefix) task "install:full" => "install:full:#{build.name}" From 11513bae43915f9fc2b95a56961c703d82636116 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sun, 12 Feb 2023 21:02:32 +0900 Subject: [PATCH 6/7] Make `bin/mruby-config` output a directory based on itself --- mrbgems/mruby-bin-config/mrbgem.rake | 18 ++++++++++-- mrbgems/mruby-bin-config/mruby-config.bat | 12 ++++++++ tasks/libmruby.rake | 35 +++++++++++++++++++---- 3 files changed, 58 insertions(+), 7 deletions(-) diff --git a/mrbgems/mruby-bin-config/mrbgem.rake b/mrbgems/mruby-bin-config/mrbgem.rake index b4c437640..8a484d69c 100644 --- a/mrbgems/mruby-bin-config/mrbgem.rake +++ b/mrbgems/mruby-bin-config/mrbgem.rake @@ -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 diff --git a/mrbgems/mruby-bin-config/mruby-config.bat b/mrbgems/mruby-bin-config/mruby-config.bat index 949fea06f..8d8a589fe 100644 --- a/mrbgems/mruby-bin-config/mruby-config.bat +++ b/mrbgems/mruby-bin-config/mruby-config.bat @@ -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 diff --git a/tasks/libmruby.rake b/tasks/libmruby.rake index 3f357c921..cc25aa047 100644 --- a/tasks/libmruby.rake +++ b/tasks/libmruby.rake @@ -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 From 7c7ed3c27a87f3f01f4ca1da4c57bd1c335db271 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sun, 12 Feb 2023 21:02:33 +0900 Subject: [PATCH 7/7] Write symbolik links or batch files in `INSTALL_DIR` Since `bin/mruby-config` now points to a directory relative to itself, it is no longer possible to reach `include/` or `lib/`. Therefore, avoid placing entities in them. --- lib/mruby/build.rb | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/mruby/build.rb b/lib/mruby/build.rb index 71aed7667..3864e6c97 100644 --- a/lib/mruby/build.rb +++ b/lib/mruby/build.rb @@ -375,14 +375,35 @@ EOS end end - def define_installer(src) - dst = "#{self.class.install_dir}/#{File.basename(src)}" + def define_installer_outline(src, dst) file dst => src do - install_D src, dst + _pp "GEN", src.relative_path, dst.relative_path + mkdir_p(File.dirname(dst)) + yield dst end dst end + if ENV['OS'] == 'Windows_NT' + def define_installer(src) + dst = "#{self.class.install_dir}/#{File.basename(src)}".pathmap("%X.bat") + define_installer_outline(src, dst) do + File.write dst, <<~BATCHFILE + @echo off + call "#{src}" %* + BATCHFILE + end + end + else + def define_installer(src) + dst = "#{self.class.install_dir}/#{File.basename(src)}" + define_installer_outline(src, dst) do + File.unlink(dst) if File.exist?(dst) + File.symlink(src, dst) + end + end + end + def define_installer_if_needed(bin) exe = exefile("#{build_dir}/bin/#{bin}") host? ? define_installer(exe) : exe