blob: b6b95af4e6ed12a6e5ea542e30287679f2fa2ebd [file] [log] [blame]
The Android Open Source Project88b60792009-03-03 19:28:42 -08001# Copyright (C) 2007 The Android Open Source Project
2#
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
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
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.
14#
15
16INTERNAL_CLEAN_STEPS :=
17
18# Builds up a list of clean steps. Creates a unique
Ying Wangfa9ae7b2010-03-03 10:45:14 -080019# id for each step by taking makefile path, INTERNAL_CLEAN_BUILD_VERSION
The Android Open Source Project88b60792009-03-03 19:28:42 -080020# and appending an increasing number of '@' characters.
21#
22# $(1): shell command to run
Ying Wangfa9ae7b2010-03-03 10:45:14 -080023# $(2): indicate to not use makefile path as part of step id if not empty.
24# $(2) should only be used in build/core/cleanspec.mk: just for compatibility.
The Android Open Source Project88b60792009-03-03 19:28:42 -080025define _add-clean-step
26 $(if $(strip $(INTERNAL_CLEAN_BUILD_VERSION)),, \
27 $(error INTERNAL_CLEAN_BUILD_VERSION not set))
Ying Wangfa9ae7b2010-03-03 10:45:14 -080028 $(eval _acs_makefile_prefix := $(lastword $(MAKEFILE_LIST)))
29 $(eval _acs_makefile_prefix := $(subst /,_,$(_acs_makefile_prefix)))
30 $(eval _acs_makefile_prefix := $(subst .,-,$(_acs_makefile_prefix)))
31 $(eval _acs_makefile_prefix := $(_acs_makefile_prefix)_acs)
32 $(if $($(_acs_makefile_prefix)),,\
33 $(eval $(_acs_makefile_prefix) := $(INTERNAL_CLEAN_BUILD_VERSION)))
34 $(eval $(_acs_makefile_prefix) := $($(_acs_makefile_prefix))@)
35 $(if $(strip $(2)),$(eval _acs_id := $($(_acs_makefile_prefix))),\
36 $(eval _acs_id := $(_acs_makefile_prefix)$($(_acs_makefile_prefix))))
The Android Open Source Project88b60792009-03-03 19:28:42 -080037 $(eval INTERNAL_CLEAN_STEPS += $(_acs_id))
38 $(eval INTERNAL_CLEAN_STEP.$(_acs_id) := $(1))
39 $(eval _acs_id :=)
Ying Wangfa9ae7b2010-03-03 10:45:14 -080040 $(eval _acs_makefile_prefix :=)
The Android Open Source Project88b60792009-03-03 19:28:42 -080041endef
42define add-clean-step
Ying Wangfa9ae7b2010-03-03 10:45:14 -080043$(eval # for build/core/cleanspec.mk, dont use makefile path as part of step id) \
44$(if $(filter %/cleanspec.mk,$(lastword $(MAKEFILE_LIST))),\
45 $(eval $(call _add-clean-step,$(1),true)),\
46 $(eval $(call _add-clean-step,$(1))))
The Android Open Source Project88b60792009-03-03 19:28:42 -080047endef
48
49# Defines INTERNAL_CLEAN_BUILD_VERSION and the individual clean steps.
50# cleanspec.mk is outside of the core directory so that more people
51# can have permission to touch it.
Ying Wangfa9ae7b2010-03-03 10:45:14 -080052include $(BUILD_SYSTEM)/cleanspec.mk
The Android Open Source Project88b60792009-03-03 19:28:42 -080053INTERNAL_CLEAN_BUILD_VERSION := $(strip $(INTERNAL_CLEAN_BUILD_VERSION))
54
55# If the clean_steps.mk file is missing (usually after a clean build)
56# then we won't do anything.
57CURRENT_CLEAN_BUILD_VERSION := $(INTERNAL_CLEAN_BUILD_VERSION)
58CURRENT_CLEAN_STEPS := $(INTERNAL_CLEAN_STEPS)
59
60# Read the current state from the file, if present.
61# Will set CURRENT_CLEAN_BUILD_VERSION and CURRENT_CLEAN_STEPS.
62#
63clean_steps_file := $(PRODUCT_OUT)/clean_steps.mk
64-include $(clean_steps_file)
65
66ifneq ($(CURRENT_CLEAN_BUILD_VERSION),$(INTERNAL_CLEAN_BUILD_VERSION))
67 # The major clean version is out-of-date. Do a full clean, and
68 # don't even bother with the clean steps.
69 $(info *** A clean build is required because of a recent change.)
70 $(shell rm -rf $(OUT_DIR))
71 $(info *** Done with the cleaning, now starting the real build.)
72else
73 # The major clean version is correct. Find the list of clean steps
74 # that we need to execute to get up-to-date.
75 steps := \
76 $(filter-out $(CURRENT_CLEAN_STEPS),$(INTERNAL_CLEAN_STEPS))
77 $(foreach step,$(steps), \
78 $(info Clean step: $(INTERNAL_CLEAN_STEP.$(step))) \
79 $(shell $(INTERNAL_CLEAN_STEP.$(step))) \
80 )
Ying Wang6ea58cb2012-09-26 16:00:54 -070081 # If we are running mm/mmm, we should copy over the other clean steps too.
82 ifneq ($(ONE_SHOT_MAKEFILE),)
83 INTERNAL_CLEAN_STEPS := $(strip $(CURRENT_CLEAN_STEPS) $(steps))
84 endif
The Android Open Source Project88b60792009-03-03 19:28:42 -080085 steps :=
86endif
87CURRENT_CLEAN_BUILD_VERSION :=
88CURRENT_CLEAN_STEPS :=
89
90# Write the new state to the file.
Ying Wang4a2f1732013-02-13 11:50:02 -080091# Don't write the file if we are running mm/mmm but without a preexisting clean_steps_file.
92ifneq (,$(wildcard $(clean_steps_file))$(filter ||,|$(ONE_SHOT_MAKEFILE)|))
The Android Open Source Project88b60792009-03-03 19:28:42 -080093$(shell \
94 mkdir -p $(dir $(clean_steps_file)) && \
95 echo "CURRENT_CLEAN_BUILD_VERSION := $(INTERNAL_CLEAN_BUILD_VERSION)" > \
96 $(clean_steps_file) ;\
97 echo "CURRENT_CLEAN_STEPS := $(INTERNAL_CLEAN_STEPS)" >> \
98 $(clean_steps_file) \
99 )
Ying Wang4a2f1732013-02-13 11:50:02 -0800100endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800101
102clean_steps_file :=
103INTERNAL_CLEAN_STEPS :=
104INTERNAL_CLEAN_BUILD_VERSION :=
105
106
107# Since products and build variants (unfortunately) share the same
108# PRODUCT_OUT staging directory, things can get out of sync if different
109# build configurations are built in the same tree. The following logic
110# will notice when the configuration has changed and remove the files
111# necessary to keep things consistent.
112
113previous_build_config_file := $(PRODUCT_OUT)/previous_build_config.mk
114
115# TODO: this special case for the sdk is only necessary while "sdk"
116# is a valid make target. Eventually, it will just be a product, at
117# which point TARGET_PRODUCT will handle it and we can avoid this check
118# of MAKECMDGOALS. The "addprefix" is just to keep things pretty.
119ifneq ($(TARGET_PRODUCT),sdk)
120 building_sdk := $(addprefix -,$(filter sdk,$(MAKECMDGOALS)))
121else
122 # Don't bother with this extra part when explicitly building the sdk product.
123 building_sdk :=
124endif
125
Ying Wang4f1ab922011-03-15 13:19:30 -0700126# A change in the list of aapt configs warrants an installclean, too.
Dianne Hackborna0f464a2011-10-14 19:37:57 -0700127aapt_config_list := $(strip $(PRODUCT_AAPT_CONFIG) $(PRODUCT_AAPT_PREF_CONFIG))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800128
129current_build_config := \
Ying Wang4f1ab922011-03-15 13:19:30 -0700130 $(TARGET_PRODUCT)-$(TARGET_BUILD_VARIANT)$(building_sdk)-{$(aapt_config_list)}
The Android Open Source Project88b60792009-03-03 19:28:42 -0800131building_sdk :=
Ying Wang4f1ab922011-03-15 13:19:30 -0700132aapt_config_list :=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800133force_installclean := false
134
135# Read the current state from the file, if present.
136# Will set PREVIOUS_BUILD_CONFIG.
137#
138PREVIOUS_BUILD_CONFIG :=
139-include $(previous_build_config_file)
140PREVIOUS_BUILD_CONFIG := $(strip $(PREVIOUS_BUILD_CONFIG))
141ifdef PREVIOUS_BUILD_CONFIG
142 ifneq "$(current_build_config)" "$(PREVIOUS_BUILD_CONFIG)"
143 $(info *** Build configuration changed: "$(PREVIOUS_BUILD_CONFIG)" -> "$(current_build_config)")
144 ifneq ($(DISABLE_AUTO_INSTALLCLEAN),true)
145 force_installclean := true
146 else
147 $(info DISABLE_AUTO_INSTALLCLEAN is set; skipping auto-clean. Your tree may be in an inconsistent state.)
148 endif
149 endif
150endif # else, this is the first build, so no need to clean.
151PREVIOUS_BUILD_CONFIG :=
152
153# Write the new state to the file.
154#
155$(shell \
156 mkdir -p $(dir $(previous_build_config_file)) && \
157 echo "PREVIOUS_BUILD_CONFIG := $(current_build_config)" > \
158 $(previous_build_config_file) \
159 )
160previous_build_config_file :=
161current_build_config :=
162
163#
164# installclean logic
165#
166
167# The files/dirs to delete during an installclean. This includes the
168# non-common APPS directory, which may contain the wrong resources.
The Android Open Source Project88b60792009-03-03 19:28:42 -0800169#
170# Deletes all of the files that change between different build types,
171# like "make user" vs. "make sdk". This lets you work with different
172# build types without having to do a full clean each time. E.g.:
173#
174# $ make -j8 all
175# $ make installclean
176# $ make -j8 user
177# $ make installclean
178# $ make -j8 sdk
179#
180installclean_files := \
Ying Wang096bb3d2011-01-04 12:55:14 -0800181 $(HOST_OUT)/obj/NOTICE_FILES \
182 $(HOST_OUT)/sdk \
183 $(PRODUCT_OUT)/*.img \
184 $(PRODUCT_OUT)/*.txt \
185 $(PRODUCT_OUT)/*.xlb \
186 $(PRODUCT_OUT)/*.zip \
187 $(PRODUCT_OUT)/data \
188 $(PRODUCT_OUT)/obj/APPS \
189 $(PRODUCT_OUT)/obj/NOTICE_FILES \
190 $(PRODUCT_OUT)/obj/PACKAGING \
191 $(PRODUCT_OUT)/recovery \
192 $(PRODUCT_OUT)/root \
193 $(PRODUCT_OUT)/system \
194 $(PRODUCT_OUT)/dex_bootjars \
Dima Zavin7dac5902011-10-11 15:54:10 -0700195 $(PRODUCT_OUT)/obj/JAVA_LIBRARIES \
Ying Wangfab76052012-09-21 14:11:41 -0700196 $(PRODUCT_OUT)/obj/FAKE \
197 $(PRODUCT_OUT)/obj/EXECUTABLES/adbd_intermediates \
198 $(PRODUCT_OUT)/obj/EXECUTABLES/init_intermediates
199
The Android Open Source Project88b60792009-03-03 19:28:42 -0800200
201# The files/dirs to delete during a dataclean, which removes any files
202# in the staging and emulator data partitions.
203dataclean_files := \
Ying Wang096bb3d2011-01-04 12:55:14 -0800204 $(PRODUCT_OUT)/data/* \
205 $(PRODUCT_OUT)/data-qemu/* \
206 $(PRODUCT_OUT)/userdata-qemu.img
207
208# make sure *_OUT is set so that we won't result in deleting random parts
209# of the filesystem.
210ifneq (2,$(words $(HOST_OUT) $(PRODUCT_OUT)))
211 $(error both HOST_OUT and PRODUCT_OUT should be set at this point.)
212endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800213
214# Define the rules for commandline invocation.
215.PHONY: dataclean
216dataclean: FILES := $(dataclean_files)
217dataclean:
218 $(hide) rm -rf $(FILES)
219 @echo "Deleted emulator userdata images."
220
221.PHONY: installclean
222installclean: FILES := $(installclean_files)
223installclean: dataclean
224 $(hide) rm -rf $(FILES)
225 @echo "Deleted images and staging directories."
226
227ifeq "$(force_installclean)" "true"
228 $(info *** Forcing "make installclean"...)
Ying Wang096bb3d2011-01-04 12:55:14 -0800229 $(info *** rm -rf $(dataclean_files) $(installclean_files))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800230 $(shell rm -rf $(dataclean_files) $(installclean_files))
231 $(info *** Done with the cleaning, now starting the real build.)
232endif
233force_installclean :=