Add support for LOCAL_MODULE_SYMLINKS
Specifying LOCAL_MODULE_SYMLINKS will create symlinks to the installed
module in the same directory.
Change-Id: Idecb2b75f0c9999eb000eed9a79a989244ccf6c2
diff --git a/core/base_rules.mk b/core/base_rules.mk
index a84ea27..8a1c5ee 100644
--- a/core/base_rules.mk
+++ b/core/base_rules.mk
@@ -323,6 +323,9 @@
## Module installation rule
###########################################################
+my_init_rc_installed :=
+my_init_rc_pairs :=
+my_installed_symlinks :=
ifndef LOCAL_UNINSTALLABLE_MODULE
$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := $(LOCAL_POST_INSTALL_CMD)
$(LOCAL_INSTALLED_MODULE): $(LOCAL_BUILT_MODULE)
@@ -331,8 +334,6 @@
$(PRIVATE_POST_INSTALL_CMD)
# Rule to install the module's companion init.rc.
-my_init_rc_installed :=
-my_init_rc_pairs :=
my_init_rc := $(LOCAL_INIT_RC_$(my_32_64_bit_suffix))
ifneq ($(my_init_rc),)
my_init_rc_pairs += $(LOCAL_PATH)/$(my_init_rc):$(TARGET_OUT$(partition_tag)_ETC)/init/$(notdir $(my_init_rc))
@@ -347,6 +348,12 @@
$(my_register_name) : $(my_init_rc_installed)
endif # my_init_rc_pairs
+
+# Rule to install the module's companion symlinks
+my_installed_symlinks := $(addprefix $(my_module_path)/,$(LOCAL_MODULE_SYMLINKS) $(LOCAL_MODULE_SYMLINKS_$(my_32_64_bit_suffix)))
+$(foreach symlink,$(my_installed_symlinks),\
+ $(call symlink-file,$(LOCAL_INSTALLED_MODULE),$(my_installed_module_stem),$(symlink)))
+
endif # !LOCAL_UNINSTALLABLE_MODULE
###########################################################
@@ -395,7 +402,7 @@
ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE))
ALL_MODULES.$(my_register_name).INSTALLED := \
$(strip $(ALL_MODULES.$(my_register_name).INSTALLED) \
- $(LOCAL_INSTALLED_MODULE) $(my_init_rc_installed))
+ $(LOCAL_INSTALLED_MODULE) $(my_init_rc_installed) $(my_installed_symlinks))
ALL_MODULES.$(my_register_name).BUILT_INSTALLED := \
$(strip $(ALL_MODULES.$(my_register_name).BUILT_INSTALLED) \
$(LOCAL_BUILT_MODULE):$(LOCAL_INSTALLED_MODULE) \
diff --git a/core/clear_vars.mk b/core/clear_vars.mk
index 7733a3e..31b337a 100644
--- a/core/clear_vars.mk
+++ b/core/clear_vars.mk
@@ -192,6 +192,7 @@
LOCAL_NOSANITIZE:=
LOCAL_DBUS_PROXY_PREFIX:=
LOCAL_INIT_RC:=
+LOCAL_MODULE_SYMLINKS:=
LOCAL_MODULE_HOST_OS:=
LOCAL_NOTICE_FILE:=
# Used to replace the installed file of a presigned prebuilt apk in PDK fusion build,
@@ -355,6 +356,8 @@
LOCAL_CLANG_64:=
LOCAL_INIT_RC_32:=
LOCAL_INIT_RC_64:=
+LOCAL_MODULE_SYMLINKS_32:=
+LOCAL_MODULE_SYMLINKS_64:=
LOCAL_JAVA_LANGUAGE_VERSION:=
LOCAL_CTS_GTEST_LIST_EXECUTABLE:=
diff --git a/core/definitions.mk b/core/definitions.mk
index 11caedf..a1df134 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -2605,6 +2605,24 @@
$(hide) mkdir -p $(dir $(3)/$(s)); cp -Rf $(t) $(3)/$(s)$(newline))
endef
+# Define a rule to create a symlink to a file.
+# $(1): full path to source
+# $(2): source (may be relative)
+# $(3): full path to destination
+define symlink-file
+$(eval $(_symlink-file))
+endef
+
+# Order-only dependency because make/ninja will follow the link when checking
+# the timestamp, so the file must exist
+define _symlink-file
+$(3): | $(1)
+ @echo "Symlink: $$@ -> $(2)"
+ @mkdir -p $(dir $$@)
+ @rm -rf $$@
+ $(hide) ln -sf $(2) $$@
+endef
+
###########################################################
## Commands to call Proguard
###########################################################
diff --git a/core/executable_prefer_symlink.mk b/core/executable_prefer_symlink.mk
index 1640b32..e59e8c2 100644
--- a/core/executable_prefer_symlink.mk
+++ b/core/executable_prefer_symlink.mk
@@ -10,43 +10,37 @@
# et al. since those variables make no sense in that context.
ifneq ($(LOCAL_IS_HOST_MODULE),true)
my_symlink := $(addprefix $(TARGET_OUT)/bin/, $(LOCAL_MODULE))
+ my_src_binary_name :=
ifeq ($(TARGET_IS_64_BIT),true)
ifeq ($(TARGET_SUPPORTS_64_BIT_APPS)|$(TARGET_SUPPORTS_32_BIT_APPS),true|true)
# We support both 32 and 64 bit apps, so we will have to
# base our decision on whether the target prefers one or the
# other.
ifeq ($(TARGET_PREFER_32_BIT_APPS),true)
- $(my_symlink): PRIVATE_SRC_BINARY_NAME := $(LOCAL_MODULE_STEM_32)
+ my_src_binary_name := $(LOCAL_MODULE_STEM_32)
else
- $(my_symlink): PRIVATE_SRC_BINARY_NAME := $(LOCAL_MODULE_STEM_64)
+ my_src_binary_name := $(LOCAL_MODULE_STEM_64)
endif
else ifeq ($(TARGET_SUPPORTS_64_BIT_APPS),true)
# We support only 64 bit apps.
- $(my_symlink): PRIVATE_SRC_BINARY_NAME := $(LOCAL_MODULE_STEM_64)
+ my_src_binary_name := $(LOCAL_MODULE_STEM_64)
else
# We support only 32 bit apps.
- $(my_symlink): PRIVATE_SRC_BINARY_NAME := $(LOCAL_MODULE_STEM_32)
+ my_src_binary_name := $(LOCAL_MODULE_STEM_32)
endif
else
- $(my_symlink): PRIVATE_SRC_BINARY_NAME := $(LOCAL_MODULE_STEM_32)
+ my_src_binary_name := $(LOCAL_MODULE_STEM_32)
endif
else
my_symlink := $(addprefix $(HOST_OUT)/bin/, $(LOCAL_MODULE))
ifneq ($(HOST_PREFER_32_BIT),true)
-$(my_symlink): PRIVATE_SRC_BINARY_NAME := $(LOCAL_MODULE_STEM_64)
+ my_src_binary_name := $(LOCAL_MODULE_STEM_64)
else
-$(my_symlink): PRIVATE_SRC_BINARY_NAME := $(LOCAL_MODULE_STEM_32)
+ my_src_binary_name := $(LOCAL_MODULE_STEM_32)
endif
endif
-# $(my_symlink) doesn't need to depend on $(PRIVATE_SRC_BINARY_NAME): we can generate symlink to nonexistent file.
-# If you add the dependency, make would compare the timestamp of a file against that of its symlink:
-# they are always equal, because make follows symlink.
-$(my_symlink):
- @echo "Symlink: $@ -> $(PRIVATE_SRC_BINARY_NAME)"
- @mkdir -p $(dir $@)
- @rm -rf $@
- $(hide) ln -sf $(PRIVATE_SRC_BINARY_NAME) $@
+$(call symlink-file,$(my_module_path)/$(my_src_binary_name),$(my_src_binary_name),$(my_symlink))
# We need this so that the installed files could be picked up based on the
# local module name