blob: 06ceecb7a4a9e572f81683aac6197b039950b822 [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))
Ying Wangeadaa952015-08-04 12:11:54 -070057INTERNAL_CLEAN_STEPS := $(strip $(INTERNAL_CLEAN_STEPS))
The Android Open Source Project88b60792009-03-03 19:28:42 -080058
59# If the clean_steps.mk file is missing (usually after a clean build)
60# then we won't do anything.
61CURRENT_CLEAN_BUILD_VERSION := $(INTERNAL_CLEAN_BUILD_VERSION)
62CURRENT_CLEAN_STEPS := $(INTERNAL_CLEAN_STEPS)
63
64# Read the current state from the file, if present.
65# Will set CURRENT_CLEAN_BUILD_VERSION and CURRENT_CLEAN_STEPS.
66#
67clean_steps_file := $(PRODUCT_OUT)/clean_steps.mk
68-include $(clean_steps_file)
69
70ifneq ($(CURRENT_CLEAN_BUILD_VERSION),$(INTERNAL_CLEAN_BUILD_VERSION))
71 # The major clean version is out-of-date. Do a full clean, and
72 # don't even bother with the clean steps.
73 $(info *** A clean build is required because of a recent change.)
74 $(shell rm -rf $(OUT_DIR))
75 $(info *** Done with the cleaning, now starting the real build.)
76else
77 # The major clean version is correct. Find the list of clean steps
78 # that we need to execute to get up-to-date.
79 steps := \
80 $(filter-out $(CURRENT_CLEAN_STEPS),$(INTERNAL_CLEAN_STEPS))
81 $(foreach step,$(steps), \
82 $(info Clean step: $(INTERNAL_CLEAN_STEP.$(step))) \
83 $(shell $(INTERNAL_CLEAN_STEP.$(step))) \
84 )
Ying Wangf6268b82014-06-18 12:07:48 -070085
86 # Rewrite the clean step for the second arch.
87 ifdef TARGET_2ND_ARCH
88 # $(1): the clean step cmd
89 # $(2): the prefix to search for
90 # $(3): the prefix to replace with
91 define -cs-rewrite-cleanstep
92 $(if $(filter $(2)/%,$(1)),\
93 $(eval _crs_new_cmd := $(patsubst $(2)/%,$(3)/%,$(1)))\
94 $(info Clean step: $(_crs_new_cmd))\
95 $(shell $(_crs_new_cmd)))
96 endef
97 $(foreach step,$(steps), \
98 $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$(TARGET_OUT_INTERMEDIATES),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATES))\
99 $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$(TARGET_OUT_SHARED_LIBRARIES),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_SHARED_LIBRARIES))\
100 $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$(TARGET_OUT_VENDOR_SHARED_LIBRARIES),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_VENDOR_SHARED_LIBRARIES))\
101 $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATES),$(TARGET_OUT_INTERMEDIATES))\
102 $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_SHARED_LIBRARIES),$(TARGET_OUT_SHARED_LIBRARIES))\
103 $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_VENDOR_SHARED_LIBRARIES),$(TARGET_OUT_VENDOR_SHARED_LIBRARIES))\
104 )
105 endif
106 _crs_new_cmd :=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800107 steps :=
108endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800109
110# Write the new state to the file.
Ying Wang50e52fa2013-02-22 18:15:29 -0800111#
Ying Wangeadaa952015-08-04 12:11:54 -0700112rewrite_clean_steps_file :=
Shinichiro Hamaji14da1422015-07-21 07:28:39 +0900113ifneq ($(CURRENT_CLEAN_BUILD_VERSION)-$(CURRENT_CLEAN_STEPS),$(INTERNAL_CLEAN_BUILD_VERSION)-$(INTERNAL_CLEAN_STEPS))
Ying Wangeadaa952015-08-04 12:11:54 -0700114rewrite_clean_steps_file := true
115endif
116ifeq ($(wildcard $(clean_steps_file)),)
117# This is the first build.
118rewrite_clean_steps_file := true
119endif
120ifeq ($(rewrite_clean_steps_file),true)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800121$(shell \
122 mkdir -p $(dir $(clean_steps_file)) && \
123 echo "CURRENT_CLEAN_BUILD_VERSION := $(INTERNAL_CLEAN_BUILD_VERSION)" > \
124 $(clean_steps_file) ;\
125 echo "CURRENT_CLEAN_STEPS := $(INTERNAL_CLEAN_STEPS)" >> \
126 $(clean_steps_file) \
127 )
Shinichiro Hamaji14da1422015-07-21 07:28:39 +0900128endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800129
Shinichiro Hamaji14da1422015-07-21 07:28:39 +0900130CURRENT_CLEAN_BUILD_VERSION :=
131CURRENT_CLEAN_STEPS :=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800132clean_steps_file :=
Ying Wangeadaa952015-08-04 12:11:54 -0700133rewrite_clean_steps_file :=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800134INTERNAL_CLEAN_STEPS :=
135INTERNAL_CLEAN_BUILD_VERSION :=
136
Ying Wangad7fd292013-08-08 16:34:29 -0700137endif # if not ONE_SHOT_MAKEFILE dont_bother
The Android Open Source Project88b60792009-03-03 19:28:42 -0800138
139# Since products and build variants (unfortunately) share the same
140# PRODUCT_OUT staging directory, things can get out of sync if different
141# build configurations are built in the same tree. The following logic
142# will notice when the configuration has changed and remove the files
143# necessary to keep things consistent.
144
145previous_build_config_file := $(PRODUCT_OUT)/previous_build_config.mk
146
Ying Wang4f1ab922011-03-15 13:19:30 -0700147# A change in the list of aapt configs warrants an installclean, too.
Dianne Hackborna0f464a2011-10-14 19:37:57 -0700148aapt_config_list := $(strip $(PRODUCT_AAPT_CONFIG) $(PRODUCT_AAPT_PREF_CONFIG))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800149
150current_build_config := \
Ying Wang961096f2015-01-06 16:49:20 -0800151 $(TARGET_PRODUCT)-$(TARGET_BUILD_VARIANT)-{$(aapt_config_list)}
Evgenii Stepanova36223e2015-06-11 17:36:06 -0700152current_sanitize_target := $(strip $(SANITIZE_TARGET))
153ifeq (,$(current_sanitize_target))
154 current_sanitize_target := false
155endif
Ying Wang4f1ab922011-03-15 13:19:30 -0700156aapt_config_list :=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800157force_installclean := false
Evgenii Stepanova36223e2015-06-11 17:36:06 -0700158force_objclean := false
The Android Open Source Project88b60792009-03-03 19:28:42 -0800159
160# Read the current state from the file, if present.
161# Will set PREVIOUS_BUILD_CONFIG.
162#
163PREVIOUS_BUILD_CONFIG :=
Evgenii Stepanova36223e2015-06-11 17:36:06 -0700164PREVIOUS_SANITIZE_TARGET :=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800165-include $(previous_build_config_file)
166PREVIOUS_BUILD_CONFIG := $(strip $(PREVIOUS_BUILD_CONFIG))
Evgenii Stepanova36223e2015-06-11 17:36:06 -0700167PREVIOUS_SANITIZE_TARGET := $(strip $(PREVIOUS_SANITIZE_TARGET))
168
The Android Open Source Project88b60792009-03-03 19:28:42 -0800169ifdef PREVIOUS_BUILD_CONFIG
170 ifneq "$(current_build_config)" "$(PREVIOUS_BUILD_CONFIG)"
171 $(info *** Build configuration changed: "$(PREVIOUS_BUILD_CONFIG)" -> "$(current_build_config)")
172 ifneq ($(DISABLE_AUTO_INSTALLCLEAN),true)
173 force_installclean := true
174 else
175 $(info DISABLE_AUTO_INSTALLCLEAN is set; skipping auto-clean. Your tree may be in an inconsistent state.)
176 endif
177 endif
178endif # else, this is the first build, so no need to clean.
The Android Open Source Project88b60792009-03-03 19:28:42 -0800179
Evgenii Stepanova36223e2015-06-11 17:36:06 -0700180ifdef PREVIOUS_SANITIZE_TARGET
181 ifneq "$(current_sanitize_target)" "$(PREVIOUS_SANITIZE_TARGET)"
182 $(info *** SANITIZE_TARGET changed: "$(PREVIOUS_SANITIZE_TARGET)" -> "$(current_sanitize_target)")
183 force_objclean := true
184 endif
185endif # else, this is the first build, so no need to clean.
Evgenii Stepanova36223e2015-06-11 17:36:06 -0700186
The Android Open Source Project88b60792009-03-03 19:28:42 -0800187# Write the new state to the file.
188#
Shinichiro Hamaji14da1422015-07-21 07:28:39 +0900189ifneq ($(PREVIOUS_BUILD_CONFIG)-$(PREVIOUS_SANITIZE_TARGET),$(current_build_config)-$(current_sanitize_target))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800190$(shell \
191 mkdir -p $(dir $(previous_build_config_file)) && \
192 echo "PREVIOUS_BUILD_CONFIG := $(current_build_config)" > \
Evgenii Stepanova36223e2015-06-11 17:36:06 -0700193 $(previous_build_config_file) && \
194 echo "PREVIOUS_SANITIZE_TARGET := $(current_sanitize_target)" >> \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800195 $(previous_build_config_file) \
196 )
Shinichiro Hamaji14da1422015-07-21 07:28:39 +0900197endif
198PREVIOUS_BUILD_CONFIG :=
199PREVIOUS_SANITIZE_TARGET :=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800200previous_build_config_file :=
201current_build_config :=
202
203#
204# installclean logic
205#
206
207# The files/dirs to delete during an installclean. This includes the
208# non-common APPS directory, which may contain the wrong resources.
The Android Open Source Project88b60792009-03-03 19:28:42 -0800209#
210# Deletes all of the files that change between different build types,
211# like "make user" vs. "make sdk". This lets you work with different
212# build types without having to do a full clean each time. E.g.:
213#
214# $ make -j8 all
215# $ make installclean
216# $ make -j8 user
217# $ make installclean
218# $ make -j8 sdk
219#
220installclean_files := \
Ying Wang096bb3d2011-01-04 12:55:14 -0800221 $(HOST_OUT)/obj/NOTICE_FILES \
222 $(HOST_OUT)/sdk \
223 $(PRODUCT_OUT)/*.img \
Ji-Hwan Lee0a5b1782014-05-15 20:59:01 +0900224 $(PRODUCT_OUT)/*.ini \
Ying Wang096bb3d2011-01-04 12:55:14 -0800225 $(PRODUCT_OUT)/*.txt \
226 $(PRODUCT_OUT)/*.xlb \
227 $(PRODUCT_OUT)/*.zip \
Ying Wang949c4eb2013-08-01 15:41:53 -0700228 $(PRODUCT_OUT)/kernel \
Ying Wang096bb3d2011-01-04 12:55:14 -0800229 $(PRODUCT_OUT)/data \
Ji-Hwan Lee0a5b1782014-05-15 20:59:01 +0900230 $(PRODUCT_OUT)/skin \
Ying Wang096bb3d2011-01-04 12:55:14 -0800231 $(PRODUCT_OUT)/obj/APPS \
232 $(PRODUCT_OUT)/obj/NOTICE_FILES \
233 $(PRODUCT_OUT)/obj/PACKAGING \
234 $(PRODUCT_OUT)/recovery \
235 $(PRODUCT_OUT)/root \
236 $(PRODUCT_OUT)/system \
Ying Wang42218732014-07-18 09:56:13 -0700237 $(PRODUCT_OUT)/vendor \
238 $(PRODUCT_OUT)/oem \
Ying Wang096bb3d2011-01-04 12:55:14 -0800239 $(PRODUCT_OUT)/dex_bootjars \
Dima Zavin7dac5902011-10-11 15:54:10 -0700240 $(PRODUCT_OUT)/obj/JAVA_LIBRARIES \
Ying Wangfab76052012-09-21 14:11:41 -0700241 $(PRODUCT_OUT)/obj/FAKE \
242 $(PRODUCT_OUT)/obj/EXECUTABLES/adbd_intermediates \
Paul Lawrencea6a04352014-10-08 15:05:21 -0700243 $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libfs_mgr_intermediates \
repo syncd3e01c12013-03-26 17:21:01 -0700244 $(PRODUCT_OUT)/obj/EXECUTABLES/init_intermediates \
William Robertsa8b3d542013-03-26 14:51:18 -0700245 $(PRODUCT_OUT)/obj/ETC/mac_permissions.xml_intermediates \
Adam Hampson57afaa52014-03-07 15:53:44 -0800246 $(PRODUCT_OUT)/obj/ETC/sepolicy_intermediates \
247 $(PRODUCT_OUT)/obj/ETC/init.environ.rc_intermediates
The Android Open Source Project88b60792009-03-03 19:28:42 -0800248
249# The files/dirs to delete during a dataclean, which removes any files
250# in the staging and emulator data partitions.
251dataclean_files := \
Ying Wang096bb3d2011-01-04 12:55:14 -0800252 $(PRODUCT_OUT)/data/* \
253 $(PRODUCT_OUT)/data-qemu/* \
254 $(PRODUCT_OUT)/userdata-qemu.img
255
Evgenii Stepanova36223e2015-06-11 17:36:06 -0700256# The files/dirs to delete during an objclean, which removes any files
257# in the staging and emulator data partitions.
258objclean_files := \
259 $(TARGET_OUT_INTERMEDIATES) \
260 $($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATES)
261
Ying Wang096bb3d2011-01-04 12:55:14 -0800262# make sure *_OUT is set so that we won't result in deleting random parts
263# of the filesystem.
264ifneq (2,$(words $(HOST_OUT) $(PRODUCT_OUT)))
265 $(error both HOST_OUT and PRODUCT_OUT should be set at this point.)
266endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800267
268# Define the rules for commandline invocation.
269.PHONY: dataclean
270dataclean: FILES := $(dataclean_files)
271dataclean:
272 $(hide) rm -rf $(FILES)
273 @echo "Deleted emulator userdata images."
274
275.PHONY: installclean
276installclean: FILES := $(installclean_files)
277installclean: dataclean
278 $(hide) rm -rf $(FILES)
279 @echo "Deleted images and staging directories."
280
Evgenii Stepanova36223e2015-06-11 17:36:06 -0700281.PHONY: objclean
282objclean: FILES := $(objclean_files)
283objclean:
284 $(hide) rm -rf $(FILES)
285 @echo "Deleted images and staging directories."
286
The Android Open Source Project88b60792009-03-03 19:28:42 -0800287ifeq "$(force_installclean)" "true"
288 $(info *** Forcing "make installclean"...)
Ying Wang096bb3d2011-01-04 12:55:14 -0800289 $(info *** rm -rf $(dataclean_files) $(installclean_files))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800290 $(shell rm -rf $(dataclean_files) $(installclean_files))
291 $(info *** Done with the cleaning, now starting the real build.)
292endif
293force_installclean :=
Yohann Rousself09e59e2014-09-08 14:45:14 +0200294
Evgenii Stepanova36223e2015-06-11 17:36:06 -0700295ifeq "$(force_objclean)" "true"
296 $(info *** Forcing cleanup of intermediate files...)
297 $(info *** rm -rf $(objclean_files))
298 $(shell rm -rf $(objclean_files))
299 $(info *** Done with the cleaning, now starting the real build.)
300endif
301force_objclean :=
302
Ying Wangd37b5402015-04-14 14:10:46 -0700303###########################################################
Ying Wangd37b5402015-04-14 14:10:46 -0700304
Yohann Rousself09e59e2014-09-08 14:45:14 +0200305.PHONY: clean-jack-files
306clean-jack-files: clean-dex-files
307 $(hide) find $(OUT_DIR) -name "*.jack" | xargs rm -f
308 $(hide) find $(OUT_DIR) -type d -name "jack" | xargs rm -rf
309 @echo "All jack files have been removed."
310
311.PHONY: clean-dex-files
312clean-dex-files:
313 $(hide) find $(OUT_DIR) -name "*.dex" ! -path "*/jack-incremental/*" | xargs rm -f
314 $(hide) for i in `find $(OUT_DIR) -name "*.jar" -o -name "*.apk"` ; do ((unzip -l $$i 2> /dev/null | \
315 grep -q "\.dex$$" && rm -f $$i) || continue ) ; done
316 @echo "All dex files and archives containing dex files have been removed."
317
318.PHONY: clean-jack-incremental
319clean-jack-incremental:
320 $(hide) find $(OUT_DIR) -name "jack-incremental" -type d | xargs rm -rf
321 @echo "All jack incremental dirs have been removed."