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