1 # $NetBSD: ccache.mk,v 1.32 2009/08/31 08:38:50 tnn Exp $
3 # Copyright (c) 2004 The NetBSD Foundation, Inc.
6 # This code is derived from software contributed to The NetBSD Foundation
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
12 # 1. Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # 2. Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in the
16 # documentation and/or other materials provided with the distribution.
17 # 3. All advertising materials mentioning features or use of this software
18 # must display the following acknowledgement:
19 # This product includes software developed by the NetBSD
20 # Foundation, Inc. and its contributors.
21 # 4. Neither the name of The NetBSD Foundation nor the names of its
22 # contributors may be used to endorse or promote products derived
23 # from this software without specific prior written permission.
25 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 # POSSIBILITY OF SUCH DAMAGE.
38 # === User-settable variables ===
41 # The directory where ccache is installed. The build dependency on
42 # devel/ccache is only added when this is ${LOCALBASE}.
44 # Default: ${LOCALBASE}
47 # The directory where the cached compiler results are stored. By
48 # default, they are stored inside WRKDIR, so they are lost after
51 # === Package-settable variables ===
54 # Can be set to "yes" for packages that have problems with ccache.
59 .if !defined(COMPILER_CCACHE_MK)
60 COMPILER_CCACHE_MK= defined
63 _USER_VARS.ccache= CCACHE_BASE CCACHE_DIR
64 _PKG_VARS.ccache= IGNORE_CCACHE
66 .include "../bsd.fast.prefs.mk"
68 CCACHE_BASE?= ${LOCALBASE}
69 CCACHE_DIR?= ${WRKDIR}/.ccache-cache
73 .if ${CCACHE_BASE} == ${LOCALBASE} && (${PKGPATH} == "devel/ccache" || ${PKGPATH} == "devel/patch" || ${PKGPATH} == "pkgtools/digest")
75 MAKEFLAGS+= _USE_CCACHE=${_USE_CCACHE}
78 .if defined(IGNORE_CCACHE)
82 # LANGUAGES.<compiler> is the list of supported languages by the compiler.
83 # _LANGUAGES.<compiler> is ${LANGUAGES.<compiler>} restricted to the ones
84 # requested by the package in USE_LANGUAGES.
86 LANGUAGES.ccache= c c++
87 _LANGUAGES.ccache= # empty
88 .for _lang_ in ${USE_LANGUAGES}
89 _LANGUAGES.ccache+= ${LANGUAGES.ccache:M${_lang_}}
91 .if empty(_LANGUAGES.ccache)
95 .if ${_USE_CCACHE} == "yes"
97 _CCACHE_DIR= ${WRKDIR}/.ccache
99 . if !empty(_LANGUAGES.ccache:Mc)
102 _CCACHE_CC:= ${_CCACHE_DIR}/bin/${PKG_CC:T}
104 PKG_CC:= ${_CCACHE_CC}
106 . if !empty(_LANGUAGES.ccache:Mc++)
109 _CCACHE_CXX:= ${_CCACHE_DIR}/bin/${PKG_CXX:T}
111 PKG_CXX:= ${_CCACHE_CXX}
114 PREPEND_PATH+= ${_CCACHE_DIR}/bin
116 # Add the dependency on ccache.
117 . if ${CCACHE_BASE} == ${LOCALBASE}
118 BUILD_DEPENDS+= ccache-[0-9]*:../../devel/ccache
121 # Override the compiler-specific hash with the version string for the
124 PKGSRC_MAKE_ENV+= CCACHE_HASHCC=${CC_VERSION_STRING:Q}
125 PKGSRC_MAKE_ENV+= CCACHE_DIR=${CCACHE_DIR:Q}
127 # Create symlinks for the compiler into ${WRKDIR}.
128 . for _var_ in ${_CCACHE_VARS}
129 . if !target(${_CCACHE_${_var_}})
130 override-tools: ${_CCACHE_${_var_}}
132 ${RUN}${MKDIR} ${.TARGET:H}
134 ${LN} -fs ${CCACHE_BASE}/bin/ccache ${.TARGET}
135 . for _alias_ in ${_ALIASES.${_var_}:S/^/${.TARGET:H}\//}
137 if [ ! -x "${_alias_}" ]; then \
138 ${LN} -fs ${CCACHE_BASE}/bin/ccache ${_alias_}; \
143 .endif # _USE_CCACHE == "yes"
145 .endif # COMPILER_CCACHE_MK