distdir.mk revision b6c1cf6de79035f58b512f4400db458c8401379a
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# HACK HACK HACK
18# *** Do not use any of the following as an example for anything else ***
19
20# TODO: remove this hack once the build machine no longer needs "user-dist"
21user-dist: user
22ifneq (,$(filter user-dist,$(MAKECMDGOALS)))
23  MAKECMDGOALS := $(patsubst user-dist,user dist,$(MAKECMDGOALS))
24endif
25
26# When specifying "dist", the user has asked that we copy the important
27# files from this build into DIST_DIR.
28
29.PHONY: dist
30dist: ;
31
32dist_goal := $(strip $(filter dist,$(MAKECMDGOALS)))
33MAKECMDGOALS := $(strip $(filter-out dist,$(MAKECMDGOALS)))
34ifeq (,$(strip $(filter-out $(INTERNAL_MODIFIER_TARGETS),$(MAKECMDGOALS))))
35# The commandline was something like "make dist" or "make dist showcommands".
36# Add a dependency on a real target.
37dist: $(DEFAULT_TARGET)
38endif
39
40ifdef dist_goal
41
42# $(1): source file
43# $(2): destination file
44# $(3): goals that should copy the file
45#
46define copy-one-dist-file
47$(3): $(2)
48$(2): $(1)
49	@echo "Dist: $$@"
50	$$(copy-file-to-new-target-with-cp)
51endef
52
53# Other parts of the system should use this function to associate
54# certain files with certain goals.  When those goals are built
55# and "dist" is specified, the marked files will be copied to DIST_DIR.
56#
57# $(1): a list of goals (e.g., "user all")
58# $(2): the dist files to add to those goals
59define dist-for-goals
60$(foreach file,$(2), \
61  $(eval \
62      $(call copy-one-dist-file, \
63          $(file), \
64          $(DIST_DIR)/$(notdir $(file)), \
65	  $(1) \
66       ) \
67   ) \
68 )
69endef
70
71else # !dist_goal
72
73# empty definition when not building dist
74define dist-for-goals
75endef
76
77endif # !dist_goal
78