4 # bsd.gcc.mk - Support for smarter USE_GCC usage.
6 # Created by: Edwin Groothuis <edwin@freebsd.org>
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 uses the canonical version of GCC defined in bsd.default-versions.mk.
12 # USE_GCC=any is similar, except that it also accepts the old GCC 4.2-
13 # based system compiler in older versions of FreeBSD.
15 # If your port needs a specific (minimum) version of GCC, you can easily
16 # specify that with a USE_GCC= statement. Unless absolutely necessary
17 # do so by specifying USE_GCC=X.Y+ which requests at least GCC version
18 # X.Y. To request a specific version omit the trailing + sign.
21 # USE_GCC= yes # port requires a current version of GCC
22 # # as defined in bsd.default-versions.mk.
23 # USE_GCC= any # port requires GCC 4.2 or later.
24 # USE_GCC= 4.9+ # port requires GCC 4.9 or later.
25 # USE_GCC= 4.9 # port requires GCC 4.9.
27 # If you are wondering what your port exactly does, use "make test-gcc"
28 # to see some debugging.
32 GCC_Include_MAINTAINER= gerald@FreeBSD.org
34 .include "${PORTSDIR}/Mk/bsd.default-versions.mk"
36 # All GCC versions supported by the ports framework. Keep them in
37 # ascending order and in sync with the table below.
38 GCCVERSIONS= 040200 040600 040700 040800 040900 050000
40 # The first field if the OSVERSION in which it appeared in the base.
41 # The second field is the OSVERSION in which it disappeared from the base.
42 # The third field is the version as USE_GCC would use.
43 GCCVERSION_040200= 0 0 4.2 42
44 GCCVERSION_040600= 0 0 4.6 43
45 GCCVERSION_040800= 0 0 4.8 48
46 GCCVERSION_040900= 0 0 4.9 49
48 .if defined(NO_GCC50) || !defined(DPORTS_BUILDER)
49 GCCVERSION_040700= 300400 9999999 4.7 47
50 GCCVERSION_050000= 0 0 5 50
52 GCCVERSION_040700= 300400 400102 4.7 47
53 GCCVERSION_050000= 400103 9999999 5 50
56 # No configurable parts below this. ####################################
59 # Extract the fields from GCCVERSION_...
60 .for v in ${GCCVERSIONS}
61 . for j in ${GCCVERSION_${v}}
62 . if !defined(_GCCVERSION_${v}_L)
63 _GCCVERSION_${v}_L= ${j}
64 . elif !defined(_GCCVERSION_${v}_R)
65 _GCCVERSION_${v}_R= ${j}
66 . elif !defined(_GCCVERSION_${v}_V)
67 _GCCVERSION_${v}_V= ${j}
68 . elif !defined(_GCCVERSION_${v}_VV)
69 _GCCVERSION_${v}_VV= ${j}
74 .if defined(DPORTS_BUILDER) && !defined(NO_GCC50) && ${DFLYVERSION} >= ${_GCCVERSION_050000_L}
76 DFLY_DEFAULT_VERSION= 50
79 DFLY_DEFAULT_VERSION= 47
86 .if defined(USE_GCC) && !defined(FORCE_BASE_CC_FOR_TESTING)
88 . if ${USE_GCC} == any
90 # Enable the clang-is-cc workaround. Default to the last GCC imported
92 _USE_GCC:= ${LASTBASE}
95 . else # ${USE_GCC} == any
97 # See if we can use a later version or exclusively the one specified.
98 _USE_GCC:= ${USE_GCC:S/+//}
99 .if ${USE_GCC} != ${_USE_GCC}
103 . endif # ${USE_GCC} == any
105 # Initialize _GCC_FOUND${v}. In parallel, check if USE_GCC points to a
106 # valid version to begin with.
107 .for v in ${GCCVERSIONS}
108 . if ${DFLY_DEFAULT_VERSION} >= ${_GCCVERSION_${v}_VV}
110 . elif exists(${LOCALBASE}/bin/gcc${_GCCVERSION_${v}_V:S/.//})
113 . if ${_USE_GCC}==${_GCCVERSION_${v}_V}
114 _GCCVERSION_OKAY= true
118 .if !defined(_GCCVERSION_OKAY)
119 IGNORE= Unknown version of GCC specified (USE_GCC=${USE_GCC})
122 # If the GCC package defined in USE_GCC does not exist, but a later
123 # version is allowed (for example 4.7+), see if there is a later.
124 # First check if the base installed version is good enough, otherwise
125 # get the first available version.
127 .if defined(_GCC_ORLATER)
128 . if ${_USE_GCC:M5} && ${DFLY_DEFAULT_VERSION:M50}
129 # _USE_GCC is already correct
130 . elif ${_USE_GCC:N5} && (${_USE_GCC:S/.//} <= ${DFLY_DEFAULT_VERSION})
131 _USE_GCC= ${LASTBASE}
132 . else # HEAD ORIG - run on 4.0 and below
133 . for v in ${GCCVERSIONS}
134 . if ${_USE_GCC} == ${_GCCVERSION_${v}_V}
137 . if defined(_GCC_MIN1) && defined(_GCC_FOUND${v}) && ${_GCC_FOUND${v}}=="base" && !defined(_GCC_FOUND)
138 _GCC_FOUND:= ${_GCCVERSION_${v}_V}
141 . for v in ${GCCVERSIONS}
142 . if ${_USE_GCC} == ${_GCCVERSION_${v}_V}
145 . if defined(_GCC_MIN2) && defined(_GCC_FOUND${v}) && !defined(_GCC_FOUND)
146 _GCC_FOUND:= ${_GCCVERSION_${v}_V}
150 . if defined(_GCC_FOUND)
151 _USE_GCC:= ${_GCC_FOUND}
152 . elif ${_USE_GCC} < ${GCC_DEFAULT}
153 _USE_GCC:= ${GCC_DEFAULT}
156 .else # defined(_GCC_ORLATER)
157 . if ${_USE_GCC:M4.[67]}
159 DFLY_DEFAULT_VERSION= 47
161 .endif # defined(_GCC_ORLATER)
163 .endif # defined(USE_GCC)
166 .if defined(_USE_GCC)
167 # A concrete version has been selected. Determine if the installed OS
168 # features this version in the base, and if not then set proper ports
169 # dependencies, CC, CXX, CPP, and flags.
170 .for v in ${GCCVERSIONS}
171 . if ${_USE_GCC} == ${_GCCVERSION_${v}_V}
172 . if (${_GCCVERSION_${v}_L} == 0 && ${_GCCVERSION_${v}_R} == 0) || \
173 ${DFLYVERSION} < ${_GCCVERSION_${v}_L}
174 V:= ${_GCCVERSION_${v}_V:S/.//}
175 _GCC_PORT_DEPENDS:= gcc${V}
176 . if ${_USE_GCC} == ${LANG_GCC_IS}
184 _GCC_RUNTIME:= ${LOCALBASE}/lib/gcc${V}
185 CFLAGS+= -Wl,-rpath=${_GCC_RUNTIME}
186 CXXFLAGS+= -Wl,-rpath=${_GCC_RUNTIME}
187 LDFLAGS+= -Wl,-rpath=${_GCC_RUNTIME} -L${_GCC_RUNTIME}
188 . else # Use GCC in base.
192 CONFIGURE_ENV+= CCVER=gcc${DFLY_DEFAULT_VERSION}
193 MAKE_ENV+= CCVER=gcc${DFLY_DEFAULT_VERSION}
194 . endif # Use GCC in base.
195 . endif # ${_USE_GCC} == ${_GCCVERSION_${v}_V}
199 .if defined(_GCC_PORT_DEPENDS)
200 BUILD_DEPENDS+= ${_GCC_PORT_DEPENDS}:${PORTSDIR}/lang/${_GCC_PORT}
201 RUN_DEPENDS+= ${_GCC_PORT_DEPENDS}:${PORTSDIR}/lang/${_GCC_PORT}
202 # Later GCC ports already depend on binutils; make sure whatever we
203 # build leverages this as well.
206 .endif # defined(_USE_GCC) && !defined(FORCE_BASE_CC_FOR_TESTING)
210 @echo USE_GCC=${USE_GCC}
212 @echo "IGNORE: ${IGNORE}"
215 .if defined(_GCC_ORLATER)
216 @echo Port can use later versions.
218 @echo Port cannot use later versions.
220 .for v in ${GCCVERSIONS}
221 @echo -n "GCC version: ${_GCCVERSION_${v}_V} "
222 .if defined(_GCC_FOUND${v})
223 @echo -n "(${_GCC_FOUND${v}}) "
225 @echo "- OSVERSION from ${_GCCVERSION_${v}_L} to ${_GCCVERSION_${v}_R}"
226 # @echo ${v} - ${_GCC_FOUND${v}} - ${_GCCVERSION_${v}_L} to ${_GCCVERSION_${v}_R} - ${_GCCVERSION_${v}_V}
228 @echo Using GCC version ${_USE_GCC}
230 @echo CC=${CC} - CXX=${CXX} - CPP=${CPP} - CFLAGS=\"${CFLAGS}\"
231 @echo LDFLAGS=\"${LDFLAGS}\"
232 @echo CONFIGURE_ENV=${CONFIGURE_ENV}
233 @echo MAKE_ENV=${MAKE_ENV}
234 @echo "BUILD_DEPENDS=${BUILD_DEPENDS}"
235 @echo "RUN_DEPENDS=${RUN_DEPENDS}"