1# Auto-generate module defitions from platform.zip.
2# We use these rules to rebuild .odex files of the .jar/.apk inside the platform.zip.
3#
4
5ifdef PDK_FUSION_PLATFORM_ZIP
6pdk_dexpreopt_config_mk := $(TARGET_OUT_INTERMEDIATES)/pdk_dexpreopt_config.mk
7
8$(shell rm -f $(pdk_dexpreopt_config_mk) && mkdir -p $(dir $(pdk_dexpreopt_config_mk)) && \
9        unzip -qo $(PDK_FUSION_PLATFORM_ZIP) -d $(dir $(pdk_dexpreopt_config_mk)) pdk_dexpreopt_config.mk 2>/dev/null)
10endif
11
12ifdef PDK_FUSION_PLATFORM_DIR
13pdk_dexpreopt_config_mk := $(PDK_FUSION_PLATFORM_DIR)/pdk_dexpreopt_config.mk
14endif
15
16-include $(pdk_dexpreopt_config_mk)
17
18# Define a PDK prebuilt module that comes from platform.zip.
19# Must be called with $(eval)
20define prebuilt-pdk-java-module
21include $(CLEAR_VARS)
22LOCAL_MODULE:=$(1)
23LOCAL_MODULE_CLASS:=$(2)
24# Use LOCAL_PREBUILT_MODULE_FILE instead of LOCAL_SRC_FILES so we don't need to deal with LOCAL_PATH.
25LOCAL_PREBUILT_MODULE_FILE:=$(3)
26LOCAL_DEX_PREOPT:=$(4)
27LOCAL_MULTILIB:=$(5)
28LOCAL_DEX_PREOPT_FLAGS:=$(6)
29LOCAL_BUILT_MODULE_STEM:=$(7)
30LOCAL_MODULE_SUFFIX:=$(suffix $(7))
31LOCAL_PRIVILEGED_MODULE:=$(8)
32LOCAL_VENDOR_MODULE:=$(9)
33LOCAL_MODULE_TARGET_ARCH:=$(10)
34LOCAL_REPLACE_PREBUILT_APK_INSTALLED:=$(11)
35LOCAL_CERTIFICATE:=PRESIGNED
36include $(BUILD_PREBUILT)
37
38# The source prebuilts are extracted in the rule of _pdk_fusion_stamp.
39# Use a touch rule to establish the dependency.
40ifndef PDK_FUSION_PLATFORM_DIR
41$(3) $(11) : $(_pdk_fusion_stamp)
42	$(hide) if [ ! -f $$@ ]; then \
43	  echo 'Error: $$@ does not exist. Check your platform.zip.' 1>&2; \
44	  exit 1; \
45	fi
46	$(hide) touch $$@
47endif
48endef
49
50# We don't have a LOCAL_PATH for the auto-generated modules, so let it be the $(BUILD_SYSTEM).
51LOCAL_PATH := $(BUILD_SYSTEM)
52
53##### Java libraries.
54# Only set up rules for modules that aren't built from source.
55pdk_prebuilt_libraries := $(foreach l,$(PDK.DEXPREOPT.JAVA_LIBRARIES),\
56  $(if $(MODULE.TARGET.JAVA_LIBRARIES.$(l)),,$(l)))
57
58$(foreach l,$(pdk_prebuilt_libraries), $(eval \
59  $(call prebuilt-pdk-java-module,\
60    $(l),\
61    JAVA_LIBRARIES,\
62    $(_pdk_fusion_intermediates)/$(PDK.DEXPREOPT.$(l).SRC),\
63    $(PDK.DEXPREOPT.$(l).DEX_PREOPT),\
64    $(PDK.DEXPREOPT.$(l).MULTILIB),\
65    $(PDK.DEXPREOPT.$(l).DEX_PREOPT_FLAGS),\
66    javalib.jar,\
67    )))
68
69###### Apps.
70pdk_prebuilt_apps := $(foreach a,$(PDK.DEXPREOPT.APPS),\
71  $(if $(MODULE.TARGET.APPS.$(a)),,$(a)))
72
73$(foreach a,$(pdk_prebuilt_apps), $(eval \
74  $(call prebuilt-pdk-java-module,\
75    $(a),\
76    APPS,\
77    $(_pdk_fusion_intermediates)/$(PDK.DEXPREOPT.$(a).SRC),\
78    $(PDK.DEXPREOPT.$(a).DEX_PREOPT),\
79    $(PDK.DEXPREOPT.$(a).MULTILIB),\
80    $(PDK.DEXPREOPT.$(a).DEX_PREOPT_FLAGS),\
81    package.apk,\
82    $(PDK.DEXPREOPT.$(a).PRIVILEGED_MODULE),\
83    $(PDK.DEXPREOPT.$(a).VENDOR_MODULE),\
84    $(PDK.DEXPREOPT.$(a).TARGET_ARCH),\
85    $(_pdk_fusion_intermediates)/$(PDK.DEXPREOPT.$(a).STRIPPED_SRC),\
86    )))
87