blob: 0e1c88d33e0b15606b9765a62b3af3aed97ce7cc [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
Dan Willemsen37150012017-05-15 13:32:43 -070017ifeq ($(ONE_SHOT_MAKEFILE)$(dont_bother)$(NO_ANDROID_CLEANSPEC),)
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) ;\
Shinichiro Hamaji1326f652016-01-27 14:59:56 +0900125 echo "CURRENT_CLEAN_STEPS := $(wordlist 1,500,$(INTERNAL_CLEAN_STEPS))" >> $(clean_steps_file) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800126 )
Shinichiro Hamaji1326f652016-01-27 14:59:56 +0900127define -cs-write-clean-steps-if-arg1-not-empty
128$(if $(1),$(shell echo "CURRENT_CLEAN_STEPS += $(1)" >> $(clean_steps_file)))
129endef
130$(call -cs-write-clean-steps-if-arg1-not-empty,$(wordlist 501,1000,$(INTERNAL_CLEAN_STEPS)))
131$(call -cs-write-clean-steps-if-arg1-not-empty,$(wordlist 1001,1500,$(INTERNAL_CLEAN_STEPS)))
132$(call -cs-write-clean-steps-if-arg1-not-empty,$(wordlist 1501,2000,$(INTERNAL_CLEAN_STEPS)))
133$(call -cs-write-clean-steps-if-arg1-not-empty,$(wordlist 2001,2500,$(INTERNAL_CLEAN_STEPS)))
134$(call -cs-write-clean-steps-if-arg1-not-empty,$(wordlist 2501,3000,$(INTERNAL_CLEAN_STEPS)))
135$(call -cs-write-clean-steps-if-arg1-not-empty,$(wordlist 3001,99999,$(INTERNAL_CLEAN_STEPS)))
Shinichiro Hamaji14da1422015-07-21 07:28:39 +0900136endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800137
Shinichiro Hamaji14da1422015-07-21 07:28:39 +0900138CURRENT_CLEAN_BUILD_VERSION :=
139CURRENT_CLEAN_STEPS :=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800140clean_steps_file :=
Ying Wangeadaa952015-08-04 12:11:54 -0700141rewrite_clean_steps_file :=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800142INTERNAL_CLEAN_STEPS :=
143INTERNAL_CLEAN_BUILD_VERSION :=
144
Dan Willemsen37150012017-05-15 13:32:43 -0700145endif # if not ONE_SHOT_MAKEFILE dont_bother NO_ANDROID_CLEANSPEC
The Android Open Source Project88b60792009-03-03 19:28:42 -0800146
Ying Wangd37b5402015-04-14 14:10:46 -0700147###########################################################
Ying Wangd37b5402015-04-14 14:10:46 -0700148
Yohann Rousself09e59e2014-09-08 14:45:14 +0200149.PHONY: clean-jack-files
150clean-jack-files: clean-dex-files
151 $(hide) find $(OUT_DIR) -name "*.jack" | xargs rm -f
152 $(hide) find $(OUT_DIR) -type d -name "jack" | xargs rm -rf
153 @echo "All jack files have been removed."
154
155.PHONY: clean-dex-files
156clean-dex-files:
157 $(hide) find $(OUT_DIR) -name "*.dex" ! -path "*/jack-incremental/*" | xargs rm -f
158 $(hide) for i in `find $(OUT_DIR) -name "*.jar" -o -name "*.apk"` ; do ((unzip -l $$i 2> /dev/null | \
159 grep -q "\.dex$$" && rm -f $$i) || continue ) ; done
160 @echo "All dex files and archives containing dex files have been removed."
161
162.PHONY: clean-jack-incremental
163clean-jack-incremental:
164 $(hide) find $(OUT_DIR) -name "jack-incremental" -type d | xargs rm -rf
165 @echo "All jack incremental dirs have been removed."