The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1 | # |
| 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 Willemsen | 78c40be | 2018-10-17 16:50:49 -0700 | [diff] [blame] | 20 | # 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 Wang | 534fcd7 | 2013-03-01 16:45:35 -0800 | [diff] [blame] | 25 | _all_dist_src_dst_pairs := |
Dan Willemsen | 78c40be | 2018-10-17 16:50:49 -0700 | [diff] [blame] | 26 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 27 | # 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 Willemsen | a3f6632 | 2020-05-28 15:46:33 -0700 | [diff] [blame] | 31 | # $(1): a list of goals (e.g. droid, sdk, ndk). These must be PHONY |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 32 | # $(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. |
| 36 | define dist-for-goals |
Dan Willemsen | c904e48 | 2018-10-20 16:59:41 -0700 | [diff] [blame] | 37 | $(if $(strip $(2)), \ |
| 38 | $(eval _all_dist_goals += $$(1))) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 39 | $(foreach file,$(2), \ |
Dan Willemsen | 78c40be | 2018-10-17 16:50:49 -0700 | [diff] [blame] | 40 | $(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 Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 46 | endef |
| 47 | |
Jeongik Cha | 45c0c2c | 2023-04-27 11:04:30 +0900 | [diff] [blame] | 48 | define add_file_name_tag_suffix |
| 49 | $(basename $(notdir $1))-FILE_NAME_TAG_PLACEHOLDER$(suffix $1) |
| 50 | endef |
| 51 | |
| 52 | # This function appends suffix FILE_NAME_TAG_PLACEHOLDER from the input file |
| 53 | # $(1): a list of goals (e.g. droid, sdk, ndk). These must be PHONY |
| 54 | # $(2): the dist files to add to those goals. |
| 55 | define dist-for-goals-with-filenametag |
| 56 | $(if $(strip $(2)), \ |
| 57 | $(foreach file,$(2), \ |
| 58 | $(call dist-for-goals,$(1),$(file):$(call add_file_name_tag_suffix,$(file))))) |
| 59 | endef |
Bob Badour | d227fac | 2022-06-14 18:18:45 +0000 | [diff] [blame] | 60 | .PHONY: shareprojects |
Bob Badour | d227fac | 2022-06-14 18:18:45 +0000 | [diff] [blame] | 61 | |
| 62 | define __share-projects-rule |
| 63 | $(1) : PRIVATE_TARGETS := $(2) |
Bob Badour | d227fac | 2022-06-14 18:18:45 +0000 | [diff] [blame] | 64 | $(1): $(2) $(COMPLIANCE_LISTSHARE) |
| 65 | $(hide) rm -f $$@ |
| 66 | mkdir -p $$(dir $$@) |
Bob Badour | 40d38b4 | 2022-06-22 00:58:39 +0000 | [diff] [blame] | 67 | $$(if $$(strip $$(PRIVATE_TARGETS)),OUT_DIR=$(OUT_DIR) $(COMPLIANCE_LISTSHARE) -o $$@ $$(PRIVATE_TARGETS),touch $$@) |
Bob Badour | d227fac | 2022-06-14 18:18:45 +0000 | [diff] [blame] | 68 | endef |
| 69 | |
Bob Badour | 40d38b4 | 2022-06-22 00:58:39 +0000 | [diff] [blame] | 70 | # build list of projects to share in $(1) for meta_lic in $(2) |
Bob Badour | d227fac | 2022-06-14 18:18:45 +0000 | [diff] [blame] | 71 | # |
| 72 | # $(1): the intermediate project sharing file |
Bob Badour | 40d38b4 | 2022-06-22 00:58:39 +0000 | [diff] [blame] | 73 | # $(2): the license metadata to base the sharing on |
Bob Badour | d227fac | 2022-06-14 18:18:45 +0000 | [diff] [blame] | 74 | define _share-projects-rule |
Bob Badour | 40d38b4 | 2022-06-22 00:58:39 +0000 | [diff] [blame] | 75 | $(eval $(call __share-projects-rule,$(1),$(2))) |
Bob Badour | d227fac | 2022-06-14 18:18:45 +0000 | [diff] [blame] | 76 | endef |
| 77 | |
Bob Badour | dce80ab | 2022-06-14 18:19:30 +0000 | [diff] [blame] | 78 | .PHONY: alllicensetexts |
| 79 | |
| 80 | define __license-texts-rule |
| 81 | $(2) : PRIVATE_GOAL := $(1) |
| 82 | $(2) : PRIVATE_TARGETS := $(3) |
| 83 | $(2) : PRIVATE_ROOTS := $(4) |
| 84 | $(2) : PRIVATE_ARGUMENT_FILE := $(call intermediates-dir-for,METAPACKAGING,licensetexts)/$(2)/arguments |
| 85 | $(2): $(3) $(TEXTNOTICE) |
| 86 | $(hide) rm -f $$@ |
| 87 | mkdir -p $$(dir $$@) |
| 88 | mkdir -p $$(dir $$(PRIVATE_ARGUMENT_FILE)) |
| 89 | $$(if $$(strip $$(PRIVATE_TARGETS)),$$(call dump-words-to-file,\ |
| 90 | -product="$$(PRIVATE_GOAL)" -title="$$(PRIVATE_GOAL)" \ |
| 91 | $$(addprefix -strip_prefix ,$$(PRIVATE_ROOTS)) \ |
| 92 | -strip_prefix=$(PRODUCT_OUT)/ -strip_prefix=$(HOST_OUT)/\ |
| 93 | $$(PRIVATE_TARGETS),\ |
| 94 | $$(PRIVATE_ARGUMENT_FILE))) |
| 95 | $$(if $$(strip $$(PRIVATE_TARGETS)),OUT_DIR=$(OUT_DIR) $(TEXTNOTICE) -o $$@ @$$(PRIVATE_ARGUMENT_FILE),touch $$@) |
| 96 | endef |
| 97 | |
Bob Badour | 40d38b4 | 2022-06-22 00:58:39 +0000 | [diff] [blame] | 98 | # build list of projects to share in $(2) for meta_lic in $(3) for dist goals $(1) |
| 99 | # Strip `out/dist/` used as proxy for 'DIST_DIR' |
Bob Badour | dce80ab | 2022-06-14 18:19:30 +0000 | [diff] [blame] | 100 | # |
Bob Badour | 40d38b4 | 2022-06-22 00:58:39 +0000 | [diff] [blame] | 101 | # $(1): the name of the dist goals |
Bob Badour | dce80ab | 2022-06-14 18:19:30 +0000 | [diff] [blame] | 102 | # $(2): the intermediate project sharing file |
Bob Badour | 40d38b4 | 2022-06-22 00:58:39 +0000 | [diff] [blame] | 103 | # $(3): the license metadata to base the sharing on |
Bob Badour | dce80ab | 2022-06-14 18:19:30 +0000 | [diff] [blame] | 104 | define _license-texts-rule |
Bob Badour | 40d38b4 | 2022-06-22 00:58:39 +0000 | [diff] [blame] | 105 | $(eval $(call __license-texts-rule,$(1),$(2),$(3),out/dist/)) |
Bob Badour | dce80ab | 2022-06-14 18:19:30 +0000 | [diff] [blame] | 106 | endef |
| 107 | |
Bob Badour | 40d38b4 | 2022-06-22 00:58:39 +0000 | [diff] [blame] | 108 | ########################################################### |
| 109 | ## License metadata build rule for dist target $(1) with meta_lic $(2) copied from $(3) |
| 110 | ########################################################### |
| 111 | define _dist-target-license-metadata-rule |
| 112 | $(strip $(eval _meta :=$(2))) |
| 113 | $(strip $(eval _dep:=)) |
| 114 | # 0p is the indicator for a non-copyrightable file where no party owns the copyright. |
| 115 | # i.e. pure data with no copyrightable expression. |
| 116 | # If all of the sources are 0p and only 0p, treat the copied file as 0p. Otherwise, all |
| 117 | # of the sources must either be 0p or originate from a single metadata file to copy. |
| 118 | $(strip $(foreach s,$(strip $(3)),\ |
| 119 | $(eval _dmeta:=$(ALL_TARGETS.$(s).META_LIC))\ |
| 120 | $(if $(strip $(_dmeta)),\ |
| 121 | $(if $(filter-out 0p,$(_dep)),\ |
| 122 | $(if $(filter-out $(_dep) 0p,$(_dmeta)),\ |
| 123 | $(error cannot copy target from multiple modules: $(1) from $(_dep) and $(_dmeta)),\ |
| 124 | $(if $(filter 0p,$(_dep)),$(eval _dep:=$(_dmeta)))),\ |
| 125 | $(eval _dep:=$(_dmeta))\ |
| 126 | ),\ |
| 127 | $(eval TARGETS_MISSING_LICENSE_METADATA += $(s) $(1))))) |
| 128 | |
| 129 | |
| 130 | ifeq (0p,$(strip $(_dep))) |
| 131 | # Not copyrightable. No emcumbrances, no license text, no license kind etc. |
| 132 | $(_meta): PRIVATE_CONDITIONS := unencumbered |
| 133 | $(_meta): PRIVATE_SOURCES := $(3) |
| 134 | $(_meta): PRIVATE_INSTALLED := $(1) |
| 135 | # use `$(1)` which is the unique and relatively short `out/dist/$(target)` |
| 136 | $(_meta): PRIVATE_ARGUMENT_FILE := $(call intermediates-dir-for,METAPACKAGING,notice)/$(1)/arguments |
| 137 | $(_meta): $(BUILD_LICENSE_METADATA) |
| 138 | $(_meta) : |
| 139 | rm -f $$@ |
| 140 | mkdir -p $$(dir $$@) |
| 141 | mkdir -p $$(dir $$(PRIVATE_ARGUMENT_FILE)) |
| 142 | $$(call dump-words-to-file,\ |
| 143 | $$(addprefix -c ,$$(PRIVATE_CONDITIONS))\ |
| 144 | $$(addprefix -s ,$$(PRIVATE_SOURCES))\ |
| 145 | $$(addprefix -t ,$$(PRIVATE_TARGETS))\ |
| 146 | $$(addprefix -i ,$$(PRIVATE_INSTALLED)),\ |
| 147 | $$(PRIVATE_ARGUMENT_FILE)) |
| 148 | OUT_DIR=$(OUT_DIR) $(BUILD_LICENSE_METADATA) \ |
| 149 | @$$(PRIVATE_ARGUMENT_FILE) \ |
| 150 | -o $$@ |
| 151 | |
| 152 | else ifneq (,$(strip $(_dep))) |
| 153 | # Not a missing target, copy metadata and `is_container` etc. from license metadata file `$(_dep)` |
| 154 | $(_meta): PRIVATE_DEST_TARGET := $(1) |
| 155 | $(_meta): PRIVATE_SOURCE_TARGETS := $(3) |
| 156 | $(_meta): PRIVATE_SOURCE_METADATA := $(_dep) |
| 157 | # use `$(1)` which is the unique and relatively short `out/dist/$(target)` |
| 158 | $(_meta): PRIVATE_ARGUMENT_FILE := $(call intermediates-dir-for,METAPACKAGING,copynotice)/$(1)/arguments |
| 159 | $(_meta) : $(_dep) $(COPY_LICENSE_METADATA) |
| 160 | rm -f $$@ |
| 161 | mkdir -p $$(dir $$@) |
| 162 | mkdir -p $$(dir $$(PRIVATE_ARGUMENT_FILE)) |
| 163 | $$(call dump-words-to-file,\ |
| 164 | $$(addprefix -i ,$$(PRIVATE_DEST_TARGET))\ |
| 165 | $$(addprefix -s ,$$(PRIVATE_SOURCE_TARGETS))\ |
| 166 | $$(addprefix -d ,$$(PRIVATE_SOURCE_METADATA)),\ |
| 167 | $$(PRIVATE_ARGUMENT_FILE)) |
| 168 | OUT_DIR=$(OUT_DIR) $(COPY_LICENSE_METADATA) \ |
| 169 | @$$(PRIVATE_ARGUMENT_FILE) \ |
| 170 | -o $$@ |
| 171 | |
| 172 | endif |
| 173 | endef |
| 174 | |
| 175 | # use `out/dist/` as a proxy for 'DIST_DIR' |
Bob Badour | d227fac | 2022-06-14 18:18:45 +0000 | [diff] [blame] | 176 | define _add_projects_to_share |
Bob Badour | 40d38b4 | 2022-06-22 00:58:39 +0000 | [diff] [blame] | 177 | $(strip $(eval _mdir := $(call intermediates-dir-for,METAPACKAGING,meta)/out/dist)) \ |
Bob Badour | dce80ab | 2022-06-14 18:19:30 +0000 | [diff] [blame] | 178 | $(strip $(eval _idir := $(call intermediates-dir-for,METAPACKAGING,shareprojects))) \ |
| 179 | $(strip $(eval _tdir := $(call intermediates-dir-for,METAPACKAGING,licensetexts))) \ |
Bob Badour | 40d38b4 | 2022-06-22 00:58:39 +0000 | [diff] [blame] | 180 | $(strip $(eval _allt := $(sort $(foreach goal,$(_all_dist_goal_output_pairs),$(call word-colon,2,$(goal)))))) \ |
| 181 | $(foreach target,$(_allt), \ |
| 182 | $(eval _goals := $(sort $(foreach dg,$(filter %:$(target),$(_all_dist_goal_output_pairs)),$(call word-colon,1,$(dg))))) \ |
| 183 | $(eval _srcs := $(sort $(foreach sdp,$(filter %:$(target),$(_all_dist_src_dst_pairs)),$(call word-colon,1,$(sdp))))) \ |
| 184 | $(eval $(call _dist-target-license-metadata-rule,out/dist/$(target),$(_mdir)/out/dist/$(target).meta_lic,$(_srcs))) \ |
| 185 | $(eval _f := $(_idir)/$(target).shareprojects) \ |
| 186 | $(eval _n := $(_tdir)/$(target).txt) \ |
| 187 | $(eval $(call dist-for-goals,$(_goals),$(_f):shareprojects/$(target).shareprojects)) \ |
| 188 | $(eval $(call dist-for-goals,$(_goals),$(_n):licensetexts/$(target).txt)) \ |
| 189 | $(eval $(call _share-projects-rule,$(_f),$(foreach t, $(filter-out $(TARGETS_MISSING_LICENSE_METADATA),out/dist/$(target)),$(_mdir)/$(t).meta_lic))) \ |
| 190 | $(eval $(call _license-texts-rule,$(_goals),$(_n),$(foreach t,$(filter-out $(TARGETS_MISSING_LICENSE_METADATA),out/dist/$(target)),$(_mdir)/$(t).meta_lic))) \ |
Bob Badour | d227fac | 2022-06-14 18:18:45 +0000 | [diff] [blame] | 191 | ) |
| 192 | endef |
| 193 | |
Dan Willemsen | 78c40be | 2018-10-17 16:50:49 -0700 | [diff] [blame] | 194 | #------------------------------------------------------------------ |
| 195 | # To be used at the end of the build to collect all the uses of |
| 196 | # dist-for-goals, and write them into a file for the packaging step to use. |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 197 | |
Dan Willemsen | 78c40be | 2018-10-17 16:50:49 -0700 | [diff] [blame] | 198 | # $(1): The file to write |
| 199 | define dist-write-file |
| 200 | $(strip \ |
Bob Badour | d227fac | 2022-06-14 18:18:45 +0000 | [diff] [blame] | 201 | $(call _add_projects_to_share)\ |
| 202 | $(if $(strip $(ANDROID_REQUIRE_LICENSE_METADATA)),\ |
| 203 | $(foreach target,$(sort $(TARGETS_MISSING_LICENSE_METADATA)),$(warning target $(target) missing license metadata))\ |
| 204 | $(if $(strip $(TARGETS_MISSING_LICENSE_METADATA)),\ |
| 205 | $(if $(filter true error,$(ANDROID_REQUIRE_LICENSE_METADATA)),\ |
| 206 | $(error $(words $(sort $(TARGETS_MISSING_LICENSE_METADATA))) targets need license metadata))))\ |
| 207 | $(foreach t,$(sort $(ALL_NON_MODULES)),$(call record-missing-non-module-dependencies,$(t))) \ |
| 208 | $(eval $(call report-missing-licenses-rule)) \ |
| 209 | $(eval $(call report-all-notice-library-names-rule)) \ |
Dan Willemsen | 78c40be | 2018-10-17 16:50:49 -0700 | [diff] [blame] | 210 | $(KATI_obsolete_var dist-for-goals,Cannot be used after dist-write-file) \ |
| 211 | $(foreach goal,$(sort $(_all_dist_goals)), \ |
| 212 | $(eval $$(goal): _dist_$$(goal))) \ |
| 213 | $(shell mkdir -p $(dir $(1))) \ |
| 214 | $(file >$(1).tmp, \ |
| 215 | DIST_GOAL_OUTPUT_PAIRS := $(sort $(_all_dist_goal_output_pairs)) \ |
| 216 | $(newline)DIST_SRC_DST_PAIRS := $(sort $(_all_dist_src_dst_pairs))) \ |
| 217 | $(shell if ! cmp -s $(1).tmp $(1); then \ |
| 218 | mv $(1).tmp $(1); \ |
| 219 | else \ |
| 220 | rm $(1).tmp; \ |
| 221 | fi)) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 222 | endef |
| 223 | |
Jeongik Cha | 45c0c2c | 2023-04-27 11:04:30 +0900 | [diff] [blame] | 224 | .KATI_READONLY := dist-for-goals dist-write-file dist-for-goals-with-filenametag |