1 |
#-*- tab-width: 4; -*- |
2 |
# ex:ts=4 |
3 |
# |
4 |
# 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 uses the canonical version of GCC defined in bsd.default-versions.mk. |
11 |
# |
12 |
# USE_GCC=any is similar, except that it also accepts the old GCC 4.2- |
13 |
# based system compiler in older versions of MidnightBSD. |
14 |
# |
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. |
19 |
# |
20 |
# Examples: |
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= 6+ # port requires GCC 6 or later. |
25 |
# USE_GCC= 4.9 # port requires GCC 4.9. |
26 |
# |
27 |
# If you are wondering what your port exactly does, use "make test-gcc" |
28 |
# to see some debugging. |
29 |
# |
30 |
# $MidnightBSD$ |
31 |
|
32 |
.if defined(_POSTMKINCLUDED) && !defined(Gcc_Post_Include) |
33 |
|
34 |
Gcc_Post_Include= gcc.mk |
35 |
Gcc_Include_MAINTAINER= ports@MidnightBSD.org |
36 |
|
37 |
.include "${PORTSDIR}/Mk/components/default-versions.mk" |
38 |
|
39 |
# All GCC versions supported by the ports framework. Keep them in |
40 |
# ascending order and in sync with the table below. |
41 |
GCCVERSIONS= 040200 040600 040700 040800 040900 050000 060000 070000 |
42 |
|
43 |
# The first field is the OSVERSION in which it disappeared from the base. |
44 |
# The second field is the version as USE_GCC would use. |
45 |
GCCVERSION_040200= 9999999 4.2 |
46 |
GCCVERSION_040600= 0 4.6 |
47 |
GCCVERSION_040700= 0 4.7 |
48 |
GCCVERSION_040800= 0 4.8 |
49 |
GCCVERSION_040900= 0 4.9 |
50 |
GCCVERSION_050000= 0 5 |
51 |
GCCVERSION_060000= 0 6 |
52 |
GCCVERSION_070000= 0 7 |
53 |
|
54 |
# No configurable parts below this. #################################### |
55 |
# |
56 |
|
57 |
.if defined(USE_GCC) && ${USE_GCC} == yes |
58 |
USE_GCC= ${GCC_DEFAULT}+ |
59 |
.endif |
60 |
|
61 |
# Extract the fields from GCCVERSION_... |
62 |
.for v in ${GCCVERSIONS} |
63 |
. for j in ${GCCVERSION_${v}} |
64 |
. if !defined(_GCCVERSION_${v}_R) |
65 |
_GCCVERSION_${v}_R= ${j} |
66 |
. elif !defined(_GCCVERSION_${v}_V) |
67 |
_GCCVERSION_${v}_V= ${j} |
68 |
. endif |
69 |
. endfor |
70 |
.endfor |
71 |
|
72 |
.if defined(USE_GCC) && !defined(FORCE_BASE_CC_FOR_TESTING) |
73 |
|
74 |
. if ${USE_GCC} == any |
75 |
|
76 |
# Enable the clang-is-cc workaround. Default to the last GCC imported |
77 |
# into base. |
78 |
_USE_GCC:= 4.2 |
79 |
_GCC_ORLATER:= true |
80 |
|
81 |
. else # ${USE_GCC} == any |
82 |
|
83 |
# See if we can use a later version or exclusively the one specified. |
84 |
_USE_GCC:= ${USE_GCC:S/+//} |
85 |
.if ${USE_GCC} != ${_USE_GCC} |
86 |
_GCC_ORLATER:= true |
87 |
.endif |
88 |
|
89 |
. endif # ${USE_GCC} == any |
90 |
|
91 |
# Initialize _GCC_FOUND${v}. In parallel, check if USE_GCC points to a |
92 |
# valid version to begin with. |
93 |
.for v in ${GCCVERSIONS} |
94 |
. if exists(${LOCALBASE}/bin/gcc${_GCCVERSION_${v}_V:S/.//}) |
95 |
_GCC_FOUND${v}= port |
96 |
. elif ${OSVERSION} < ${_GCCVERSION_${v}_R} |
97 |
. if exists(/usr/bin/gcc) |
98 |
_GCC_FOUND${v}= base |
99 |
. endif |
100 |
. endif |
101 |
. if ${_USE_GCC}==${_GCCVERSION_${v}_V} |
102 |
_GCCVERSION_OKAY= true |
103 |
. endif |
104 |
.endfor |
105 |
|
106 |
.if !defined(_GCCVERSION_OKAY) |
107 |
IGNORE= Unknown version of GCC specified (USE_GCC=${USE_GCC}) |
108 |
.endif |
109 |
|
110 |
# If the GCC package defined in USE_GCC does not exist, but a later |
111 |
# version is allowed (for example 4.7+), see if there is a later. |
112 |
# First check if the base installed version is good enough, otherwise |
113 |
# get the first available version. |
114 |
# |
115 |
.if defined(_GCC_ORLATER) |
116 |
. for v in ${GCCVERSIONS} |
117 |
. if ${_USE_GCC} == ${_GCCVERSION_${v}_V} |
118 |
_GCC_MIN1:= true |
119 |
. endif |
120 |
. if defined(_GCC_MIN1) && defined(_GCC_FOUND${v}) && ${_GCC_FOUND${v}}=="base" && !defined(_GCC_FOUND) |
121 |
_GCC_FOUND:= ${_GCCVERSION_${v}_V} |
122 |
. endif |
123 |
. endfor |
124 |
. for v in ${GCCVERSIONS} |
125 |
. if ${_USE_GCC} == ${_GCCVERSION_${v}_V} |
126 |
_GCC_MIN2:= true |
127 |
. endif |
128 |
. if defined(_GCC_MIN2) && defined(_GCC_FOUND${v}) && !defined(_GCC_FOUND) |
129 |
_GCC_FOUND:= ${_GCCVERSION_${v}_V} |
130 |
. endif |
131 |
. endfor |
132 |
|
133 |
. if defined(_GCC_FOUND) |
134 |
_USE_GCC:= ${_GCC_FOUND} |
135 |
. elif ${_USE_GCC} < ${GCC_DEFAULT} |
136 |
_USE_GCC:= ${GCC_DEFAULT} |
137 |
. endif |
138 |
.endif # defined(_GCC_ORLATER) |
139 |
|
140 |
.endif # defined(USE_GCC) |
141 |
|
142 |
|
143 |
.if defined(_USE_GCC) |
144 |
# A concrete version has been selected. Determine if the installed OS |
145 |
# features this version in the base, and if not then set proper ports |
146 |
# dependencies, CC, CXX, CPP, and flags. |
147 |
.for v in ${GCCVERSIONS} |
148 |
. if ${_USE_GCC} == ${_GCCVERSION_${v}_V} |
149 |
. if ${OSVERSION} > ${_GCCVERSION_${v}_R} || !exists(/usr/bin/gcc) |
150 |
V:= ${_GCCVERSION_${v}_V:S/.//} |
151 |
_GCC_PORT_DEPENDS:= gcc${V} |
152 |
_GCC_PORT:= gcc${V} |
153 |
CC:= gcc${V} |
154 |
CXX:= g++${V} |
155 |
CPP:= cpp${V} |
156 |
_GCC_RUNTIME:= ${LOCALBASE}/lib/gcc${V} |
157 |
CFLAGS+= -Wl,-rpath=${_GCC_RUNTIME} |
158 |
CXXFLAGS+= -Wl,-rpath=${_GCC_RUNTIME} |
159 |
LDFLAGS+= -Wl,-rpath=${_GCC_RUNTIME} -L${_GCC_RUNTIME} |
160 |
. else # Use GCC in base. |
161 |
CC:= gcc |
162 |
CXX:= g++ |
163 |
. if exists(/usr/bin/gcpp) |
164 |
CPP:= gcpp |
165 |
. else |
166 |
CPP:= cpp |
167 |
. endif |
168 |
. endif # Use GCC in base. |
169 |
. endif # ${_USE_GCC} == ${_GCCVERSION_${v}_V} |
170 |
.endfor |
171 |
.undef V |
172 |
|
173 |
.if defined(_GCC_PORT_DEPENDS) |
174 |
BUILD_DEPENDS+= ${_GCC_PORT_DEPENDS}:lang/${_GCC_PORT} |
175 |
RUN_DEPENDS+= ${_GCC_PORT_DEPENDS}:lang/${_GCC_PORT} |
176 |
# Later GCC ports already depend on binutils; make sure whatever we |
177 |
# build leverages this as well. |
178 |
USE_BINUTILS= yes |
179 |
.endif |
180 |
.endif # defined(_USE_GCC) && !defined(FORCE_BASE_CC_FOR_TESTING) |
181 |
|
182 |
|
183 |
test-gcc: |
184 |
@echo USE_GCC=${USE_GCC} |
185 |
.if defined(IGNORE) |
186 |
@echo "IGNORE: ${IGNORE}" |
187 |
.else |
188 |
.if defined(USE_GCC) |
189 |
.if defined(_GCC_ORLATER) |
190 |
@echo Port can use later versions. |
191 |
.else |
192 |
@echo Port cannot use later versions. |
193 |
.endif |
194 |
.for v in ${GCCVERSIONS} |
195 |
@echo -n "GCC version: ${_GCCVERSION_${v}_V} " |
196 |
.if defined(_GCC_FOUND${v}) |
197 |
@echo -n "(${_GCC_FOUND${v}}) " |
198 |
.endif |
199 |
@echo "- OSVERSION up to ${_GCCVERSION_${v}_R}" |
200 |
# @echo ${v} - ${_GCC_FOUND${v}} - up to ${_GCCVERSION_${v}_R} - ${_GCCVERSION_${v}_V} |
201 |
.endfor |
202 |
@echo Using GCC version ${_USE_GCC} |
203 |
.endif |
204 |
@echo CC=${CC} - CXX=${CXX} - CPP=${CPP} - CFLAGS=\"${CFLAGS}\" |
205 |
@echo LDFLAGS=\"${LDFLAGS}\" |
206 |
@echo "BUILD_DEPENDS=${BUILD_DEPENDS}" |
207 |
@echo "RUN_DEPENDS=${RUN_DEPENDS}" |
208 |
.endif |
209 |
|
210 |
.endif |