Mk/Uses/iconv: support iconv+
[dports.git] / Mk / bsd.gcc.mk
1 #-*- tab-width: 4; -*-
2 # ex:ts=4
3 #
4 # bsd.gcc.mk - Support for smarter USE_GCC usage.
5 #
6 # Created by: Edwin Groothuis <edwin@freebsd.org>
7 #
8 # To request the use of a current version of GCC, specify USE_GCC=yes in
9 # your port/system configuration.  This is the preferred use of USE_GCC.
10 # It defines a canonical, default version of GCC; the same version of
11 # GCC is also implied by USE_FORTRAN=yes.
12
13 # If your port needs a specific (minimum) version of GCC, you can easily
14 # specify that with a USE_GCC= statement.  Unless absolutely necessary
15 # do so by specifying USE_GCC=X.Y+ which requests at least GCC version
16 # X.Y.  To request a specific version omit the trailing + sign.  Use of
17 # a Fortran compiler is declared by the USE_FORTRAN knob, not USE_GCC.
18 #
19 # Examples:
20 #   USE_GCC=    yes                     # port requires a current version of GCC
21 #                                                       # (4.6 as of today, subject to change).
22 #   USE_GCC=    4.2+            # port requires GCC 4.2 or later.
23 #   USE_GCC=    4.7                     # port requires GCC 4.7.
24 #
25 # If your port needs a Fortran compiler, please specify that with the
26 # USE_FORTRAN= knob.  Here is the list of options for that knob:
27 #
28 #   USE_FORTRAN=        yes             # use gfortran47 (lang/gcc-aux)
29 #   USE_FORTRAN=        g77             # use g77-34 (lang/gcc34)
30 #   USE_FORTRAN=        ifort   # use the Intel compiler (lang/ifc)
31 #
32 # Due to object file incompatiblity between Fortran compilers, we strongly
33 # recommend to use only one of them on any system.
34 #
35 # If you are wondering what your port exactly does, use "make test-gcc"
36 # to see some debugging.
37 #
38 # $FreeBSD: Mk/bsd.gcc.mk 315538 2013-03-29 11:26:14Z gerald $
39 #
40
41 GCC_Include_MAINTAINER=         gerald@FreeBSD.org
42
43 # All GCC versions supported by the ports framework.  Keep them in
44 # ascending order and in sync with the table below. 
45 GCCVERSIONS=    030402 040200 040400 040600 040700 040800
46
47 # The first field if the DFLYVERSION in which it appeared in the base.
48 # The second field is the DFLYVERSION in which it disappeared from the base.
49 # The third field is the version as USE_GCC would use.
50 # This doesn't work so well with DragonFly due to dual compilers
51 # DPorts wasn't supported until DragonFly 3.3.
52 GCCVERSION_030402=      100000  200000 3.4
53 GCCVERSION_040100=      200000  300200 4.1
54 GCCVERSION_040200=           0       0 4.2
55 GCCVERSION_040400=      300200  300400 4.4
56 GCCVERSION_040600=           0       0 4.6
57 GCCVERSION_040700=      300400 9999999 4.7
58 GCCVERSION_040800=           0       0 4.8
59
60 GCC_DEFAULT_VERSION=    4.7
61 DFLY_DEFAULT_VERSION=   47
62 GCC_DEFAULT_V=  ${GCC_DEFAULT_VERSION:S/.//}
63
64 # No configurable parts below this. ####################################
65 #
66
67 .if defined(USE_GCC) && ${USE_GCC} == yes
68 USE_GCC=        ${GCC_DEFAULT_VERSION}
69 .endif
70
71 # Extract the fields from GCCVERSION_...
72 .for v in ${GCCVERSIONS}
73 . for j in ${GCCVERSION_${v}}
74 .  if !defined(_GCCVERSION_${v}_L)
75 _GCCVERSION_${v}_L=     ${j}
76 .  elif !defined(_GCCVERSION_${v}_R)
77 _GCCVERSION_${v}_R=     ${j}
78 .  elif !defined(_GCCVERSION_${v}_V)
79 _GCCVERSION_${v}_V=     ${j}
80 .  endif
81 . endfor
82 .endfor
83
84 # bsd.gcc.mk can also be used for primarily requesting a Fortran compiler.
85 # If we are using GCC we still define whatever we'd usually do for C and
86 # C++ as well.
87
88 .if defined (USE_FORTRAN)
89
90 # The default case, with a current lang/gcc port.
91 . if ${USE_FORTRAN} == yes
92 BUILD_DEPENDS+= ${LOCALBASE}/gcc-aux/bin/gfortran:${PORTSDIR}/lang/gcc-aux
93 RUN_DEPENDS+=   ${LOCALBASE}/gcc-aux/bin/gfortran:${PORTSDIR}/lang/gcc-aux
94 _USE_GCC:=      ${GCC_DEFAULT_VERSION}  # dummy to avoid further depends
95 _GCC_RUNTIME:=  ${LOCALBASE}/gcc-aux/lib
96 FC:=            ${LOCALBASE}/gcc-aux/bin/gfortran
97 F77:=           ${LOCALBASE}/gcc-aux/bin/gfortran
98 CC:=            ${LOCALBASE}/gcc-aux/bin/gcc
99 CXX:=           ${LOCALBASE}/gcc-aux/bin/g++
100 CPP:=           ${LOCALBASE}/gcc-aux/bin/cpp
101 LDFLAGS+=       -L${LOCALBASE}/gcc-aux/lib -Wl,-rpath,${LOCALBASE}/gcc-aux/lib
102
103 # Intel Fortran compiler from lang/ifc.
104 . elif ${USE_FORTRAN} == ifort
105 BUILD_DEPENDS+= ${LOCALBASE}/intel_fc_80/bin/ifort:${PORTSDIR}/lang/ifc
106 RUN_DEPENDS+=   ${LOCALBASE}/intel_fc_80/bin/ifort:${PORTSDIR}/lang/ifc
107 FC:=    ${LOCALBASE}/intel_fc_80/bin/ifort
108 F77:=   ${LOCALBASE}/intel_fc_80/bin/ifort
109
110 # g77 from lang/gcc34.
111 . elif ${USE_FORTRAN} == g77
112 _USE_GCC:=      3.4
113 FC:=    g77-34
114 F77:=   g77-34
115 . else
116 IGNORE= specifies unknown value "${USE_FORTRAN}" for USE_FORTRAN
117 . endif
118
119 CONFIGURE_ENV+= F77="${F77}" FC="${FC}" FFLAGS="${FFLAGS}"
120 MAKE_ENV+=              F77="${F77}" FC="${FC}" FFLAGS="${FFLAGS}"
121 .endif
122
123
124 .if defined(USE_GCC) && !defined(FORCE_BASE_CC_FOR_TESTING)
125
126 . if empty(USE_GCC) || ${USE_GCC} == any || ${USE_GCC:tl} == "yes"
127
128 # Enable the clang-is-cc workaround.  Default to the last GCC imported
129 # into base.
130 _USE_GCC:=      ${GCC_DEFAULT_VERSION}
131 _GCC_ORLATER:=  false
132
133 . else # ${USE_GCC} == any
134
135 # See if we can use a later version or exclusively the one specified.
136 _USE_GCC:=      ${USE_GCC:S/+//}
137 .if ${USE_GCC} != ${_USE_GCC}
138 _GCC_ORLATER:=  true
139 .endif
140
141 . endif # ${USE_GCC} == any
142
143 # Initialize _GCC_FOUND${v}.  In parallel, check if USE_GCC points to a
144 # valid version to begin with.
145 # Set USE_GCC=3.4(4.2, 4.4, 4.6) all to base compiler (4.7)
146 .for v in ${GCCVERSIONS}
147 . if ${DFLYVERSION} >= ${_GCCVERSION_${v}_L} \
148   && ${DFLYVERSION} <  ${_GCCVERSION_${v}_R} \
149   && ${DFLY_DEFAULT_VERSION} <= ${_GCCVERSION_${v}_V:S/.//}
150 _GCC_FOUND${v}= base
151 . elif exists(${LOCALBASE}/bin/gcc${_GCCVERSION_${v}_V:S/.//})
152 _GCC_FOUND${v}= port
153 . endif
154 . if ${_USE_GCC}==${_GCCVERSION_${v}_V}
155 _GCCVERSION_OKAY=       true
156 . endif
157 .endfor
158
159 .if !defined(_GCCVERSION_OKAY)
160 IGNORE= Unknown version of GCC specified (USE_GCC=${USE_GCC})
161 .endif
162
163 # If the GCC package defined in USE_GCC does not exist, but a later
164 # version is allowed (for example 4.2+), see if there is a later.
165 # First check if the base installed version is good enough, otherwise
166 # get the first available version.
167 #
168 .if defined(_GCC_ORLATER)
169 . for v in ${GCCVERSIONS}
170 .  if ${_USE_GCC} == ${_GCCVERSION_${v}_V}
171 _GCC_MIN1:=     true
172 .  endif
173 .  if defined(_GCC_MIN1) && defined(_GCC_FOUND${v}) && ${_GCC_FOUND${v}}=="base" && !defined(_GCC_FOUND)
174 _GCC_FOUND:=    ${_GCCVERSION_${v}_V}
175 .  endif
176 . endfor
177 . for v in ${GCCVERSIONS}
178 .  if ${_USE_GCC} == ${_GCCVERSION_${v}_V}
179 _GCC_MIN2:=     true
180 .  endif
181 .  if defined(_GCC_MIN2) && defined(_GCC_FOUND${v}) && !defined(_GCC_FOUND)
182 _GCC_FOUND:=    ${_GCCVERSION_${v}_V}
183 .  endif
184 . endfor
185
186 . if defined(_GCC_FOUND)
187 _USE_GCC:=      ${_GCC_FOUND}
188 . elif ${_USE_GCC} < ${GCC_DEFAULT_VERSION}
189 _USE_GCC:=      ${GCC_DEFAULT_VERSION}
190 . endif
191 .endif # defined(_GCC_ORLATER)
192
193 .endif # defined(USE_GCC)
194
195
196 .if defined(_USE_GCC)
197 # A concrete version has been selected.  Determine if the installed OS 
198 # features this version in the base, and if not then set proper ports
199 # dependencies, CC, CXX, CPP, and flags.
200 .for v in ${GCCVERSIONS}
201 . if ${_USE_GCC} == ${_GCCVERSION_${v}_V}
202 .  if ${DFLYVERSION} < ${_GCCVERSION_${v}_L} || ${DFLYVERSION} > ${_GCCVERSION_${v}_R}
203 V:=                     ${_GCCVERSION_${v}_V:S/.//}
204 _GCC_PORT_DEPENDS:=     gcc${V}
205 .   if ${_USE_GCC} == ${GCC_DEFAULT_VERSION}
206 _GCC_PORT:=             gcc
207 .   else
208 _GCC_PORT:=             gcc${V}
209 .   endif
210 CC:=                    gcc${V}
211 CXX:=                   g++${V}
212 CPP:=                   cpp${V}
213 .   if ${_USE_GCC} != 3.4
214 _GCC_RUNTIME:=          ${LOCALBASE}/lib/gcc${V}
215 CFLAGS+=                -Wl,-rpath=${_GCC_RUNTIME}
216 CXXFLAGS+=              -Wl,-rpath=${_GCC_RUNTIME}
217 LDFLAGS+=               -Wl,-rpath=${_GCC_RUNTIME}
218 .    if defined (USE_FORTRAN)
219 .    if ${USE_FORTRAN} == yes
220 FFLAGS+=                -Wl,-rpath=${_GCC_RUNTIME}
221 .    endif
222 .    endif
223 # The following is for the sakes of some ports which use this without
224 # ever telling us; to be fixed.
225 _GCC_BUILD_DEPENDS:=    ${_GCC_PORT_DEPENDS}
226 .   endif # ${_USE_GCC} != 3.4
227 .  else # Use GCC in base.
228 CC:=                    gcc
229 CXX:=                   g++
230 CPP:=                   cpp
231 CONFIGURE_ENV+=         CCVER=gcc${DFLY_DEFAULT_VERSION}
232 MAKE_ENV+=              CCVER=gcc${DFLY_DEFAULT_VERSION}
233 .  endif # Use GCC in base.
234 . endif # ${_USE_GCC} == ${_GCCVERSION_${v}_V}
235 .endfor
236 .undef V
237
238 .if defined(_GCC_PORT_DEPENDS)
239 BUILD_DEPENDS+= ${_GCC_PORT_DEPENDS}:${PORTSDIR}/lang/${_GCC_PORT}
240 . if ${_USE_GCC} != 3.4
241 RUN_DEPENDS+=   ${_GCC_PORT_DEPENDS}:${PORTSDIR}/lang/${_GCC_PORT}
242 .  if ${_USE_GCC:S/.//} > ${GCC_DEFAULT_VERSION}
243 # Later GCC ports already depend on binutils; make sure whatever we
244 # build leverages this as well.
245 USE_BINUTILS=   yes
246 .  endif
247 . endif
248 .endif
249 .endif # defined(_USE_GCC) && !defined(FORCE_BASE_CC_FOR_TESTING)
250
251
252 test-gcc:
253         @echo USE_GCC=${USE_GCC}
254         @echo USE_FORTRAN=${USE_FORTRAN}
255 .if defined(IGNORE)
256         @echo "IGNORE: ${IGNORE}"
257 .else
258 .if defined(USE_GCC)
259 .if defined(_GCC_ORLATER)
260         @echo Port can use later versions.
261 .else
262         @echo Port cannot use later versions.
263 .endif
264 .for v in ${GCCVERSIONS}
265         @echo -n "GCC version: ${_GCCVERSION_${v}_V} "
266 .if defined(_GCC_FOUND${v})
267         @echo -n "(${_GCC_FOUND${v}}) "
268 .endif
269         @echo "- OSVERSION from ${_GCCVERSION_${v}_L} to ${_GCCVERSION_${v}_R}"
270 #       @echo ${v} - ${_GCC_FOUND${v}} - ${_GCCVERSION_${v}_L} to ${_GCCVERSION_${v}_R} - ${_GCCVERSION_${v}_V}
271 .endfor
272         @echo Using GCC version ${_USE_GCC}
273 .endif
274         @echo CC=${CC} - CXX=${CXX} - CPP=${CPP} - CFLAGS=\"${CFLAGS}\"
275         @echo F77=${F77} - FC=${FC} - FFLAGS=\"${FFLAGS}\"
276         @echo LDFLAGS=\"${LDFLAGS}\"
277         @echo CONFIGURE_ENV=${CONFIGURE_ENV}
278         @echo MAKE_ENV=${MAKE_ENV}
279         @echo "BUILD_DEPENDS=${BUILD_DEPENDS}"
280         @echo "RUN_DEPENDS=${RUN_DEPENDS}"
281 .endif