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.8+ # port requires GCC 4.8 or later.
25 # USE_GCC= 4.8 # port requires GCC 4.8.
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
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
44 GCCVERSION_040600= 0 0 4.6
45 GCCVERSION_040700= 300400 9999999 4.7
46 GCCVERSION_040800= 0 0 4.8
47 GCCVERSION_040900= 0 0 4.9
51 DFLY_DEFAULT_VERSION= 47
53 # No configurable parts below this. ####################################
56 .if defined(USE_GCC) && ${USE_GCC} == yes
57 USE_GCC= ${GCC_DEFAULT}
60 # Extract the fields from GCCVERSION_...
61 .for v in ${GCCVERSIONS}
62 . for j in ${GCCVERSION_${v}}
63 . if !defined(_GCCVERSION_${v}_L)
64 _GCCVERSION_${v}_L= ${j}
65 . elif !defined(_GCCVERSION_${v}_R)
66 _GCCVERSION_${v}_R= ${j}
67 . elif !defined(_GCCVERSION_${v}_V)
68 _GCCVERSION_${v}_V= ${j}
73 .if defined(USE_GCC) && !defined(FORCE_BASE_CC_FOR_TESTING)
75 . if empty(USE_GCC) || ${USE_GCC} == any || ${USE_GCC:tl} == "yes"
77 # Enable the clang-is-cc workaround. Default to the last GCC imported
79 _USE_GCC:= ${GCC_DEFAULT}
82 . else # ${USE_GCC} == any
84 # See if we can use a later version or exclusively the one specified.
85 _USE_GCC:= ${USE_GCC:S/+//}
86 .if ${USE_GCC} != ${_USE_GCC}
90 . endif # ${USE_GCC} == any
92 # Initialize _GCC_FOUND${v}. In parallel, check if USE_GCC points to a
93 # valid version to begin with.
94 # Set USE_GCC=3.4(4.2, 4.4, 4.6) all to base compiler (4.7)
95 .for v in ${GCCVERSIONS}
96 . if ${DFLYVERSION} >= ${_GCCVERSION_${v}_L} \
97 && ${DFLYVERSION} < ${_GCCVERSION_${v}_R} \
98 && ${DFLY_DEFAULT_VERSION} <= ${_GCCVERSION_${v}_V:S/.//}
100 . elif exists(${LOCALBASE}/bin/gcc${_GCCVERSION_${v}_V:S/.//})
103 . if ${_USE_GCC}==${_GCCVERSION_${v}_V}
104 _GCCVERSION_OKAY= true
108 .if !defined(_GCCVERSION_OKAY)
109 IGNORE= Unknown version of GCC specified (USE_GCC=${USE_GCC})
112 # If the GCC package defined in USE_GCC does not exist, but a later
113 # version is allowed (for example 4.7+), see if there is a later.
114 # First check if the base installed version is good enough, otherwise
115 # get the first available version.
117 .if defined(_GCC_ORLATER)
118 . for v in ${GCCVERSIONS}
119 . if ${_USE_GCC} == ${_GCCVERSION_${v}_V}
122 . if defined(_GCC_MIN1) && defined(_GCC_FOUND${v}) && ${_GCC_FOUND${v}}=="base" && !defined(_GCC_FOUND)
123 _GCC_FOUND:= ${_GCCVERSION_${v}_V}
126 . for v in ${GCCVERSIONS}
127 . if ${_USE_GCC} == ${_GCCVERSION_${v}_V}
130 . if defined(_GCC_MIN2) && defined(_GCC_FOUND${v}) && !defined(_GCC_FOUND)
131 _GCC_FOUND:= ${_GCCVERSION_${v}_V}
135 . if defined(_GCC_FOUND)
136 _USE_GCC:= ${_GCC_FOUND}
137 . elif ${_USE_GCC} < ${GCC_DEFAULT}
138 _USE_GCC:= ${GCC_DEFAULT}
140 .endif # defined(_GCC_ORLATER)
142 .endif # defined(USE_GCC)
145 .if defined(_USE_GCC)
146 # A concrete version has been selected. Determine if the installed OS
147 # features this version in the base, and if not then set proper ports
148 # dependencies, CC, CXX, CPP, and flags.
149 .for v in ${GCCVERSIONS}
150 . if ${_USE_GCC} == ${_GCCVERSION_${v}_V}
151 . if ${DFLYVERSION} < ${_GCCVERSION_${v}_L} || ${DFLYVERSION} > ${_GCCVERSION_${v}_R}
152 V:= ${_GCCVERSION_${v}_V:S/.//}
153 _GCC_PORT_DEPENDS:= gcc${V}
154 . if ${_USE_GCC} == ${GCC_DEFAULT_V}
162 _GCC_RUNTIME:= ${LOCALBASE}/lib/gcc${V}
163 CFLAGS+= -Wl,-rpath=${_GCC_RUNTIME}
164 CXXFLAGS+= -Wl,-rpath=${_GCC_RUNTIME}
165 LDFLAGS+= -Wl,-rpath=${_GCC_RUNTIME} -L${_GCC_RUNTIME}
166 . else # Use GCC in base.
170 CONFIGURE_ENV+= CCVER=gcc${DFLY_DEFAULT_VERSION}
171 MAKE_ENV+= CCVER=gcc${DFLY_DEFAULT_VERSION}
172 . endif # Use GCC in base.
173 . endif # ${_USE_GCC} == ${_GCCVERSION_${v}_V}
177 .if defined(_GCC_PORT_DEPENDS)
178 BUILD_DEPENDS+= ${_GCC_PORT_DEPENDS}:${PORTSDIR}/lang/${_GCC_PORT}
179 RUN_DEPENDS+= ${_GCC_PORT_DEPENDS}:${PORTSDIR}/lang/${_GCC_PORT}
180 . if ${_USE_GCC:S/.//} > ${GCC_DEFAULT}
181 # Later GCC ports already depend on binutils; make sure whatever we
182 # build leverages this as well.
186 .endif # defined(_USE_GCC) && !defined(FORCE_BASE_CC_FOR_TESTING)
190 @echo USE_GCC=${USE_GCC}
192 @echo "IGNORE: ${IGNORE}"
195 .if defined(_GCC_ORLATER)
196 @echo Port can use later versions.
198 @echo Port cannot use later versions.
200 .for v in ${GCCVERSIONS}
201 @echo -n "GCC version: ${_GCCVERSION_${v}_V} "
202 .if defined(_GCC_FOUND${v})
203 @echo -n "(${_GCC_FOUND${v}}) "
205 @echo "- OSVERSION from ${_GCCVERSION_${v}_L} to ${_GCCVERSION_${v}_R}"
206 # @echo ${v} - ${_GCC_FOUND${v}} - ${_GCCVERSION_${v}_L} to ${_GCCVERSION_${v}_R} - ${_GCCVERSION_${v}_V}
208 @echo Using GCC version ${_USE_GCC}
210 @echo CC=${CC} - CXX=${CXX} - CPP=${CPP} - CFLAGS=\"${CFLAGS}\"
211 @echo LDFLAGS=\"${LDFLAGS}\"
212 @echo CONFIGURE_ENV=${CONFIGURE_ENV}
213 @echo MAKE_ENV=${MAKE_ENV}
214 @echo "BUILD_DEPENDS=${BUILD_DEPENDS}"
215 @echo "RUN_DEPENDS=${RUN_DEPENDS}"