1 #################################### 2 # dexpreopt support for Dalvik 3 # 4 #################################### 5 6 DEXOPT := $(HOST_OUT_EXECUTABLES)/dexopt$(HOST_EXECUTABLE_SUFFIX) 7 DEXPREOPT := dalvik/tools/dex-preopt 8 9 DEXPREOPT_DEXOPT := $(patsubst $(DEXPREOPT_BUILD_DIR)/%,%,$(DEXOPT)) 10 11 DEXPREOPT_BOOT_ODEXS := $(foreach b,$(DEXPREOPT_BOOT_JARS_MODULES),\ 12 $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/$(b).odex) 13 14 # If the target is a uniprocessor, then explicitly tell the preoptimizer 15 # that fact. (By default, it always optimizes for an SMP target.) 16 ifeq ($(TARGET_CPU_SMP),true) 17 DEXPREOPT_UNIPROCESSOR := 18 else 19 DEXPREOPT_UNIPROCESSOR := --uniprocessor 20 endif 21 22 # By default, do not run rerun dexopt if the tool changes. 23 # Comment out the | to force dex2oat to rerun on after all changes. 24 DEXOPT_DEPENDENCY := | 25 DEXOPT_DEPENDENCY += $(DEXPREOPT) $(DEXOPT) 26 27 # $(1): the input .jar or .apk file 28 # $(2): the output .odex file 29 define dexopt-one-file 30 $(hide) rm -f $(2) 31 $(hide) mkdir -p $(dir $(2)) 32 $(hide) $(DEXPREOPT) \ 33 --dexopt=$(DEXPREOPT_DEXOPT) \ 34 --build-dir=$(DEXPREOPT_BUILD_DIR) \ 35 --product-dir=$(DEXPREOPT_PRODUCT_DIR) \ 36 --boot-dir=$(DEXPREOPT_BOOT_JAR_DIR) \ 37 --boot-jars=$(DEXPREOPT_BOOT_JARS) \ 38 $(DEXPREOPT_UNIPROCESSOR) \ 39 $(patsubst $(DEXPREOPT_BUILD_DIR)/%,%,$(1)) \ 40 $(patsubst $(DEXPREOPT_BUILD_DIR)/%,%,$(2)) 41 endef 42 43 # Special rules for building odex files for boot jars that override java_library.mk rules 44 45 # $(1): boot jar module name 46 define _dexpreopt-boot-odex 47 _dbj_jar := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/$(1).jar 48 _dbj_odex := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/$(1).odex 49 _dbj_src_jar := $(call intermediates-dir-for,JAVA_LIBRARIES,$(1),,COMMON)/javalib.jar 50 $$(_dbj_odex): PRIVATE_DBJ_JAR := $$(_dbj_jar) 51 $$(_dbj_odex) : $$(_dbj_src_jar) | $(ACP) $(DEXPREOPT) $(DEXOPT) 52 @echo "Dexpreopt Boot Jar: $$@" 53 $(hide) mkdir -p $$(dir $$(PRIVATE_DBJ_JAR)) && $(ACP) -fp $$< $$(PRIVATE_DBJ_JAR) 54 $$(call dexopt-one-file,$$(PRIVATE_DBJ_JAR),$$@) 55 56 _dbj_jar := 57 _dbj_odex := 58 _dbj_src_jar := 59 endef 60 61 $(foreach b,$(DEXPREOPT_BOOT_JARS_MODULES),$(eval $(call _dexpreopt-boot-odex,$(b)))) 62 63 # $(1): the rest list of boot jars 64 define _build-dexpreopt-boot-jar-dependency-pair 65 $(if $(filter 1,$(words $(1)))$(filter 0,$(words $(1))),,\ 66 $(eval _bdbjdp_target := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/$(word 2,$(1)).odex) \ 67 $(eval _bdbjdp_dep := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/$(word 1,$(1)).odex) \ 68 $(eval $(call add-dependency,$(_bdbjdp_target),$(_bdbjdp_dep))) \ 69 $(eval $(call _build-dexpreopt-boot-jar-dependency-pair,$(wordlist 2,999,$(1))))) 70 endef 71 72 define _build-dexpreopt-boot-jar-dependency 73 $(call _build-dexpreopt-boot-jar-dependency-pair,$(DEXPREOPT_BOOT_JARS_MODULES)) 74 endef 75 76 $(eval $(call _build-dexpreopt-boot-jar-dependency)) 77