pullup 3232
[pkgsrcv2.git] / mk / compiler.mk
1 # $NetBSD: compiler.mk,v 1.69 2009/05/30 18:16:26 joerg Exp $
2 #
3 # This Makefile fragment implements handling for supported C/C++/Fortran
4 # compilers.
5 #
6 # The following variables may be set by the pkgsrc user in mk.conf:
7 #
8 # PKGSRC_COMPILER
9 #       A list of values specifying the chain of compilers to be used by
10 #       pkgsrc to build packages.
11 #
12 #       Valid values are:
13 #               ccc             Compaq C Compilers (Tru64)
14 #               ccache          compiler cache (chainable)
15 #               distcc          distributed C/C++ (chainable)
16 #               f2c             Fortran 77 to C compiler (chainable)
17 #               icc             Intel C++ Compiler (Linux)
18 #               ido             SGI IRIS Development Option cc (IRIX 5)
19 #               gcc             GNU
20 #               hp              HP-UX C/aC++ compilers
21 #               mipspro         Silicon Graphics, Inc. MIPSpro (n32/n64)
22 #               mipspro-ucode   Silicon Graphics, Inc. MIPSpro (o32)
23 #               pcc             Portable C Compiler
24 #               sunpro          Sun Microsystems, Inc. WorkShip/Forte/Sun
25 #                               ONE Studio
26 #               xlc             IBM's XL C/C++ compiler suite (Darwin/MacOSX)
27 #
28 #       The default is "gcc".  You can use ccache and/or distcc with
29 #       an appropriate PKGSRC_COMPILER setting, e.g. "ccache distcc
30 #       gcc".  You can also use "f2c" to overlay the lang/f2c package
31 #       over the C compiler instead of using the system Fortran
32 #       compiler.  The chain should always end in a real compiler.
33 #       This should only be set in /etc/mk.conf.
34 #
35 # USE_PKGSRC_GCC
36 #       Force using the appropriate version of GCC from pkgsrc based on
37 #       GCC_REQD instead of the native compiler.
38 #
39 #       This should be disabled only for debugging.
40 #
41 # COMPILER_USE_SYMLINKS
42 #       If set to yes, use symlinks for the compiler drivers, otherwise
43 #       shell scripts are created.  The default is yes.
44 #
45 # The following variables may be set by a package:
46 #
47 # GCC_REQD
48 #       A list of version numbers used to determine the minimum
49 #       version of GCC required by a package.  This value should only
50 #       be appended to by a package Makefile.
51 #
52 #       NOTE: Be conservative when setting GCC_REQD, as lang/gcc3 is
53 #       known not to build on some platforms, e.g. Darwin.  If gcc3 is
54 #       required, set GCC_REQD=3.0 so that we do not try to pull in
55 #       lang/gcc3 unnecessarily and have it fail.
56 #
57 # USE_LANGUAGES
58 #       Lists the languages used in the source code of the package,
59 #       and is used to determine the correct compilers to install.
60 #       Valid values are: c, c99, c++, fortran, java, objc.  The
61 #       default is "c".
62 #
63 # The following variables are defined, and available for testing in
64 # package Makefiles:
65 #
66 # CC_VERSION
67 #       The compiler and version being used, e.g.,
68 #
69 #       .include "../../mk/compiler.mk"
70 #
71 #       .if !empty(CC_VERSION:Mgcc-3*)
72 #       ...
73 #       .endif
74 #
75 # Keywords: compiler
76
77 .if !defined(BSD_COMPILER_MK)
78 BSD_COMPILER_MK=        defined
79
80 _VARGROUPS+=            compiler
81 _USER_VARS.compiler=    PKGSRC_COMPILER USE_PKGSRC_GCC ABI COMPILER_USE_SYMLINKS
82 _PKG_VARS.compiler=     USE_LANGUAGES GCC_REQD NOT_FOR_COMPILER ONLY_FOR_COMPILER
83 _SYS_VARS.compiler=     CC_VERSION
84
85 .include "bsd.fast.prefs.mk"
86
87 # Since most packages need a C compiler, this is the default value.
88 USE_LANGUAGES?= c
89
90 # Add c support if c99 is set
91 .if !empty(USE_LANGUAGES:Mc99)
92 USE_LANGUAGES+= c
93 .endif
94
95 COMPILER_USE_SYMLINKS?= yes
96
97 # For environments where there is an external gcc too, but pkgsrc
98 # should use the pkgsrc one for consistency.
99 #
100 .if defined(USE_PKGSRC_GCC)
101 _USE_PKGSRC_GCC=        yes
102 .endif
103
104 _COMPILERS=             ccc gcc icc ido mipspro mipspro-ucode sunpro xlc hp pcc
105 _PSEUDO_COMPILERS=      ccache distcc f2c g95
106
107 .if defined(NOT_FOR_COMPILER) && !empty(NOT_FOR_COMPILER)
108 .  for _compiler_ in ${_COMPILERS}
109 .    if ${NOT_FOR_COMPILER:M${_compiler_}} == ""
110 _ACCEPTABLE_COMPILERS+= ${_compiler_}
111 .    endif
112 .  endfor
113 .elif defined(ONLY_FOR_COMPILER) && !empty(ONLY_FOR_COMPILER)
114 .  for _compiler_ in ${_COMPILERS}
115 .    if ${ONLY_FOR_COMPILER:M${_compiler_}} != ""
116 _ACCEPTABLE_COMPILERS+= ${_compiler_}
117 .    endif
118 .  endfor
119 .else
120 _ACCEPTABLE_COMPILERS+= ${_COMPILERS}
121 .endif
122
123 .if defined(_ACCEPTABLE_COMPILERS)
124 .  for _acceptable_ in ${_ACCEPTABLE_COMPILERS}
125 .    for _compiler_ in ${PKGSRC_COMPILER}
126 .      if !empty(_ACCEPTABLE_COMPILERS:M${_compiler_}) && !defined(_COMPILER)
127 _COMPILER=      ${_compiler_}
128 .      endif
129 .    endfor
130 .  endfor
131 .endif
132
133 .if !defined(_COMPILER)
134 PKG_FAIL_REASON+=       "No acceptable compiler found for ${PKGNAME}."
135 .endif
136
137 .for _compiler_ in ${PKGSRC_COMPILER}
138 .  if !empty(_PSEUDO_COMPILERS:M${_compiler_})
139 _PKGSRC_COMPILER:=      ${_compiler_} ${_PKGSRC_COMPILER}
140 .  endif
141 .endfor
142 _PKGSRC_COMPILER:=      ${_COMPILER} ${_PKGSRC_COMPILER}
143
144 _COMPILER_STRIP_VARS=   # empty
145
146 .for _compiler_ in ${_PKGSRC_COMPILER}
147 .  include "compiler/${_compiler_}.mk"
148 .endfor
149 .undef _compiler_
150
151 .if !defined(PKG_CPP)
152 PKG_CPP:=${CPP}
153 .endif
154
155 # Strip the leading paths from the toolchain variables since we manipulate
156 # the PATH to use the correct executable.
157 #
158 .for _var_ in ${_COMPILER_STRIP_VARS}
159 .  if empty(${_var_}:C/^/_asdf_/1:N_asdf_*)
160 ${_var_}:=      ${${_var_}:C/^/_asdf_/1:M_asdf_*:S/^_asdf_//:T}
161 .  else
162 ${_var_}:=      ${${_var_}:C/^/_asdf_/1:M_asdf_*:S/^_asdf_//:T} ${${_var_}:C/^/_asdf_/1:N_asdf_*}
163 .  endif
164 .endfor
165
166 .if defined(ABI) && !empty(ABI)
167 _WRAP_EXTRA_ARGS.CC+=   ${_COMPILER_ABI_FLAG.${ABI}}
168 _WRAP_EXTRA_ARGS.CXX+=  ${_COMPILER_ABI_FLAG.${ABI}}
169 _WRAP_EXTRA_ARGS.LD+=   ${_LINKER_ABI_FLAG.${ABI}}
170 .endif
171
172 # If the languages are not requested, force them not to be available
173 # in the generated wrappers.
174 #
175 _FAIL_WRAPPER.CC=       ${WRKDIR}/.compiler/bin/c-fail-wrapper
176 _FAIL_WRAPPER.CXX=      ${WRKDIR}/.compiler/bin/c++-fail-wrapper
177 _FAIL_WRAPPER.FC=       ${WRKDIR}/.compiler/bin/fortran-fail-wrapper
178
179 ${_FAIL_WRAPPER.CC}: fail-wrapper
180 ${_FAIL_WRAPPER.CXX}: fail-wrapper
181 ${_FAIL_WRAPPER.FC}: fail-wrapper
182
183 .PHONY: fail-wrapper
184 fail-wrapper: .USE
185         ${RUN}${MKDIR} ${.TARGET:H}
186         ${RUN}                                  \
187         exec 1>${.TARGET};                                              \
188         ${ECHO} '#!'${TOOLS_SHELL:Q};                                   \
189         ${ECHO} 'wrapperlog="$${TOOLS_WRAPPER_LOG-'${_TOOLS_WRAP_LOG:Q}'}"'; \
190         ${ECHO} 'lang="${.TARGET:T:S/-fail-wrapper//}"'; \
191         ${ECHO} 'msg="*** Please consider adding $$lang to USE_LANGUAGES in the package Makefile."'; \
192         ${ECHO} '${ECHO} "$$msg" >> $$wrapperlog'; \
193         ${ECHO} '${ECHO} "$$msg" > ${WARNING_DIR}/${.TARGET:T}'; \
194         ${ECHO} '${ECHO} "PKGSRC-WARNING: Something is trying to run the $$lang compiler," 1>&2'; \
195         ${ECHO} '${ECHO} "PKGSRC-WARNING: but it is not added to USE_LANGUAGES in the package Makefile." 1>&2'; \
196         ${ECHO} 'exit 1'
197         ${RUN}${CHMOD} +x ${.TARGET}
198
199 .if empty(USE_LANGUAGES:Mc) && empty(USE_LANGUAGES:Mobjc)
200 PKG_CC:=                ${_FAIL_WRAPPER.CC}
201 ALL_ENV+=               CPP=${CPP:Q}
202 override-tools: ${_FAIL_WRAPPER.CC}
203 .endif
204 .if empty(USE_LANGUAGES:Mc++)
205 PKG_CXX:=               ${_FAIL_WRAPPER.CXX}
206 ALL_ENV+=               CXXCPP=${CPP:Q} # to make some Autoconf scripts happy
207 override-tools: ${_FAIL_WRAPPER.CXX}
208 .endif
209 .if empty(USE_LANGUAGES:Mfortran)
210 PKG_FC:=                ${_FAIL_WRAPPER.FC}
211 override-tools: ${_FAIL_WRAPPER.FC}
212 .endif
213
214 .endif  # BSD_COMPILER_MK