@@ -40,15 +40,34 @@ def generate_templates
4040 end
4141end
4242
43+ # We're going to need to run `make` using prism's `Makefile`. We want to match
44+ # up as much of the configuration to the configuration that built the current
45+ # version of Ruby as possible.
4346require "rbconfig"
47+ env = RbConfig ::CONFIG . slice ( "SOEXT" , "CPPFLAGS" , "CFLAGS" , "CC" , "AR" , "ARFLAGS" , "MAKEDIRS" , "RMALL" )
48+
49+ # It's possible that the Ruby that is being run wasn't actually compiled on this
50+ # machine, in which case the configuration might be incorrect. In this case
51+ # we'll need to do some additional checks and potentially fall back to defaults.
52+ if env . key? ( "CC" ) && !File . exist? ( env [ "CC" ] )
53+ env . delete ( "CC" )
54+ env . delete ( "CFLAGS" )
55+ env . delete ( "CPPFLAGS" )
56+ end
57+
58+ if env . key? ( "AR" ) && !File . exist? ( env [ "AR" ] )
59+ env . delete ( "AR" )
60+ env . delete ( "ARFLAGS" )
61+ end
4462
4563# Runs `make` in the root directory of the project. Note that this is the
4664# `Makefile` for the overall project, not the `Makefile` that is being generated
4765# by this script.`
48- def make ( target )
66+ def make ( env , target )
67+ puts "Running make #{ target } with #{ env . inspect } "
4968 Dir . chdir ( File . expand_path ( "../.." , __dir__ ) ) do
5069 system (
51- RbConfig :: CONFIG . slice ( * %w[ SOEXT CPPFLAGS CFLAGS CC AR ARFLAGS MAKEDIRS RMALL ] ) , # env
70+ env ,
5271 RUBY_PLATFORM . include? ( "openbsd" ) ? "gmake" : "make" ,
5372 target ,
5473 exception : true
@@ -62,7 +81,7 @@ def make(target)
6281# but we want to use the native toolchain here since libprism is run natively.
6382if RUBY_ENGINE != "ruby"
6483 generate_templates
65- make ( "build/libprism.#{ RbConfig ::CONFIG [ "SOEXT" ] } " )
84+ make ( env , "build/libprism.#{ RbConfig ::CONFIG [ "SOEXT" ] } " )
6685 File . write ( "Makefile" , "all install clean:\n \t @#{ RbConfig ::CONFIG [ "NULLCMD" ] } \n " )
6786 return
6887end
@@ -110,7 +129,7 @@ def make(target)
110129archive_target = "build/libprism.a"
111130archive_path = File . expand_path ( "../../#{ archive_target } " , __dir__ )
112131
113- make ( archive_target ) unless File . exist? ( archive_path )
132+ make ( env , archive_target ) unless File . exist? ( archive_path )
114133$LOCAL_LIBS << " #{ archive_path } "
115134
116135# Finally, we'll create the `Makefile` that is going to be used to configure and
0 commit comments