Sync Mk with ports
[dports.git] / Mk / bsd.ccache.mk
1 # $FreeBSD$
2
3 COMMANDS_Include_MAINTAINER=    portmgr@FreeBSD.org
4
5 .if !defined(_CCACHEMKINCLUDED)
6
7 _CCACHEMKINCLUDED=      yes
8
9 # HOME is always set to ${WRKDIR} now. Try to use /root/.ccache as default.
10 .if defined(WITH_CCACHE_BUILD) && !defined(CCACHE_DIR)
11 .  if defined(USER) && ${USER} == root
12 CCACHE_DIR=     /root/.ccache
13 .  else
14 NO_CCACHE=      yes
15 WARNING+=       WITH_CCACHE_BUILD support disabled, please set CCACHE_DIR.
16 .  endif
17 .endif
18
19 # Support NO_CCACHE for common setups, require WITH_CCACHE_BUILD, and
20 # don't use if ccache already set in CC
21 .if !defined(NO_CCACHE) && defined(WITH_CCACHE_BUILD) && !${CC:M*ccache*} && \
22   !defined(NO_BUILD) && !defined(NOCCACHE)
23 # Avoid depends loops between pkg and ccache
24 .       if !${.CURDIR:M*/devel/ccache} && !${.CURDIR:M*/ports-mgmt/pkg}
25 BUILD_DEPENDS+=         ${LOCALBASE}/bin/ccache:${PORTSDIR}/devel/ccache
26 .       endif
27
28 _CCACHE_PATH=   ${LOCALBASE}/libexec/ccache
29
30 # Prepend the ccache dir into the PATH and setup ccache env
31 PATH:=  ${_CCACHE_PATH}:${PATH}
32 #.MAKEFLAGS:            PATH=${PATH}
33 .if !${MAKE_ENV:MPATH=*} && !${CONFIGURE_ENV:MPATH=*}
34 MAKE_ENV+=                      PATH=${PATH}
35 CONFIGURE_ENV+=         PATH=${PATH}
36 .endif
37
38 # Ensure this is always in subchild environments
39 .       if defined(CCACHE_DIR)
40 #.MAKEFLAGS:            CCACHE_DIR=${CCACHE_DIR}
41 MAKE_ENV+=              CCACHE_DIR="${CCACHE_DIR}"
42 CONFIGURE_ENV+= CCACHE_DIR="${CCACHE_DIR}"
43 .       endif
44 .endif
45
46 .endif