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