Merge from vendor branch TNF:
[pkgsrcv2.git] / mk / compiler.mk
1 # $NetBSD: compiler.mk,v 1.46 2005/02/16 08:41:20 grant Exp $
2 #
3 # This Makefile fragment implements handling for supported C/C++/Fortran
4 # compilers.
5 #
6 # The following variables are used by this file:
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 #               mipspro         Silicon Graphics, Inc. MIPSpro (n32/n64)
21 #               mipspro-ucode   Silicon Graphics, Inc. MIPSpro (o32)
22 #               sunpro          Sun Microsystems, Inc. WorkShip/Forte/Sun
23 #                               ONE Studio
24 #               xlc             IBM's XL C/C++ compiler suite (Darwin/MacOSX)
25 #
26 #       The default is "gcc".  You can use ccache and/or distcc with
27 #       an appropriate PKGSRC_COMPILER setting, e.g. "ccache distcc
28 #       gcc".  You can also use "f2c" to overlay the lang/f2c package
29 #       over the C compiler instead of using the system Fortran
30 #       compiler.  The chain should always end in a real compiler.
31 #       This should only be set in /etc/mk.conf.
32 #
33 # GCC_REQD
34 #       A list of version numbers used to determine the minimum
35 #       version of GCC required by a package.  This value should only
36 #       be appended to by a package Makefile.
37 #
38 #       NOTE: Be conservative when setting GCC_REQD, as lang/gcc3 is
39 #       known not to build on some platforms, e.g. Darwin.  If gcc3 is
40 #       required, set GCC_REQD=3.0 so that we do not try to pull in
41 #       lang/gcc3 unnecessarily and have it fail.
42 #
43 # USE_PKGSRC_GCC
44 #       Force using the appropriate version of GCC from pkgsrc based on
45 #       GCC_REQD instead of the native compiler.  Should only be set in
46 #       /etc/mk.conf.
47 #
48 #
49 # USE_LANGUAGES
50 #       Lists the languages used in the source code of the package,
51 #       and is used to determine the correct compilers to install.
52 #       Valid values are: c, c++, fortran, java, objc.  The default
53 #       is "c" ("c" is actually _always_ implicitly in this list).
54 #
55 # The following variables are defined, and available for testing in
56 # package Makefiles:
57 #
58 # CC_VERSION
59 #       The compiler and version being used, e.g.,
60 #
61 #       .include "../../mk/compiler.mk"
62 #
63 #       .if !empty(CC_VERSION:Mgcc-3*)
64 #       ...
65 #       .endif
66 #
67
68 .if !defined(BSD_COMPILER_MK)
69 BSD_COMPILER_MK=        defined
70
71 .include "../../mk/bsd.prefs.mk"
72
73 # Always require a C compiler for proper compiler detection.
74 USE_LANGUAGES?= c
75 .if empty(USE_LANGUAGES:Mc)
76 USE_LANGUAGES:= c ${USE_LANGUAGES}
77 .endif
78
79 # For environments where there is an external gcc too, but pkgsrc
80 # should use the pkgsrc one for consistency.
81 #
82 .if defined(USE_PKGSRC_GCC)
83 _USE_PKGSRC_GCC=        yes
84 .endif
85
86 _COMPILERS=             ccc gcc icc ido mipspro mipspro-ucode sunpro xlc
87 _PSEUDO_COMPILERS=      ccache distcc f2c
88
89 .if defined(NOT_FOR_COMPILER) && !empty(NOT_FOR_COMPILER)
90 .  for _compiler_ in ${_COMPILERS}
91 .    if ${NOT_FOR_COMPILER:M${_compiler_}} == ""
92 _ACCEPTABLE_COMPILERS+= ${_compiler_}
93 .    endif
94 .  endfor
95 .elif defined(ONLY_FOR_COMPILER) && !empty(ONLY_FOR_COMPILER)
96 .  for _compiler_ in ${_COMPILERS}
97 .    if ${ONLY_FOR_COMPILER:M${_compiler_}} != ""
98 _ACCEPTABLE_COMPILERS+= ${_compiler_}
99 .    endif
100 .  endfor
101 .else
102 _ACCEPTABLE_COMPILERS+= ${_COMPILERS}
103 .endif
104
105 .if defined(_ACCEPTABLE_COMPILERS)
106 .  for _acceptable_ in ${_ACCEPTABLE_COMPILERS}
107 .    for _compiler_ in ${PKGSRC_COMPILER}
108 .      if !empty(_ACCEPTABLE_COMPILERS:M${_compiler_}) && !defined(_COMPILER)
109 _COMPILER=      ${_compiler_}
110 .      endif
111 .    endfor
112 .  endfor
113 .endif
114
115 .if !defined(_COMPILER)
116 PKG_FAIL_REASON+=       "No acceptable compiler found for ${PKGNAME}."
117 .endif
118
119 .for _compiler_ in ${PKGSRC_COMPILER}
120 .  if !empty(_PSEUDO_COMPILERS:M${_compiler_})
121 _PKGSRC_COMPILER:=      ${_compiler_} ${_PKGSRC_COMPILER}
122 .  endif
123 .endfor
124 _PKGSRC_COMPILER:=      ${_COMPILER} ${_PKGSRC_COMPILER}
125
126 _COMPILER_STRIP_VARS=   # empty
127
128 .for _compiler_ in ${_PKGSRC_COMPILER}
129 .  include "../../mk/compiler/${_compiler_}.mk"
130 .endfor
131 .undef _compiler_
132
133 # Strip the leading paths from the toolchain variables since we manipulate
134 # the PATH to use the correct executable.
135 #
136 .for _var_ in ${_COMPILER_STRIP_VARS}
137 .  if empty(${_var_}:C/^/_asdf_/1:N_asdf_*)
138 ${_var_}:=      ${${_var_}:C/^/_asdf_/1:M_asdf_*:S/^_asdf_//:T}
139 .  else
140 ${_var_}:=      ${${_var_}:C/^/_asdf_/1:M_asdf_*:S/^_asdf_//:T} ${${_var_}:C/^/_asdf_/1:N_asdf_*}
141 .  endif
142 .endfor
143
144 .if defined(ABI) && !empty(ABI)
145 _WRAP_EXTRA_ARGS.CC+=   ${_COMPILER_ABI_FLAG.${ABI}}
146 _WRAP_EXTRA_ARGS.CXX+=  ${_COMPILER_ABI_FLAG.${ABI}}
147 _WRAP_EXTRA_ARGS.LD+=   ${_LINKER_ABI_FLAG.${ABI}}
148 .endif
149
150 .endif  # BSD_COMPILER_MK