blob: bdfb490e1841db1b41f159a050830849ac295b1c [file] [log] [blame]
The Android Open Source Project88b60792009-03-03 19:28:42 -08001#
2# Copyright (C) 2007 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17# When specifying "dist", the user has asked that we copy the important
18# files from this build into DIST_DIR.
19
Dan Willemsen78c40be2018-10-17 16:50:49 -070020# list of all goals that depend on any dist files
21_all_dist_goals :=
22# pairs of goal:distfile
23_all_dist_goal_output_pairs :=
24# pairs of srcfile:distfile
Ying Wang534fcd72013-03-01 16:45:35 -080025_all_dist_src_dst_pairs :=
Dan Willemsen78c40be2018-10-17 16:50:49 -070026
The Android Open Source Project88b60792009-03-03 19:28:42 -080027# Other parts of the system should use this function to associate
28# certain files with certain goals. When those goals are built
29# and "dist" is specified, the marked files will be copied to DIST_DIR.
30#
Dan Willemsena3f66322020-05-28 15:46:33 -070031# $(1): a list of goals (e.g. droid, sdk, ndk). These must be PHONY
The Android Open Source Project88b60792009-03-03 19:28:42 -080032# $(2): the dist files to add to those goals. If the file contains ':',
33# the text following the colon is the name that the file is copied
34# to under the dist directory. Subdirs are ok, and will be created
35# at copy time if necessary.
36define dist-for-goals
Dan Willemsenc904e482018-10-20 16:59:41 -070037$(if $(strip $(2)), \
38 $(eval _all_dist_goals += $$(1))) \
The Android Open Source Project88b60792009-03-03 19:28:42 -080039$(foreach file,$(2), \
Dan Willemsen78c40be2018-10-17 16:50:49 -070040 $(eval src := $(call word-colon,1,$(file))) \
41 $(eval dst := $(call word-colon,2,$(file))) \
42 $(if $(dst),,$(eval dst := $$(notdir $$(src)))) \
43 $(eval _all_dist_src_dst_pairs += $$(src):$$(dst)) \
44 $(foreach goal,$(1), \
45 $(eval _all_dist_goal_output_pairs += $$(goal):$$(dst))))
The Android Open Source Project88b60792009-03-03 19:28:42 -080046endef
47
Bob Badourd227fac2022-06-14 18:18:45 +000048.PHONY: shareprojects
49#shareprojects:
50
51define __share-projects-rule
52$(1) : PRIVATE_TARGETS := $(2)
53$(1) : PRIVATE_ARGUMENT_FILE := $(call intermediates-dir-for,PACKAGING,codesharing)/$(1)/arguments
54$(1): $(2) $(COMPLIANCE_LISTSHARE)
55 $(hide) rm -f $$@
56 mkdir -p $$(dir $$@)
57 mkdir -p $$(dir $$(PRIVATE_ARGUMENT_FILE))
58 $$(if $$(strip $$(PRIVATE_TARGETS)),$$(call dump-words-to-file,$$(PRIVATE_TARGETS),$$(PRIVATE_ARGUMENT_FILE)))
59 $$(if $$(strip $$(PRIVATE_TARGETS)),OUT_DIR=$(OUT_DIR) $(COMPLIANCE_LISTSHARE) -o $$@ @$$(PRIVATE_ARGUMENT_FILE),touch $$@)
60endef
61
62# build list of projects to share in $(1) for dist targets in $(2)
63#
64# $(1): the intermediate project sharing file
65# $(2): the dist files to base the sharing on
66define _share-projects-rule
67$(eval $(call __share-projects-rule,$(1),$(call corresponding-license-metadata,$(2))))
68endef
69
70define _add_projects_to_share
71$(strip $(eval _idir := $(call intermediates-dir-for,PACKAGING,shareprojects))) \
72$(strip $(eval _goals := $(sort $(_all_dist_goals)))) \
73$(strip $(eval _opairs := $(sort $(_all_dist_goal_output_pairs)))) \
74$(strip $(eval _dpairs := $(sort $(_all_dist_src_dst_pairs)))) \
75$(strip $(eval _allt :=)) \
76$(foreach goal,$(_goals), \
77 $(eval _f := $(_idir)/$(goal).shareprojects) \
78 $(call dist-for-goals,$(goal),$(_f):shareprojects/$(basename $(notdir $(_f)))) \
79 $(eval _targets :=) \
80 $(foreach op,$(filter $(goal):%,$(_opairs)),$(foreach p,$(filter %:$(call word-colon,2,$(op)),$(_dpairs)),$(eval _targets += $(call word-colon,1,$(p))))) \
81 $(eval _allt += $(_targets)) \
82 $(eval $(call _share-projects-rule,$(_f),$(_targets))) \
83)
84endef
85
Dan Willemsen78c40be2018-10-17 16:50:49 -070086#------------------------------------------------------------------
87# To be used at the end of the build to collect all the uses of
88# dist-for-goals, and write them into a file for the packaging step to use.
The Android Open Source Project88b60792009-03-03 19:28:42 -080089
Dan Willemsen78c40be2018-10-17 16:50:49 -070090# $(1): The file to write
91define dist-write-file
92$(strip \
Bob Badourd227fac2022-06-14 18:18:45 +000093 $(call _add_projects_to_share)\
94 $(if $(strip $(ANDROID_REQUIRE_LICENSE_METADATA)),\
95 $(foreach target,$(sort $(TARGETS_MISSING_LICENSE_METADATA)),$(warning target $(target) missing license metadata))\
96 $(if $(strip $(TARGETS_MISSING_LICENSE_METADATA)),\
97 $(if $(filter true error,$(ANDROID_REQUIRE_LICENSE_METADATA)),\
98 $(error $(words $(sort $(TARGETS_MISSING_LICENSE_METADATA))) targets need license metadata))))\
99 $(foreach t,$(sort $(ALL_NON_MODULES)),$(call record-missing-non-module-dependencies,$(t))) \
100 $(eval $(call report-missing-licenses-rule)) \
101 $(eval $(call report-all-notice-library-names-rule)) \
Dan Willemsen78c40be2018-10-17 16:50:49 -0700102 $(KATI_obsolete_var dist-for-goals,Cannot be used after dist-write-file) \
103 $(foreach goal,$(sort $(_all_dist_goals)), \
104 $(eval $$(goal): _dist_$$(goal))) \
105 $(shell mkdir -p $(dir $(1))) \
106 $(file >$(1).tmp, \
107 DIST_GOAL_OUTPUT_PAIRS := $(sort $(_all_dist_goal_output_pairs)) \
108 $(newline)DIST_SRC_DST_PAIRS := $(sort $(_all_dist_src_dst_pairs))) \
109 $(shell if ! cmp -s $(1).tmp $(1); then \
110 mv $(1).tmp $(1); \
111 else \
112 rm $(1).tmp; \
113 fi))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800114endef
115
Dan Willemsen78c40be2018-10-17 16:50:49 -0700116.KATI_READONLY := dist-for-goals dist-write-file