1 # $NetBSD: compiler.mk,v 1.69 2009/05/30 18:16:26 joerg 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 # This should be disabled only for debugging.
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.
45 # The following variables may be set by a package:
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.
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.
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
63 # The following variables are defined, and available for testing in
67 # The compiler and version being used, e.g.,
69 # .include "../../mk/compiler.mk"
71 # .if !empty(CC_VERSION:Mgcc-3*)
77 .if !defined(BSD_COMPILER_MK)
78 BSD_COMPILER_MK= defined
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
85 .include "bsd.fast.prefs.mk"
87 # Since most packages need a C compiler, this is the default value.
90 # Add c support if c99 is set
91 .if !empty(USE_LANGUAGES:Mc99)
95 COMPILER_USE_SYMLINKS?= yes
97 # For environments where there is an external gcc too, but pkgsrc
98 # should use the pkgsrc one for consistency.
100 .if defined(USE_PKGSRC_GCC)
104 _COMPILERS= ccc gcc icc ido mipspro mipspro-ucode sunpro xlc hp pcc
105 _PSEUDO_COMPILERS= ccache distcc f2c g95
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_}
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_}
120 _ACCEPTABLE_COMPILERS+= ${_COMPILERS}
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_}
133 .if !defined(_COMPILER)
134 PKG_FAIL_REASON+= "No acceptable compiler found for ${PKGNAME}."
137 .for _compiler_ in ${PKGSRC_COMPILER}
138 . if !empty(_PSEUDO_COMPILERS:M${_compiler_})
139 _PKGSRC_COMPILER:= ${_compiler_} ${_PKGSRC_COMPILER}
142 _PKGSRC_COMPILER:= ${_COMPILER} ${_PKGSRC_COMPILER}
144 _COMPILER_STRIP_VARS= # empty
146 .for _compiler_ in ${_PKGSRC_COMPILER}
147 . include "compiler/${_compiler_}.mk"
151 .if !defined(PKG_CPP)
155 # Strip the leading paths from the toolchain variables since we manipulate
156 # the PATH to use the correct executable.
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}
162 ${_var_}:= ${${_var_}:C/^/_asdf_/1:M_asdf_*:S/^_asdf_//:T} ${${_var_}:C/^/_asdf_/1:N_asdf_*}
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}}
172 # If the languages are not requested, force them not to be available
173 # in the generated wrappers.
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
179 ${_FAIL_WRAPPER.CC}: fail-wrapper
180 ${_FAIL_WRAPPER.CXX}: fail-wrapper
181 ${_FAIL_WRAPPER.FC}: fail-wrapper
185 ${RUN}${MKDIR} ${.TARGET:H}
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'; \
197 ${RUN}${CHMOD} +x ${.TARGET}
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}
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}
209 .if empty(USE_LANGUAGES:Mfortran)
210 PKG_FC:= ${_FAIL_WRAPPER.FC}
211 override-tools: ${_FAIL_WRAPPER.FC}
214 .endif # BSD_COMPILER_MK