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 16# 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 24BUILD_SYSTEM := $(TOPDIR)build/make/core 25 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# 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 40 41INTERNAL_CLEAN_STEPS := 42 43# Builds up a list of clean steps. Creates a unique 44# id for each step by taking makefile path, INTERNAL_CLEAN_BUILD_VERSION 45# and appending an increasing number of '@' characters. 46# 47# $(1): shell command to run 48# $(2): indicate to not use makefile path as part of step id if not empty. 49# $(2) should only be used in build/make/core/cleanspec.mk: just for compatibility. 50define _add-clean-step 51 $(if $(strip $(INTERNAL_CLEAN_BUILD_VERSION)),, \ 52 $(error INTERNAL_CLEAN_BUILD_VERSION not set)) 53 $(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)))) 62 $(eval INTERNAL_CLEAN_STEPS += $(_acs_id)) 63 $(eval INTERNAL_CLEAN_STEP.$(_acs_id) := $(1)) 64 $(eval _acs_id :=) 65 $(eval _acs_makefile_prefix :=) 66endef 67define add-clean-step 68$(eval # for build/make/core/cleanspec.mk, dont use makefile path as part of step id) \ 69$(if $(filter %/cleanspec.mk,$(lastword $(MAKEFILE_LIST))),\ 70 $(eval $(call _add-clean-step,$(1),true)),\ 71 $(eval $(call _add-clean-step,$(1)))) 72endef 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. 77include $(BUILD_SYSTEM)/cleanspec.mk 78INTERNAL_CLEAN_BUILD_VERSION := $(strip $(INTERNAL_CLEAN_BUILD_VERSION)) 79INTERNAL_CLEAN_STEPS := $(strip $(INTERNAL_CLEAN_STEPS)) 80 81# If the clean_steps.mk file is missing (usually after a clean build) 82# then we won't do anything. 83CURRENT_CLEAN_BUILD_VERSION := MISSING 84CURRENT_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 92ifeq ($(CURRENT_CLEAN_BUILD_VERSION),MISSING) 93 # Do nothing 94else ifneq ($(CURRENT_CLEAN_BUILD_VERSION),$(INTERNAL_CLEAN_BUILD_VERSION)) 95 # 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 ) 109 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 := 131 steps := 132endif 133 134# Write the new state to the file. 135# 136ifneq ($(CURRENT_CLEAN_BUILD_VERSION)-$(CURRENT_CLEAN_STEPS),$(INTERNAL_CLEAN_BUILD_VERSION)-$(INTERNAL_CLEAN_STEPS)) 137$(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) 144endif 145 146CURRENT_CLEAN_BUILD_VERSION := 147CURRENT_CLEAN_STEPS := 148clean_steps_file := 149INTERNAL_CLEAN_STEPS := 150INTERNAL_CLEAN_BUILD_VERSION := 151