@@ -40,15 +40,33 @@ def generate_templates
40
40
end
41
41
end
42
42
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.
43
46
require "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
44
62
45
63
# Runs `make` in the root directory of the project. Note that this is the
46
64
# `Makefile` for the overall project, not the `Makefile` that is being generated
47
65
# by this script.`
48
- def make ( target )
66
+ def make ( env , target )
49
67
Dir . chdir ( File . expand_path ( "../.." , __dir__ ) ) do
50
68
system (
51
- RbConfig :: CONFIG . slice ( * %w[ SOEXT CPPFLAGS CFLAGS CC AR ARFLAGS MAKEDIRS RMALL ] ) , # env
69
+ env ,
52
70
RUBY_PLATFORM . include? ( "openbsd" ) ? "gmake" : "make" ,
53
71
target ,
54
72
exception : true
@@ -62,7 +80,7 @@ def make(target)
62
80
# but we want to use the native toolchain here since libprism is run natively.
63
81
if RUBY_ENGINE != "ruby"
64
82
generate_templates
65
- make ( "build/libprism.#{ RbConfig ::CONFIG [ "SOEXT" ] } " )
83
+ make ( env , "build/libprism.#{ RbConfig ::CONFIG [ "SOEXT" ] } " )
66
84
File . write ( "Makefile" , "all install clean:\n \t @#{ RbConfig ::CONFIG [ "NULLCMD" ] } \n " )
67
85
return
68
86
end
@@ -110,7 +128,7 @@ def make(target)
110
128
archive_target = "build/libprism.a"
111
129
archive_path = File . expand_path ( "../../#{ archive_target } " , __dir__ )
112
130
113
- make ( archive_target ) unless File . exist? ( archive_path )
131
+ make ( env , archive_target ) unless File . exist? ( archive_path )
114
132
$LOCAL_LIBS << " #{ archive_path } "
115
133
116
134
# Finally, we'll create the `Makefile` that is going to be used to configure and
0 commit comments