From 64088f2459f37043be939dce448a7431135bd5da Mon Sep 17 00:00:00 2001 From: Ying Wang Date: Mon, 11 Jan 2016 16:28:45 -0800 Subject: [PATCH] Generate .c for .y and .l - For .l/.y source files, generate .c files; for .ll/.yy source files, generate c++ files. - Simplified the rules by adding the generated sources to my_generated_sources. - Simplified generated header file naming by always using .h extension with bison's "--defines=" option. - Removed the unnecesarry conditional inclusion to the generated headers. Bison already automatically generates such things. Bug: 26492989 Change-Id: I9ab6dc149c258f7642bc36c3fa32f90ff7ee51a4 --- core/binary.mk | 81 ++++++++++++++++----------------------------- core/config.mk | 2 -- core/definitions.mk | 16 +++------ 3 files changed, 33 insertions(+), 66 deletions(-) diff --git a/core/binary.mk b/core/binary.mk index 4cb62b30ea..73d1d22430 100644 --- a/core/binary.mk +++ b/core/binary.mk @@ -449,7 +449,6 @@ LOCAL_CPP_EXTENSION := $(strip $(LOCAL_CPP_EXTENSION)) ifeq ($(LOCAL_CPP_EXTENSION),) LOCAL_CPP_EXTENSION := .cpp endif -$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPP_EXTENSION := $(LOCAL_CPP_EXTENSION) # Certain modules like libdl have to have symbols resolved at runtime and blow # up if --no-undefined is passed to the linker. @@ -761,79 +760,57 @@ my_generated_sources += $(aidl_gen_cpp) endif # $(aidl_src) non-empty ########################################################### -## YACC: Compile .y and .yy files to .cpp and the to .o. +## YACC: Compile .y/.yy files to .c/.cpp and then to .o. ########################################################### y_yacc_sources := $(filter %.y,$(my_src_files)) -y_yacc_cpps := $(addprefix \ - $(intermediates)/,$(y_yacc_sources:.y=$(LOCAL_CPP_EXTENSION))) +y_yacc_cs := $(addprefix \ + $(intermediates)/,$(y_yacc_sources:.y=.c)) +ifneq ($(y_yacc_cs),) +$(y_yacc_cs): $(intermediates)/%.c: \ + $(TOPDIR)$(LOCAL_PATH)/%.y \ + $(my_additional_dependencies) + $(call transform-y-to-c-or-cpp) + +my_generated_sources += $(y_yacc_cs) +endif yy_yacc_sources := $(filter %.yy,$(my_src_files)) yy_yacc_cpps := $(addprefix \ $(intermediates)/,$(yy_yacc_sources:.yy=$(LOCAL_CPP_EXTENSION))) - -yacc_cpps := $(y_yacc_cpps) $(yy_yacc_cpps) -yacc_headers := $(yacc_cpps:$(LOCAL_CPP_EXTENSION)=.h) -yacc_objects := $(yacc_cpps:$(LOCAL_CPP_EXTENSION)=.o) - -ifneq ($(strip $(y_yacc_cpps)),) -$(y_yacc_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \ - $(TOPDIR)$(LOCAL_PATH)/%.y \ - $(lex_cpps) $(my_additional_dependencies) - $(call transform-y-to-cpp,$(PRIVATE_CPP_EXTENSION)) -$(yacc_headers): $(intermediates)/%.h: $(intermediates)/%$(LOCAL_CPP_EXTENSION) -endif - -ifneq ($(strip $(yy_yacc_cpps)),) +ifneq ($(yy_yacc_cpps),) $(yy_yacc_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \ $(TOPDIR)$(LOCAL_PATH)/%.yy \ - $(lex_cpps) $(my_additional_dependencies) - $(call transform-y-to-cpp,$(PRIVATE_CPP_EXTENSION)) -$(yacc_headers): $(intermediates)/%.h: $(intermediates)/%$(LOCAL_CPP_EXTENSION) -endif + $(my_additional_dependencies) + $(call transform-y-to-c-or-cpp) -ifneq ($(strip $(yacc_cpps)),) -$(yacc_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) -$(yacc_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) -$(yacc_objects): $(intermediates)/%.o: $(intermediates)/%$(LOCAL_CPP_EXTENSION) - $(transform-$(PRIVATE_HOST)cpp-to-o) +my_generated_sources += $(yy_yacc_cpps) endif ########################################################### -## LEX: Compile .l and .ll files to .cpp and then to .o. +## LEX: Compile .l/.ll files to .c/.cpp and then to .o. ########################################################### l_lex_sources := $(filter %.l,$(my_src_files)) -l_lex_cpps := $(addprefix \ - $(intermediates)/,$(l_lex_sources:.l=$(LOCAL_CPP_EXTENSION))) +l_lex_cs := $(addprefix \ + $(intermediates)/,$(l_lex_sources:.l=.c)) +ifneq ($(l_lex_cs),) +$(l_lex_cs): $(intermediates)/%.c: \ + $(TOPDIR)$(LOCAL_PATH)/%.l + $(transform-l-to-c-or-cpp) + +my_generated_sources += $(l_lex_cs) +endif ll_lex_sources := $(filter %.ll,$(my_src_files)) ll_lex_cpps := $(addprefix \ $(intermediates)/,$(ll_lex_sources:.ll=$(LOCAL_CPP_EXTENSION))) - -lex_cpps := $(l_lex_cpps) $(ll_lex_cpps) -lex_objects := $(lex_cpps:$(LOCAL_CPP_EXTENSION)=.o) - -ifneq ($(strip $(l_lex_cpps)),) -$(l_lex_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \ - $(TOPDIR)$(LOCAL_PATH)/%.l - $(transform-l-to-cpp) -endif - -ifneq ($(strip $(ll_lex_cpps)),) +ifneq ($(ll_lex_cpps),) $(ll_lex_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \ $(TOPDIR)$(LOCAL_PATH)/%.ll - $(transform-l-to-cpp) -endif + $(transform-l-to-c-or-cpp) -ifneq ($(strip $(lex_cpps)),) -$(lex_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) -$(lex_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) -$(lex_objects): $(intermediates)/%.o: \ - $(intermediates)/%$(LOCAL_CPP_EXTENSION) \ - $(my_additional_dependencies) \ - $(yacc_headers) - $(transform-$(PRIVATE_HOST)cpp-to-o) +my_generated_sources += $(ll_lex_cpps) endif ########################################################### @@ -1138,8 +1115,6 @@ normal_objects := \ $(gen_c_objects) \ $(objc_objects) \ $(objcpp_objects) \ - $(yacc_objects) \ - $(lex_objects) \ $(proto_generated_objects) \ $(addprefix $(TOPDIR)$(LOCAL_PATH)/,$(LOCAL_PREBUILT_OBJ_FILES)) diff --git a/core/config.mk b/core/config.mk index 37c781d099..c8d2dd3100 100644 --- a/core/config.mk +++ b/core/config.mk @@ -529,8 +529,6 @@ EMMA_JAR := external/emma/lib/emma$(COMMON_JAVA_PACKAGE_SUFFIX) # Tool to merge AndroidManifest.xmls ANDROID_MANIFEST_MERGER := java -classpath prebuilts/devtools/tools/lib/manifest-merger.jar com.android.manifmerger.Main merge -YACC_HEADER_SUFFIX:= .hpp - COLUMN:= column # We may not have the right JAVA_HOME/PATH set up yet when this is run from envsetup.sh. diff --git a/core/definitions.mk b/core/definitions.mk index a6218cc45d..5fe126dc50 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -875,7 +875,7 @@ endef ## Commands for running lex ########################################################### -define transform-l-to-cpp +define transform-l-to-c-or-cpp @echo "Lex: $(PRIVATE_MODULE) <= $<" @mkdir -p $(dir $@) $(hide) $(LEX) -o$@ $< @@ -884,20 +884,14 @@ endef ########################################################### ## Commands for running yacc ## -## Because the extension of c++ files can change, the -## extension must be specified in $1. -## E.g, "$(call transform-y-to-cpp,.cpp)" ########################################################### -define transform-y-to-cpp +define transform-y-to-c-or-cpp @echo "Yacc: $(PRIVATE_MODULE) <= $<" @mkdir -p $(dir $@) -$(YACC) $(PRIVATE_YACCFLAGS) -o $@ $< -touch $(@:$1=$(YACC_HEADER_SUFFIX)) -echo '#ifndef '$(@F:$1=_h) > $(@:$1=.h) -echo '#define '$(@F:$1=_h) >> $(@:$1=.h) -cat $(@:$1=$(YACC_HEADER_SUFFIX)) >> $(@:$1=.h) -echo '#endif' >> $(@:$1=.h) +$(YACC) $(PRIVATE_YACCFLAGS) \ + --defines=$(basename $@).h \ + -o $@ $< endef ###########################################################