The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1 | # 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 Wang | 50e52fa | 2013-02-22 18:15:29 -0800 | [diff] [blame] | 16 | # Don't bother with the cleanspecs if you are running mm/mmm |
Dan Willemsen | 3715001 | 2017-05-15 13:32:43 -0700 | [diff] [blame] | 17 | ifeq ($(ONE_SHOT_MAKEFILE)$(dont_bother)$(NO_ANDROID_CLEANSPEC),) |
Ying Wang | 50e52fa | 2013-02-22 18:15:29 -0800 | [diff] [blame] | 18 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 19 | INTERNAL_CLEAN_STEPS := |
| 20 | |
| 21 | # Builds up a list of clean steps. Creates a unique |
Ying Wang | fa9ae7b | 2010-03-03 10:45:14 -0800 | [diff] [blame] | 22 | # id for each step by taking makefile path, INTERNAL_CLEAN_BUILD_VERSION |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 23 | # and appending an increasing number of '@' characters. |
| 24 | # |
| 25 | # $(1): shell command to run |
Ying Wang | fa9ae7b | 2010-03-03 10:45:14 -0800 | [diff] [blame] | 26 | # $(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 Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 28 | define _add-clean-step |
| 29 | $(if $(strip $(INTERNAL_CLEAN_BUILD_VERSION)),, \ |
| 30 | $(error INTERNAL_CLEAN_BUILD_VERSION not set)) |
Ying Wang | fa9ae7b | 2010-03-03 10:45:14 -0800 | [diff] [blame] | 31 | $(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 Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 40 | $(eval INTERNAL_CLEAN_STEPS += $(_acs_id)) |
| 41 | $(eval INTERNAL_CLEAN_STEP.$(_acs_id) := $(1)) |
| 42 | $(eval _acs_id :=) |
Ying Wang | fa9ae7b | 2010-03-03 10:45:14 -0800 | [diff] [blame] | 43 | $(eval _acs_makefile_prefix :=) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 44 | endef |
| 45 | define add-clean-step |
Ying Wang | fa9ae7b | 2010-03-03 10:45:14 -0800 | [diff] [blame] | 46 | $(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 Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 50 | endef |
| 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 Wang | fa9ae7b | 2010-03-03 10:45:14 -0800 | [diff] [blame] | 55 | include $(BUILD_SYSTEM)/cleanspec.mk |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 56 | INTERNAL_CLEAN_BUILD_VERSION := $(strip $(INTERNAL_CLEAN_BUILD_VERSION)) |
Ying Wang | eadaa95 | 2015-08-04 12:11:54 -0700 | [diff] [blame] | 57 | INTERNAL_CLEAN_STEPS := $(strip $(INTERNAL_CLEAN_STEPS)) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 58 | |
| 59 | # If the clean_steps.mk file is missing (usually after a clean build) |
| 60 | # then we won't do anything. |
Dan Willemsen | e6f7560 | 2017-07-24 21:16:38 -0700 | [diff] [blame^] | 61 | CURRENT_CLEAN_BUILD_VERSION := MISSING |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 62 | CURRENT_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 | # |
| 67 | clean_steps_file := $(PRODUCT_OUT)/clean_steps.mk |
| 68 | -include $(clean_steps_file) |
| 69 | |
Dan Willemsen | e6f7560 | 2017-07-24 21:16:38 -0700 | [diff] [blame^] | 70 | ifeq ($(CURRENT_CLEAN_BUILD_VERSION),MISSING) |
| 71 | # Do nothing |
| 72 | else ifneq ($(CURRENT_CLEAN_BUILD_VERSION),$(INTERNAL_CLEAN_BUILD_VERSION)) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 73 | # The major clean version is out-of-date. Do a full clean, and |
| 74 | # don't even bother with the clean steps. |
| 75 | $(info *** A clean build is required because of a recent change.) |
| 76 | $(shell rm -rf $(OUT_DIR)) |
| 77 | $(info *** Done with the cleaning, now starting the real build.) |
| 78 | else |
| 79 | # The major clean version is correct. Find the list of clean steps |
| 80 | # that we need to execute to get up-to-date. |
| 81 | steps := \ |
| 82 | $(filter-out $(CURRENT_CLEAN_STEPS),$(INTERNAL_CLEAN_STEPS)) |
| 83 | $(foreach step,$(steps), \ |
| 84 | $(info Clean step: $(INTERNAL_CLEAN_STEP.$(step))) \ |
| 85 | $(shell $(INTERNAL_CLEAN_STEP.$(step))) \ |
| 86 | ) |
Ying Wang | f6268b8 | 2014-06-18 12:07:48 -0700 | [diff] [blame] | 87 | |
| 88 | # Rewrite the clean step for the second arch. |
| 89 | ifdef TARGET_2ND_ARCH |
| 90 | # $(1): the clean step cmd |
| 91 | # $(2): the prefix to search for |
| 92 | # $(3): the prefix to replace with |
| 93 | define -cs-rewrite-cleanstep |
| 94 | $(if $(filter $(2)/%,$(1)),\ |
| 95 | $(eval _crs_new_cmd := $(patsubst $(2)/%,$(3)/%,$(1)))\ |
| 96 | $(info Clean step: $(_crs_new_cmd))\ |
| 97 | $(shell $(_crs_new_cmd))) |
| 98 | endef |
| 99 | $(foreach step,$(steps), \ |
| 100 | $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$(TARGET_OUT_INTERMEDIATES),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATES))\ |
| 101 | $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$(TARGET_OUT_SHARED_LIBRARIES),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_SHARED_LIBRARIES))\ |
| 102 | $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$(TARGET_OUT_VENDOR_SHARED_LIBRARIES),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_VENDOR_SHARED_LIBRARIES))\ |
| 103 | $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATES),$(TARGET_OUT_INTERMEDIATES))\ |
| 104 | $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_SHARED_LIBRARIES),$(TARGET_OUT_SHARED_LIBRARIES))\ |
| 105 | $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_VENDOR_SHARED_LIBRARIES),$(TARGET_OUT_VENDOR_SHARED_LIBRARIES))\ |
| 106 | ) |
| 107 | endif |
| 108 | _crs_new_cmd := |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 109 | steps := |
| 110 | endif |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 111 | |
| 112 | # Write the new state to the file. |
Ying Wang | 50e52fa | 2013-02-22 18:15:29 -0800 | [diff] [blame] | 113 | # |
Shinichiro Hamaji | 14da142 | 2015-07-21 07:28:39 +0900 | [diff] [blame] | 114 | ifneq ($(CURRENT_CLEAN_BUILD_VERSION)-$(CURRENT_CLEAN_STEPS),$(INTERNAL_CLEAN_BUILD_VERSION)-$(INTERNAL_CLEAN_STEPS)) |
Dan Willemsen | e6f7560 | 2017-07-24 21:16:38 -0700 | [diff] [blame^] | 115 | $(shell mkdir -p $(dir $(clean_steps_file))) |
| 116 | $(file >$(clean_steps_file).tmp,CURRENT_CLEAN_BUILD_VERSION := $(INTERNAL_CLEAN_BUILD_VERSION)$(newline)CURRENT_CLEAN_STEPS := $(INTERNAL_CLEAN_STEPS)$(newline)) |
| 117 | $(shell if ! cmp -s $(clean_steps_file).tmp $(clean_steps_file); then \ |
| 118 | mv $(clean_steps_file).tmp $(clean_steps_file); \ |
| 119 | else \ |
| 120 | rm $(clean_steps_file).tmp; \ |
| 121 | fi) |
Shinichiro Hamaji | 14da142 | 2015-07-21 07:28:39 +0900 | [diff] [blame] | 122 | endif |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 123 | |
Shinichiro Hamaji | 14da142 | 2015-07-21 07:28:39 +0900 | [diff] [blame] | 124 | CURRENT_CLEAN_BUILD_VERSION := |
| 125 | CURRENT_CLEAN_STEPS := |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 126 | clean_steps_file := |
| 127 | INTERNAL_CLEAN_STEPS := |
| 128 | INTERNAL_CLEAN_BUILD_VERSION := |
| 129 | |
Dan Willemsen | 3715001 | 2017-05-15 13:32:43 -0700 | [diff] [blame] | 130 | endif # if not ONE_SHOT_MAKEFILE dont_bother NO_ANDROID_CLEANSPEC |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 131 | |
Ying Wang | d37b540 | 2015-04-14 14:10:46 -0700 | [diff] [blame] | 132 | ########################################################### |
Ying Wang | d37b540 | 2015-04-14 14:10:46 -0700 | [diff] [blame] | 133 | |
Yohann Roussel | f09e59e | 2014-09-08 14:45:14 +0200 | [diff] [blame] | 134 | .PHONY: clean-jack-files |
| 135 | clean-jack-files: clean-dex-files |
| 136 | $(hide) find $(OUT_DIR) -name "*.jack" | xargs rm -f |
| 137 | $(hide) find $(OUT_DIR) -type d -name "jack" | xargs rm -rf |
| 138 | @echo "All jack files have been removed." |
| 139 | |
| 140 | .PHONY: clean-dex-files |
| 141 | clean-dex-files: |
| 142 | $(hide) find $(OUT_DIR) -name "*.dex" ! -path "*/jack-incremental/*" | xargs rm -f |
| 143 | $(hide) for i in `find $(OUT_DIR) -name "*.jar" -o -name "*.apk"` ; do ((unzip -l $$i 2> /dev/null | \ |
| 144 | grep -q "\.dex$$" && rm -f $$i) || continue ) ; done |
| 145 | @echo "All dex files and archives containing dex files have been removed." |
| 146 | |
| 147 | .PHONY: clean-jack-incremental |
| 148 | clean-jack-incremental: |
| 149 | $(hide) find $(OUT_DIR) -name "jack-incremental" -type d | xargs rm -rf |
| 150 | @echo "All jack incremental dirs have been removed." |