Skip to content

Commit 49c0cba

Browse files
authored
Merge pull request #3289 from ruby/nomake
Don't use `make` while building Prism
2 parents a1888c8 + 7c2461f commit 49c0cba

File tree

1 file changed

+14
-31
lines changed

1 file changed

+14
-31
lines changed

ext/prism/extconf.rb

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,6 @@ def make(env, target)
7070
return
7171
end
7272

73-
# We're going to need to run `make` using prism's `Makefile`.
74-
# We want to use the same toolchain (compiler, flags, etc) to compile libprism.a and
75-
# the C extension since they will be linked together.
76-
# The C extension uses RbConfig, which contains values from the toolchain that built the running Ruby.
77-
env = RbConfig::CONFIG.slice("SOEXT", "CPPFLAGS", "CFLAGS", "CC", "AR", "ARFLAGS", "MAKEDIRS", "RMALL")
78-
79-
# It's possible that the Ruby that is being run wasn't actually compiled on this
80-
# machine, in which case parts of RbConfig might be incorrect. In this case
81-
# we'll need to do some additional checks and potentially fall back to defaults.
82-
if env.key?("CC") && !File.exist?(env["CC"])
83-
env.delete("CC")
84-
env.delete("CFLAGS")
85-
env.delete("CPPFLAGS")
86-
end
87-
88-
if env.key?("AR") && !File.exist?(env["AR"])
89-
env.delete("AR")
90-
env.delete("ARFLAGS")
91-
end
92-
9373
require "mkmf"
9474

9575
# First, ensure that we can find the header for the prism library.
@@ -133,18 +113,21 @@ def make(env, target)
133113
archive_target = "build/libprism.a"
134114
archive_path = File.expand_path("../../#{archive_target}", __dir__)
135115

136-
make(env, archive_target) unless File.exist?(archive_path)
137-
$LOCAL_LIBS << " #{archive_path}"
116+
def src_list(path)
117+
srcdir = path.dup
118+
RbConfig.expand(srcdir) # mutates srcdir :-/
119+
Dir[File.join(srcdir, "*.{#{SRC_EXT.join(%q{,})}}")]
120+
end
121+
122+
def add_libprism_source(path)
123+
$VPATH << path
124+
src_list path
125+
end
126+
127+
$srcs = src_list("$(srcdir)") +
128+
add_libprism_source("$(srcdir)/../../src") +
129+
add_libprism_source("$(srcdir)/../../src/util")
138130

139131
# Finally, we'll create the `Makefile` that is going to be used to configure and
140132
# build the C extension.
141133
create_makefile("prism/prism")
142-
143-
# Now that the `Makefile` for the C extension is built, we'll append on an extra
144-
# rule that dictates that the extension should be rebuilt if the archive is
145-
# updated.
146-
File.open("Makefile", "a") do |mf|
147-
mf.puts
148-
mf.puts("# Automatically rebuild the extension if libprism.a changed")
149-
mf.puts("$(TARGET_SO): $(LOCAL_LIBS)")
150-
end

0 commit comments

Comments
 (0)