2 # Copyright (C) 2007 The Android Open Source Project
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 # When specifying "dist", the user has asked that we copy the important
18 # files from this build into DIST_DIR.
23 dist_goal := $(strip $(filter dist,$(MAKECMDGOALS)))
24 MAKECMDGOALS := $(strip $(filter-out dist,$(MAKECMDGOALS)))
25 ifeq (,$(strip $(filter-out $(INTERNAL_MODIFIER_TARGETS),$(MAKECMDGOALS))))
26 # The commandline was something like "make dist" or "make dist showcommands".
27 # Add a dependency on a real target.
34 # $(2): destination file
35 # $(3): goals that should copy the file
37 define copy-one-dist-file
41 $$(copy-file-to-new-target-with-cp)
44 # A global variable to remember all dist'ed src:dst pairs.
45 # So if a src:dst is already dist'ed by another goal,
46 # we should just establish the dependency and don't really call the
47 # copy-one-dist-file to avoid multiple rules for the same target.
48 _all_dist_src_dst_pairs :=
49 # Other parts of the system should use this function to associate
50 # certain files with certain goals. When those goals are built
51 # and "dist" is specified, the marked files will be copied to DIST_DIR.
53 # $(1): a list of goals (e.g. droid, sdk, pdk, ndk)
54 # $(2): the dist files to add to those goals. If the file contains ':',
55 # the text following the colon is the name that the file is copied
56 # to under the dist directory. Subdirs are ok, and will be created
57 # at copy time if necessary.
59 $(foreach file,$(2), \
60 $(eval fw := $(subst :,$(space),$(file))) \
61 $(eval src := $(word 1,$(fw))) \
62 $(eval dst := $(word 2,$(fw))) \
63 $(eval dst := $(if $(dst),$(dst),$(notdir $(src)))) \
64 $(if $(filter $(_all_dist_src_dst_pairs),$(src):$(dst)),\
65 $(eval $(call add-dependency,$(1),$(DIST_DIR)/$(dst))),\
66 $(eval $(call copy-one-dist-file,\
67 $(src),$(DIST_DIR)/$(dst),$(1)))\
68 $(eval _all_dist_src_dst_pairs += $(src):$(dst))\
75 # empty definition when not building dist