1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
7 inherit eutils versionator toolchain-funcs flag-o-matic gnuconfig multilib systemd unpacker multiprocessing
9 DESCRIPTION="GNU libc6 (also called glibc2) C library"
10 HOMEPAGE="http://www.gnu.org/software/libc/libc.html"
12 LICENSE="LGPL-2.1+ BSD HPND ISC inner-net rc PCRE"
13 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86"
14 RESTRICT="strip" # strip ourself #46186
17 # Configuration variables
21 EGIT_REPO_URIS="git://sourceware.org/git/glibc.git"
22 EGIT_SOURCEDIRS="${S}"
29 GCC_BOOTSTRAP_VER="4.7.3-r1"
30 PATCH_VER="4" # Gentoo patchset
31 : ${NPTL_KERN_VER:="2.6.32"} # min kernel version nptl requires
33 IUSE="debug gd hardened multilib nscd selinux systemtap profile suid vanilla crosscompile_opts_headers-only"
35 # Here's how the cross-compile logic breaks down ...
36 # CTARGET - machine that will target the binaries
37 # CHOST - machine that will host the binaries
38 # CBUILD - machine that will build the binaries
39 # If CTARGET != CHOST, it means you want a libc for cross-compiling.
40 # If CHOST != CBUILD, it means you want to cross-compile the libc.
41 # CBUILD = CHOST = CTARGET - native build/install
42 # CBUILD != (CHOST = CTARGET) - cross-compile a native build
43 # (CBUILD = CHOST) != CTARGET - libc for cross-compiler
44 # CBUILD != CHOST != CTARGET - cross-compile a libc for a cross-compiler
46 # CHOST = CTARGET - install into /
47 # CHOST != CTARGET - install into /usr/CTARGET/
49 export CBUILD=${CBUILD:-${CHOST}}
50 export CTARGET=${CTARGET:-${CHOST}}
51 if [[ ${CTARGET} == ${CHOST} ]] ; then
52 if [[ ${CATEGORY} == cross-* ]] ; then
53 export CTARGET=${CATEGORY#cross-}
58 [[ ${CHOST} != ${CTARGET} ]]
61 # Why SLOT 2.2 you ask yourself while sippin your tea ?
62 # Everyone knows 2.2 > 0, duh.
65 # General: We need a new-enough binutils/gcc to match upstream baseline.
66 # arch: we need to make sure our binutils/gcc supports TLS.
67 DEPEND=">=app-misc/pax-utils-0.1.10
68 !<sys-apps/sandbox-1.6
69 !<sys-apps/portage-2.1.2
70 selinux? ( sys-libs/libselinux )"
71 RDEPEND="!sys-kernel/ps3-sources
72 sys-apps/gentoo-functions
73 selinux? ( sys-libs/libselinux )
76 if [[ ${CATEGORY} == cross-* ]] ; then
77 DEPEND+=" !crosscompile_opts_headers-only? (
78 >=${CATEGORY}/binutils-2.24
81 [[ ${CATEGORY} == *-linux* ]] && DEPEND+=" ${CATEGORY}/linux-headers"
84 >=sys-devel/binutils-2.24
87 RDEPEND+=" vanilla? ( !sys-libs/timezone-data )"
88 PDEPEND+=" !vanilla? ( sys-libs/timezone-data )"
92 echo mirror://gnu/glibc/$1 ftp://sourceware.org/pub/glibc/{releases,snapshots}/$1 mirror://gentoo/$1
95 local devspace="HTTP~vapier/dist/URI HTTP~azarah/glibc/URI"
96 devspace=${devspace//HTTP/https://dev.gentoo.org/}
97 echo mirror://gentoo/$1 ${devspace//URI/$1}
100 [[ -z ${EGIT_REPO_URIS} ]] && upstream_uris ${P}.tar.xz
101 [[ -n ${PATCH_VER} ]] && gentoo_uris ${P}-patches-${PATCH_VER}.tar.bz2
103 SRC_URI+=" ${GCC_BOOTSTRAP_VER:+multilib? ( $(gentoo_uris gcc-${GCC_BOOTSTRAP_VER}-multilib-bootstrap.tar.bz2) )}"
105 # eblit-include [--skip] <function> [version]
108 [[ $1 == "--skip" ]] && skipable=true && shift
109 [[ $1 == pkg_* ]] && skipable=true
111 local e v func=$1 ver=$2
112 [[ -z ${func} ]] && die "Usage: eblit-include <function> [version]"
113 for v in ${ver:+-}${ver} -${PVR} -${PV} "" ; do
114 e="${FILESDIR}/eblits/${func}${v}.eblit"
115 if [[ -e ${e} ]] ; then
120 ${skipable} && return 0
121 die "Could not locate requested eblit '${func}' in ${FILESDIR}/eblits/"
124 # eblit-run-maybe <function>
125 # run the specified function if it is defined
127 [[ $(type -t "$@") == "function" ]] && "$@"
130 # eblit-run <function> [version]
131 # aka: src_unpack() { eblit-run src_unpack ; }
133 eblit-include --skip common "${*:2}"
135 eblit-run-maybe eblit-$1-pre
137 eblit-run-maybe eblit-$1-post
140 src_unpack() { eblit-run src_unpack ; }
141 src_prepare() { eblit-run src_prepare ; }
142 src_configure() { eblit-run src_configure ; }
143 src_compile() { eblit-run src_compile ; }
144 src_test() { eblit-run src_test ; }
145 src_install() { eblit-run src_install ; }
147 # FILESDIR might not be available during binpkg install
148 for x in pretend setup {pre,post}inst ; do
149 e="${FILESDIR}/eblits/pkg_${x}.eblit"
150 if [[ -e ${e} ]] ; then
152 eval "pkg_${x}() { eblit-run pkg_${x} ; }"
156 eblit-src_unpack-pre() {
157 [[ -n ${GCC_BOOTSTRAP_VER} ]] && use multilib && unpack gcc-${GCC_BOOTSTRAP_VER}-multilib-bootstrap.tar.bz2
160 eblit-src_prepare-post() {
163 if use hardened ; then
164 einfo "Patching to get working PIE binaries on PIE (hardened) platforms"
165 gcc-specs-pie && epatch "${FILESDIR}"/2.17/glibc-2.17-hardened-pie.patch
166 epatch "${FILESDIR}"/2.20/glibc-2.20-hardened-inittls-nosysenter.patch
168 # We don't enable these for non-hardened as the output is very terse --
169 # it only states that a crash happened. The default upstream behavior
170 # includes backtraces and symbols.
171 einfo "Installing Hardened Gentoo SSP and FORTIFY_SOURCE handler"
172 cp "${FILESDIR}"/2.20/glibc-2.20-gentoo-stack_chk_fail.c debug/stack_chk_fail.c || die
173 cp "${FILESDIR}"/2.20/glibc-2.20-gentoo-chk_fail.c debug/chk_fail.c || die
176 # Allow SIGABRT to dump core on non-hardened systems, or when debug is requested.
178 -e '/^CFLAGS-backtrace.c/ iCPPFLAGS-stack_chk_fail.c = -DSSP_SMASH_DUMPS_CORE' \
179 -e '/^CFLAGS-backtrace.c/ iCPPFLAGS-chk_fail.c = -DSSP_SMASH_DUMPS_CORE' \
180 debug/Makefile || die
183 # Build various bits with ssp-all
185 -e 's:-fstack-protector$:-fstack-protector-all:' \
189 case $(gcc-fullversion) in
191 eerror "You need to switch to a newer compiler; gcc-4.8.[0-3] and gcc-4.9.0 miscompile"
192 eerror "glibc. See https://bugs.gentoo.org/547420 for details."
193 die "need to switch compilers #547420"