1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
|
# Copyright 1999-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header$
EAPI=5
PATCH_VER="1.0"
UCLIBC_VER="1.0"
# Hardened gcc 4 stuff
PIE_VER="0.6.1"
SPECS_VER="0.2.0"
SPECS_GCC_VER="4.4.3"
inherit eutils flag-o-matic toolchain-funcs
DESCRIPTION="The GNU Compiler Collection"
HOMEPAGE="http://gcc.gnu.org/"
SRC_URI="mirror://gnu/${PN}/${P}/${P}.tar.bz2
http://dev.gentoo.org/~vapier/dist/${P}-uclibc-patches-${UCLIBC_VER}.tar.bz2
http://dev.gentoo.org/~vapier/dist/${P}-patches-${PATCH_VER}.tar.bz2
http://dev.gentoo.org/~vapier/dist/${P}-piepatches-v${PIE_VER}.tar.bz2
http://dev.gentoo.org/~rhill/dist/${PN}-${SPECS_GCC_VER}-specs-${SPECS_VER}.tar.bz2"
LICENSE="GPL-3+ LGPL-3+ || ( GPL-3+ libgcc libstdc++ gcc-runtime-library-exception-3.1 ) FDL-1.3+"
SLOT="${PV%.*}"
KEYWORDS="~amd64 ~x86"
IUSE="altivec +cxx doc fixed-point +fortran go graphite hardened libssp
multilib +nls +nptl objc objc-gc objc++ +openmp +pie +sanitize +ssp
test vanilla"
RDEPEND="
>=dev-libs/gmp-4.3.2
>=dev-libs/mpc-0.8.1
>=dev-libs/mpfr-2.4.2
sys-libs/zlib
virtual/libiconv
graphite? (
>=dev-libs/cloog-0.18.0
>=dev-libs/isl-0.11.1
)
nls? ( virtual/libintl )"
DEPEND="${RDEPEND}
>=sys-devel/bison-1.875
>=sys-devel/flex-2.5.4
doc? ( >=app-doc/doxygen-1.7 )
nls? ( sys-devel/gettext )
test? (
>=dev-util/dejagnu-1.4.4
>=sys-devel/autogen-5.5.4
)
elibc_glibc? ( >=sys-libs/glibc-2.8 )
>=sys-devel/binutils-2.20"
PDEPEND="elibc_glibc? ( >=sys-libs/glibc-2.8 )
>=sys-devel/gcc-config-1.7"
REQUIRED_USE="
doc? ( cxx )
go? ( cxx )
hardened? ( pie ssp )
objc++? ( cxx )
pie? ( !vanilla )
ssp? ( !vanilla )"
pkg_setup() {
export CTARGET=${CTARGET:-${CHOST}}
# we dont want to use the installed compiler's specs to build gcc
unset GCC_SPECS
unset LANGUAGES #265283
}
setup_multilib_osdirnames() {
use multilib || return 0
local config
local libdirs="../lib64 ../lib32"
# this only makes sense for some Linux targets
case ${CTARGET} in
x86_64*-linux*) config="i386" ;;
powerpc64*-linux*) config="rs6000" ;;
sparc64*-linux*) config="sparc" ;;
s390x*-linux*) config="s390" ;;
*) return 0 ;;
esac
config+="/t-linux64"
local sed_args=()
sed_args+=( -e 's:$[(]call if_multiarch[^)]*[)]::g' )
if [[ ${SYMLINK_LIB} == "yes" ]] ; then
einfo "updating multilib directories to be: ${libdirs}"
sed_args+=( -e '/^MULTILIB_OSDIRNAMES.*lib32/s:[$][(]if.*):../lib32:' )
else
einfo "using upstream multilib; disabling lib32 autodetection"
sed_args+=( -r -e 's:[$][(]if.*,(.*)[)]:\1:' )
fi
sed -i "${sed_args[@]}" "${S}"/gcc/config/${config} || die
}
src_prepare() {
export BRANDING_GCC_PKGVERSION="Gentoo ${PVR}::mgorny"
if has_version '<sys-libs/glibc-2.12' ; then
ewarn "Your host glibc is too old; disabling automatic fortify."
ewarn "Please rebuild gcc after upgrading to >=glibc-2.12 #362315"
rm "${WORKDIR}"/patch/10_all_default-fortify-source.patch || die
fi
if ! use vanilla; then
BRANDING_GCC_PKGVERSION+=" p${PATCH_VER}"
einfo "Applying Gentoo patches ..."
epatch "${WORKDIR}"/patch/*.patch
einfo "Applying uClibc patches ..."
epatch "${WORKDIR}"/uclibc/*.patch
if use pie; then
BRANDING_GCC_PKGVERSION+=", pie-${PIE_VER}"
einfo "Applying pie patches ..."
epatch "${WORKDIR}"/piepatch/*.patch
fi
# Hardening stuff.
local hard_flags=()
if use hardened; then
BRANDING_GCC_PKGVERSION=${BRANDING_GCC_PKGVERSION/Gentoo/Gentoo Hardened}
hard_flags+=( -DEFAULT_PIE_SSP )
else
hard_flags+=( -DEFAULT_SSP )
fi
sed -i \
-e "/^ALL_CFLAGS = /s|=|= ${hard_flags[*]} |" \
-e "/^ALL_CXXFLAGS = /s|=|= ${hard_flags[*]} |" \
"${S}"/gcc/Makefile.in || die
#Use -r1 for newer piepatchet that use DRIVER_SELF_SPECS for the hardened specs.
[[ ${CHOST} == ${CTARGET} ]] && epatch "${FILESDIR}"/gcc-spec-env-r1.patch
fi
epatch_user
find "${S}" -name Makefile.in \
-exec sed -i '/^pkgconfigdir/s:=.*:=$(toolexeclibdir)/pkgconfig:' {} +
setup_multilib_osdirnames
# Prevent new texinfo from breaking old versions (see #198182, #464008)
epatch "${FILESDIR}"/gcc-configure-texinfo.patch
einfo "Touching generated files ..."
./contrib/gcc_update --touch
}
gcc-abi-map() {
# Convert the ABI name we use in Gentoo to what gcc uses
local map=()
case ${CTARGET} in
mips*) map=("o32 32" "n32 n32" "n64 64") ;;
x86_64*) map=("amd64 m64" "x86 m32" "x32 mx32") ;;
esac
local m
for m in "${map[@]}" ; do
if [[ $1 == ${l% *} ]]; then
echo "${l#* }"
break
fi
done
}
src_configure() {
strip-flags
filter-flags '-mabi*' -m31 -m32 -m64
replace-flags -O3 -O2
filter-flags -frecord-gcc-switches # 490738
filter-flags -mno-rtm -mno-htm # 506202
filter-flags '-mcpu=*'
einfo "CFLAGS: ${CFLAGS}"
einfo "CXXFLAGS: ${CXXFLAGS}"
einfo "LDFLAGS: ${LDFLAGS}"
local prefix=/usr
local binpath=${prefix}/${CTARGET}/gcc-bin/${PV}
local libpath=${prefix}/lib/gcc/${CTARGET}/${PV}
local incpath=${libpath}/include
local datapath=${prefix}/share/gcc-data/${CTARGET}/${PV}
local stdcxx_incdir=${libpath}/include/g++-v${GCC_BRANCH_VER%%.*}
local langs=( c )
use cxx && langs+=( c++ )
use go && langs+=( go )
use objc && langs+=( objc )
use objc++ && langs+=( obj-c++ )
use fortran && langs+=( fortran )
langs=${langs[*]}
local myconf=(
--host=${CHOST}
--build=${CBUILD:-${CHOST}}
--prefix="${prefix}"
--bindir="${binpath}"
--includedir="${incpath}"
--datadir="${datapath}"
--mandir="${datapath}/man"
--infodir="${datapath}/info"
--with-gxx-include-dir="${stdcxx_incdir}"
--with-python-dir=${datapath#${prefix}/}/python
--enable-languages="${langs// /,}"
--disable-libgcj
--enable-obsolete
--enable-secureplt
--disable-werror
--with-system-zlib
--disable-libunwind-exceptions
--enable-checking=release
$(use_enable nls)
--without-included-gettext
# branding
--with-bugurl=https://bugs.gentoo.org/
--with-pkgversion="${BRANDING_GCC_PKGVERSION}"
$(use_enable hardened esp)
# allow gcc to search for clock funcs in the main C lib.
# if it can't find them, then tough cookies -- we aren't
# going to link in -lrt to all C++ apps. #411681
$(use_enable cxx libstdcxx-time)
--enable-lto
--enable-shared
--enable-threads=posix
# ppc altivec
$(use_enable altivec)
# mips fixed-point arithmetic
$(use_enable fixed-point)
$(use_enable multilib)
$(use_enable openmp libgomp)
--disable-libmudflap
$(use_enable libssp)
# used only by fortran
$(use_enable fortran libquadmath)
$(use_with graphite cloog)
$(use_enable '!graphite' isl-version-check)
$(use_enable sanitize libsanitizer)
$(use_enable objc-gc)
)
# __cxa_atexit is "essential for fully standards-compliant handling of
# destructors", but apparently requires glibc.
case ${CTARGET} in
*-uclibc*)
myconf+=(
--disable-__cxa_atexit
$(use_enable nptl tls)
)
;;
*-elf|*-eabi)
myconf+=( --with-newlib )
;;
*-gnu*)
myconf+=(
--enable-__cxa_atexit
--enable-clocale=gnu
)
;;
*-freebsd*)
myconf+=( --enable-__cxa_atexit )
;;
*-solaris*)
myconf+=( --enable-__cxa_atexit )
;;
esac
: ${TARGET_ABI:=${ABI}}
: ${TARGET_MULTILIB_ABIS:=${MULTILIB_ABIS}}
: ${TARGET_DEFAULT_ABI:=${DEFAULT_ABI}}
# translate our notion of multilibs into gcc's
local abi list
for abi in $(get_all_abis TARGET); do
local l=$(gcc-abi-map ${abi})
[[ -n ${l} ]] && list+=",${l}"
done
if [[ -n ${list} ]] ; then
case ${CTARGET} in
x86_64*)
myconf+=( --with-multilib-list=${list:1} )
;;
esac
fi
case $(tc-is-softfloat) in
yes) myconf+=( --with-float=soft ) ;;
softfp) myconf+=( --with-float=softfp ) ;;
*)
# If they've explicitly opt-ed in, do hardfloat,
# otherwise let the gcc default kick in.
case ${CTARGET//_/-} in
*-hardfloat-*|*eabihf) myconf+=( --with-float=hard ) ;;
esac
esac
local with_abi_map=()
case $(tc-arch) in
arm) #264534 #414395
local a arm_arch=${CTARGET%%-*}
# Remove trailing endian variations first: eb el be bl b l
for a in e{b,l} {b,l}e b l ; do
if [[ ${arm_arch} == *${a} ]] ; then
arm_arch=${arm_arch%${a}}
break
fi
done
# Convert armv7{a,r,m} to armv7-{a,r,m}
[[ ${arm_arch} == armv7? ]] && arm_arch=${arm_arch/7/7-}
# See if this is a valid --with-arch flag
if (srcdir=${S}/gcc target=${CTARGET} with_arch=${arm_arch};
. "${srcdir}"/config.gcc) &>/dev/null
then
myconf+=( --with-arch=${arm_arch} )
fi
# Make default mode thumb for microcontroller classes #418209
[[ ${arm_arch} == *-m ]] && myconf+=( --with-mode=thumb )
# Enable hardvfp
if [[ $(tc-is-softfloat) == "no" && ${CTARGET} == armv[67]* ]]
then
# Follow the new arm hardfp distro standard by default
myconf+=( --with-float=hard )
case ${CTARGET} in
armv6*) myconf+=( --with-fpu=vfp ) ;;
armv7*) myconf+=( --with-fpu=vfpv3-d16 ) ;;
esac
fi
;;
mips)
# Add --with-abi flags to set default ABI
myconf+=( --with-abi=$(gcc-abi-map "${TARGET_DEFAULT_ABI}") )
;;
amd64)
# drop the older/ABI checks once this get's merged into some
# version of gcc upstream
# translate our notion of multilibs into gcc's
local abi list
for abi in $(get_all_abis TARGET) ; do
local l=$(gcc-abi-map ${abi})
[[ -n ${l} ]] && list+=",${l}"
done
if [[ -n ${list} ]] ; then
case ${CTARGET} in
x86_64*)
myconf+=( --with-multilib-list=${list:1} )
;;
esac
fi
if has x32 $(get_all_abis TARGET) ; then
myconf+=( --with-abi=$(gcc-abi-map ${TARGET_DEFAULT_ABI}) )
fi
;;
x86)
# Default arch for x86 is normally i386, lets give it a bump
# since glibc will do so based on CTARGET anyways
myconf+=( --with-arch="${CTARGET%%-*}" )
;;
ppc)
# Set up defaults based on current CFLAGS
is-flagq -mfloat-gprs=double && myconf+=( --enable-e500-double )
[[ ${CTARGET//_/-} == *-e500v2-* ]] && myconf+=( --enable-e500-double )
;;
esac
# if the target can do biarch (-m32/-m64), enable it. overhead should
# be small, and should simplify building of 64bit kernels in a 32bit
# userland by not needing sys-devel/kgcc64. #349405
case $(tc-arch) in
ppc|ppc64) myconf+=( --enable-targets=all ) ;;
sparc) myconf+=( --enable-targets=all ) ;;
amd64|x86) myconf+=( --enable-targets=all ) ;;
esac
# On Darwin we need libdir to be set in order to get correct install names
# for things like libobjc-gnu, libgcj and libfortran. If we enable it on
# non-Darwin we screw up the behaviour this eclass relies on. We in
# particular need this over --libdir for bug #255315.
[[ ${CTARGET} == *-darwin* ]] && \
myconf+=( --enable-version-specific-runtime-libs )
# Disable gcc info regeneration #464008
export gcc_cv_prog_makeinfo_modern=no
# Build in a separate build tree
mkdir -p "${WORKDIR}"/build
pushd "${WORKDIR}"/build > /dev/null
# and now to do the actual configuration
addwrite /dev/zero
set -- "${S}"/configure "${myconf[@]}" ${EXTRA_ECONF}
echo "${@}"
"${@}" || die 'configure failed'
# return to whatever directory we were in before
popd > /dev/null
# TODO: crap
cat <<-EOF > envd
PATH="${binpath}"
ROOTPATH="${binpath}"
GCC_PATH="${binpath}"
LDPATH="${ldpaths}"
MANPATH="${datapath}/man"
INFOPATH="${datapath}/info"
STDCXX_INCDIR="${stdcxx_incdir##*/}"
CTARGET="${CTARGET}"
GCC_SPECS="${gcc_specs_file}"
MULTIOSDIRS="${mosdirs}"
EOF
}
src_compile() {
touch "${S}"/gcc/c-gperf.h
local prefix=/usr
local libpath=${prefix}/lib/gcc/${CTARGET}/${PV}
emake -C "${WORKDIR}"/build all \
LDFLAGS="${LDFLAGS}" \
STAGE1_CFLAGS="${CFLAGS}" \
LIBPATH="${libpath}" \
BOOT_CFLAGS="$(get_abi_CFLAGS "${TARGET_DEFAULT_ABI}") ${CFLAGS}"
if use cxx && use doc; then
emake -C "${WORKDIR}"/build/"${CTARGET}"/libstdc++-v3/doc \
doc-man-doxygen
fi
}
src_test() {
emake -k -C "${WORKDIR}"/build check
}
|