OSDN Git Service

am b43cf696: am 848b8e9d: am fa2ce3b3: am f73f79f1: Merge "Use /filelist when OUT_DIR...
[android-x86/build.git] / core / distdir.mk
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 .PHONY: dist
21 dist: ;
22
23 dist_goal := $(strip $(filter dist,$(MAKECMDGOALS)))
24 MAKECMDGOALS := $(strip $(filter-out dist,$(MAKECMDGOALS)))
25
26 ifdef dist_goal
27
28 # $(1): source file
29 # $(2): destination file
30 # $(3): goals that should copy the file
31 #
32 define copy-one-dist-file
33 $(3): $(2)
34 $(2): $(1)
35         @echo "Dist: $$@"
36         $$(copy-file-to-new-target-with-cp)
37 endef
38
39 # A global variable to remember all dist'ed src:dst pairs.
40 # So if a src:dst is already dist'ed by another goal,
41 # we should just establish the dependency and don't really call the
42 # copy-one-dist-file to avoid multiple rules for the same target.
43 _all_dist_src_dst_pairs :=
44 # Other parts of the system should use this function to associate
45 # certain files with certain goals.  When those goals are built
46 # and "dist" is specified, the marked files will be copied to DIST_DIR.
47 #
48 # $(1): a list of goals  (e.g. droid, sdk, pdk, ndk)
49 # $(2): the dist files to add to those goals.  If the file contains ':',
50 #       the text following the colon is the name that the file is copied
51 #       to under the dist directory.  Subdirs are ok, and will be created
52 #       at copy time if necessary.
53 define dist-for-goals
54 $(foreach file,$(2), \
55   $(eval fw := $(subst :,$(space),$(file))) \
56   $(eval src := $(word 1,$(fw))) \
57   $(eval dst := $(word 2,$(fw))) \
58   $(eval dst := $(if $(dst),$(dst),$(notdir $(src)))) \
59   $(if $(filter $(_all_dist_src_dst_pairs),$(src):$(dst)),\
60     $(eval $(call add-dependency,$(1),$(DIST_DIR)/$(dst))),\
61     $(eval $(call copy-one-dist-file,\
62       $(src),$(DIST_DIR)/$(dst),$(1)))\
63       $(eval _all_dist_src_dst_pairs += $(src):$(dst))\
64   )\
65 )
66 endef
67
68 else # !dist_goal
69
70 # empty definition when not building dist
71 define dist-for-goals
72 endef
73
74 endif # !dist_goal