blob: 8f48cf817c0961a46fd0d9803e2d7852fbffd183 [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
Bob Badourd227fac2022-06-14 18:18:45 +000049
50define __share-projects-rule
51$(1) : PRIVATE_TARGETS := $(2)
Bob Badourdce80ab2022-06-14 18:19:30 +000052$(1) : PRIVATE_ARGUMENT_FILE := $(call intermediates-dir-for,METAPACKAGING,codesharing)/$(1)/arguments
Bob Badourd227fac2022-06-14 18:18:45 +000053$(1): $(2) $(COMPLIANCE_LISTSHARE)
54 $(hide) rm -f $$@
55 mkdir -p $$(dir $$@)
56 mkdir -p $$(dir $$(PRIVATE_ARGUMENT_FILE))
57 $$(if $$(strip $$(PRIVATE_TARGETS)),$$(call dump-words-to-file,$$(PRIVATE_TARGETS),$$(PRIVATE_ARGUMENT_FILE)))
58 $$(if $$(strip $$(PRIVATE_TARGETS)),OUT_DIR=$(OUT_DIR) $(COMPLIANCE_LISTSHARE) -o $$@ @$$(PRIVATE_ARGUMENT_FILE),touch $$@)
59endef
60
61# build list of projects to share in $(1) for dist targets in $(2)
62#
63# $(1): the intermediate project sharing file
64# $(2): the dist files to base the sharing on
65define _share-projects-rule
66$(eval $(call __share-projects-rule,$(1),$(call corresponding-license-metadata,$(2))))
67endef
68
Bob Badourdce80ab2022-06-14 18:19:30 +000069.PHONY: alllicensetexts
70
71define __license-texts-rule
72$(2) : PRIVATE_GOAL := $(1)
73$(2) : PRIVATE_TARGETS := $(3)
74$(2) : PRIVATE_ROOTS := $(4)
75$(2) : PRIVATE_ARGUMENT_FILE := $(call intermediates-dir-for,METAPACKAGING,licensetexts)/$(2)/arguments
76$(2): $(3) $(TEXTNOTICE)
77 $(hide) rm -f $$@
78 mkdir -p $$(dir $$@)
79 mkdir -p $$(dir $$(PRIVATE_ARGUMENT_FILE))
80 $$(if $$(strip $$(PRIVATE_TARGETS)),$$(call dump-words-to-file,\
81 -product="$$(PRIVATE_GOAL)" -title="$$(PRIVATE_GOAL)" \
82 $$(addprefix -strip_prefix ,$$(PRIVATE_ROOTS)) \
83 -strip_prefix=$(PRODUCT_OUT)/ -strip_prefix=$(HOST_OUT)/\
84 $$(PRIVATE_TARGETS),\
85 $$(PRIVATE_ARGUMENT_FILE)))
86 $$(if $$(strip $$(PRIVATE_TARGETS)),OUT_DIR=$(OUT_DIR) $(TEXTNOTICE) -o $$@ @$$(PRIVATE_ARGUMENT_FILE),touch $$@)
87endef
88
89# build list of projects to share in $(2) for dist targets in $(3) for dist goal $(1)
90#
91# $(1): the name of the dist goal
92# $(2): the intermediate project sharing file
93# $(3): the dist files to base the sharing on
94define _license-texts-rule
95$(eval $(call __license-texts-rule,$(1),$(2),$(call corresponding-license-metadata,$(3)),$(sort $(dir $(3)))))
96endef
97
Bob Badourd227fac2022-06-14 18:18:45 +000098define _add_projects_to_share
Bob Badourdce80ab2022-06-14 18:19:30 +000099$(strip $(eval _idir := $(call intermediates-dir-for,METAPACKAGING,shareprojects))) \
100$(strip $(eval _tdir := $(call intermediates-dir-for,METAPACKAGING,licensetexts))) \
Bob Badourd227fac2022-06-14 18:18:45 +0000101$(strip $(eval _goals := $(sort $(_all_dist_goals)))) \
102$(strip $(eval _opairs := $(sort $(_all_dist_goal_output_pairs)))) \
103$(strip $(eval _dpairs := $(sort $(_all_dist_src_dst_pairs)))) \
104$(strip $(eval _allt :=)) \
105$(foreach goal,$(_goals), \
106 $(eval _f := $(_idir)/$(goal).shareprojects) \
Bob Badourdce80ab2022-06-14 18:19:30 +0000107 $(eval _n := $(_tdir)/$(goal).txt) \
Bob Badourd227fac2022-06-14 18:18:45 +0000108 $(call dist-for-goals,$(goal),$(_f):shareprojects/$(basename $(notdir $(_f)))) \
Bob Badourdce80ab2022-06-14 18:19:30 +0000109 $(call dist-for-goals,$(goal),$(_n):licensetexts/$(basename $(notdir $(_n)))) \
Bob Badourd227fac2022-06-14 18:18:45 +0000110 $(eval _targets :=) \
111 $(foreach op,$(filter $(goal):%,$(_opairs)),$(foreach p,$(filter %:$(call word-colon,2,$(op)),$(_dpairs)),$(eval _targets += $(call word-colon,1,$(p))))) \
112 $(eval _allt += $(_targets)) \
113 $(eval $(call _share-projects-rule,$(_f),$(_targets))) \
Bob Badourdce80ab2022-06-14 18:19:30 +0000114 $(eval $(call _license-texts-rule,$(goal),$(_n),$(_targets))) \
Bob Badourd227fac2022-06-14 18:18:45 +0000115)
116endef
117
Dan Willemsen78c40be2018-10-17 16:50:49 -0700118#------------------------------------------------------------------
119# To be used at the end of the build to collect all the uses of
120# 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 -0800121
Dan Willemsen78c40be2018-10-17 16:50:49 -0700122# $(1): The file to write
123define dist-write-file
124$(strip \
Bob Badourd227fac2022-06-14 18:18:45 +0000125 $(call _add_projects_to_share)\
126 $(if $(strip $(ANDROID_REQUIRE_LICENSE_METADATA)),\
127 $(foreach target,$(sort $(TARGETS_MISSING_LICENSE_METADATA)),$(warning target $(target) missing license metadata))\
128 $(if $(strip $(TARGETS_MISSING_LICENSE_METADATA)),\
129 $(if $(filter true error,$(ANDROID_REQUIRE_LICENSE_METADATA)),\
130 $(error $(words $(sort $(TARGETS_MISSING_LICENSE_METADATA))) targets need license metadata))))\
131 $(foreach t,$(sort $(ALL_NON_MODULES)),$(call record-missing-non-module-dependencies,$(t))) \
132 $(eval $(call report-missing-licenses-rule)) \
133 $(eval $(call report-all-notice-library-names-rule)) \
Dan Willemsen78c40be2018-10-17 16:50:49 -0700134 $(KATI_obsolete_var dist-for-goals,Cannot be used after dist-write-file) \
135 $(foreach goal,$(sort $(_all_dist_goals)), \
136 $(eval $$(goal): _dist_$$(goal))) \
137 $(shell mkdir -p $(dir $(1))) \
138 $(file >$(1).tmp, \
139 DIST_GOAL_OUTPUT_PAIRS := $(sort $(_all_dist_goal_output_pairs)) \
140 $(newline)DIST_SRC_DST_PAIRS := $(sort $(_all_dist_src_dst_pairs))) \
141 $(shell if ! cmp -s $(1).tmp $(1); then \
142 mv $(1).tmp $(1); \
143 else \
144 rm $(1).tmp; \
145 fi))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800146endef
147
Dan Willemsen78c40be2018-10-17 16:50:49 -0700148.KATI_READONLY := dist-for-goals dist-write-file