Add files from parent branch HEAD:
[pkgsrc.git] / mk / compiler / distcc.mk
1 # $NetBSD: distcc.mk,v 1.29 2006/12/15 12:46:24 martti 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 .if !defined(COMPILER_DISTCC_MK)
39 COMPILER_DISTCC_MK=     defined
40
41 .include "../../mk/bsd.prefs.mk"
42
43 .if !empty(PKGPATH:Mdevel/distcc)
44 IGNORE_DISTCC=  yes
45 MAKEFLAGS+=     IGNORE_DISTCC=yes
46 .endif
47
48 .if defined(IGNORE_DISTCC)
49 _USE_DISTCC=    NO
50 .endif
51
52 # LANGUAGES.<compiler> is the list of supported languages by the compiler.
53 # _LANGUAGES.<compiler> is ${LANGUAGES.<compiler>} restricted to the ones
54 # requested by the package in USE_LANGUAGES.
55 #
56 LANGUAGES.distcc=       c c++
57 _LANGUAGES.distcc=      # empty
58 .for _lang_ in ${USE_LANGUAGES}
59 _LANGUAGES.distcc+=     ${LANGUAGES.distcc:M${_lang_}}
60 .endfor
61 .if empty(_LANGUAGES.distcc)
62 _USE_DISTCC=    NO
63 .endif
64
65 .if !defined(_USE_DISTCC)
66 _USE_DISTCC=    YES
67 .endif
68
69 .if !empty(_USE_DISTCC:M[yY][eE][sS])
70 EVAL_PREFIX+=           _DISTCCBASE=distcc
71 _DISTCCBASE_DEFAULT=    ${LOCALBASE}
72
73 _DISTCC_DIR=    ${WRKDIR}/.distcc
74 _DISTCC_VARS=   # empty
75 .  if !empty(_LANGUAGES.distcc:Mc)
76 PKG_CC?=        ${CC}
77 _DISTCC_VARS+=  CC
78 _DISTCC_CC:=    ${_DISTCC_DIR}/bin/${PKG_CC:T}
79 _ALIASES.CC+=   cc
80 PKG_CC:=        ${_DISTCC_CC}
81 .  endif
82 .  if !empty(_LANGUAGES.distcc:Mc++)
83 PKG_CXX?=       ${CXX}
84 _DISTCC_VARS+=  CXX
85 _DISTCC_CXX:=   ${_DISTCC_DIR}/bin/${PKG_CXX:T}
86 _ALIASES.CXX+=  c++
87 PKG_CXX:=       ${_DISTCC_CXX}
88 .  endif
89
90 # Prepend the path to the compiler to the PATH.
91 .  if !empty(_LANGUAGES.distcc)
92 PREPEND_PATH+=  ${_DISTCC_DIR}/bin
93 .  endif
94
95 # Add the dependency on distcc.
96 BUILD_DEPENDS+= distcc-[0-9]*:../../devel/distcc
97
98 .  if defined(DISTCC_HOSTS) && !empty(DISTCC_HOSTS)
99 PKGSRC_MAKE_ENV+=       DISTCC_HOSTS=${DISTCC_HOSTS:Q}
100 .  endif
101 .  if defined(DISTCC_SSH) && !empty(DISTCC_SSH)
102 PKGSRC_MAKE_ENV+=       DISTCC_SSH=${DISTCC_SSH:Q}
103 .  endif
104 .  if defined(DISTCC_VERBOSE) && !empty(DISTCC_VERBOSE)
105 PKGSRC_MAKE_ENV+=       DISTCC_VERBOSE=${DISTCC_VERBOSE:Q}
106 .  endif
107
108 # Create symlinks for the compiler into ${WRKDIR}.
109 .  for _var_ in ${_DISTCC_VARS}
110 .    if !target(${_DISTCC_${_var_}})
111 override-tools: ${_DISTCC_${_var_}}
112 ${_DISTCC_${_var_}}:
113         ${RUN}${MKDIR} ${.TARGET:H}
114         ${RUN}                                  \
115         ${LN} -fs ${_DISTCCBASE}/bin/distcc ${.TARGET}
116 .      for _alias_ in ${_ALIASES.${_var_}:S/^/${.TARGET:H}\//}
117         ${RUN}                                  \
118         if [ ! -x "${_alias_}" ]; then                                  \
119                 ${LN} -fs ${_DISTCCBASE}/bin/distcc ${_alias_};         \
120         fi
121 .      endfor
122 .    endif
123 .  endfor
124 .endif  # _USE_DISTCC == "yes"
125
126 .endif # COMPILER_DISTCC_MK