From 2e45fd036ad308cfa6094b181a67f97002ebf10f Mon Sep 17 00:00:00 2001 From: Shinichiro Hamaji Date: Mon, 25 Jan 2016 18:59:43 +0900 Subject: [PATCH] Use dependency files generated by llvm-rs-cc This was a regression since kati has been introduced. This CL introduces include-depfile function to make it easier to write Makefiles which work with both make and kati. As ninja can handle only a single dependency file per a build rule, now we merge multiple .d files generated by llvm-rs-cc into a .d file. Change-Id: Iaf64a8f0523ab98115837e6e06abd50f06620363 --- core/binary.mk | 8 ++------ core/definitions.mk | 39 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/core/binary.mk b/core/binary.mk index af8d74780..5f7ba663c 100644 --- a/core/binary.mk +++ b/core/binary.mk @@ -562,7 +562,7 @@ $(RenderScript_file_stamp): $(renderscript_sources_fullpath) $(LOCAL_RENDERSCRIP $(transform-renderscripts-to-cpp-and-bc) # include the dependency files (.d/.P) generated by llvm-rs-cc. --include $(bc_dep_files:%.d=%.P) +$(call include-depfile,$(RenderScript_file_stamp).P,$(RenderScript_file_stamp)) LOCAL_INTERMEDIATE_TARGETS += $(RenderScript_file_stamp) @@ -741,12 +741,8 @@ aidl_gen_include_root := $(intermediates)/aidl-generated/include # Thus we'll actually generate source for each architecture. $(foreach s,$(aidl_src),\ $(eval $(call define-aidl-cpp-rule,$(s),$(aidl_gen_cpp_root),aidl_gen_cpp))) -ifeq ($(BUILDING_WITH_NINJA),true) $(foreach cpp,$(aidl_gen_cpp), \ - $(eval $(cpp) : .KATI_DEPFILE := $(addsuffix .aidl.P,$(basename $(cpp))))) -else - -include $(addsuffix .aidl.P,$(basename $(aidl_gen_cpp))) -endif + $(call include-depfile,$(addsuffix .aidl.P,$(basename $(cpp))),$(cpp))) $(aidl_gen_cpp) : PRIVATE_MODULE := $(LOCAL_MODULE) diff --git a/core/definitions.mk b/core/definitions.mk index 916dfa2c1..78b607b63 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -874,7 +874,7 @@ endef endif ########################################################### -## Commands for munging the dependency files GCC generates +## Commands for munging the dependency files the compiler generates ########################################################### # $(1): the input .d file # $(2): the output .P file @@ -889,6 +889,21 @@ define transform-d-to-p $(call transform-d-to-p-args,$(@:%.o=%.d),$(@:%.o=%.P)) endef +########################################################### +## Commands for including the dependency files the compiler generates +########################################################### +# $(1): the .P file +# $(2): the main build target +ifeq ($(BUILDING_WITH_NINJA),true) +define include-depfile +$(eval $(2) : .KATI_DEPFILE := $1) +endef +else +define include-depfile +$(eval -include $1) +endef +endif + ########################################################### ## Commands for running lex ########################################################### @@ -954,6 +969,24 @@ endef ## Commands to compile RenderScript to C++ ########################################################### +## Merge multiple .d files generated by llvm-rs-cc. This is necessary +## because ninja can handle only a single depfile per build target. +## We assume .d files start with two targets and their prerequisites +## follow. The first line is for the stamp file and the second line is +## for .bc file. There's no way to let ninja know dependencies to .bc +## files, so we give up build targets for .bc files. As we write the +## .stamp file as the target by ourselves, the sed script removes the +## first two lines and append a backslash to the last line to +## concatenate contents of multiple files. +# $(1): .d files to be merged +# $(2): merged .d file +define _merge-renderscript-d +$(hide) echo '$@: $(backslash)' > $2 +$(foreach d,$1, \ + $(hide) sed '1d; 2d; s/\( \\\)\?$$/ \\/' $d >> $2$(newline)) +$(hide) echo >> $2 +endef + define transform-renderscripts-to-cpp-and-bc @echo "RenderScript: $(PRIVATE_MODULE) <= $(PRIVATE_RS_SOURCE_FILES)" $(hide) rm -rf $(PRIVATE_RS_OUTPUT_DIR) @@ -967,8 +1000,8 @@ $(hide) $(PRIVATE_RS_CC) \ $(PRIVATE_RS_FLAGS) \ $(addprefix -I , $(PRIVATE_RS_INCLUDES)) \ $(PRIVATE_RS_SOURCE_FILES) - $(foreach d,$(PRIVATE_DEP_FILES),\ - $(call transform-d-to-p-args,$(d),$(d:%.d=%.P))$(newline)) +$(call _merge-renderscript-d,$(PRIVATE_DEP_FILES),$@.d) +$(call transform-d-to-p-args,$@.d,$@.P) $(hide) mkdir -p $(dir $@) $(hide) touch $@ endef