blob: 7e68d6f48c8c33fe6fb07dc0a629a31956cf6b18 [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 )
81 steps :=
82endif
83CURRENT_CLEAN_BUILD_VERSION :=
84CURRENT_CLEAN_STEPS :=
85
86# Write the new state to the file.
87#
88$(shell \
89 mkdir -p $(dir $(clean_steps_file)) && \
90 echo "CURRENT_CLEAN_BUILD_VERSION := $(INTERNAL_CLEAN_BUILD_VERSION)" > \
91 $(clean_steps_file) ;\
92 echo "CURRENT_CLEAN_STEPS := $(INTERNAL_CLEAN_STEPS)" >> \
93 $(clean_steps_file) \
94 )
95
96clean_steps_file :=
97INTERNAL_CLEAN_STEPS :=
98INTERNAL_CLEAN_BUILD_VERSION :=
99
100
101# Since products and build variants (unfortunately) share the same
102# PRODUCT_OUT staging directory, things can get out of sync if different
103# build configurations are built in the same tree. The following logic
104# will notice when the configuration has changed and remove the files
105# necessary to keep things consistent.
106
107previous_build_config_file := $(PRODUCT_OUT)/previous_build_config.mk
108
109# TODO: this special case for the sdk is only necessary while "sdk"
110# is a valid make target. Eventually, it will just be a product, at
111# which point TARGET_PRODUCT will handle it and we can avoid this check
112# of MAKECMDGOALS. The "addprefix" is just to keep things pretty.
113ifneq ($(TARGET_PRODUCT),sdk)
114 building_sdk := $(addprefix -,$(filter sdk,$(MAKECMDGOALS)))
115else
116 # Don't bother with this extra part when explicitly building the sdk product.
117 building_sdk :=
118endif
119
120# A change in the list of locales warrants an installclean, too.
121locale_list := $(subst $(space),$(comma),$(strip $(PRODUCT_LOCALES)))
122
123current_build_config := \
124 $(TARGET_PRODUCT)-$(TARGET_BUILD_VARIANT)$(building_sdk)-{$(locale_list)}
125building_sdk :=
126locale_list :=
127force_installclean := false
128
129# Read the current state from the file, if present.
130# Will set PREVIOUS_BUILD_CONFIG.
131#
132PREVIOUS_BUILD_CONFIG :=
133-include $(previous_build_config_file)
134PREVIOUS_BUILD_CONFIG := $(strip $(PREVIOUS_BUILD_CONFIG))
135ifdef PREVIOUS_BUILD_CONFIG
136 ifneq "$(current_build_config)" "$(PREVIOUS_BUILD_CONFIG)"
137 $(info *** Build configuration changed: "$(PREVIOUS_BUILD_CONFIG)" -> "$(current_build_config)")
138 ifneq ($(DISABLE_AUTO_INSTALLCLEAN),true)
139 force_installclean := true
140 else
141 $(info DISABLE_AUTO_INSTALLCLEAN is set; skipping auto-clean. Your tree may be in an inconsistent state.)
142 endif
143 endif
144endif # else, this is the first build, so no need to clean.
145PREVIOUS_BUILD_CONFIG :=
146
147# Write the new state to the file.
148#
149$(shell \
150 mkdir -p $(dir $(previous_build_config_file)) && \
151 echo "PREVIOUS_BUILD_CONFIG := $(current_build_config)" > \
152 $(previous_build_config_file) \
153 )
154previous_build_config_file :=
155current_build_config :=
156
157#
158# installclean logic
159#
160
161# The files/dirs to delete during an installclean. This includes the
162# non-common APPS directory, which may contain the wrong resources.
163# Use "./" in front of the paths to avoid accidentally deleting random
164# parts of the filesystem if any of the *_OUT vars resolve to blank.
165#
166# Deletes all of the files that change between different build types,
167# like "make user" vs. "make sdk". This lets you work with different
168# build types without having to do a full clean each time. E.g.:
169#
170# $ make -j8 all
171# $ make installclean
172# $ make -j8 user
173# $ make installclean
174# $ make -j8 sdk
175#
176installclean_files := \
177 ./$(HOST_OUT)/obj/NOTICE_FILES \
178 ./$(HOST_OUT)/sdk \
179 ./$(PRODUCT_OUT)/*.img \
180 ./$(PRODUCT_OUT)/*.txt \
181 ./$(PRODUCT_OUT)/*.xlb \
182 ./$(PRODUCT_OUT)/*.zip \
183 ./$(PRODUCT_OUT)/data \
Eric Fischer7bbec3a2009-03-25 16:12:29 -0700184 ./$(PRODUCT_OUT)/obj/lib \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800185 ./$(PRODUCT_OUT)/obj/APPS \
186 ./$(PRODUCT_OUT)/obj/NOTICE_FILES \
187 ./$(PRODUCT_OUT)/obj/PACKAGING \
188 ./$(PRODUCT_OUT)/recovery \
189 ./$(PRODUCT_OUT)/root \
Eric Fischer7bbec3a2009-03-25 16:12:29 -0700190 ./$(PRODUCT_OUT)/symbols/system/lib \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800191 ./$(PRODUCT_OUT)/system
192
193# The files/dirs to delete during a dataclean, which removes any files
194# in the staging and emulator data partitions.
195dataclean_files := \
196 ./$(PRODUCT_OUT)/data/* \
197 ./$(PRODUCT_OUT)/data-qemu/* \
198 ./$(PRODUCT_OUT)/userdata-qemu.img
199
200# Define the rules for commandline invocation.
201.PHONY: dataclean
202dataclean: FILES := $(dataclean_files)
203dataclean:
204 $(hide) rm -rf $(FILES)
205 @echo "Deleted emulator userdata images."
206
207.PHONY: installclean
208installclean: FILES := $(installclean_files)
209installclean: dataclean
210 $(hide) rm -rf $(FILES)
211 @echo "Deleted images and staging directories."
212
213ifeq "$(force_installclean)" "true"
214 $(info *** Forcing "make installclean"...)
215 $(shell rm -rf $(dataclean_files) $(installclean_files))
216 $(info *** Done with the cleaning, now starting the real build.)
217endif
218force_installclean :=