Skip to content

Commit b730cbf

Browse files
committed
Simplify and comment logic in mkmf.rb for $extmk and related
* $extmk should be true iff building core extensions, so we can use the building.core.cexts option. * $extmk must be false when building gems, which causes extconf.h to not be created by default. This affects, e.g., backup.c of sqlite3 1.3.13 as HAVE_SQLITE3_BACKUP_INIT is only defined before the <includes> if passed as `-D` and not through extconf.h.
1 parent 1f0a382 commit b730cbf

File tree

1 file changed

+35
-28
lines changed

1 file changed

+35
-28
lines changed

lib/mri/mkmf.rb

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -233,36 +233,43 @@ def map_dir(dir, map = nil)
233233
end
234234

235235
if RUBY_ENGINE == 'truffleruby'
236-
topdir = RbConfig::CONFIG['prefix']
236+
$extmk = Truffle::Boot.get_option('building.core.cexts')
237+
topdir = RbConfig::CONFIG['prefix'] # the TruffleRuby home
238+
$hdrdir = RbConfig::CONFIG["rubyhdrdir"] # lib/cext/include
239+
$arch_hdrdir = RbConfig::CONFIG["rubyarchhdrdir"] # lib/cext/include
240+
241+
unless File.exist?("#{$hdrdir}/ruby/ruby.h")
242+
abort "mkmf.rb can't find header files for ruby at #{$hdrdir}/ruby/ruby.h"
243+
end
244+
245+
if not $extmk
246+
$topdir = $hdrdir # lib/cext/include
247+
$top_srcdir = $hdrdir # lib/cext/include
248+
else
249+
$top_srcdir ||= topdir + "/lib/cext" # lib/cext
250+
$topdir ||= RbConfig::CONFIG["topdir"] # lib/mri
251+
end
237252
else
238253
topdir = File.dirname(File.dirname(__FILE__))
239-
end
240-
241-
path = File.expand_path($0)
242-
until (dir = File.dirname(path)) == path
243-
if File.identical?(dir, topdir)
244-
if RUBY_ENGINE == 'truffleruby'
245-
$extmk = true if %r"\A(?:ext|enc|tool|test|src)\z" =~ File.basename(path)
246-
else
254+
path = File.expand_path($0)
255+
until (dir = File.dirname(path)) == path
256+
if File.identical?(dir, topdir)
247257
$extmk = true if %r"\A(?:ext|enc|tool|test)\z" =~ File.basename(path)
248-
end
249-
break
250-
end
251-
path = dir
252-
end
253-
$extmk ||= false
254-
if not $extmk and File.exist?(($hdrdir = RbConfig::CONFIG["rubyhdrdir"]) + "/ruby/ruby.h")
255-
$topdir = $hdrdir
256-
$top_srcdir = $hdrdir
257-
$arch_hdrdir = RbConfig::CONFIG["rubyarchhdrdir"]
258-
elsif RUBY_ENGINE != 'truffleruby' && File.exist?(($hdrdir = ($top_srcdir ||= topdir) + "/include") + "/ruby.h")
259-
$topdir ||= RbConfig::CONFIG["topdir"]
260-
$arch_hdrdir = "$(extout)/include/$(arch)"
261-
elsif RUBY_ENGINE == 'truffleruby' && File.exist?(($hdrdir = ($top_srcdir ||= topdir + "/lib/cext") + "/include") + "/ruby.h")
262-
$topdir ||= RbConfig::CONFIG["topdir"]
263-
$arch_hdrdir = $top_srcdir + "/include"
264-
else
265-
abort "mkmf.rb can't find header files for ruby at #{$hdrdir}/ruby.h"
258+
break
259+
end
260+
path = dir
261+
end
262+
$extmk ||= false
263+
if not $extmk and File.exist?(($hdrdir = RbConfig::CONFIG["rubyhdrdir"]) + "/ruby/ruby.h")
264+
$topdir = $hdrdir
265+
$top_srcdir = $hdrdir
266+
$arch_hdrdir = RbConfig::CONFIG["rubyarchhdrdir"]
267+
elsif File.exist?(($hdrdir = ($top_srcdir ||= topdir) + "/include") + "/ruby.h")
268+
$topdir ||= RbConfig::CONFIG["topdir"]
269+
$arch_hdrdir = "$(extout)/include/$(arch)"
270+
else
271+
abort "mkmf.rb can't find header files for ruby at #{$hdrdir}/ruby.h"
272+
end
266273
end
267274

268275
CONFTEST = "conftest".freeze
@@ -2651,7 +2658,7 @@ def MAIN_DOES_NOTHING(*refs)
26512658
RbConfig::CONFIG["topdir"] = curdir
26522659
end
26532660
$configure_args["--topdir"] ||= $curdir
2654-
2661+
26552662
if RUBY_ENGINE == 'truffleruby'
26562663
$ruby = arg_config("--ruby", RbConfig.ruby)
26572664
else

0 commit comments

Comments
 (0)