Add an inherit-package macro to the build system.

This lets you use the source code from one apk to build a new one
with a new module name, a new android package name and optionally,
a new certificate.

To use this, in a makefile, add this:

$(call inherit-package, \
    packages/apps/Music/Android.mk, \
    Music, \
    MusicFork, \
    my_cert, \
    com.example.music)

You don't need the LOCAL_PATH and CLEAR_VARS stuff.  It will override
only the packages that are defined in the makefile name you give, but
if other modules of other types are defined, you will get an error
saying that it's defined twice.  In that case, you need to move the
duplicate library (for example a .so) out into a different makefile.

A LOCAL_OVERRIDES_PACKAGES entry is automatically created for the
forked app.
diff --git a/core/package.mk b/core/package.mk
index 2ee3996..388435a 100644
--- a/core/package.mk
+++ b/core/package.mk
@@ -25,6 +25,19 @@
 ## be set for you.
 ###########################################################
 
+
+# If this makefile is being read from within an inheritance,
+# use the new values.
+skip_definition:=
+ifdef LOCAL_PACKAGE_OVERRIDES
+  package_overridden := $(call set-inherited-package-variables)
+  ifeq ($(strip $(package_overridden)),)
+    skip_definition := true
+  endif
+endif
+
+ifndef skip_definition
+
 LOCAL_PACKAGE_NAME := $(strip $(LOCAL_PACKAGE_NAME))
 ifeq ($(LOCAL_PACKAGE_NAME),)
 $(error $(LOCAL_PATH): Package modules must define LOCAL_PACKAGE_NAME)
@@ -291,3 +304,5 @@
 PACKAGES.$(LOCAL_PACKAGE_NAME).RESOURCE_FILES := $(all_resources)
 
 PACKAGES := $(PACKAGES) $(LOCAL_PACKAGE_NAME)
+
+endif # skip_definition