1####################################
2# ART boot image installation
3# Input variables:
4#   my_boot_image_name: the boot image to install
5#   my_boot_image_arch: the architecture to install (e.g. TARGET_ARCH, not expanded)
6#   my_boot_image_out:  the install directory (e.g. $(PRODUCT_OUT))
7#   my_boot_image_syms: the symbols director (e.g. $(TARGET_OUT_UNSTRIPPED))
8#
9# Output variables:
10#   my_boot_image_module: the created module name. Empty if no module is created.
11#
12# Install the boot images compiled by Soong.
13# Create a module named dexpreopt_bootjar.$(my_boot_image_name)_$($(my_boot_image_arch))
14# that installs all of boot image files.
15# If there is no file to install for $(my_boot_image_name), for example when
16# building an unbundled build, then no module is created.
17#
18####################################
19
20# Takes a list of src:dest install pairs and returns a new list with a path
21# prefixed to each dest value.
22# $(1): list of src:dest install pairs
23# $(2): path to prefix to each dest value
24define prefix-copy-many-files-dest
25$(foreach v,$(1),$(call word-colon,1,$(v)):$(2)$(call word-colon,2,$(v)))
26endef
27
28# Converts an architecture-specific vdex path into a location that can be shared
29# between architectures.
30define vdex-shared-install-path
31$(dir $(patsubst %/,%,$(dir $(1))))$(notdir $(1))
32endef
33
34# Takes a list of src:dest install pairs of vdex files and returns a new list
35# where each dest has been rewritten to the shared location for vdex files.
36define vdex-copy-many-files-shared-dest
37$(foreach v,$(1),$(call word-colon,1,$(v)):$(call vdex-shared-install-path,$(call word-colon,2,$(v))))
38endef
39
40# Creates a rule to symlink an architecture specific vdex file to the shared
41# location for that vdex file.
42define symlink-vdex-file
43$(strip \
44  $(call symlink-file,\
45    $(call vdex-shared-install-path,$(1)),\
46    ../$(notdir $(1)),\
47    $(1))\
48  $(1))
49endef
50
51# Takes a list of src:dest install pairs of vdex files and creates rules to
52# symlink each dest to the shared location for that vdex file.
53define symlink-vdex-files
54$(foreach v,$(1),$(call symlink-vdex-file,$(call word-colon,2,$(v))))
55endef
56
57my_boot_image_module :=
58
59my_suffix := $(my_boot_image_name)_$($(my_boot_image_arch))
60my_copy_pairs := $(call prefix-copy-many-files-dest,$(DEXPREOPT_IMAGE_BUILT_INSTALLED_$(my_suffix)),$(my_boot_image_out))
61my_vdex_copy_pairs := $(call prefix-copy-many-files-dest,$(DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_$(my_suffix)),$(my_boot_image_out))
62my_vdex_copy_shared_pairs := $(call vdex-copy-many-files-shared-dest,$(my_vdex_copy_pairs))
63ifeq (,$(filter %_2ND_ARCH,$(my_boot_image_arch)))
64  # Only install the vdex to the shared location for the primary architecture.
65  my_copy_pairs += $(my_vdex_copy_shared_pairs)
66endif
67
68my_unstripped_copy_pairs := $(call prefix-copy-many-files-dest,$(DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_$(my_suffix)),$(my_boot_image_syms))
69
70# Generate the boot image module only if there is any file to install.
71ifneq (,$(strip $(my_copy_pairs)))
72  my_first_pair := $(firstword $(my_copy_pairs))
73  my_rest_pairs := $(wordlist 2,$(words $(my_copy_pairs)),$(my_copy_pairs))
74
75  my_first_src := $(call word-colon,1,$(my_first_pair))
76  my_first_dest := $(call word-colon,2,$(my_first_pair))
77
78  my_installed := $(call copy-many-files,$(my_copy_pairs))
79  my_unstripped_installed := $(call copy-many-files,$(my_unstripped_copy_pairs))
80
81  my_symlinks := $(call symlink-vdex-files,$(my_vdex_copy_pairs))
82
83  # We don't have a LOCAL_PATH for the auto-generated modules, so let it be the $(BUILD_SYSTEM).
84  LOCAL_PATH := $(BUILD_SYSTEM)
85  # Hack to let these pseudo-modules wrapped around Soong modules use LOCAL_SOONG_INSTALLED_MODULE.
86  LOCAL_MODULE_MAKEFILE := $(SOONG_ANDROID_MK)
87
88  include $(CLEAR_VARS)
89  LOCAL_MODULE := dexpreopt_bootjar.$(my_suffix)
90  LOCAL_PREBUILT_MODULE_FILE := $(my_first_src)
91  LOCAL_MODULE_PATH := $(dir $(my_first_dest))
92  LOCAL_MODULE_STEM := $(notdir $(my_first_dest))
93  LOCAL_SOONG_INSTALL_PAIRS := $(my_copy_pairs)
94  LOCAL_SOONG_INSTALL_SYMLINKS := $(my_symlinks)
95  LOCAL_SOONG_INSTALLED_MODULE := $(my_first_dest)
96  LOCAL_SOONG_LICENSE_METADATA := $(DEXPREOPT_IMAGE_LICENSE_METADATA_$(my_suffix))
97  ifneq (,$(strip $(filter HOST_%,$(my_boot_image_arch))))
98    LOCAL_IS_HOST_MODULE := true
99  endif
100  LOCAL_MODULE_CLASS := ETC
101  include $(BUILD_PREBUILT)
102  $(LOCAL_BUILT_MODULE): | $(my_unstripped_installed)
103  # Installing boot.art causes all boot image bits to be installed.
104  # Keep this old behavior in case anyone still needs it.
105  $(LOCAL_INSTALLED_MODULE): $(wordlist 2,$(words $(my_installed)),$(my_installed)) $(my_symlinks)
106  $(my_all_targets): $(my_installed) $(my_symlinks)
107
108  my_boot_image_module := $(LOCAL_MODULE)
109endif  # my_copy_pairs != empty
110