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, pdk, 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. 36 define 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)))) 46 endef 47 48 #------------------------------------------------------------------ 49 # To be used at the end of the build to collect all the uses of 50 # dist-for-goals, and write them into a file for the packaging step to use. 51 52 # $(1): The file to write 53 define dist-write-file 54 $(strip \ 55 $(KATI_obsolete_var dist-for-goals,Cannot be used after dist-write-file) \ 56 $(foreach goal,$(sort $(_all_dist_goals)), \ 57 $(eval $$(goal): _dist_$$(goal))) \ 58 $(shell mkdir -p $(dir $(1))) \ 59 $(file >$(1).tmp, \ 60 DIST_GOAL_OUTPUT_PAIRS := $(sort $(_all_dist_goal_output_pairs)) \ 61 $(newline)DIST_SRC_DST_PAIRS := $(sort $(_all_dist_src_dst_pairs))) \ 62 $(shell if ! cmp -s $(1).tmp $(1); then \ 63 mv $(1).tmp $(1); \ 64 else \ 65 rm $(1).tmp; \ 66 fi)) 67 endef 68 69 .KATI_READONLY := dist-for-goals dist-write-file 70