update Mon Mar 15 12:37:00 PDT 2010
[pkgsrc.git] / mk / compiler / ccache.mk
1 # $NetBSD: ccache.mk,v 1.32 2009/08/31 08:38:50 tnn Exp $
2 #
3 # Copyright (c) 2004 The NetBSD Foundation, Inc.
4 # All rights reserved.
5 #
6 # This code is derived from software contributed to The NetBSD Foundation
7 # by Johnny C. Lam.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
11 # are met:
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.
24 #
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.
36 #
37
38 # === User-settable variables ===
39 #
40 # CCACHE_BASE
41 #       The directory where ccache is installed. The build dependency on
42 #       devel/ccache is only added when this is ${LOCALBASE}.
43 #
44 #       Default: ${LOCALBASE}
45 #
46 # CCACHE_DIR
47 #       The directory where the cached compiler results are stored. By
48 #       default, they are stored inside WRKDIR, so they are lost after
49 #       a "make clean".
50 #
51 # === Package-settable variables ===
52 #
53 # IGNORE_CCACHE
54 #       Can be set to "yes" for packages that have problems with ccache.
55 #
56 # Keywords: ccache
57 #
58
59 .if !defined(COMPILER_CCACHE_MK)
60 COMPILER_CCACHE_MK=     defined
61
62 _VARGROUPS+=            ccache
63 _USER_VARS.ccache=      CCACHE_BASE CCACHE_DIR
64 _PKG_VARS.ccache=       IGNORE_CCACHE
65
66 .include "../bsd.fast.prefs.mk"
67
68 CCACHE_BASE?=   ${LOCALBASE}
69 CCACHE_DIR?=    ${WRKDIR}/.ccache-cache
70
71 _USE_CCACHE=    yes
72
73 .if ${CCACHE_BASE} == ${LOCALBASE} && (${PKGPATH} == "devel/ccache" || ${PKGPATH} == "devel/patch" || ${PKGPATH} == "pkgtools/digest")
74 _USE_CCACHE=    no
75 MAKEFLAGS+=     _USE_CCACHE=${_USE_CCACHE}
76 .endif
77
78 .if defined(IGNORE_CCACHE)
79 _USE_CCACHE=    no
80 .endif
81
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.
85 #
86 LANGUAGES.ccache=       c c++
87 _LANGUAGES.ccache=      # empty
88 .for _lang_ in ${USE_LANGUAGES}
89 _LANGUAGES.ccache+=     ${LANGUAGES.ccache:M${_lang_}}
90 .endfor
91 .if empty(_LANGUAGES.ccache)
92 _USE_CCACHE=    no
93 .endif
94
95 .if ${_USE_CCACHE} == "yes"
96
97 _CCACHE_DIR=    ${WRKDIR}/.ccache
98 _CCACHE_VARS=   # empty
99 .  if !empty(_LANGUAGES.ccache:Mc)
100 PKG_CC?=        ${CC}
101 _CCACHE_VARS+=  CC
102 _CCACHE_CC:=    ${_CCACHE_DIR}/bin/${PKG_CC:T}
103 _ALIASES.CC+=   cc
104 PKG_CC:=        ${_CCACHE_CC}
105 .  endif
106 .  if !empty(_LANGUAGES.ccache:Mc++)
107 PKG_CXX?=       ${CXX}
108 _CCACHE_VARS+=  CXX
109 _CCACHE_CXX:=   ${_CCACHE_DIR}/bin/${PKG_CXX:T}
110 _ALIASES.CXX+=  c++
111 PKG_CXX:=       ${_CCACHE_CXX}
112 .  endif
113
114 PREPEND_PATH+=  ${_CCACHE_DIR}/bin
115
116 # Add the dependency on ccache.
117 .  if ${CCACHE_BASE} == ${LOCALBASE}
118 BUILD_DEPENDS+= ccache-[0-9]*:../../devel/ccache
119 .  endif
120
121 # Override the compiler-specific hash with the version string for the
122 # compiler.
123 #
124 PKGSRC_MAKE_ENV+=       CCACHE_HASHCC=${CC_VERSION_STRING:Q}
125 PKGSRC_MAKE_ENV+=       CCACHE_DIR=${CCACHE_DIR:Q}
126
127 # Create symlinks for the compiler into ${WRKDIR}.
128 .  for _var_ in ${_CCACHE_VARS}
129 .    if !target(${_CCACHE_${_var_}})
130 override-tools: ${_CCACHE_${_var_}}
131 ${_CCACHE_${_var_}}:
132         ${RUN}${MKDIR} ${.TARGET:H}
133         ${RUN}                                  \
134         ${LN} -fs ${CCACHE_BASE}/bin/ccache ${.TARGET}
135 .      for _alias_ in ${_ALIASES.${_var_}:S/^/${.TARGET:H}\//}
136         ${RUN}                                  \
137         if [ ! -x "${_alias_}" ]; then                                  \
138                 ${LN} -fs ${CCACHE_BASE}/bin/ccache ${_alias_};         \
139         fi
140 .      endfor
141 .    endif
142 .  endfor
143 .endif  # _USE_CCACHE == "yes"
144
145 .endif  # COMPILER_CCACHE_MK