blob: f41f1b7c4125280a179c33ee57d0263a676bcec3 [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
Dan Willemsen514d4992017-07-24 22:27:17 -070036# device-tests-specific-config.
37-include tools/tradefederation/build/suites/device-tests/config.mk
38# general-tests-specific-config.
39-include tools/tradefederation/build/suites/general-tests/config.mk
Ying Wang50e52fa2013-02-22 18:15:29 -080040
The Android Open Source Project88b60792009-03-03 19:28:42 -080041INTERNAL_CLEAN_STEPS :=
42
43# Builds up a list of clean steps. Creates a unique
Ying Wangfa9ae7b2010-03-03 10:45:14 -080044# id for each step by taking makefile path, INTERNAL_CLEAN_BUILD_VERSION
The Android Open Source Project88b60792009-03-03 19:28:42 -080045# and appending an increasing number of '@' characters.
46#
47# $(1): shell command to run
Ying Wangfa9ae7b2010-03-03 10:45:14 -080048# $(2): indicate to not use makefile path as part of step id if not empty.
Colin Cross6cdc5d22017-10-20 11:37:33 -070049# $(2) should only be used in build/make/core/cleanspec.mk: just for compatibility.
The Android Open Source Project88b60792009-03-03 19:28:42 -080050define _add-clean-step
51 $(if $(strip $(INTERNAL_CLEAN_BUILD_VERSION)),, \
52 $(error INTERNAL_CLEAN_BUILD_VERSION not set))
Ying Wangfa9ae7b2010-03-03 10:45:14 -080053 $(eval _acs_makefile_prefix := $(lastword $(MAKEFILE_LIST)))
54 $(eval _acs_makefile_prefix := $(subst /,_,$(_acs_makefile_prefix)))
55 $(eval _acs_makefile_prefix := $(subst .,-,$(_acs_makefile_prefix)))
56 $(eval _acs_makefile_prefix := $(_acs_makefile_prefix)_acs)
57 $(if $($(_acs_makefile_prefix)),,\
58 $(eval $(_acs_makefile_prefix) := $(INTERNAL_CLEAN_BUILD_VERSION)))
59 $(eval $(_acs_makefile_prefix) := $($(_acs_makefile_prefix))@)
60 $(if $(strip $(2)),$(eval _acs_id := $($(_acs_makefile_prefix))),\
61 $(eval _acs_id := $(_acs_makefile_prefix)$($(_acs_makefile_prefix))))
The Android Open Source Project88b60792009-03-03 19:28:42 -080062 $(eval INTERNAL_CLEAN_STEPS += $(_acs_id))
63 $(eval INTERNAL_CLEAN_STEP.$(_acs_id) := $(1))
64 $(eval _acs_id :=)
Ying Wangfa9ae7b2010-03-03 10:45:14 -080065 $(eval _acs_makefile_prefix :=)
The Android Open Source Project88b60792009-03-03 19:28:42 -080066endef
67define add-clean-step
Colin Cross6cdc5d22017-10-20 11:37:33 -070068$(eval # for build/make/core/cleanspec.mk, dont use makefile path as part of step id) \
Ying Wangfa9ae7b2010-03-03 10:45:14 -080069$(if $(filter %/cleanspec.mk,$(lastword $(MAKEFILE_LIST))),\
70 $(eval $(call _add-clean-step,$(1),true)),\
71 $(eval $(call _add-clean-step,$(1))))
The Android Open Source Project88b60792009-03-03 19:28:42 -080072endef
73
74# Defines INTERNAL_CLEAN_BUILD_VERSION and the individual clean steps.
75# cleanspec.mk is outside of the core directory so that more people
76# can have permission to touch it.
Ying Wangfa9ae7b2010-03-03 10:45:14 -080077include $(BUILD_SYSTEM)/cleanspec.mk
The Android Open Source Project88b60792009-03-03 19:28:42 -080078INTERNAL_CLEAN_BUILD_VERSION := $(strip $(INTERNAL_CLEAN_BUILD_VERSION))
Ying Wangeadaa952015-08-04 12:11:54 -070079INTERNAL_CLEAN_STEPS := $(strip $(INTERNAL_CLEAN_STEPS))
The Android Open Source Project88b60792009-03-03 19:28:42 -080080
81# If the clean_steps.mk file is missing (usually after a clean build)
82# then we won't do anything.
Dan Willemsene6f75602017-07-24 21:16:38 -070083CURRENT_CLEAN_BUILD_VERSION := MISSING
The Android Open Source Project88b60792009-03-03 19:28:42 -080084CURRENT_CLEAN_STEPS := $(INTERNAL_CLEAN_STEPS)
85
86# Read the current state from the file, if present.
87# Will set CURRENT_CLEAN_BUILD_VERSION and CURRENT_CLEAN_STEPS.
88#
89clean_steps_file := $(PRODUCT_OUT)/clean_steps.mk
90-include $(clean_steps_file)
91
Dan Willemsene6f75602017-07-24 21:16:38 -070092ifeq ($(CURRENT_CLEAN_BUILD_VERSION),MISSING)
93 # Do nothing
94else ifneq ($(CURRENT_CLEAN_BUILD_VERSION),$(INTERNAL_CLEAN_BUILD_VERSION))
The Android Open Source Project88b60792009-03-03 19:28:42 -080095 # The major clean version is out-of-date. Do a full clean, and
96 # don't even bother with the clean steps.
97 $(info *** A clean build is required because of a recent change.)
98 $(shell rm -rf $(OUT_DIR))
99 $(info *** Done with the cleaning, now starting the real build.)
100else
101 # The major clean version is correct. Find the list of clean steps
102 # that we need to execute to get up-to-date.
103 steps := \
104 $(filter-out $(CURRENT_CLEAN_STEPS),$(INTERNAL_CLEAN_STEPS))
105 $(foreach step,$(steps), \
106 $(info Clean step: $(INTERNAL_CLEAN_STEP.$(step))) \
107 $(shell $(INTERNAL_CLEAN_STEP.$(step))) \
108 )
Ying Wangf6268b82014-06-18 12:07:48 -0700109
110 # Rewrite the clean step for the second arch.
111 ifdef TARGET_2ND_ARCH
112 # $(1): the clean step cmd
113 # $(2): the prefix to search for
114 # $(3): the prefix to replace with
115 define -cs-rewrite-cleanstep
116 $(if $(filter $(2)/%,$(1)),\
117 $(eval _crs_new_cmd := $(patsubst $(2)/%,$(3)/%,$(1)))\
118 $(info Clean step: $(_crs_new_cmd))\
119 $(shell $(_crs_new_cmd)))
120 endef
121 $(foreach step,$(steps), \
122 $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$(TARGET_OUT_INTERMEDIATES),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATES))\
123 $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$(TARGET_OUT_SHARED_LIBRARIES),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_SHARED_LIBRARIES))\
124 $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$(TARGET_OUT_VENDOR_SHARED_LIBRARIES),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_VENDOR_SHARED_LIBRARIES))\
125 $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATES),$(TARGET_OUT_INTERMEDIATES))\
126 $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_SHARED_LIBRARIES),$(TARGET_OUT_SHARED_LIBRARIES))\
127 $(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_VENDOR_SHARED_LIBRARIES),$(TARGET_OUT_VENDOR_SHARED_LIBRARIES))\
128 )
129 endif
130 _crs_new_cmd :=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800131 steps :=
132endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800133
134# Write the new state to the file.
Ying Wang50e52fa2013-02-22 18:15:29 -0800135#
Shinichiro Hamaji14da1422015-07-21 07:28:39 +0900136ifneq ($(CURRENT_CLEAN_BUILD_VERSION)-$(CURRENT_CLEAN_STEPS),$(INTERNAL_CLEAN_BUILD_VERSION)-$(INTERNAL_CLEAN_STEPS))
Dan Willemsene6f75602017-07-24 21:16:38 -0700137$(shell mkdir -p $(dir $(clean_steps_file)))
138$(file >$(clean_steps_file).tmp,CURRENT_CLEAN_BUILD_VERSION := $(INTERNAL_CLEAN_BUILD_VERSION)$(newline)CURRENT_CLEAN_STEPS := $(INTERNAL_CLEAN_STEPS)$(newline))
139$(shell if ! cmp -s $(clean_steps_file).tmp $(clean_steps_file); then \
140 mv $(clean_steps_file).tmp $(clean_steps_file); \
141 else \
142 rm $(clean_steps_file).tmp; \
143 fi)
Shinichiro Hamaji14da1422015-07-21 07:28:39 +0900144endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800145
Shinichiro Hamaji14da1422015-07-21 07:28:39 +0900146CURRENT_CLEAN_BUILD_VERSION :=
147CURRENT_CLEAN_STEPS :=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800148clean_steps_file :=
149INTERNAL_CLEAN_STEPS :=
150INTERNAL_CLEAN_BUILD_VERSION :=