Skip to content

Commit d690fc3

Browse files
committed
Refactor compilation command to extract common parts.
1 parent c7d4dfe commit d690fc3

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

lib/truffle/rbconfig-for-mkmf.rb

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,25 @@
135135
Truffle::CExt::Preprocessor.makefile_matcher("#{preprocess_ruby} #{cext_dir}/preprocess.rb $< | #{command1}", command2)
136136
end
137137

138+
for_file = proc do |compiler, flags, opt_command|
139+
"#{compiler} #{flags} $< && #{opt_command}"
140+
end
141+
142+
for_pipe = proc do |compiler, flags, opt_command|
143+
"#{compiler} -I$(<D) #{flags} - -o $@ && #{opt_command}"
144+
end
145+
146+
c_flags = "$(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG) -xc"
147+
cxx_flags = "$(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG) -xc++"
148+
opt_command = "#{opt} #{opt_passes} $@ -o $@"
149+
138150
mkconfig['COMPILE_C'] = with_conditional_preprocessing.call(
139-
"$(CC) -I$(<D) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG) -xc - -o $@ && #{opt} #{opt_passes} $@ -o $@",
140-
"$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG) -xc $(<) && #{opt} #{opt_passes} $@ -o $@")
141-
mkconfig['COMPILE_CXX'] = with_conditional_preprocessing.call(
142-
"$(CXX) -I$(<D) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG) -xc++ - -o $@ && #{opt} #{opt_passes} $@ -o $@",
143-
"$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG) -xc++ $(<) && #{opt} #{opt_passes} $@ -o $@")
151+
for_pipe.call("$(CC)", c_flags, opt_command),
152+
for_file.call("$(CC)", c_flags, opt_command))
153+
154+
mkconfig['COMPILE_CXX'] = with_conditional_preprocessing.call(
155+
for_pipe.call("$(CXX)", cxx_flags, opt_command),
156+
for_file.call("$(CXX)", cxx_flags, opt_command))
144157
end
145158

146159
# From mkmf.rb: "$(CC) #{OUTFLAG}#{CONFTEST}#{$EXEEXT} $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(src) $(LIBPATH) $(LDFLAGS) $(ARCH_FLAG) $(LOCAL_LIBS) $(LIBS)"

0 commit comments

Comments
 (0)