blob: 89c5966c03ef8e0de6b21dab0bfe60986a8cbb58 [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
The Android Open Source Project88b60792009-03-03 19:28:42 -080020dist_goal := $(strip $(filter dist,$(MAKECMDGOALS)))
21MAKECMDGOALS := $(strip $(filter-out dist,$(MAKECMDGOALS)))
The Android Open Source Project88b60792009-03-03 19:28:42 -080022
23ifdef dist_goal
24
25# $(1): source file
26# $(2): destination file
27# $(3): goals that should copy the file
28#
29define copy-one-dist-file
30$(3): $(2)
31$(2): $(1)
32 @echo "Dist: $$@"
33 $$(copy-file-to-new-target-with-cp)
34endef
35
Ying Wang534fcd72013-03-01 16:45:35 -080036# A global variable to remember all dist'ed src:dst pairs.
37# So if a src:dst is already dist'ed by another goal,
38# we should just establish the dependency and don't really call the
39# copy-one-dist-file to avoid multiple rules for the same target.
40_all_dist_src_dst_pairs :=
The Android Open Source Project88b60792009-03-03 19:28:42 -080041# Other parts of the system should use this function to associate
42# certain files with certain goals. When those goals are built
43# and "dist" is specified, the marked files will be copied to DIST_DIR.
44#
45# $(1): a list of goals (e.g. droid, sdk, pdk, ndk)
46# $(2): the dist files to add to those goals. If the file contains ':',
47# the text following the colon is the name that the file is copied
48# to under the dist directory. Subdirs are ok, and will be created
49# at copy time if necessary.
50define dist-for-goals
51$(foreach file,$(2), \
52 $(eval fw := $(subst :,$(space),$(file))) \
53 $(eval src := $(word 1,$(fw))) \
54 $(eval dst := $(word 2,$(fw))) \
55 $(eval dst := $(if $(dst),$(dst),$(notdir $(src)))) \
Ying Wang534fcd72013-03-01 16:45:35 -080056 $(if $(filter $(_all_dist_src_dst_pairs),$(src):$(dst)),\
57 $(eval $(call add-dependency,$(1),$(DIST_DIR)/$(dst))),\
58 $(eval $(call copy-one-dist-file,\
59 $(src),$(DIST_DIR)/$(dst),$(1)))\
60 $(eval _all_dist_src_dst_pairs += $(src):$(dst))\
61 )\
62)
The Android Open Source Project88b60792009-03-03 19:28:42 -080063endef
64
65else # !dist_goal
66
67# empty definition when not building dist
68define dist-for-goals
69endef
70
71endif # !dist_goal