Sync Mk with ports
[dports.git] / Mk / bsd.ccache.mk
1 # $FreeBSD$
2 #-*- tab-width: 4; -*-
3 # ex:ts=4
4 #
5 # WITH_CCACHE_BUILD=yes enables depending on ccache and using it in the build.
6 # NO_CCACHE_DEPEND will additionally not add the dependency on ccache.
7 # NO_CCACHE will disable this entirely.
8
9 COMMANDS_Include_MAINTAINER=    portmgr@FreeBSD.org
10
11 .if !defined(_CCACHEMKINCLUDED)
12
13 _CCACHEMKINCLUDED=      yes
14
15 # HOME is always set to ${WRKDIR} now. Try to use /root/.ccache as default.
16 .if defined(WITH_CCACHE_BUILD) && !defined(CCACHE_DIR)
17 .  if defined(USER) && ${USER} == root
18 CCACHE_DIR=     /root/.ccache
19 .  else
20 NO_CCACHE=      yes
21 WARNING+=       WITH_CCACHE_BUILD support disabled, please set CCACHE_DIR.
22 .  endif
23 .endif
24
25 # Support NO_CCACHE for common setups, require WITH_CCACHE_BUILD, and
26 # don't use if ccache already set in CC
27 .if !defined(NO_CCACHE) && defined(WITH_CCACHE_BUILD) && !${CC:M*ccache*} && \
28   !defined(NO_BUILD) && !defined(NOCCACHE)
29
30 # Avoid depends loops between ccache and pkg
31 .       if !defined(NO_CCACHE_DEPEND) && \
32     ${PKGORIGIN} != ${PKG_ORIGIN}
33 BUILD_DEPENDS+=         ${LOCALBASE}/bin/ccache:devel/ccache
34 .       endif
35
36 CCACHE_WRAPPER_PATH?=   ${LOCALBASE}/libexec/ccache
37
38 .if exists(${CCACHE_WRAPPER_PATH})
39 # Prepend the ccache dir into the PATH and setup ccache env
40 PATH:=  ${CCACHE_WRAPPER_PATH}:${PATH}
41 #.MAKEFLAGS:            PATH=${PATH}
42 .if !${MAKE_ENV:MPATH=*} && !${CONFIGURE_ENV:MPATH=*}
43 MAKE_ENV+=                      PATH=${PATH}
44 CONFIGURE_ENV+=         PATH=${PATH}
45 .endif
46
47 # Ensure this is always in subchild environments
48 .       if defined(CCACHE_DIR)
49 #.MAKEFLAGS:            CCACHE_DIR=${CCACHE_DIR}
50 MAKE_ENV+=              CCACHE_DIR="${CCACHE_DIR}"
51 CONFIGURE_ENV+= CCACHE_DIR="${CCACHE_DIR}"
52 .       endif
53 .endif
54
55 # Some ports will truncate CCACHE_DIR from the env and due to HOME=${WRKDIR}
56 # will incorrectly use ${WRKDIR}/.ccache.  Symlink to the proper place.
57 ${WRKDIR}/.ccache: ${WRKDIR}
58         @${LN} -sf ${CCACHE_DIR} ${WRKDIR}/.ccache
59 ccache-wrkdir-link: ${WRKDIR}/.ccache .PHONY
60 post-extract: ccache-wrkdir-link
61 .endif
62
63 .endif