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 | |
Bob Badour | d227fac | 2022-06-14 18:18:45 +0000 | [diff] [blame] | 48 | .PHONY: shareprojects |
Bob Badour | d227fac | 2022-06-14 18:18:45 +0000 | [diff] [blame] | 49 | |
| 50 | define __share-projects-rule |
| 51 | $(1) : PRIVATE_TARGETS := $(2) |
Bob Badour | dce80ab | 2022-06-14 18:19:30 +0000 | [diff] [blame^] | 52 | $(1) : PRIVATE_ARGUMENT_FILE := $(call intermediates-dir-for,METAPACKAGING,codesharing)/$(1)/arguments |
Bob Badour | d227fac | 2022-06-14 18:18:45 +0000 | [diff] [blame] | 53 | $(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 $$@) |
| 59 | endef |
| 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 |
| 65 | define _share-projects-rule |
| 66 | $(eval $(call __share-projects-rule,$(1),$(call corresponding-license-metadata,$(2)))) |
| 67 | endef |
| 68 | |
Bob Badour | dce80ab | 2022-06-14 18:19:30 +0000 | [diff] [blame^] | 69 | .PHONY: alllicensetexts |
| 70 | |
| 71 | define __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 $$@) |
| 87 | endef |
| 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 |
| 94 | define _license-texts-rule |
| 95 | $(eval $(call __license-texts-rule,$(1),$(2),$(call corresponding-license-metadata,$(3)),$(sort $(dir $(3))))) |
| 96 | endef |
| 97 | |
Bob Badour | d227fac | 2022-06-14 18:18:45 +0000 | [diff] [blame] | 98 | define _add_projects_to_share |
Bob Badour | dce80ab | 2022-06-14 18:19:30 +0000 | [diff] [blame^] | 99 | $(strip $(eval _idir := $(call intermediates-dir-for,METAPACKAGING,shareprojects))) \ |
| 100 | $(strip $(eval _tdir := $(call intermediates-dir-for,METAPACKAGING,licensetexts))) \ |
Bob Badour | d227fac | 2022-06-14 18:18:45 +0000 | [diff] [blame] | 101 | $(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 Badour | dce80ab | 2022-06-14 18:19:30 +0000 | [diff] [blame^] | 107 | $(eval _n := $(_tdir)/$(goal).txt) \ |
Bob Badour | d227fac | 2022-06-14 18:18:45 +0000 | [diff] [blame] | 108 | $(call dist-for-goals,$(goal),$(_f):shareprojects/$(basename $(notdir $(_f)))) \ |
Bob Badour | dce80ab | 2022-06-14 18:19:30 +0000 | [diff] [blame^] | 109 | $(call dist-for-goals,$(goal),$(_n):licensetexts/$(basename $(notdir $(_n)))) \ |
Bob Badour | d227fac | 2022-06-14 18:18:45 +0000 | [diff] [blame] | 110 | $(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 Badour | dce80ab | 2022-06-14 18:19:30 +0000 | [diff] [blame^] | 114 | $(eval $(call _license-texts-rule,$(goal),$(_n),$(_targets))) \ |
Bob Badour | d227fac | 2022-06-14 18:18:45 +0000 | [diff] [blame] | 115 | ) |
| 116 | endef |
| 117 | |
Dan Willemsen | 78c40be | 2018-10-17 16:50:49 -0700 | [diff] [blame] | 118 | #------------------------------------------------------------------ |
| 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 Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 121 | |
Dan Willemsen | 78c40be | 2018-10-17 16:50:49 -0700 | [diff] [blame] | 122 | # $(1): The file to write |
| 123 | define dist-write-file |
| 124 | $(strip \ |
Bob Badour | d227fac | 2022-06-14 18:18:45 +0000 | [diff] [blame] | 125 | $(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 Willemsen | 78c40be | 2018-10-17 16:50:49 -0700 | [diff] [blame] | 134 | $(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 Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 146 | endef |
| 147 | |
Dan Willemsen | 78c40be | 2018-10-17 16:50:49 -0700 | [diff] [blame] | 148 | .KATI_READONLY := dist-for-goals dist-write-file |