summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-01-28 23:14:30 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2026-04-09 12:18:32 +0900
commitf104525c71fbd6338e98050201253f2fe464ec9b (patch)
treef5963647cb52133dc1ca8ea5e53d87415e510f66
parenta4fa75ee73d0b017a6ac3879844d42fadd2760db (diff)
mkmf: cpp_command in C++ mode
-rw-r--r--lib/mkmf.rb16
-rw-r--r--test/mkmf/test_egrep_cpp.rb12
2 files changed, 27 insertions, 1 deletions
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