Home | History | Annotate | Download | only in core
      1 ###########################################################
      2 ## Track NOTICE files
      3 ###########################################################
      4 $(call record-module-type,NOTICE_FILE)
      5 
      6 ifneq ($(LOCAL_NOTICE_FILE),)
      7 notice_file:=$(strip $(LOCAL_NOTICE_FILE))
      8 else
      9 notice_file:=$(strip $(wildcard $(LOCAL_PATH)/NOTICE))
     10 endif
     11 
     12 ifeq ($(LOCAL_MODULE_CLASS),GYP)
     13   # We ignore NOTICE files for modules of type GYP.
     14   notice_file :=
     15 endif
     16 
     17 # Soong generates stub libraries that don't need NOTICE files
     18 ifdef LOCAL_NO_NOTICE_FILE
     19   ifneq ($(LOCAL_MODULE_MAKEFILE),$(SOONG_ANDROID_MK))
     20     $(call pretty-error,LOCAL_NO_NOTICE_FILE should not be used by Android.mk files)
     21   endif
     22   notice_file :=
     23 endif
     24 
     25 ifeq ($(LOCAL_MODULE_CLASS),NOTICE_FILES)
     26 # If this is a NOTICE-only module, we don't include base_rule.mk,
     27 # so my_prefix is not set at this point.
     28 ifeq ($(LOCAL_IS_HOST_MODULE),true)
     29   my_prefix := HOST_
     30   LOCAL_HOST_PREFIX :=
     31 else
     32   my_prefix := TARGET_
     33 endif
     34 endif
     35 
     36 ifdef notice_file
     37 
     38 # This relies on the name of the directory in PRODUCT_OUT matching where
     39 # it's installed on the target - i.e. system, data, etc.  This does
     40 # not work for root and isn't exact, but it's probably good enough for
     41 # compliance.
     42 # Includes the leading slash
     43 ifdef LOCAL_INSTALLED_MODULE
     44   module_installed_filename := $(patsubst $(PRODUCT_OUT)/%,%,$(LOCAL_INSTALLED_MODULE))
     45 else
     46   # This module isn't installable
     47   ifneq ($(filter STATIC_LIBRARIES HEADER_LIBRARIES,$(LOCAL_MODULE_CLASS)),)
     48     # Stick the static libraries with the dynamic libraries.
     49     # We can't use xxx_OUT_STATIC_LIBRARIES because it points into
     50     # device-obj or host-obj.
     51     module_installed_filename := \
     52         $(patsubst $(PRODUCT_OUT)/%,%,$($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT_SHARED_LIBRARIES))/$(notdir $(LOCAL_BUILT_MODULE))
     53   else
     54     ifeq ($(LOCAL_MODULE_CLASS),JAVA_LIBRARIES)
     55       # Stick the static java libraries with the regular java libraries.
     56       module_leaf := $(notdir $(LOCAL_BUILT_MODULE))
     57       # javalib.jar is the default name for the build module (and isn't meaningful)
     58       # If that's what we have, substitute the module name instead.  These files
     59       # aren't included on the device, so this name is synthetic anyway.
     60       ifneq ($(filter javalib.jar classes.jack,$(module_leaf)),)
     61         module_leaf := $(LOCAL_MODULE).jar
     62       endif
     63       module_installed_filename := \
     64           $(patsubst $(PRODUCT_OUT)/%,%,$($(my_prefix)OUT_JAVA_LIBRARIES))/$(module_leaf)
     65     else
     66       $(error Cannot determine where to install NOTICE file for $(LOCAL_MODULE))
     67     endif # JAVA_LIBRARIES
     68   endif # STATIC_LIBRARIES
     69 endif
     70 
     71 # In case it's actually a host file
     72 module_installed_filename := $(patsubst $(HOST_OUT)/%,%,$(module_installed_filename))
     73 module_installed_filename := $(patsubst $(HOST_CROSS_OUT)/%,%,$(module_installed_filename))
     74 
     75 installed_notice_file := $($(my_prefix)OUT_NOTICE_FILES)/src/$(module_installed_filename).txt
     76 
     77 $(installed_notice_file): PRIVATE_INSTALLED_MODULE := $(module_installed_filename)
     78 
     79 $(installed_notice_file): $(notice_file)
     80 	@echo Notice file: $< -- $@
     81 	$(hide) mkdir -p $(dir $@)
     82 	$(hide) cat $< > $@
     83 
     84 ifdef LOCAL_INSTALLED_MODULE
     85 # Make LOCAL_INSTALLED_MODULE depend on NOTICE files if they exist
     86 # libraries so they get installed along with it.  Make it an order-only
     87 # dependency so we don't re-install a module when the NOTICE changes.
     88 $(LOCAL_INSTALLED_MODULE): | $(installed_notice_file)
     89 endif
     90 
     91 # To facilitate collecting NOTICE files for apps_only build,
     92 # we install the NOTICE file even if a module gets built but not installed,
     93 # because shared jni libraries won't be installed to the system image.
     94 ifdef TARGET_BUILD_APPS
     95 # for static Java libraries, we don't need to even build LOCAL_BUILT_MODULE,
     96 # but just javalib.jar in the common intermediate dir.
     97 ifeq ($(LOCAL_MODULE_CLASS),JAVA_LIBRARIES)
     98 $(intermediates.COMMON)/javalib.jar : | $(installed_notice_file)
     99 else
    100 $(LOCAL_BUILT_MODULE): | $(installed_notice_file)
    101 endif  # JAVA_LIBRARIES
    102 endif  # TARGET_BUILD_APPS
    103 
    104 else
    105 # NOTICE file does not exist
    106 installed_notice_file :=
    107 endif
    108 
    109 # Create a predictable, phony target to build this notice file.
    110 # Define it even if the notice file doesn't exist so that other
    111 # modules can depend on it.
    112 notice_target := NOTICE-$(if \
    113     $(LOCAL_IS_HOST_MODULE),HOST,TARGET)-$(LOCAL_MODULE_CLASS)-$(LOCAL_MODULE)
    114 .PHONY: $(notice_target)
    115 $(notice_target): $(installed_notice_file)
    116