blob: 5576785eca6e81f1226a66d431f243e48f33feec [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
Dan Willemsen514d4992017-07-24 22:27:17 -070016# Absolute path of the present working direcotry.
17# This overrides the shell variable $PWD, which does not necessarily points to
18# the top of the source tree, for example when "make -C" is used in m/mm/mmm.
19PWD := $(shell pwd)
20
21TOP := .
22TOPDIR :=
23
Colin Cross6cdc5d22017-10-20 11:37:33 -070024BUILD_SYSTEM := $(TOPDIR)build/make/core
Dan Willemsen514d4992017-07-24 22:27:17 -070025
26# Set up various standard variables based on configuration
27# and host information.
28include $(BUILD_SYSTEM)/config.mk
29
30include $(SOONG_MAKEVARS_MK)
31
32include $(BUILD_SYSTEM)/clang/config.mk
33
34# CTS-specific config.
35-include cts/build/config.mk
36# VTS-specific config.
37-include test/vts/tools/vts-tradefed/build/config.mk
38# device-tests-specific-config.
39-include tools/tradefederation/build/suites/device-tests/config.mk
40# general-tests-specific-config.
41-include tools/tradefederation/build/suites/general-tests/config.mk
Ying Wang50e52fa2013-02-22 18:15:29 -080042
The Android Open Source Project88b60792009-03-03 19:28:42 -080043INTERNAL_CLEAN_STEPS :=
44
45# Builds up a list of clean steps. Creates a unique
Ying Wangfa9ae7b2010-03-03 10:45:14 -080046# id for each step by taking makefile path, INTERNAL_CLEAN_BUILD_VERSION
The Android Open Source Project88b60792009-03-03 19:28:42 -080047# and appending an increasing number of '@' characters.
48#
49# $(1): shell command to run
Ying Wangfa9ae7b2010-03-03 10:45:14 -080050# $(2): indicate to not use makefile path as part of step id if not empty.
Colin Cross6cdc5d22017-10-20 11:37:33 -070051# $(2) should only be used in build/make/core/cleanspec.mk: just for compatibility.
The Android Open Source Project88b60792009-03-03 19:28:42 -080052define _add-clean-step
53 $(if $(strip $(INTERNAL_CLEAN_BUILD_VERSION)),, \
54 $(error INTERNAL_CLEAN_BUILD_VERSION not set))
Ying Wangfa9ae7b2010-03-03 10:45:14 -080055 $(eval _acs_makefile_prefix := $(lastword $(MAKEFILE_LIST)))
56 $(eval _acs_makefile_prefix := $(subst /,_,$(_acs_makefile_prefix)))
57 $(eval _acs_makefile_prefix := $(subst .,-,$(_acs_makefile_prefix)))
58 $(eval _acs_makefile_prefix := $(_acs_makefile_prefix)_acs)
59 $(if $($(_acs_makefile_prefix)),,\
60 $(eval $(_acs_makefile_prefix) := $(INTERNAL_CLEAN_BUILD_VERSION)))
61 $(eval $(_acs_makefile_prefix) := $($(_acs_makefile_prefix))@)
62 $(if $(strip $(2)),$(eval _acs_id := $($(_acs_makefile_prefix))),\
63 $(eval _acs_id := $(_acs_makefile_prefix)$($(_acs_makefile_prefix))))
The Android Open Source Project88b60792009-03-03 19:28:42 -080064 $(eval INTERNAL_CLEAN_STEPS += $(_acs_id))
65 $(eval INTERNAL_CLEAN_STEP.$(_acs_id) := $(1))
66 $(eval _acs_id :=)
Ying Wangfa9ae7b2010-03-03 10:45:14 -080067 $(eval _acs_makefile_prefix :=)
The Android Open Source Project88b60792009-03-03 19:28:42 -080068endef
69define add-clean-step
Colin Cross6cdc5d22017-10-20 11:37:33 -070070$(eval # for build/make/core/cleanspec.mk, dont use makefile path as part of step id) \
Ying Wangfa9ae7b2010-03-03 10:45:14 -080071$(if $(filter %/cleanspec.mk,$(lastword $(MAKEFILE_LIST))),\
72 $(eval $(call _add-clean-step,$(1),true)),\
73 $(eval $(call _add-clean-step,$(1))))
The Android Open Source Project88b60792009-03-03 19:28:42 -080074endef
75
76# Defines INTERNAL_CLEAN_BUILD_VERSION and the individual clean steps.
77# cleanspec.mk is outside of the core directory so that more people
78# can have permission to touch it.
Ying Wangfa9ae7b2010-03-03 10:45:14 -080079include $(BUILD_SYSTEM)/cleanspec.mk
The Android Open Source Project88b60792009-03-03 19:28:42 -080080INTERNAL_CLEAN_BUILD_VERSION := $(strip $(INTERNAL_CLEAN_BUILD_VERSION))
Ying Wangeadaa952015-08-04 12:11:54 -070081INTERNAL_CLEAN_STEPS := $(strip $(INTERNAL_CLEAN_STEPS))
The Android Open Source Project88b60792009-03-03 19:28:42 -080082
83# If the clean_steps.mk file is missing (usually after a clean build)
84# then we won't do anything.
Dan Willemsene6f75602017-07-24 21:16:38 -070085CURRENT_CLEAN_BUILD_VERSION := MISSING
The Android Open Source Project88b60792009-03-03 19:28:42 -080086CURRENT_CLEAN_STEPS := $(INTERNAL_CLEAN_STEPS)
87
88# Read the current state from the file, if present.
89# Will set CURRENT_CLEAN_BUILD_VERSION and CURRENT_CLEAN_STEPS.
90#
91clean_steps_file := $(PRODUCT_OUT)/clean_steps.mk
92-include $(clean_steps_file)
93
Dan Willemsene6f75602017-07-24 21:16:38 -070094ifeq ($(CURRENT_CLEAN_BUILD_VERSION),MISSING)
95 # Do nothing
96else ifneq ($(CURRENT_CLEAN_BUILD_VERSION),$(INTERNAL_CLEAN_BUILD_VERSION))
The Android Open Source Project88b60792009-03-03 19:28:42 -080097 # The major clean version is out-of-date. Do a full clean, and
98 # don't even bother with the clean steps.
99 $(info *** A clean build is required because of a recent change.)
100 $(shell rm -rf $(OUT_DIR))
101 $(info *** Done with the cleaning, now starting the real build.)
102else
103 # The major clean version is correct. Find the list of clean steps
104 # that we need to execute to get up-to-date.
105 steps := \
106 $(filter-out $(CURRENT_CLEAN_STEPS),$(INTERNAL_CLEAN_STEPS))
107 $(foreach step,$(steps), \
108 $(info Clean step: $(INTERNAL_CLEAN_STEP.$(step))) \
109 $(shell $(INTERNAL_CLEAN_STEP.$(step))) \
110 )
Ying Wangf6268b82014-06-18 12:07:48 -0700111
112 # Rewrite the clean step for the second arch.
113 ifdef TARGET_2ND_ARCH
114 # $(1): the clean step cmd
115 # $(2): the prefix to search for
116 # $(3): the prefix to replace with
117 define -cs-rewrite-cleanstep
118 $(if $(filter $(2)/%,$(1)),\
119 $(eval _crs_new_cmd := $(patsubst $(2)/%,$(3)/%,$(1)))\
120 $(info Clean step: $(_crs_new_cmd))\
121 $(shell $(_crs_new_cmd)))
122 endef
123 $(foreach step,$(steps), \
124 $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$(TARGET_OUT_INTERMEDIATES),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATES))\
125 $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$(TARGET_OUT_SHARED_LIBRARIES),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_SHARED_LIBRARIES))\
126 $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$(TARGET_OUT_VENDOR_SHARED_LIBRARIES),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_VENDOR_SHARED_LIBRARIES))\
127 $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATES),$(TARGET_OUT_INTERMEDIATES))\
128 $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_SHARED_LIBRARIES),$(TARGET_OUT_SHARED_LIBRARIES))\
129 $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_VENDOR_SHARED_LIBRARIES),$(TARGET_OUT_VENDOR_SHARED_LIBRARIES))\
130 )
131 endif
132 _crs_new_cmd :=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800133 steps :=
134endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800135
136# Write the new state to the file.
Ying Wang50e52fa2013-02-22 18:15:29 -0800137#
Shinichiro Hamaji14da1422015-07-21 07:28:39 +0900138ifneq ($(CURRENT_CLEAN_BUILD_VERSION)-$(CURRENT_CLEAN_STEPS),$(INTERNAL_CLEAN_BUILD_VERSION)-$(INTERNAL_CLEAN_STEPS))
Dan Willemsene6f75602017-07-24 21:16:38 -0700139$(shell mkdir -p $(dir $(clean_steps_file)))
140$(file >$(clean_steps_file).tmp,CURRENT_CLEAN_BUILD_VERSION := $(INTERNAL_CLEAN_BUILD_VERSION)$(newline)CURRENT_CLEAN_STEPS := $(INTERNAL_CLEAN_STEPS)$(newline))
141$(shell if ! cmp -s $(clean_steps_file).tmp $(clean_steps_file); then \
142 mv $(clean_steps_file).tmp $(clean_steps_file); \
143 else \
144 rm $(clean_steps_file).tmp; \
145 fi)
Shinichiro Hamaji14da1422015-07-21 07:28:39 +0900146endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800147
Shinichiro Hamaji14da1422015-07-21 07:28:39 +0900148CURRENT_CLEAN_BUILD_VERSION :=
149CURRENT_CLEAN_STEPS :=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800150clean_steps_file :=
151INTERNAL_CLEAN_STEPS :=
152INTERNAL_CLEAN_BUILD_VERSION :=