1 # $NetBSD: compiler.mk,v 1.67 2008/10/20 18:33:50 ahoka Exp $
3 # This Makefile fragment implements handling for supported C/C++/Fortran
6 # The following variables may be set by the pkgsrc user in mk.conf:
9 # A list of values specifying the chain of compilers to be used by
10 # pkgsrc to build packages.
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)
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
26 # xlc IBM's XL C/C++ compiler suite (Darwin/MacOSX)
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.
36 # Force using the appropriate version of GCC from pkgsrc based on
37 # GCC_REQD instead of the native compiler.
39 # The following variables may be set by a package:
42 # A list of version numbers used to determine the minimum
43 # version of GCC required by a package. This value should only
44 # be appended to by a package Makefile.
46 # NOTE: Be conservative when setting GCC_REQD, as lang/gcc3 is
47 # known not to build on some platforms, e.g. Darwin. If gcc3 is
48 # required, set GCC_REQD=3.0 so that we do not try to pull in
49 # lang/gcc3 unnecessarily and have it fail.
52 # Lists the languages used in the source code of the package,
53 # and is used to determine the correct compilers to install.
54 # Valid values are: c, c99, c++, fortran, java, objc. The
57 # The following variables are defined, and available for testing in
61 # The compiler and version being used, e.g.,
63 # .include "../../mk/compiler.mk"
65 # .if !empty(CC_VERSION:Mgcc-3*)
71 .if !defined(BSD_COMPILER_MK)
72 BSD_COMPILER_MK= defined
75 _USER_VARS.compiler= PKGSRC_COMPILER USE_PKGSRC_GCC ABI
76 _PKG_VARS.compiler= USE_LANGUAGES GCC_REQD NOT_FOR_COMPILER ONLY_FOR_COMPILER
77 _SYS_VARS.compiler= CC_VERSION
79 .include "bsd.fast.prefs.mk"
81 # Since most packages need a C compiler, this is the default value.
84 # Add c support if c99 is set
85 .if !empty(USE_LANGUAGES:Mc99)
89 # For environments where there is an external gcc too, but pkgsrc
90 # should use the pkgsrc one for consistency.
92 .if defined(USE_PKGSRC_GCC)
96 _COMPILERS= ccc gcc icc ido mipspro mipspro-ucode sunpro xlc hp pcc
97 _PSEUDO_COMPILERS= ccache distcc f2c
99 .if defined(NOT_FOR_COMPILER) && !empty(NOT_FOR_COMPILER)
100 . for _compiler_ in ${_COMPILERS}
101 . if ${NOT_FOR_COMPILER:M${_compiler_}} == ""
102 _ACCEPTABLE_COMPILERS+= ${_compiler_}
105 .elif defined(ONLY_FOR_COMPILER) && !empty(ONLY_FOR_COMPILER)
106 . for _compiler_ in ${_COMPILERS}
107 . if ${ONLY_FOR_COMPILER:M${_compiler_}} != ""
108 _ACCEPTABLE_COMPILERS+= ${_compiler_}
112 _ACCEPTABLE_COMPILERS+= ${_COMPILERS}
115 .if defined(_ACCEPTABLE_COMPILERS)
116 . for _acceptable_ in ${_ACCEPTABLE_COMPILERS}
117 . for _compiler_ in ${PKGSRC_COMPILER}
118 . if !empty(_ACCEPTABLE_COMPILERS:M${_compiler_}) && !defined(_COMPILER)
119 _COMPILER= ${_compiler_}
125 .if !defined(_COMPILER)
126 PKG_FAIL_REASON+= "No acceptable compiler found for ${PKGNAME}."
129 .for _compiler_ in ${PKGSRC_COMPILER}
130 . if !empty(_PSEUDO_COMPILERS:M${_compiler_})
131 _PKGSRC_COMPILER:= ${_compiler_} ${_PKGSRC_COMPILER}
134 _PKGSRC_COMPILER:= ${_COMPILER} ${_PKGSRC_COMPILER}
136 _COMPILER_STRIP_VARS= # empty
138 .for _compiler_ in ${_PKGSRC_COMPILER}
139 . include "compiler/${_compiler_}.mk"
143 .if !defined(PKG_CPP)
147 # Strip the leading paths from the toolchain variables since we manipulate
148 # the PATH to use the correct executable.
150 .for _var_ in ${_COMPILER_STRIP_VARS}
151 . if empty(${_var_}:C/^/_asdf_/1:N_asdf_*)
152 ${_var_}:= ${${_var_}:C/^/_asdf_/1:M_asdf_*:S/^_asdf_//:T}
154 ${_var_}:= ${${_var_}:C/^/_asdf_/1:M_asdf_*:S/^_asdf_//:T} ${${_var_}:C/^/_asdf_/1:N_asdf_*}
158 .if defined(ABI) && !empty(ABI)
159 _WRAP_EXTRA_ARGS.CC+= ${_COMPILER_ABI_FLAG.${ABI}}
160 _WRAP_EXTRA_ARGS.CXX+= ${_COMPILER_ABI_FLAG.${ABI}}
161 _WRAP_EXTRA_ARGS.LD+= ${_LINKER_ABI_FLAG.${ABI}}
164 # If the languages are not requested, force them not to be available
165 # in the generated wrappers.
167 _FAIL_WRAPPER.CC= ${WRKDIR}/.compiler/bin/c-fail-wrapper
168 _FAIL_WRAPPER.CXX= ${WRKDIR}/.compiler/bin/c++-fail-wrapper
169 _FAIL_WRAPPER.FC= ${WRKDIR}/.compiler/bin/fortran-fail-wrapper
171 ${_FAIL_WRAPPER.CC}: fail-wrapper
172 ${_FAIL_WRAPPER.CXX}: fail-wrapper
173 ${_FAIL_WRAPPER.FC}: fail-wrapper
177 ${RUN}${MKDIR} ${.TARGET:H}
180 ${ECHO} '#!'${TOOLS_SHELL:Q}; \
181 ${ECHO} 'wrapperlog="$${TOOLS_WRAPPER_LOG-'${_TOOLS_WRAP_LOG:Q}'}"'; \
182 ${ECHO} 'lang="${.TARGET:T:S/-fail-wrapper//}"'; \
183 ${ECHO} 'msg="*** Please consider adding $$lang to USE_LANGUAGES in the package Makefile."'; \
184 ${ECHO} '${ECHO} "$$msg" >> $$wrapperlog'; \
185 ${ECHO} '${ECHO} "$$msg" > ${WARNING_DIR}/${.TARGET:T}'; \
186 ${ECHO} '${ECHO} "PKGSRC-WARNING: Something is trying to run the $$lang compiler," 1>&2'; \
187 ${ECHO} '${ECHO} "PKGSRC-WARNING: but it is not added to USE_LANGUAGES in the package Makefile." 1>&2'; \
189 ${RUN}${CHMOD} +x ${.TARGET}
191 .if empty(USE_LANGUAGES:Mc) && empty(USE_LANGUAGES:Mobjc)
192 PKG_CC:= ${_FAIL_WRAPPER.CC}
193 ALL_ENV+= CPP=${CPP:Q}
194 override-tools: ${_FAIL_WRAPPER.CC}
196 .if empty(USE_LANGUAGES:Mc++)
197 PKG_CXX:= ${_FAIL_WRAPPER.CXX}
198 ALL_ENV+= CXXCPP=${CPP:Q} # to make some Autoconf scripts happy
199 override-tools: ${_FAIL_WRAPPER.CXX}
201 .if empty(USE_LANGUAGES:Mfortran)
202 PKG_FC:= ${_FAIL_WRAPPER.FC}
203 override-tools: ${_FAIL_WRAPPER.FC}
206 .endif # BSD_COMPILER_MK