summaryrefslogtreecommitdiffstats
path: root/core/ccache.mk
blob: bd60ebf265194664fd567c3226a4fa70df08e377 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#
# Copyright (C) 2015 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

ifneq ($(USE_CCACHE),)
  # The default check uses size and modification time, causing false misses
  # since the mtime depends when the repo was checked out
  export CCACHE_COMPILERCHECK := content

  # See man page, optimizations to get more cache hits
  # implies that __DATE__ and __TIME__ are not critical for functionality.
  # Ignore include file modification time since it will depend on when
  # the repo was checked out
  export CCACHE_SLOPPINESS := time_macros,include_file_mtime,file_macro

  # Turn all preprocessor absolute paths into relative paths.
  # Fixes absolute paths in preprocessed source due to use of -g.
  # We don't really use system headers much so the rootdir is
  # fine; ensures these paths are relative for all Android trees
  # on a workstation.
  ifeq ($(CCACHE_BASEDIR),)
    export CCACHE_BASEDIR := $(ANDROID_BUILD_TOP)
  endif

  # Workaround for ccache with clang.
  # See http://petereisentraut.blogspot.com/2011/09/ccache-and-clang-part-2.html
  export CCACHE_CPP2 := true

  # Detect if the system already has ccache installed to use instead of the prebuilt
  ccache := $(shell which ccache)

  ifeq ($(ccache),)
    CCACHE_HOST_TAG := $(HOST_PREBUILT_TAG)
    # If we are cross-compiling Windows binaries on Linux
    # then use the linux ccache binary instead.
    ifeq ($(HOST_OS)-$(BUILD_OS),windows-linux)
      CCACHE_HOST_TAG := linux-$(HOST_PREBUILT_ARCH)
    endif
    ccache := prebuilts/misc/$(CCACHE_HOST_TAG)/ccache/ccache
  endif

  # Check that the executable is here.
  ccache := $(strip $(wildcard $(ccache)))
  ifdef ccache
    ifndef CC_WRAPPER
      CC_WRAPPER := $(ccache)
    endif
    ifndef CXX_WRAPPER
      CXX_WRAPPER := $(ccache)
    endif
    ifeq ($(ANDROID_CCACHE_DIR), $(CCACHE_DIR))
      ifneq ($(ANDROID_CCACHE_SIZE),)
        ACCSIZE_RESULT := $(shell $(ccache) -M$(ANDROID_CCACHE_SIZE))
      endif
    endif
    ccache =
    ACCSIZE_RESULT =
  endif
endif