Merge "ota_from_target_files: Add an option to not sign OTA packages"
diff --git a/core/base_rules.mk b/core/base_rules.mk
index 29c6c7f..e87624a 100644
--- a/core/base_rules.mk
+++ b/core/base_rules.mk
@@ -41,6 +41,8 @@
   my_host :=
 endif
 
+my_module_tags := $(LOCAL_MODULE_TAGS)
+
 ###########################################################
 ## Validate and define fallbacks for input LOCAL_* variables.
 ###########################################################
@@ -50,17 +52,17 @@
 #$(shell rm -f tag-list.csv)
 #tag-list-first-time := false
 #endif
-#$(shell echo $(lastword $(filter-out config/% out/%,$(MAKEFILE_LIST))),$(LOCAL_MODULE),$(strip $(LOCAL_MODULE_CLASS)),$(subst $(space),$(comma),$(sort $(LOCAL_MODULE_TAGS))) >> tag-list.csv)
+#$(shell echo $(lastword $(filter-out config/% out/%,$(MAKEFILE_LIST))),$(LOCAL_MODULE),$(strip $(LOCAL_MODULE_CLASS)),$(subst $(space),$(comma),$(sort $(my_module_tags))) >> tag-list.csv)
 
 LOCAL_UNINSTALLABLE_MODULE := $(strip $(LOCAL_UNINSTALLABLE_MODULE))
-LOCAL_MODULE_TAGS := $(sort $(LOCAL_MODULE_TAGS))
-ifeq (,$(LOCAL_MODULE_TAGS))
-  LOCAL_MODULE_TAGS := optional
+my_module_tags := $(sort $(my_module_tags))
+ifeq (,$(my_module_tags))
+  my_module_tags := optional
 endif
 
 # User tags are not allowed anymore.  Fail early because it will not be installed
 # like it used to be.
-ifneq ($(filter $(LOCAL_MODULE_TAGS),user),)
+ifneq ($(filter $(my_module_tags),user),)
   $(warning *** Module name: $(LOCAL_MODULE))
   $(warning *** Makefile location: $(LOCAL_MODULE_MAKEFILE))
   $(warning * )
@@ -75,8 +77,8 @@
 # Only the tags mentioned in this test are expected to be set by module
 # makefiles. Anything else is either a typo or a source of unexpected
 # behaviors.
-ifneq ($(filter-out debug eng tests optional samples,$(LOCAL_MODULE_TAGS)),)
-$(warning unusual tags $(LOCAL_MODULE_TAGS) on $(LOCAL_MODULE) at $(LOCAL_PATH))
+ifneq ($(filter-out debug eng tests optional samples,$(my_module_tags)),)
+$(warning unusual tags $(my_module_tags) on $(LOCAL_MODULE) at $(LOCAL_PATH))
 endif
 
 # Add implicit tags.
@@ -88,7 +90,7 @@
 #
 gpl_license_file := $(call find-parent-file,$(LOCAL_PATH),MODULE_LICENSE*_GPL* MODULE_LICENSE*_MPL*)
 ifneq ($(gpl_license_file),)
-  LOCAL_MODULE_TAGS += gnu
+  my_module_tags += gnu
   ALL_GPL_MODULE_LICENSE_FILES := $(sort $(ALL_GPL_MODULE_LICENSE_FILES) $(gpl_license_file))
 endif
 
@@ -99,6 +101,7 @@
 
 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 :=
@@ -108,7 +111,7 @@
   else
     # The definition of should-install-to-system will be different depending
     # on which goal (e.g., sdk or just droid) is being built.
-    partition_tag := $(if $(call should-install-to-system,$(LOCAL_MODULE_TAGS)),,_DATA)
+    partition_tag := $(if $(call should-install-to-system,$(my_module_tags)),,_DATA)
   endif
   endif
   install_path_var := $(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT$(partition_tag)_$(LOCAL_MODULE_CLASS)
@@ -121,6 +124,9 @@
     $(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)),)
@@ -141,6 +147,7 @@
 
 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
@@ -580,7 +587,7 @@
 ALL_MODULES.$(my_register_name).PATH := \
     $(ALL_MODULES.$(my_register_name).PATH) $(LOCAL_PATH)
 ALL_MODULES.$(my_register_name).TAGS := \
-    $(ALL_MODULES.$(my_register_name).TAGS) $(LOCAL_MODULE_TAGS)
+    $(ALL_MODULES.$(my_register_name).TAGS) $(my_module_tags)
 ALL_MODULES.$(my_register_name).CHECKED := \
     $(ALL_MODULES.$(my_register_name).CHECKED) $(LOCAL_CHECKED_MODULE)
 ALL_MODULES.$(my_register_name).BUILT := \
@@ -603,22 +610,22 @@
 INSTALLABLE_FILES.$(LOCAL_INSTALLED_MODULE).MODULE := $(my_register_name)
 
 ###########################################################
-## Take care of LOCAL_MODULE_TAGS
+## Take care of my_module_tags
 ###########################################################
 
 # Keep track of all the tags we've seen.
-ALL_MODULE_TAGS := $(sort $(ALL_MODULE_TAGS) $(LOCAL_MODULE_TAGS))
+ALL_MODULE_TAGS := $(sort $(ALL_MODULE_TAGS) $(my_module_tags))
 
 # Add this module to the tag list of each specified tag.
 # Don't use "+=". If the variable hasn't been set with ":=",
 # it will default to recursive expansion.
-$(foreach tag,$(LOCAL_MODULE_TAGS),\
+$(foreach tag,$(my_module_tags),\
     $(eval ALL_MODULE_TAGS.$(tag) := \
         $(ALL_MODULE_TAGS.$(tag)) \
         $(LOCAL_INSTALLED_MODULE)))
 
 # Add this module name to the tag list of each specified tag.
-$(foreach tag,$(LOCAL_MODULE_TAGS),\
+$(foreach tag,$(my_module_tags),\
     $(eval ALL_MODULE_NAME_TAGS.$(tag) += $(my_register_name)))
 
 ###########################################################
@@ -640,7 +647,7 @@
 
 ifdef j_or_n
 $(j_or_n) $(h_or_t) $(j_or_n)-$(h_or_t) : $(LOCAL_CHECKED_MODULE)
-ifneq (,$(filter $(LOCAL_MODULE_TAGS),tests))
+ifneq (,$(filter $(my_module_tags),tests))
 $(j_or_n)-$(h_or_t)-tests $(j_or_n)-tests $(h_or_t)-tests : $(LOCAL_CHECKED_MODULE)
 endif
 endif
diff --git a/core/binary.mk b/core/binary.mk
index 3582ba0..3556b99 100644
--- a/core/binary.mk
+++ b/core/binary.mk
@@ -94,7 +94,7 @@
 my_asflags := $(LOCAL_ASFLAGS) $(LOCAL_ASFLAGS_$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH))
 my_cc := $(LOCAL_CC)
 my_cxx := $(LOCAL_CXX)
-my_c_includes := $(LOCAL_C_INCLUDES)
+my_c_includes := $(LOCAL_C_INCLUDES) $(LOCAL_C_INCLUDES_$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH))
 my_generated_sources := $(LOCAL_GENERATED_SOURCES)
 
 
@@ -377,8 +377,15 @@
 ###########################################################
 $(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 397eef4..caade58 100644
--- a/core/build-system.html
+++ b/core/build-system.html
@@ -383,7 +383,7 @@
 if you need them again later.</p>
 <p>By default, on the target these are built into /system/bin, and on the
 host, they're built into <combo>/host/bin.  These can be overridden by setting
-<code>LOCAL_MODULE_PATH</code>.  See
+<code>LOCAL_MODULE_PATH</code> or <code>LOCAL_MODULE_RELATIVE_PATH</code>.  See
 <a href="#moving-targets">Putting targets elsewhere</a>
 for more.</p>
 
@@ -409,8 +409,8 @@
 need to change.</p>
 
 <p>You need to put this after you have declared <code>LOCAL_PATH</code> and
-<code>LOCAL_MODULE</code>, because the <code>$(local-intermediates-dir)</code>
-and <code>$(local-host-intermediates-dir)</code> macros use these variables
+<code>LOCAL_MODULE</code>, because the <code>$(local-generated-sources-dir)</code>
+and <code>$(local-host-generated-sources-dir)</code> macros use these variables
 to determine where to put the files.
 
 <h5>Example 1</h5>
@@ -419,7 +419,7 @@
 built to $(HOST_OUT_EXECUTABLES)/dftables.  Note on the second to last line
 that a dependency is created on the tool.</p>
 <pre>
-intermediates:= $(local-intermediates-dir)
+intermediates:= $(local-generated-sources-dir)
 GEN := $(intermediates)/<font color=red>chartables.c</font>
 $(GEN): PRIVATE_CUSTOM_TOOL = <font color=red>$(HOST_OUT_EXECUTABLES)/dftables $@</font>
 $(GEN): <font color=red>$(HOST_OUT_EXECUTABLES)/dftables</font>
@@ -433,7 +433,7 @@
 target-specific variable called PRIVATE_INPUT_FILE to store the name of the
 input file.</p>
 <pre>
-intermediates:= $(local-intermediates-dir)
+intermediates:= $(local-generated-sources-dir)
 GEN := $(intermediates)/<font color=red>file.c</font>
 $(GEN): PRIVATE_INPUT_FILE := $(LOCAL_PATH)/<font color=red>input.file</font>
 $(GEN): PRIVATE_CUSTOM_TOOL = <font color=red>cat $(PRIVATE_INPUT_FILE) &gt; $@</font>
@@ -447,7 +447,7 @@
 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)</p>
 <pre>
-intermediates:= $(local-intermediates-dir)
+intermediates:= $(local-generated-sources-dir)
 GEN := $(addprefix $(intermediates)<font color=red>/kjs/, \
             array_object.lut.h \
             bool_object.lut.h \</font>
@@ -533,16 +533,27 @@
 
 <h3><a name="moving-modules"/>Putting modules elsewhere</h3>
 <p>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:</p>
+build somewhere else, read this.</p>
+<p>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:</p>
+<pre>
+LOCAL_MODULE_RELATIVE_PATH := hw
+</pre>
+<p>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:</p>
 <pre>
 LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT_SBIN)
 LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_SBIN_UNSTRIPPED)
 </pre>
-<p>For executables and libraries, you need to also specify a
-<code>LOCAL_UNSTRIPPED_PATH</code> location, because on target builds, we keep
-the unstripped executables so GDB can find the symbols.</code>
+<p>For executables and libraries, you need to specify a
+<code>LOCAL_UNSTRIPPED_PATH</code> location if you specified a
+<code>LOCAL_MODULE_PATH</code>, because on target builds, we keep
+the unstripped executables so GDB can find the symbols.
+<code>LOCAL_UNSTRIPPED_PATH</code> is not necessary if you only specified
+<code>LOCAL_MODULE_RELATIVE_PATH</code>.</p>
 <p>Look in <code>config/envsetup.make</code> for all of the variables defining
 places to build things.</p>
 <p>FYI: If you're installing an executable to /sbin, you probably also want to
@@ -818,6 +829,13 @@
 to.</p>
 <p>See <a href="#moving-modules">Putting modules elsewhere</a> for more.</p>
 
+<h4>LOCAL_MODULE_RELATIVE_PATH</h4>
+<p>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 <code>LOCAL_UNSTRIPPED_PATH</code>, the unstripped binaries will also use
+the relative path.</p>
+<p>See <a href="#moving-modules">Putting modules elsewhere</a> for more.</p>
+
 <h4>LOCAL_UNSTRIPPED_PATH</h4>
 <p>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 42ce742..8863fe6 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:=
@@ -148,12 +149,14 @@
 # arch specific variables
 LOCAL_SRC_FILES_$(TARGET_ARCH):=
 LOCAL_CFLAGS_$(TARGET_ARCH):=
+LOCAL_C_INCLUDES_$(TARGET_ARCH):=
 LOCAL_ASFLAGS_$(TARGET_ARCH):=
 LOCAL_NO_CRT_$(TARGET_ARCH):=
 LOCAL_LDFLAGS_$(TARGET_ARCH):=
 ifdef TARGET_2ND_ARCH
 LOCAL_SRC_FILES_$(TARGET_2ND_ARCH):=
 LOCAL_CFLAGS_$(TARGET_2ND_ARCH):=
+LOCAL_C_INCLUDES_$(TARGET_2ND_ARCH):=
 LOCAL_ASFLAGS_$(TARGET_2ND_ARCH):=
 LOCAL_NO_CRT_$(TARGET_2ND_ARCH):=
 LOCAL_LDFLAGS_$(TARGET_2ND_ARCH):=
diff --git a/core/definitions.mk b/core/definitions.mk
index eb462a3..7c29e30 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -462,6 +462,51 @@
 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 a348eb7..4cb389b 100644
--- a/core/envsetup.mk
+++ b/core/envsetup.mk
@@ -208,11 +208,17 @@
 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
diff --git a/core/shared_library.mk b/core/shared_library.mk
index b3e319f..9a75a7b 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 :=
diff --git a/core/tasks/collect_gpl_sources.mk b/core/tasks/collect_gpl_sources.mk
index 3c7afcc..30ba62b 100644
--- a/core/tasks/collect_gpl_sources.mk
+++ b/core/tasks/collect_gpl_sources.mk
@@ -14,8 +14,9 @@
 
 gpl_source_tgz := $(call intermediates-dir-for,PACKAGING,gpl_source,HOST,COMMON)/gpl_source.tgz
 
+# FORCE since we can't know whether any of the sources changed
 $(gpl_source_tgz): PRIVATE_PATHS := $(sort $(patsubst %/, %, $(dir $(ALL_GPL_MODULE_LICENSE_FILES))))
-$(gpl_source_tgz) : $(ALL_GPL_MODULE_LICENSE_FILES)
+$(gpl_source_tgz) : $(ALL_GPL_MODULE_LICENSE_FILES) FORCE
 	@echo Package gpl sources: $@
 	@rm -rf $(dir $@) && mkdir -p $(dir $@)
 	$(hide) tar cfz $@ --exclude ".git*" $(PRIVATE_PATHS)