summaryrefslogtreecommitdiff
blob: 8c0755819652f58e337ef52936f9bde9ae3f675a (plain)
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
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/sys-libs/glibc/files/eblits/src_compile.eblit,v 1.35 2013/04/05 18:25:21 vapier Exp $

glibc_do_configure() {
	local myconf=()

	einfo "Configuring GLIBC for $1"

	# set addons
	pushd "${S}" > /dev/null
	local ADDONS=$(echo */configure | sed \
		-e 's:/configure::g' \
		-e 's:\(linuxthreads\|nptl\|rtkaio\|glibc-compat\)\( \|$\)::g' \
		-e 's: \+$::' \
		-e 's! !,!g' \
		-e 's!^!,!' \
		-e '/^,\*$/d')
	[[ -d ports ]] && ADDONS="${ADDONS},ports"
	popd > /dev/null

	myconf+=( $(use_enable hardened stackguard-randomization) )
	if has_version '<sys-libs/glibc-2.13' ; then
		myconf+=( --enable-old-ssp-compat )
	fi

	[[ ${CTARGET//_/-} == *-softfloat-* ]] && myconf+=( --without-fp )

	if [[ $1 == "linuxthreads" ]] ; then
		if want_tls ; then
			myconf+=( --with-tls )

			if ! want__thread || use glibc-compat20 || [[ ${LT_KER_VER} == 2.[02].* ]] ; then
				myconf+=( --without-__thread )
			else
				myconf+=( --with-__thread )
			fi
		else
			myconf+=( --without-tls --without-__thread )
		fi

		myconf+=( --disable-sanity-checks )
		myconf+=( --enable-add-ons="linuxthreads${ADDONS}" )
		myconf+=( --enable-kernel=${LT_KER_VER} )
	elif [[ $1 == "nptl" ]] ; then
		myconf+=( --enable-add-ons="nptl${ADDONS}" )
		myconf+=( --enable-kernel=${NPTL_KERN_VER} )
	else
		die "invalid pthread option"
	fi

	# Since SELinux support is only required for nscd, only enable it if:
	# 1. USE selinux
	# 2. only for the primary ABI on multilib systems
	# 3. Not a crosscompile
	if ! is_crosscompile && use selinux ; then
		if use multilib || has_multilib_profile ; then
			if is_final_abi ; then
				myconf+=( --with-selinux )
			else
				myconf+=( --without-selinux )
			fi
		else
			myconf+=( --with-selinux )
		fi
	else
		myconf+=( --without-selinux )
	fi

	myconf+=(
		--without-cvs
		--enable-bind-now
		--build=${CBUILD_OPT:-${CBUILD}}
		--host=${CTARGET_OPT:-${CTARGET}}
		$(use_enable profile)
		$(use_with gd)
		--with-headers="$(alt_eprefix)"$(alt_build_headers)
		--prefix="$(alt_eprefix)"/usr
		--libdir="$(alt_eprefix)"/usr/$(get_libdir)
		--mandir="$(alt_eprefix)"/usr/share/man
		--infodir="$(alt_eprefix)"/usr/share/info
		--libexecdir="$(alt_eprefix)"/usr/$(get_libdir)/misc/glibc
		--sysconfdir="$(alt_eprefix)"/etc
		--localstatedir="$(alt_eprefix)"/var
		--with-bugurl=http://bugs.gentoo.org/
		--with-pkgversion="$(glibc_banner)"
		$(use_multiarch || echo --disable-multi-arch)
		--enable-obsolete-rpc
		$(in_iuse systemtap && use_enable systemtap)
		$(in_iuse nscd && use_enable nscd)
		${EXTRA_ECONF}
	)

	# There is no configure option for this and we need to export it
	# since the glibc build will re-run configure on itself
	export libc_cv_slibdir="$(alt_eprefix)"/$(get_libdir)

	# We take care of patching our binutils to use both hash styles,
	# and many people like to force gnu hash style only, so disable
	# this overriding check.  #347761
	export libc_cv_hashstyle=no

	local GBUILDDIR=${WORKDIR}/build-${ABI}-${CTARGET}-$1
	mkdir -p "${GBUILDDIR}"
	cd "${GBUILDDIR}"
	set -- "${S}"/configure "${myconf[@]}"
	echo "$@"
	"$@" || die "failed to configure glibc"

	# ia64 static cross-compilers are a pita in so much that they
	# can't produce static ELFs (as the libgcc.a is broken).  so
	# disable building of the programs for those targets if it
	# doesn't work.
	# XXX: We could turn this into a compiler test, but ia64 is
	# the only one that matters, so this should be fine for now.
	if is_crosscompile && [[ ${CTARGET} == ia64* ]] ; then
		sed -i '1i+link-static = touch $@' config.make
	fi
}

toolchain-glibc_src_compile() {
	echo
	local v
	for v in ABI CBUILD CHOST CTARGET CBUILD_OPT CTARGET_OPT CC {AS,C,CPP,CXX,LD}FLAGS ; do
		einfo " $(printf '%15s' ${v}:)   ${!v}"
	done

	export CC=$(tc-getCC ${CTARGET})
	# Glibc does not work with gold (for various reasons) #269274.
	if $(tc-getLD ${CTARGET}) --version | grep -q 'GNU gold' ; then
		local d="${T}/bfd-linker"
		mkdir -p "${d}"
		ln -sf $(which ${CTARGET}-ld.bfd) "${d}"/ld
		CC+=" -B${d}"
	fi
	einfo " $(printf '%15s' 'Manual CC:')   ${CC}"
	echo

	if want_linuxthreads ; then
		glibc_do_configure linuxthreads
		emake || die "make for ${ABI} failed"
	fi
	if want_nptl ; then
		# ... and then do the optional nptl build
		unset LD_ASSUME_KERNEL
		glibc_do_configure nptl
		emake || die "make for ${ABI} failed"
	fi
}

toolchain-glibc_headers_compile() {
	local GBUILDDIR=${WORKDIR}/build-${ABI}-${CTARGET}-headers
	mkdir -p "${GBUILDDIR}"
	cd "${GBUILDDIR}"

	# if we don't have a compiler yet, we cant really test it now ...
	# hopefully they don't affect header geneation, so let's hope for
	# the best here ...
	local v vars=(
		ac_cv_header_cpuid_h=yes
		libc_cv_{386,390,alpha,arm,hppa,ia64,mips,{powerpc,sparc}{,32,64},sh,x86_64}_tls=yes
		libc_cv_asm_cfi_directives=yes
		libc_cv_broken_visibility_attribute=no
		libc_cv_gcc___thread=yes
		libc_cv_mlong_double_128=yes
		libc_cv_mlong_double_128ibm=yes
		libc_cv_ppc_machine=yes
		libc_cv_ppc_rel16=yes
		libc_cv_predef_{fortify_source,stack_protector}=no
		libc_cv_visibility_attribute=yes
		libc_cv_z_combreloc=yes
		libc_cv_z_execstack=yes
		libc_cv_z_initfirst=yes
		libc_cv_z_nodelete=yes
		libc_cv_z_nodlopen=yes
		libc_cv_z_relro=yes
		libc_mips_abi=${ABI}
		libc_mips_float=$([[ $(tc-is-softfloat) == "yes" ]] && echo soft || echo hard)
	)
	einfo "Forcing cached settings:"
	for v in "${vars[@]}" ; do
		einfo " ${v}"
		export ${v}
	done

	# Pick out the correct location for build headers
	local ports="" myconf=()
	[[ -d ${S}/ports ]] && ports=",ports"
	myconf+=(
		--disable-sanity-checks
		--enable-hacker-mode
		--enable-add-ons=nptl${ports}
		--without-cvs
		--enable-bind-now
		--build=${CBUILD_OPT:-${CBUILD}}
		--host=${CTARGET_OPT:-${CTARGET}}
		--with-headers=$(alt_eprefix)$(alt_build_headers)
		--prefix="$(alt_eprefix)"/usr
		${EXTRA_ECONF}
	)

	# Nothing is compiled here which would affect the headers for the target.
	# so forcing CC/CFLAGS is sane.  unless you dont have `gcc`.  then i
	# dont care :p.
	set -- "${S}"/configure "${myconf[@]}"
	CC=gcc \
	CFLAGS="-O1 -pipe" \
	CPPFLAGS="-U_FORTIFY_SOURCE" \
	LDFLAGS="" \
	"$@" || die "failed to configure glibc"
}

eblit-glibc-src_compile() {
	if is_crosscompile ; then
		export \
			libc_cv_c_cleanup=yes \
			libc_cv_forced_unwind=yes
	fi

	if just_headers ; then
		export ABI=default
		toolchain-glibc_headers_compile
		return
	fi

	setup_env

	if [[ -z ${OABI} ]] ; then
		local abilist=""
		if has_multilib_profile ; then
			abilist=$(get_install_abis)
		elif is_crosscompile || tc-is-cross-compiler ; then
			abilist=${DEFAULT_ABI}
		fi
		einfo "Building glibc for ABIs: ${abilist}"
		if [[ -n ${abilist} ]] ; then
			OABI=${ABI}
			for ABI in ${abilist} ; do
				export ABI
				src_compile
			done
			ABI=${OABI}
			unset OABI
			return 0
		fi
	fi

	toolchain-glibc_src_compile
}