Sha256: 372ad67dd00bb1c88f0cc14170c1efdf71ba38dfd330708ded232e2dbf543065

Contents?: true

Size: 1.69 KB

Versions: 1

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true

require "mkmf"
cflags = " -Wall"
$CFLAGS += cflags
$CPPFLAGS += cflags if RUBY_VERSION >= "2.0.0"
$LOCAL_LIBS += " -lstdc++ "

IO_TARGETS = [
  [Kernel, :instance_eval],
  [(class << File; self; end), :class_eval], # https://github.com/ruby/ruby/commit/19beb028
]
def IO_TARGETS.mod(&b)
  self.each{|class_, func| class_.send(func, &b)}
end

IO_TARGETS.mod{
  alias_method(:open_orig, :open)
}

Dir::glob(File::join(File::dirname(__FILE__), "*/")).each{|dir|
  mod_name = File::basename(dir)
  
  dst = File::join(Dir.getwd, mod_name)
  FileUtils::mkdir_p(dst) if dir != dst
  
  $stderr.puts "For #{mod_name} ..."

  # @see https://stackoverflow.com/a/35842162/15992898
  $srcs = Dir::glob(File::join(dir, '*.cxx')).collect{|path|
    File::join(mod_name, File::basename(path))
  }
  $objs = $srcs.collect{|path|
    path.sub(/\.[^\.]+$/, '.o')
  }

  IO_TARGETS.mod{
    # rename Makefile to Makefile.#{mod_name}
    define_method(:open){|*args, &b|
      args[0] += ".#{mod_name}" if (args[0] && (args[0] == "Makefile"))
      open_orig(*args, &b)
    }
  }
  create_makefile("boost_distributions/#{mod_name}")
}

IO_TARGETS.mod{
  alias_method(:open, :open_orig)
}

# manual generation of top-level Makefile
# @see https://yorickpeterse.com/articles/hacking-extconf-rb/
open("Makefile", 'w'){|io|
  # @see https://stackoverflow.com/a/17845120/15992898
  io.write(<<-__TOPLEVEL_MAKEFILE__)
TOPTARGETS := all clean distclean realclean install site-install

SUBMFS := $(wildcard Makefile.*)

$(TOPTARGETS): $(SUBMFS)
$(SUBMFS):
#{"\t"}$(MAKE) -f $@ $(MAKECMDGOALS)

.PHONY: $(TOPTARGETS) $(SUBMFS)
  __TOPLEVEL_MAKEFILE__
}

require 'fileutils'
FileUtils::touch("boost_distributions.so") # dummy

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
boost_distributions-0.1.0 ext/boost_distributions/extconf.rb