1 # Copyright (C) 2007 The Android Open Source Project
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
16 INTERNAL_CLEAN_STEPS :=
18 # Builds up a list of clean steps. Creates a unique
19 # id for each step by taking INTERNAL_CLEAN_BUILD_VERSION
20 # and appending an increasing number of '@' characters.
22 # $(1): shell command to run
23 define _add-clean-step
24 $(if $(strip $(INTERNAL_CLEAN_BUILD_VERSION)),, \
25 $(error INTERNAL_CLEAN_BUILD_VERSION not set))
26 $(eval _acs_id := $(strip $(lastword $(INTERNAL_CLEAN_STEPS))))
27 $(if $(_acs_id),,$(eval _acs_id := $(INTERNAL_CLEAN_BUILD_VERSION)))
28 $(eval _acs_id := $(_acs_id)@)
29 $(eval INTERNAL_CLEAN_STEPS += $(_acs_id))
30 $(eval INTERNAL_CLEAN_STEP.$(_acs_id) := $(1))
34 $(if $(call _add-clean-step,$(1)),)
37 # Defines INTERNAL_CLEAN_BUILD_VERSION and the individual clean steps.
38 # cleanspec.mk is outside of the core directory so that more people
39 # can have permission to touch it.
40 include build/cleanspec.mk
41 INTERNAL_CLEAN_BUILD_VERSION := $(strip $(INTERNAL_CLEAN_BUILD_VERSION))
43 # If the clean_steps.mk file is missing (usually after a clean build)
44 # then we won't do anything.
45 CURRENT_CLEAN_BUILD_VERSION := $(INTERNAL_CLEAN_BUILD_VERSION)
46 CURRENT_CLEAN_STEPS := $(INTERNAL_CLEAN_STEPS)
48 # Read the current state from the file, if present.
49 # Will set CURRENT_CLEAN_BUILD_VERSION and CURRENT_CLEAN_STEPS.
51 clean_steps_file := $(PRODUCT_OUT)/clean_steps.mk
52 -include $(clean_steps_file)
54 ifneq ($(CURRENT_CLEAN_BUILD_VERSION),$(INTERNAL_CLEAN_BUILD_VERSION))
55 # The major clean version is out-of-date. Do a full clean, and
56 # don't even bother with the clean steps.
57 $(info *** A clean build is required because of a recent change.)
58 $(shell rm -rf $(OUT_DIR))
59 $(info *** Done with the cleaning, now starting the real build.)
61 # The major clean version is correct. Find the list of clean steps
62 # that we need to execute to get up-to-date.
64 $(filter-out $(CURRENT_CLEAN_STEPS),$(INTERNAL_CLEAN_STEPS))
65 $(foreach step,$(steps), \
66 $(info Clean step: $(INTERNAL_CLEAN_STEP.$(step))) \
67 $(shell $(INTERNAL_CLEAN_STEP.$(step))) \
71 CURRENT_CLEAN_BUILD_VERSION :=
72 CURRENT_CLEAN_STEPS :=
74 # Write the new state to the file.
77 mkdir -p $(dir $(clean_steps_file)) && \
78 echo "CURRENT_CLEAN_BUILD_VERSION := $(INTERNAL_CLEAN_BUILD_VERSION)" > \
79 $(clean_steps_file) ;\
80 echo "CURRENT_CLEAN_STEPS := $(INTERNAL_CLEAN_STEPS)" >> \
85 INTERNAL_CLEAN_STEPS :=
86 INTERNAL_CLEAN_BUILD_VERSION :=
89 # Since products and build variants (unfortunately) share the same
90 # PRODUCT_OUT staging directory, things can get out of sync if different
91 # build configurations are built in the same tree. The following logic
92 # will notice when the configuration has changed and remove the files
93 # necessary to keep things consistent.
95 previous_build_config_file := $(PRODUCT_OUT)/previous_build_config.mk
97 # TODO: this special case for the sdk is only necessary while "sdk"
98 # is a valid make target. Eventually, it will just be a product, at
99 # which point TARGET_PRODUCT will handle it and we can avoid this check
100 # of MAKECMDGOALS. The "addprefix" is just to keep things pretty.
101 ifneq ($(TARGET_PRODUCT),sdk)
102 building_sdk := $(addprefix -,$(filter sdk,$(MAKECMDGOALS)))
104 # Don't bother with this extra part when explicitly building the sdk product.
108 # A change in the list of locales warrants an installclean, too.
109 locale_list := $(subst $(space),$(comma),$(strip $(PRODUCT_LOCALES)))
111 current_build_config := \
112 $(TARGET_PRODUCT)-$(TARGET_BUILD_VARIANT)$(building_sdk)-{$(locale_list)}
115 force_installclean := false
117 # Read the current state from the file, if present.
118 # Will set PREVIOUS_BUILD_CONFIG.
120 PREVIOUS_BUILD_CONFIG :=
121 -include $(previous_build_config_file)
122 PREVIOUS_BUILD_CONFIG := $(strip $(PREVIOUS_BUILD_CONFIG))
123 ifdef PREVIOUS_BUILD_CONFIG
124 ifneq "$(current_build_config)" "$(PREVIOUS_BUILD_CONFIG)"
125 $(info *** Build configuration changed: "$(PREVIOUS_BUILD_CONFIG)" -> "$(current_build_config)")
126 ifneq ($(DISABLE_AUTO_INSTALLCLEAN),true)
127 force_installclean := true
129 $(info DISABLE_AUTO_INSTALLCLEAN is set; skipping auto-clean. Your tree may be in an inconsistent state.)
132 endif # else, this is the first build, so no need to clean.
133 PREVIOUS_BUILD_CONFIG :=
135 # Write the new state to the file.
138 mkdir -p $(dir $(previous_build_config_file)) && \
139 echo "PREVIOUS_BUILD_CONFIG := $(current_build_config)" > \
140 $(previous_build_config_file) \
142 previous_build_config_file :=
143 current_build_config :=
149 # The files/dirs to delete during an installclean. This includes the
150 # non-common APPS directory, which may contain the wrong resources.
151 # Use "./" in front of the paths to avoid accidentally deleting random
152 # parts of the filesystem if any of the *_OUT vars resolve to blank.
154 # Deletes all of the files that change between different build types,
155 # like "make user" vs. "make sdk". This lets you work with different
156 # build types without having to do a full clean each time. E.g.:
159 # $ make installclean
161 # $ make installclean
164 installclean_files := \
165 ./$(HOST_OUT)/obj/NOTICE_FILES \
167 ./$(PRODUCT_OUT)/*.img \
168 ./$(PRODUCT_OUT)/*.txt \
169 ./$(PRODUCT_OUT)/*.xlb \
170 ./$(PRODUCT_OUT)/*.zip \
171 ./$(PRODUCT_OUT)/data \
172 ./$(PRODUCT_OUT)/obj/lib \
173 ./$(PRODUCT_OUT)/obj/APPS \
174 ./$(PRODUCT_OUT)/obj/NOTICE_FILES \
175 ./$(PRODUCT_OUT)/obj/PACKAGING \
176 ./$(PRODUCT_OUT)/recovery \
177 ./$(PRODUCT_OUT)/root \
178 ./$(PRODUCT_OUT)/symbols/system/lib \
179 ./$(PRODUCT_OUT)/system
181 # The files/dirs to delete during a dataclean, which removes any files
182 # in the staging and emulator data partitions.
184 ./$(PRODUCT_OUT)/data/* \
185 ./$(PRODUCT_OUT)/data-qemu/* \
186 ./$(PRODUCT_OUT)/userdata-qemu.img
188 # Define the rules for commandline invocation.
190 dataclean: FILES := $(dataclean_files)
192 $(hide) rm -rf $(FILES)
193 @echo "Deleted emulator userdata images."
196 installclean: FILES := $(installclean_files)
197 installclean: dataclean
198 $(hide) rm -rf $(FILES)
199 @echo "Deleted images and staging directories."
201 ifeq "$(force_installclean)" "true"
202 $(info *** Forcing "make installclean"...)
203 $(shell rm -rf $(dataclean_files) $(installclean_files))
204 $(info *** Done with the cleaning, now starting the real build.)
206 force_installclean :=