зеркало из https://github.com/github/ruby.git
[EXPERIMENTAL] MakeMakefile::CXX for C++
This commit is contained in:
Родитель
7d354175d7
Коммит
c3f03da494
|
@ -1,21 +1,8 @@
|
|||
# frozen_string_literal: false
|
||||
|
||||
cfg = RbConfig::CONFIG.merge(
|
||||
'hdrdir' => $hdrdir.quote,
|
||||
'src' => "#{CONFTEST_C}",
|
||||
'arch_hdrdir' => $arch_hdrdir.quote,
|
||||
'top_srcdir' => $top_srcdir.quote,
|
||||
'CC' => RbConfig::CONFIG['CXX'],
|
||||
'CFLAGS' => RbConfig::CONFIG['CXXFLAGS'],
|
||||
'INCFLAGS' => "#$INCFLAGS",
|
||||
'CPPFLAGS' => "#$CPPFLAGS",
|
||||
'ARCH_FLAG' => "#$ARCH_FLAG",
|
||||
'LDFLAGS' => "#$LDFLAGS",
|
||||
'LOCAL_LIBS' => "#$LOCAL_LIBS",
|
||||
'LIBS' => "#$LIBS"
|
||||
)
|
||||
cxx = RbConfig::expand(TRY_LINK.dup, cfg)
|
||||
src = create_tmpsrc(<<~'begin') do |x|
|
||||
cxx = MakeMakefile::CXX
|
||||
|
||||
ok = cxx.try_compile(<<~'begin', "", lang: 'C++') do |x|
|
||||
#include "ruby/config.h"
|
||||
|
||||
namespace {
|
||||
|
@ -34,8 +21,6 @@ begin
|
|||
x.sub! %<#include "ruby.h">, ''
|
||||
end
|
||||
|
||||
begin
|
||||
create_makefile("-test-/cxxanyargs") if xsystem(cxx)
|
||||
ensure
|
||||
log_src src
|
||||
if ok
|
||||
create_makefile("-test-/cxxanyargs")
|
||||
end
|
||||
|
|
47
lib/mkmf.rb
47
lib/mkmf.rb
|
@ -434,6 +434,10 @@ EOM
|
|||
EOM
|
||||
end
|
||||
|
||||
def conftest_source
|
||||
CONFTEST_C
|
||||
end
|
||||
|
||||
def create_tmpsrc(src)
|
||||
src = "#{COMMON_HEADERS}\n#{src}"
|
||||
src = yield(src) if block_given?
|
||||
|
@ -442,7 +446,7 @@ EOM
|
|||
src.sub!(/[^\n]\z/, "\\&\n")
|
||||
count = 0
|
||||
begin
|
||||
open(CONFTEST_C, "wb") do |cfile|
|
||||
open(conftest_source, "wb") do |cfile|
|
||||
cfile.print src
|
||||
end
|
||||
rescue Errno::EACCES
|
||||
|
@ -477,10 +481,10 @@ MSG
|
|||
end
|
||||
end
|
||||
|
||||
def link_command(ldflags, opt="", libpath=$DEFLIBPATH|$LIBPATH)
|
||||
def link_config(ldflags, opt="", libpath=$DEFLIBPATH|$LIBPATH)
|
||||
librubyarg = $extmk ? $LIBRUBYARG_STATIC : "$(LIBRUBYARG)"
|
||||
conf = RbConfig::CONFIG.merge('hdrdir' => $hdrdir.quote,
|
||||
'src' => "#{CONFTEST_C}",
|
||||
'src' => "#{conftest_source}",
|
||||
'arch_hdrdir' => $arch_hdrdir.quote,
|
||||
'top_srcdir' => $top_srcdir.quote,
|
||||
'INCFLAGS' => "#$INCFLAGS",
|
||||
|
@ -491,21 +495,29 @@ MSG
|
|||
'LOCAL_LIBS' => "#$LOCAL_LIBS #$libs",
|
||||
'LIBS' => "#{librubyarg} #{opt} #$LIBS")
|
||||
conf['LIBPATH'] = libpathflag(libpath.map {|s| RbConfig::expand(s.dup, conf)})
|
||||
conf
|
||||
end
|
||||
|
||||
def link_command(ldflags, *opts)
|
||||
conf = link_config(ldflags, *opts)
|
||||
RbConfig::expand(TRY_LINK.dup, conf)
|
||||
end
|
||||
|
||||
def cc_command(opt="")
|
||||
def cc_config(opt="")
|
||||
conf = RbConfig::CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote,
|
||||
'arch_hdrdir' => $arch_hdrdir.quote,
|
||||
'top_srcdir' => $top_srcdir.quote)
|
||||
conf
|
||||
end
|
||||
|
||||
def cc_command(opt="")
|
||||
conf = cc_config(opt)
|
||||
RbConfig::expand("$(CC) #$INCFLAGS #$CPPFLAGS #$CFLAGS #$ARCH_FLAG #{opt} -c #{CONFTEST_C}",
|
||||
conf)
|
||||
end
|
||||
|
||||
def cpp_command(outfile, opt="")
|
||||
conf = RbConfig::CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote,
|
||||
'arch_hdrdir' => $arch_hdrdir.quote,
|
||||
'top_srcdir' => $top_srcdir.quote)
|
||||
conf = cc_config(opt)
|
||||
if $universal and (arch_flag = conf['ARCH_FLAG']) and !arch_flag.empty?
|
||||
conf['ARCH_FLAG'] = arch_flag.gsub(/(?:\G|\s)-arch\s+\S+/, '')
|
||||
end
|
||||
|
@ -2763,6 +2775,27 @@ distclean: clean distclean-so distclean-static distclean-rb-default distclean-rb
|
|||
|
||||
realclean: distclean
|
||||
"
|
||||
|
||||
C = self
|
||||
|
||||
module CXX
|
||||
include MakeMakefile
|
||||
extend self
|
||||
|
||||
# Logging.message "CXX_EXT=#{CONFIG['CXX_EXT']}\n"
|
||||
|
||||
CONFTEST_CXX = "#{CONFTEST}.#{config_string('CXX_EXT') || CXX_EXT[0]}"
|
||||
|
||||
def conftest_source
|
||||
CONFTEST_CXX
|
||||
end
|
||||
|
||||
def cc_command(opt="")
|
||||
conf = cc_config(opt)
|
||||
RbConfig::expand("$(CXX) #$INCFLAGS #$CPPFLAGS #$CXXFLAGS #$ARCH_FLAG #{opt} -c #{CONFTEST_CXX}",
|
||||
conf)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
include MakeMakefile
|
||||
|
|
|
@ -1041,6 +1041,7 @@ s,@COMPILE_CXX@,$$(CXX) $$(INCFLAGS) $$(CXXFLAGS) $$(CPPFLAGS) $$(COUTFLAG)$$(@)
|
|||
s,@ASSEMBLE_C@,$$(CC) $$(CFLAGS) $$(CPPFLAGS) -Fa$$(@) -c $$(CSRCFLAG)$$(<:\=/),;t t
|
||||
s,@ASSEMBLE_CXX@,$$(CXX) $$(CXXFLAGS) $$(CPPFLAGS) -Fa$$(@) -c -Tp$$(<:\=/),;t t
|
||||
s,@COMPILE_RULES@,{$$(*VPATH*)}.%s.%s: .%s.%s:,;t t
|
||||
s,@CXX_EXT@,cpp,;t t
|
||||
s,@RULE_SUBST@,{.;$$(VPATH)}%s,;t t
|
||||
s,@TRY_LINK@,$$(CC) -Feconftest $$(INCFLAGS) -I$$(hdrdir) $$(CPPFLAGS) $$(CFLAGS) $$(src) $$(LOCAL_LIBS) $$(LIBS) -link $$(LDFLAGS) $$(LIBPATH) $$(XLDFLAGS),;t t
|
||||
s,@COMMON_LIBS@,$(COMMON_LIBS),;t t
|
||||
|
|
Загрузка…
Ссылка в новой задаче