blob: b2e04a7ddb6411bd9e90fa2fd38b60c6cde542b4 [file] [log] [blame]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001# 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
19# id for each step by taking INTERNAL_CLEAN_BUILD_VERSION
20# and appending an increasing number of '@' characters.
21#
22# $(1): shell command to run
23define _add-clean-step
24 $(if $(strip $(INTERNAL_CLEAN_BUILD_VERSION)),, \
25 $(error INTERNAL_CLEAN_BUILD_VERSION not set))
26 $(eval _acs_id := $(strip $(lastword $(INTERNAL_CLEAN_STEPS))))
27 $(if $(_acs_id),,$(eval _acs_id := $(INTERNAL_CLEAN_BUILD_VERSION)))
28 $(eval _acs_id := $(_acs_id)@)
29 $(eval INTERNAL_CLEAN_STEPS += $(_acs_id))
30 $(eval INTERNAL_CLEAN_STEP.$(_acs_id) := $(1))
31 $(eval _acs_id :=)
32endef
33define add-clean-step
34$(if $(call _add-clean-step,$(1)),)
35endef
36
37# Defines INTERNAL_CLEAN_BUILD_VERSION and the individual clean steps.
38# cleanspec.mk is outside of the core directory so that more people
39# can have permission to touch it.
40include build/cleanspec.mk
41INTERNAL_CLEAN_BUILD_VERSION := $(strip $(INTERNAL_CLEAN_BUILD_VERSION))
42
43# If the clean_steps.mk file is missing (usually after a clean build)
44# then we won't do anything.
45CURRENT_CLEAN_BUILD_VERSION := $(INTERNAL_CLEAN_BUILD_VERSION)
46CURRENT_CLEAN_STEPS := $(INTERNAL_CLEAN_STEPS)
47
48# Read the current state from the file, if present.
49# Will set CURRENT_CLEAN_BUILD_VERSION and CURRENT_CLEAN_STEPS.
50#
51clean_steps_file := $(PRODUCT_OUT)/clean_steps.mk
52-include $(clean_steps_file)
53
54ifneq ($(CURRENT_CLEAN_BUILD_VERSION),$(INTERNAL_CLEAN_BUILD_VERSION))
55 # The major clean version is out-of-date. Do a full clean, and
56 # don't even bother with the clean steps.
57 $(info *** A clean build is required because of a recent change.)
58 $(shell rm -rf $(OUT_DIR))
59 $(info *** Done with the cleaning, now starting the real build.)
60else
61 # The major clean version is correct. Find the list of clean steps
62 # that we need to execute to get up-to-date.
63 steps := \
64 $(filter-out $(CURRENT_CLEAN_STEPS),$(INTERNAL_CLEAN_STEPS))
65 $(foreach step,$(steps), \
66 $(info Clean step: $(INTERNAL_CLEAN_STEP.$(step))) \
67 $(shell $(INTERNAL_CLEAN_STEP.$(step))) \
68 )
69 steps :=
70endif
71CURRENT_CLEAN_BUILD_VERSION :=
72CURRENT_CLEAN_STEPS :=
73
74# Write the new state to the file.
75#
76$(shell \
77 mkdir -p $(dir $(clean_steps_file)) && \
78 echo "CURRENT_CLEAN_BUILD_VERSION := $(INTERNAL_CLEAN_BUILD_VERSION)" > \
79 $(clean_steps_file) ;\
80 echo "CURRENT_CLEAN_STEPS := $(INTERNAL_CLEAN_STEPS)" >> \
81 $(clean_steps_file) \
82 )
83
84clean_steps_file :=
85INTERNAL_CLEAN_STEPS :=
86INTERNAL_CLEAN_BUILD_VERSION :=