blob: 0932aa1ccd1ea3f7b418bb07a40228519477dc6b [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
Ying Wang50e52fa2013-02-22 18:15:29 -080016# Don't bother with the cleanspecs if you are running mm/mmm
Ying Wangad7fd292013-08-08 16:34:29 -070017ifeq ($(ONE_SHOT_MAKEFILE)$(dont_bother),)
Ying Wang50e52fa2013-02-22 18:15:29 -080018
The Android Open Source Project88b60792009-03-03 19:28:42 -080019INTERNAL_CLEAN_STEPS :=
20
21# Builds up a list of clean steps. Creates a unique
Ying Wangfa9ae7b2010-03-03 10:45:14 -080022# id for each step by taking makefile path, INTERNAL_CLEAN_BUILD_VERSION
The Android Open Source Project88b60792009-03-03 19:28:42 -080023# and appending an increasing number of '@' characters.
24#
25# $(1): shell command to run
Ying Wangfa9ae7b2010-03-03 10:45:14 -080026# $(2): indicate to not use makefile path as part of step id if not empty.
27# $(2) should only be used in build/core/cleanspec.mk: just for compatibility.
The Android Open Source Project88b60792009-03-03 19:28:42 -080028define _add-clean-step
29 $(if $(strip $(INTERNAL_CLEAN_BUILD_VERSION)),, \
30 $(error INTERNAL_CLEAN_BUILD_VERSION not set))
Ying Wangfa9ae7b2010-03-03 10:45:14 -080031 $(eval _acs_makefile_prefix := $(lastword $(MAKEFILE_LIST)))
32 $(eval _acs_makefile_prefix := $(subst /,_,$(_acs_makefile_prefix)))
33 $(eval _acs_makefile_prefix := $(subst .,-,$(_acs_makefile_prefix)))
34 $(eval _acs_makefile_prefix := $(_acs_makefile_prefix)_acs)
35 $(if $($(_acs_makefile_prefix)),,\
36 $(eval $(_acs_makefile_prefix) := $(INTERNAL_CLEAN_BUILD_VERSION)))
37 $(eval $(_acs_makefile_prefix) := $($(_acs_makefile_prefix))@)
38 $(if $(strip $(2)),$(eval _acs_id := $($(_acs_makefile_prefix))),\
39 $(eval _acs_id := $(_acs_makefile_prefix)$($(_acs_makefile_prefix))))
The Android Open Source Project88b60792009-03-03 19:28:42 -080040 $(eval INTERNAL_CLEAN_STEPS += $(_acs_id))
41 $(eval INTERNAL_CLEAN_STEP.$(_acs_id) := $(1))
42 $(eval _acs_id :=)
Ying Wangfa9ae7b2010-03-03 10:45:14 -080043 $(eval _acs_makefile_prefix :=)
The Android Open Source Project88b60792009-03-03 19:28:42 -080044endef
45define add-clean-step
Ying Wangfa9ae7b2010-03-03 10:45:14 -080046$(eval # for build/core/cleanspec.mk, dont use makefile path as part of step id) \
47$(if $(filter %/cleanspec.mk,$(lastword $(MAKEFILE_LIST))),\
48 $(eval $(call _add-clean-step,$(1),true)),\
49 $(eval $(call _add-clean-step,$(1))))
The Android Open Source Project88b60792009-03-03 19:28:42 -080050endef
51
52# Defines INTERNAL_CLEAN_BUILD_VERSION and the individual clean steps.
53# cleanspec.mk is outside of the core directory so that more people
54# can have permission to touch it.
Ying Wangfa9ae7b2010-03-03 10:45:14 -080055include $(BUILD_SYSTEM)/cleanspec.mk
The Android Open Source Project88b60792009-03-03 19:28:42 -080056INTERNAL_CLEAN_BUILD_VERSION := $(strip $(INTERNAL_CLEAN_BUILD_VERSION))
57
58# If the clean_steps.mk file is missing (usually after a clean build)
59# then we won't do anything.
60CURRENT_CLEAN_BUILD_VERSION := $(INTERNAL_CLEAN_BUILD_VERSION)
61CURRENT_CLEAN_STEPS := $(INTERNAL_CLEAN_STEPS)
62
63# Read the current state from the file, if present.
64# Will set CURRENT_CLEAN_BUILD_VERSION and CURRENT_CLEAN_STEPS.
65#
66clean_steps_file := $(PRODUCT_OUT)/clean_steps.mk
67-include $(clean_steps_file)
68
69ifneq ($(CURRENT_CLEAN_BUILD_VERSION),$(INTERNAL_CLEAN_BUILD_VERSION))
70 # The major clean version is out-of-date. Do a full clean, and
71 # don't even bother with the clean steps.
72 $(info *** A clean build is required because of a recent change.)
73 $(shell rm -rf $(OUT_DIR))
74 $(info *** Done with the cleaning, now starting the real build.)
75else
76 # The major clean version is correct. Find the list of clean steps
77 # that we need to execute to get up-to-date.
78 steps := \
79 $(filter-out $(CURRENT_CLEAN_STEPS),$(INTERNAL_CLEAN_STEPS))
80 $(foreach step,$(steps), \
81 $(info Clean step: $(INTERNAL_CLEAN_STEP.$(step))) \
82 $(shell $(INTERNAL_CLEAN_STEP.$(step))) \
83 )
Ying Wangf6268b82014-06-18 12:07:48 -070084
85 # Rewrite the clean step for the second arch.
86 ifdef TARGET_2ND_ARCH
87 # $(1): the clean step cmd
88 # $(2): the prefix to search for
89 # $(3): the prefix to replace with
90 define -cs-rewrite-cleanstep
91 $(if $(filter $(2)/%,$(1)),\
92 $(eval _crs_new_cmd := $(patsubst $(2)/%,$(3)/%,$(1)))\
93 $(info Clean step: $(_crs_new_cmd))\
94 $(shell $(_crs_new_cmd)))
95 endef
96 $(foreach step,$(steps), \
97 $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$(TARGET_OUT_INTERMEDIATES),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATES))\
98 $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$(TARGET_OUT_SHARED_LIBRARIES),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_SHARED_LIBRARIES))\
99 $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$(TARGET_OUT_VENDOR_SHARED_LIBRARIES),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_VENDOR_SHARED_LIBRARIES))\
100 $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATES),$(TARGET_OUT_INTERMEDIATES))\
101 $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_SHARED_LIBRARIES),$(TARGET_OUT_SHARED_LIBRARIES))\
102 $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_VENDOR_SHARED_LIBRARIES),$(TARGET_OUT_VENDOR_SHARED_LIBRARIES))\
103 )
104 endif
105 _crs_new_cmd :=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800106 steps :=
107endif
108CURRENT_CLEAN_BUILD_VERSION :=
109CURRENT_CLEAN_STEPS :=
110
111# Write the new state to the file.
Ying Wang50e52fa2013-02-22 18:15:29 -0800112#
The Android Open Source Project88b60792009-03-03 19:28:42 -0800113$(shell \
114 mkdir -p $(dir $(clean_steps_file)) && \
115 echo "CURRENT_CLEAN_BUILD_VERSION := $(INTERNAL_CLEAN_BUILD_VERSION)" > \
116 $(clean_steps_file) ;\
117 echo "CURRENT_CLEAN_STEPS := $(INTERNAL_CLEAN_STEPS)" >> \
118 $(clean_steps_file) \
119 )
120
121clean_steps_file :=
122INTERNAL_CLEAN_STEPS :=
123INTERNAL_CLEAN_BUILD_VERSION :=
124
Ying Wangad7fd292013-08-08 16:34:29 -0700125endif # if not ONE_SHOT_MAKEFILE dont_bother
The Android Open Source Project88b60792009-03-03 19:28:42 -0800126
127# Since products and build variants (unfortunately) share the same
128# PRODUCT_OUT staging directory, things can get out of sync if different
129# build configurations are built in the same tree. The following logic
130# will notice when the configuration has changed and remove the files
131# necessary to keep things consistent.
132
133previous_build_config_file := $(PRODUCT_OUT)/previous_build_config.mk
134
135# TODO: this special case for the sdk is only necessary while "sdk"
136# is a valid make target. Eventually, it will just be a product, at
137# which point TARGET_PRODUCT will handle it and we can avoid this check
138# of MAKECMDGOALS. The "addprefix" is just to keep things pretty.
139ifneq ($(TARGET_PRODUCT),sdk)
140 building_sdk := $(addprefix -,$(filter sdk,$(MAKECMDGOALS)))
141else
142 # Don't bother with this extra part when explicitly building the sdk product.
143 building_sdk :=
144endif
145
Ying Wang4f1ab922011-03-15 13:19:30 -0700146# A change in the list of aapt configs warrants an installclean, too.
Dianne Hackborna0f464a2011-10-14 19:37:57 -0700147aapt_config_list := $(strip $(PRODUCT_AAPT_CONFIG) $(PRODUCT_AAPT_PREF_CONFIG))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800148
149current_build_config := \
Ying Wang4f1ab922011-03-15 13:19:30 -0700150 $(TARGET_PRODUCT)-$(TARGET_BUILD_VARIANT)$(building_sdk)-{$(aapt_config_list)}
The Android Open Source Project88b60792009-03-03 19:28:42 -0800151building_sdk :=
Ying Wang4f1ab922011-03-15 13:19:30 -0700152aapt_config_list :=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800153force_installclean := false
154
155# Read the current state from the file, if present.
156# Will set PREVIOUS_BUILD_CONFIG.
157#
158PREVIOUS_BUILD_CONFIG :=
159-include $(previous_build_config_file)
160PREVIOUS_BUILD_CONFIG := $(strip $(PREVIOUS_BUILD_CONFIG))
161ifdef PREVIOUS_BUILD_CONFIG
162 ifneq "$(current_build_config)" "$(PREVIOUS_BUILD_CONFIG)"
163 $(info *** Build configuration changed: "$(PREVIOUS_BUILD_CONFIG)" -> "$(current_build_config)")
164 ifneq ($(DISABLE_AUTO_INSTALLCLEAN),true)
165 force_installclean := true
166 else
167 $(info DISABLE_AUTO_INSTALLCLEAN is set; skipping auto-clean. Your tree may be in an inconsistent state.)
168 endif
169 endif
170endif # else, this is the first build, so no need to clean.
171PREVIOUS_BUILD_CONFIG :=
172
173# Write the new state to the file.
174#
175$(shell \
176 mkdir -p $(dir $(previous_build_config_file)) && \
177 echo "PREVIOUS_BUILD_CONFIG := $(current_build_config)" > \
178 $(previous_build_config_file) \
179 )
180previous_build_config_file :=
181current_build_config :=
182
183#
184# installclean logic
185#
186
187# The files/dirs to delete during an installclean. This includes the
188# non-common APPS directory, which may contain the wrong resources.
The Android Open Source Project88b60792009-03-03 19:28:42 -0800189#
190# Deletes all of the files that change between different build types,
191# like "make user" vs. "make sdk". This lets you work with different
192# build types without having to do a full clean each time. E.g.:
193#
194# $ make -j8 all
195# $ make installclean
196# $ make -j8 user
197# $ make installclean
198# $ make -j8 sdk
199#
200installclean_files := \
Ying Wang096bb3d2011-01-04 12:55:14 -0800201 $(HOST_OUT)/obj/NOTICE_FILES \
202 $(HOST_OUT)/sdk \
203 $(PRODUCT_OUT)/*.img \
Ji-Hwan Lee0a5b1782014-05-15 20:59:01 +0900204 $(PRODUCT_OUT)/*.ini \
Ying Wang096bb3d2011-01-04 12:55:14 -0800205 $(PRODUCT_OUT)/*.txt \
206 $(PRODUCT_OUT)/*.xlb \
207 $(PRODUCT_OUT)/*.zip \
Ying Wang949c4eb2013-08-01 15:41:53 -0700208 $(PRODUCT_OUT)/kernel \
Ying Wang096bb3d2011-01-04 12:55:14 -0800209 $(PRODUCT_OUT)/data \
Ji-Hwan Lee0a5b1782014-05-15 20:59:01 +0900210 $(PRODUCT_OUT)/skin \
Ying Wang096bb3d2011-01-04 12:55:14 -0800211 $(PRODUCT_OUT)/obj/APPS \
212 $(PRODUCT_OUT)/obj/NOTICE_FILES \
213 $(PRODUCT_OUT)/obj/PACKAGING \
214 $(PRODUCT_OUT)/recovery \
215 $(PRODUCT_OUT)/root \
216 $(PRODUCT_OUT)/system \
217 $(PRODUCT_OUT)/dex_bootjars \
Dima Zavin7dac5902011-10-11 15:54:10 -0700218 $(PRODUCT_OUT)/obj/JAVA_LIBRARIES \
Ying Wangfab76052012-09-21 14:11:41 -0700219 $(PRODUCT_OUT)/obj/FAKE \
220 $(PRODUCT_OUT)/obj/EXECUTABLES/adbd_intermediates \
repo syncd3e01c12013-03-26 17:21:01 -0700221 $(PRODUCT_OUT)/obj/EXECUTABLES/init_intermediates \
William Robertsa8b3d542013-03-26 14:51:18 -0700222 $(PRODUCT_OUT)/obj/ETC/mac_permissions.xml_intermediates \
Adam Hampson57afaa52014-03-07 15:53:44 -0800223 $(PRODUCT_OUT)/obj/ETC/sepolicy_intermediates \
224 $(PRODUCT_OUT)/obj/ETC/init.environ.rc_intermediates
The Android Open Source Project88b60792009-03-03 19:28:42 -0800225
226# The files/dirs to delete during a dataclean, which removes any files
227# in the staging and emulator data partitions.
228dataclean_files := \
Ying Wang096bb3d2011-01-04 12:55:14 -0800229 $(PRODUCT_OUT)/data/* \
230 $(PRODUCT_OUT)/data-qemu/* \
231 $(PRODUCT_OUT)/userdata-qemu.img
232
233# make sure *_OUT is set so that we won't result in deleting random parts
234# of the filesystem.
235ifneq (2,$(words $(HOST_OUT) $(PRODUCT_OUT)))
236 $(error both HOST_OUT and PRODUCT_OUT should be set at this point.)
237endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800238
239# Define the rules for commandline invocation.
240.PHONY: dataclean
241dataclean: FILES := $(dataclean_files)
242dataclean:
243 $(hide) rm -rf $(FILES)
244 @echo "Deleted emulator userdata images."
245
246.PHONY: installclean
247installclean: FILES := $(installclean_files)
248installclean: dataclean
249 $(hide) rm -rf $(FILES)
250 @echo "Deleted images and staging directories."
251
252ifeq "$(force_installclean)" "true"
253 $(info *** Forcing "make installclean"...)
Ying Wang096bb3d2011-01-04 12:55:14 -0800254 $(info *** rm -rf $(dataclean_files) $(installclean_files))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800255 $(shell rm -rf $(dataclean_files) $(installclean_files))
256 $(info *** Done with the cleaning, now starting the real build.)
257endif
258force_installclean :=