From f104525c71fbd6338e98050201253f2fe464ec9b Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Thu, 28 Jan 2021 23:14:30 +0900 Subject: mkmf: cpp_command in C++ mode --- lib/mkmf.rb | 16 +++++++++++++++- test/mkmf/test_egrep_cpp.rb | 12 ++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/mkmf.rb b/lib/mkmf.rb index 38a5a15fb5..8db4647a40 100644 --- a/lib/mkmf.rb +++ b/lib/mkmf.rb @@ -573,11 +573,16 @@ MSG conf) end - def cpp_command(outfile, opt="") + def cpp_config(opt) 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 + conf + end + + def cpp_command(outfile, opt="") + conf = cpp_config(opt) RbConfig::expand("$(CPP) #$INCFLAGS #$CPPFLAGS #$CFLAGS #{opt} #{CONFTEST_C} #{outfile}", conf) end @@ -3037,6 +3042,15 @@ realclean: distclean conf) end + def cpp_command(outfile, opt="") + conf = cpp_config(opt) + cpp = conf['CPP'].sub(/(\A|\s)#{Regexp.quote(conf['CC'])}(?=\z|\s)/) { + "#$1#{conf['CXX']}" + } + RbConfig::expand("#{cpp} #$INCFLAGS #$CPPFLAGS #$CXXFLAGS #{opt} #{CONFTEST_CXX} #{outfile}", + conf) + end + def link_command(ldflags, *opts) conf = link_config(ldflags, *opts) RbConfig::expand(TRY_LINK_CXX.dup, conf) diff --git a/test/mkmf/test_egrep_cpp.rb b/test/mkmf/test_egrep_cpp.rb index 7ac0e60010..2d10140368 100644 --- a/test/mkmf/test_egrep_cpp.rb +++ b/test/mkmf/test_egrep_cpp.rb @@ -10,4 +10,16 @@ class TestMkmfEgrepCpp < TestMkmf def test_not_have_func assert_equal(false, egrep_cpp(/never match/, ""), MKMFLOG) end + + class TestMkmfEgrepCxx < self + def test_cxx_egrep_cpp + assert_equal(true, MakeMakefile["C++"].egrep_cpp(/^ok/, <<~SRC), MKMFLOG) + #ifdef __cplusplus + ok + #else + #error not C++ + #endif + SRC + end + end end -- cgit v1.2.3