summaryrefslogtreecommitdiff
blob: c8af4741b7d0f1e1e478664dd8e41f5cebe20a27 (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
# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/dev-libs/klibc/klibc-1.5.ebuild,v 1.2 2007/06/13 18:10:34 phreak Exp $

inherit eutils linux-info multilib toolchain-funcs

DESCRIPTION="A minimal libc subset for use with initramfs."
HOMEPAGE="http://www.zytor.com/mailman/listinfo/klibc"
SRC_URI="ftp://ftp.kernel.org/pub/linux/libs/klibc/${P}.tar.bz2
	ftp://ftp.kernel.org/pub/linux/libs/klibc/Testing/${P}.tar.bz2"

LICENSE="|| ( GPL-2 LGPL-2 )"
KEYWORDS="~amd64 -mips ~ppc ~x86 ~sparc"
SLOT="0"
IUSE="debug n32"

DEPEND="dev-lang/perl
	virtual/linux-sources"
RDEPEND="dev-lang/perl"

# Klibc has no PT_GNU_STACK support, so scanning for execstacks is moot
QA_EXECSTACK="*"

src_unpack() {
	unpack ${A}
	cd "${S}"

	# Symlink /usr/src/linux to ${S}/linux
	ln -snf ${KV_DIR} linux

	# Build interp.o with EXTRA_KLIBCAFLAGS (.S source)
	epatch "${FILESDIR}"/${PN}-1.4.11-interp-flags.patch

	# klibc detects mips64 systems as having 64bit userland
	# Force them to 32bit userlands instead
	# Do we really need this still, as klibc uses tc-arch-kernel now ?
#	if use mips ; then
#		! use n32 && epatch "${FILESDIR}"/${PN}-1.4.9-mips32.patch
#	fi

	# Fixes for sparc and ppc
	epatch "${FILESDIR}"/${P}-sigaction.patch
}

tc-detect-arch() {
	tc-arch-kernel | sed -e "s,powerpc,ppc" -e "s,sparc(.*),sparc"
}

src_compile() {
	local myconf=""

	# sparc kernel bitness (32 vs. 64) doesn't matter, as userland is always
	# compiled w/ 32 -- as pointed out by gustavoz

	# tc-arch-kernel gets the UL issue on ppc64 right, but klibc is still back
	# before 2.6.15, when ppc/ppc64 got renamed to powerpc.

	[[ ${KV_DIR} != "${KV_OUT_DIR}" ]] && \
		myconf="KLIBCKERNELOBJ='${KV_OUT_DIR}/' KBUILD_SRC='1'"

	use debug && myconf="${myargs} V=1"

	if tc-is-cross-compiler ; then
		myconf="CROSS_COMPILE=${CTARGET}-"
	fi

	emake KLIBCARCH=$(tc-detect-arch | sed "s,powerpc,ppc") \
		EXTRA_KLIBCAFLAGS="-Wa,--noexecstack" \
		EXTRA_KLIBCLDFLAGS="-z,noexecstack" \
		libdir="/usr/$(get_libdir)" \
		SHLIBDIR="/$(get_libdir)" \
		mandir="/usr/share/man" \
		INSTALLDIR="/usr/$(get_libdir)/klibc" \
		${myconf} || die "Compile failed!"
}

src_install() {
	local myconf="" klibc_prefix=""

	[[ ${KV_DIR} != "${KV_OUT_DIR}" ]] && \
		myconf="KLIBCKERNELOBJ='${KV_OUT_DIR}/' KBUILD_SRC='1'"

	use debug && myconf="${myargs} V=1"

	if tc-is-cross-compiler ; then
		klibc_prefix=$("${S}/klcc/${CTARGET}-klcc" -print-klibc-prefix)
		myconf="CROSS_COMPILE=${CTARGET}-"
	else
		klibc_prefix=$("${S}/klcc/klcc" -print-klibc-prefix)
	fi

	emake KLIBCARCH=$(tc-detect-arch) \
		EXTRA_KLIBCAFLAGS="-Wa,--noexecstack" \
		EXTRA_KLIBCLDFLAGS="-z,noexecstack" \
		INSTALLROOT="${D}" \
		libdir="/usr/$(get_libdir)" \
		SHLIBDIR="/$(get_libdir)" \
		mandir="/usr/share/man" \
		INSTALLDIR="/usr/$(get_libdir)/klibc" \
		${myargs} \
		install || die "Install failed!"

	# klibc doesn't support prelinking, so we need to mask it
	cat > "${T}/70klibc" <<-EOF
		PRELINK_PATH_MASK="/usr/$(get_libdir)/klibc"
	EOF

	doenvd "${T}"/70klibc

	# Fix the permissions (bug #178053) on /usr/$(get_libdir)/klibc/include
	# Actually I have no idea, why the includes have those weird-ass permissions
	# on a particular system, might be due to inherited permissions from parent
	# directory
	find "${D}"/usr/$(get_libdir)/klibc/include | xargs chmod o+rX

	# Hardlinks becoming copies
	for x in gunzip zcat ; do
		rm -f "${D}/${klibc_prefix}/bin/${x}"
		dosym gzip "${klibc_prefix}/bin/${x}"
	done

	if ! tc-is-cross-compiler ; then
		cd "${S}"
		insinto /usr/share/aclocal
		doins contrib/klibc.m4

		dodoc README usr/klibc/CAVEATS usr/klibc/README
		newdoc usr/klibc/arch/README README.klibc.arch
		docinto dash; newdoc usr/dash/README.klibc README
		docinto gzip; dodoc usr/gzip/README
	fi
}