From 639c336dc15c49daa27c118d10cef586ffa2633a Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Fri, 24 Jan 2014 19:23:40 -0800 Subject: [PATCH 1/3] Support LOCAL_MODULE_RELATIVE_PATH Most users of LOCAL_MODULE_PATH are setting a subdirectory of the normal install path, for example to install HALs into system/lib/hw. This is problematic for multiarch builds, where the install location depends on the arch. Allow modules to specify LOCAL_MODULE_RELATIVE_PATH. HALs will generally use: LOCAL_MODULE_RELATIVE_PATH := hw Change-Id: I4e4ceec61d026bbe74ba604554c06104bde42e5e --- core/base_rules.mk | 4 ++++ core/build-system.html | 32 +++++++++++++++++++++++++------- core/clear_vars.mk | 1 + 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/core/base_rules.mk b/core/base_rules.mk index 29c6c7fe94..ac126a7cf4 100644 --- a/core/base_rules.mk +++ b/core/base_rules.mk @@ -99,6 +99,7 @@ endif ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE)) my_module_path := $(strip $(LOCAL_MODULE_PATH)) +my_module_relative_path := $(strip $(LOCAL_MODULE_RELATIVE_PATH)) ifeq ($(my_module_path),) ifdef LOCAL_IS_HOST_MODULE partition_tag := @@ -121,6 +122,9 @@ ifeq ($(my_module_path),) $(error $(LOCAL_PATH): unhandled install path "$(install_path_var) for $(LOCAL_MODULE)") endif endif +ifneq ($(my_module_relative_path),) + my_module_path := $(my_module_path)/$(my_module_relative_path) +endif endif # not LOCAL_UNINSTALLABLE_MODULE ifneq ($(strip $(LOCAL_BUILT_MODULE)$(LOCAL_INSTALLED_MODULE)),) diff --git a/core/build-system.html b/core/build-system.html index 397eef4c01..182580c95b 100644 --- a/core/build-system.html +++ b/core/build-system.html @@ -383,7 +383,7 @@ the rest of them easier to read, and you can always refer back to the templates if you need them again later.

By default, on the target these are built into /system/bin, and on the host, they're built into /host/bin. These can be overridden by setting -LOCAL_MODULE_PATH. See +LOCAL_MODULE_PATH or LOCAL_MODULE_RELATIVE_PATH. See Putting targets elsewhere for more.

@@ -533,16 +533,27 @@ endif

Putting modules elsewhere

If you have modules that normally go somewhere, and you need to have them -build somewhere else, read this. One use of this is putting files on -the root filesystem instead of where they normally go in /system. Add these -lines to your Android.mk:

+build somewhere else, read this.

+

If you have modules that need to go in a subdirectory of their normal +location, for example HAL modules that need to go in /system/lib/hw or +/vendor/lib/hw, set LOCAL_MODULE_RELATIVE_PATH in your Android.mk, for +example:

+
+LOCAL_MODULE_RELATIVE_PATH := hw
+
+

If you have modules that need to go in an entirely different location, for +example the root filesystem instead of in /system, add these lines to your +Android.mk:

 LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT_SBIN)
 LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_SBIN_UNSTRIPPED)
 
-

For executables and libraries, you need to also specify a -LOCAL_UNSTRIPPED_PATH location, because on target builds, we keep -the unstripped executables so GDB can find the symbols. +

For executables and libraries, you need to specify a +LOCAL_UNSTRIPPED_PATH location if you specified a +LOCAL_MODULE_PATH, because on target builds, we keep +the unstripped executables so GDB can find the symbols. +LOCAL_UNSTRIPPED_PATH is not necessary if you only specified +LOCAL_MODULE_RELATIVE_PATH.

Look in config/envsetup.make for all of the variables defining places to build things.

FYI: If you're installing an executable to /sbin, you probably also want to @@ -818,6 +829,13 @@ so the unstripped binary has somewhere to go. An error will occur if you forget to.

See Putting modules elsewhere for more.

+

LOCAL_MODULE_RELATIVE_PATH

+

Instructs the build system to put the module in a subdirectory under the +directory that is normal for its type. If you set this you do not need to +set LOCAL_UNSTRIPPED_PATH, the unstripped binaries will also use +the relative path.

+

See Putting modules elsewhere for more.

+

LOCAL_UNSTRIPPED_PATH

Instructs the build system to put the unstripped version of the module somewhere other than what's normal for its type. Usually, you override this diff --git a/core/clear_vars.mk b/core/clear_vars.mk index 56e17b0a3b..8863fe6b88 100644 --- a/core/clear_vars.mk +++ b/core/clear_vars.mk @@ -4,6 +4,7 @@ LOCAL_MODULE:= LOCAL_MODULE_PATH:= +LOCAL_MODULE_RELATIVE_PATH := LOCAL_MODULE_STEM:= LOCAL_DONT_CHECK_MODULE:= LOCAL_CHECKED_MODULE:= From d0378b3f2dbb5a5ff0cf0517354606f3f808d790 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Fri, 24 Jan 2014 19:30:27 -0800 Subject: [PATCH 2/3] warn on LOCAL_MODULE_PATH in multiarch shared libraries Using LOCAL_MODULE_PATH in a shared library module while building a multiarch target will cause build rules for both architectures to install into the same path. Warn and suggest LOCAL_MODULE_RELATIVE_PATH. Change-Id: I16208ccada6d43a26a342af35096f49d8df26e81 --- core/shared_library.mk | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/shared_library.mk b/core/shared_library.mk index b3e319fff4..9a75a7b21e 100644 --- a/core/shared_library.mk +++ b/core/shared_library.mk @@ -1,3 +1,15 @@ +ifneq ($(LOCAL_MODULE_PATH),) +ifneq ($(TARGET_2ND_ARCH),) +$(warning $(LOCAL_MODULE): LOCAL_MODULE_PATH for shared libraries is unsupported in multiarch builds, use LOCAL_MODULE_RELATIVE_PATH instead) +endif +endif + +ifneq ($(LOCAL_UNSTRIPPED_PATH),) +ifneq ($(TARGET_2ND_ARCH),) +$(warning $(LOCAL_MODULE): LOCAL_UNSTRIPPED_PATH for shared libraries is unsupported in multiarch builds) +endif +endif + ifneq ($(TARGET_IS_64_BIT)|$(LOCAL_32BIT_ONLY),true|true) # Build for TARGET_ARCH LOCAL_2ND_ARCH_VAR_PREFIX := From d826264621a2c3d27228b395bc36edf5510bcc49 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Fri, 24 Jan 2014 23:17:21 -0800 Subject: [PATCH 3/3] add new gen/ directory for generated sources Allow modules to generate source into $OUT/gen, which will then be copied into $OUT/obj and $OUT/obj_$(TARGET_2ND_ARCH) as necessary. This allows a single build rule invocation that includes generated source to build for the first and second architectures. Modules will need to change calls to local-intermediates-dir into local-generated-sources-dir. Change-Id: I62504bad9454b3d9fde7b84ab9f0a487a2ecf0bf --- core/base_rules.mk | 1 + core/binary.mk | 9 ++++++++- core/build-system.html | 10 +++++----- core/definitions.mk | 45 ++++++++++++++++++++++++++++++++++++++++++ core/envsetup.mk | 6 ++++++ 5 files changed, 65 insertions(+), 6 deletions(-) diff --git a/core/base_rules.mk b/core/base_rules.mk index ac126a7cf4..63abb8dfcd 100644 --- a/core/base_rules.mk +++ b/core/base_rules.mk @@ -145,6 +145,7 @@ $(module_id) := $(LOCAL_PATH) intermediates := $(call local-intermediates-dir,,$(LOCAL_2ND_ARCH_VAR_PREFIX)) intermediates.COMMON := $(call local-intermediates-dir,COMMON) +generated_sources_dir := $(call local-generated-sources-dir) ########################################################### # Pick a name for the intermediate and final targets diff --git a/core/binary.mk b/core/binary.mk index 4dad51ae8f..3556b99c42 100644 --- a/core/binary.mk +++ b/core/binary.mk @@ -377,8 +377,15 @@ endif ########################################################### $(my_generated_sources): PRIVATE_MODULE := $(my_register_name) -ALL_GENERATED_SOURCES += $(my_generated_sources) +my_gen_sources_copy := $(patsubst $(generated_sources_dir)/%,$(intermediates)/%,$(filter $(generated_sources_dir)/%,$(my_generated_sources))) +$(my_gen_sources_copy): $(intermediates)/% : $(generated_sources_dir)/% | $(ACP) + @echo "Copy: $@" + $(copy-file-to-target) + +my_generated_sources := $(patsubst $(generated_sources_dir)/%,$(intermediates)/%,$(my_generated_sources)) + +ALL_GENERATED_SOURCES += $(my_generated_sources) ########################################################### ## Compile the .proto files to .cc and then to .o diff --git a/core/build-system.html b/core/build-system.html index 182580c95b..caade583b7 100644 --- a/core/build-system.html +++ b/core/build-system.html @@ -409,8 +409,8 @@ a couple of examples. $@ is the make built-in variable for need to change.

You need to put this after you have declared LOCAL_PATH and -LOCAL_MODULE, because the $(local-intermediates-dir) -and $(local-host-intermediates-dir) macros use these variables +LOCAL_MODULE, because the $(local-generated-sources-dir) +and $(local-host-generated-sources-dir) macros use these variables to determine where to put the files.

Example 1
@@ -419,7 +419,7 @@ chartables.c, which doesn't depend on anything. And is built by the tool built to $(HOST_OUT_EXECUTABLES)/dftables. Note on the second to last line that a dependency is created on the tool.

-intermediates:= $(local-intermediates-dir)
+intermediates:= $(local-generated-sources-dir)
 GEN := $(intermediates)/chartables.c
 $(GEN): PRIVATE_CUSTOM_TOOL = $(HOST_OUT_EXECUTABLES)/dftables $@
 $(GEN): $(HOST_OUT_EXECUTABLES)/dftables
@@ -433,7 +433,7 @@ a file.  Pretend that it does something useful.  Note how we use a
 target-specific variable called PRIVATE_INPUT_FILE to store the name of the
 input file.

-intermediates:= $(local-intermediates-dir)
+intermediates:= $(local-generated-sources-dir)
 GEN := $(intermediates)/file.c
 $(GEN): PRIVATE_INPUT_FILE := $(LOCAL_PATH)/input.file
 $(GEN): PRIVATE_CUSTOM_TOOL = cat $(PRIVATE_INPUT_FILE) > $@
@@ -447,7 +447,7 @@ LOCAL_GENERATED_SOURCES += $(GEN)
 name, and use the same tool, you can combine them.  (here the *.lut.h files are
 the generated ones, and the *.cpp files are the input files)

-intermediates:= $(local-intermediates-dir)
+intermediates:= $(local-generated-sources-dir)
 GEN := $(addprefix $(intermediates)/kjs/, \
             array_object.lut.h \
             bool_object.lut.h \
diff --git a/core/definitions.mk b/core/definitions.mk
index eb462a37da..7c29e307eb 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -461,6 +461,51 @@ $(strip \
 )
 endef
 
+###########################################################
+## The generated sources directory.  Placing generated
+## source files directly in the intermediates directory
+## causes problems for multiarch builds, where there are
+## two intermediates directories for a single target. Put
+## them in a separate directory, and they will be copied to
+## each intermediates directory automatically.
+###########################################################
+
+# $(1): target class, like "APPS"
+# $(2): target name, like "NotePad"
+# $(3): if non-empty, this is a HOST target.
+# $(4): if non-empty, force the generated sources to be COMMON
+define generated-sources-dir-for
+$(strip \
+    $(eval _idfClass := $(strip $(1))) \
+    $(if $(_idfClass),, \
+        $(error $(LOCAL_PATH): Class not defined in call to generated-sources-dir-for)) \
+    $(eval _idfName := $(strip $(2))) \
+    $(if $(_idfName),, \
+        $(error $(LOCAL_PATH): Name not defined in call to generated-sources-dir-for)) \
+    $(eval _idfPrefix := $(if $(strip $(3)),HOST,TARGET)) \
+    $(if $(filter $(_idfPrefix)-$(_idfClass),$(COMMON_MODULE_CLASSES))$(4), \
+        $(eval _idfIntBase := $($(_idfPrefix)_OUT_GEN_COMMON)) \
+      , \
+        $(eval _idfIntBase := $($(_idfPrefix)_OUT_GEN)) \
+     ) \
+    $(_idfIntBase)/$(_idfClass)/$(_idfName)_intermediates \
+)
+endef
+
+# Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE
+# to determine the generated sources directory.
+#
+# $(1): if non-empty, force the intermediates to be COMMON
+define local-generated-sources-dir
+$(strip \
+    $(if $(strip $(LOCAL_MODULE_CLASS)),, \
+        $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-generated-sources-dir)) \
+    $(if $(strip $(LOCAL_MODULE)),, \
+        $(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-generated-sources-dir)) \
+    $(call generated-sources-dir-for,$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE),$(LOCAL_IS_HOST_MODULE),$(1)) \
+)
+endef
+
 ###########################################################
 ## Convert "path/to/libXXX.so" to "-lXXX".
 ## Any "path/to/libXXX.a" elements pass through unchanged.
diff --git a/core/envsetup.mk b/core/envsetup.mk
index a348eb7dd6..4cb389bf4e 100644
--- a/core/envsetup.mk
+++ b/core/envsetup.mk
@@ -208,11 +208,17 @@ HOST_OUT_INTERMEDIATE_LIBRARIES := $(HOST_OUT_INTERMEDIATES)/lib
 HOST_OUT_NOTICE_FILES := $(HOST_OUT_INTERMEDIATES)/NOTICE_FILES
 HOST_OUT_COMMON_INTERMEDIATES := $(HOST_COMMON_OUT_ROOT)/obj
 
+HOST_OUT_GEN := $(HOST_OUT)/gen
+HOST_OUT_COMMON_GEN := $(HOST_COMMON_OUT_ROOT)/gen
+
 TARGET_OUT_INTERMEDIATES := $(PRODUCT_OUT)/obj
 TARGET_OUT_HEADERS := $(TARGET_OUT_INTERMEDIATES)/include
 TARGET_OUT_INTERMEDIATE_LIBRARIES := $(TARGET_OUT_INTERMEDIATES)/lib
 TARGET_OUT_COMMON_INTERMEDIATES := $(TARGET_COMMON_OUT_ROOT)/obj
 
+TARGET_OUT_GEN := $(PRODUCT_OUT)/gen
+TARGET_OUT_COMMON_GEN := $(TARGET_COMMON_OUT_ROOT)/gen
+
 TARGET_OUT := $(PRODUCT_OUT)/$(TARGET_COPY_OUT_SYSTEM)
 TARGET_OUT_EXECUTABLES := $(TARGET_OUT)/bin
 TARGET_OUT_OPTIONAL_EXECUTABLES := $(TARGET_OUT)/xbin