Skip to content

Commit adf14eb

Browse files
committed
Fall back to default AR and CC
1 parent 7142b76 commit adf14eb

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

ext/prism/extconf.rb

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,33 @@ def generate_templates
4040
end
4141
end
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.
4346
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
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)
4967
Dir.chdir(File.expand_path("../..", __dir__)) do
5068
system(
51-
RbConfig::CONFIG.slice(*%w[SOEXT CPPFLAGS CFLAGS CC AR ARFLAGS MAKEDIRS RMALL]), # env
69+
env,
5270
RUBY_PLATFORM.include?("openbsd") ? "gmake" : "make",
5371
target,
5472
exception: true
@@ -62,7 +80,7 @@ def make(target)
6280
# but we want to use the native toolchain here since libprism is run natively.
6381
if RUBY_ENGINE != "ruby"
6482
generate_templates
65-
make("build/libprism.#{RbConfig::CONFIG["SOEXT"]}")
83+
make(env, "build/libprism.#{RbConfig::CONFIG["SOEXT"]}")
6684
File.write("Makefile", "all install clean:\n\t@#{RbConfig::CONFIG["NULLCMD"]}\n")
6785
return
6886
end
@@ -110,7 +128,7 @@ def make(target)
110128
archive_target = "build/libprism.a"
111129
archive_path = File.expand_path("../../#{archive_target}", __dir__)
112130

113-
make(archive_target) unless File.exist?(archive_path)
131+
make(env, archive_target) unless File.exist?(archive_path)
114132
$LOCAL_LIBS << " #{archive_path}"
115133

116134
# Finally, we'll create the `Makefile` that is going to be used to configure and

0 commit comments

Comments
 (0)