Skip to content

Commit 2d27659

Browse files
committed
Only call our C preprocessor on files which require it.
1 parent ac1617a commit 2d27659

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

lib/truffle/rbconfig-for-mkmf.rb

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,44 @@
129129
# directory are include in preference to others on the include path,
130130
# and is required because we are actually piping the file into the
131131
# compiler which disables this standard behaviour of the C preprocessor.
132-
mkconfig['COMPILE_C'] = "#{preprocess_ruby} #{cext_dir}/preprocess.rb $< | $(CC) -I$(<D) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG) -xc - -o $@ && #{opt} #{opt_passes} $@ -o $@"
133-
mkconfig['COMPILE_CXX'] = "#{preprocess_ruby} #{cext_dir}/preprocess.rb $< | $(CXX) -I$(<D) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG) -xc++ - -o $@ && #{opt} #{opt_passes} $@ -o $@"
132+
begin
133+
with_conditional_preprocessing = proc do |command1, command2|
134+
<<-EOF
135+
$(if $(or\\
136+
$(and\\
137+
$(findstring nokogiri, $(realpath $(<))),\\
138+
$(or\\
139+
$(findstring xml_node_set.c, $(<)),\\
140+
$(findstring xslt_stylesheet.c, $(<)),\\
141+
$(findstring xml_document.c, $(<)),\\
142+
$(findstring xml_sax_parser.c, $(<)),\\
143+
$(findstring xml_xpath_context.c, $(<)))),\\
144+
$(and\\
145+
$(findstring pg, $(realpath $(<))),\\
146+
$(or\\
147+
$(findstring pg_binary_encoder.c, $(<)),\\
148+
$(findstring pg_result.c, $(<)),\\
149+
$(findstring pg_tuple.c, $(<)),\\
150+
$(findstring pg_text_decoder.c, $(<)),\\
151+
$(findstring pg_text_encoder.c, $(<)),\\
152+
$(findstring pg_type_map_by_class.c, $(<)))),\\
153+
$(and\\
154+
$(findstring json, $(realpath $(<))),\\
155+
$(or\\
156+
$(findstring parser.c, $(<))))\\
157+
),\\
158+
#{preprocess_ruby} #{cext_dir}/preprocess.rb $< | #{command1},\\
159+
#{command2})
160+
EOF
161+
end
162+
163+
mkconfig['COMPILE_C'] = with_conditional_preprocessing.call(
164+
"$(CC) -I$(<D) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG) -xc - -o $@ && #{opt} #{opt_passes} $@ -o $@",
165+
"$(CC) -I$(<D) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG) -xc - -o $@ <$(<) && #{opt} #{opt_passes} $@ -o $@")
166+
mkconfig['COMPILE_CXX'] = with_conditional_preprocessing.call(
167+
"$(CXX) -I$(<D) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG) -xc++ - -o $@ && #{opt} #{opt_passes} $@ -o $@",
168+
"$(CXX) -I$(<D) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG) -xc++ - -o $@ <$(<) && #{opt} #{opt_passes} $@ -o $@")
169+
end
134170

135171
# From mkmf.rb: "$(CC) #{OUTFLAG}#{CONFTEST}#{$EXEEXT} $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(src) $(LIBPATH) $(LDFLAGS) $(ARCH_FLAG) $(LOCAL_LIBS) $(LIBS)"
136172
mkconfig['TRY_LINK'] = "#{cc} -o conftest $(INCFLAGS) $(CPPFLAGS) #{base_cflags} #{link_o_files} $(src) $(LIBPATH) $(LDFLAGS) $(ARCH_FLAG) $(LOCAL_LIBS) $(LIBS)"

0 commit comments

Comments
 (0)