summaryrefslogtreecommitdiff
blob: 07f4e32fd071835c29a7134f07d2a38cd5acfe99 (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
# Copyright 1999-2004 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/dev-libs/uclibc/uclibc-0.9.26-r2.ebuild,v 1.1 2004/06/23 02:14:07 solar Exp $

inherit eutils flag-o-matic gcc

MY_P="${P/ucl/uCl}"
DESCRIPTION="C library for developing embedded Linux systems"
HOMEPAGE="http://www.uclibc.org/"
SRC_URI="http://www.kernel.org/pub/linux/libs/uclibc/${MY_P}.tar.bz2"

CVS_VER="20040613"
SRC_URI="${SRC_URI} mirror://gentoo/${MY_P}-cvs-update-${CVS_VER}.patch.bz2"

PATCH_VER="1.1"
SRC_URI="${SRC_URI} mirror://gentoo/${MY_P}-patches-${PATCH_VER}.tar.bz2"

LICENSE="LGPL-2"
SLOT="0"
KEYWORDS="~x86 ~ppc ~sparc ~mips ~arm"
IUSE="build ipv6 uclibc hardened" # nls is not supported yet

DEPEND="sys-devel/gcc"
PROVIDE="virtual/glibc"

S=${WORKDIR}/${MY_P}

check_main_libc() {
	if [ -f /lib/lib${MY_P}.so -a ! -f /lib/libc.so.6 ] ; then
		if echo "${CHOST}" | grep -q uclibc ; then
			retval=0
		else
			retval=1
		fi
	else
		retval=1
	fi
	[ "${retval}" = "0" ] && SYS_LIBC=uClibc || SYS_LIBC=glibc
	echo
	einfo "We are building for ${SYS_LIBC} system library"
	echo
}

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

	if [ -n "${CVS_VER}" ]
	then
		epatch ${DISTDIR}/${MY_P}-cvs-update-${CVS_VER}.patch.bz2
		epatch ${FILESDIR}/0.9.26/uClibc-20040613-do_rem.patch
	fi

	cp ${FILESDIR}/0.9.26/ssp.c ${S}/libc/sysdeps/linux/common/ || \
		die "failed to copy ssp.c to ${S}/libc/sysdeps/linux/common/"
	# gcc 3.4 nukes ssp without this patch
	if [ "`gcc-major-version`" -ge "3" -a "`gcc-minor-version`" -ge "4" ]
	then
		epatch ${FILESDIR}/0.9.26/uclibc-0.9.26-ssp-gcc34-after-frandom.patch
	fi

	if [ -n "${PATCH_VER}" ]
	then
		unpack ${MY_P}-patches-${PATCH_VER}.tar.bz2
		# for now we remove relro/now, no support for relro in ldso
		rm -f ${WORKDIR}/patch/*relro*
		rm -f ${WORKDIR}/patch/*now*
		# remove default ssp build
		use hardened || rm -f ${WORKDIR}/patch/*enable-ssp*
		epatch ${WORKDIR}/patch
	fi

	# support archs which dont implement all syscalls
	[ -z "${CVS_VER}" ] && epatch ${FILESDIR}/${PV}/arm-fix-missing-syscalls.patch

	# fixup for install perms
	sed -i -e "s:-fa:-dRf:g" Makefile

	local target=""
	if [ "${ARCH}" == "x86" ] ; then
		target="i386"
	elif [ "${ARCH}" == "ppc" ] ; then
		target="powerpc"
	else
		# sparc|mips|alpha|arm|sh
		target="${ARCH}"
	fi
	sed -i \
		-e "s:default TARGET_i386:default TARGET_${target}:" \
		extra/Configs/Config.in
	sed -i \
		-e "s:default CONFIG_GENERIC_386:default CONFIG_${UCLIBC_CPU:-GENERIC_386}:" \
		extra/Configs/Config.${target}

	make defconfig >/dev/null || die "could not config"

	# this could be a debug flag
	for def in UCLIBC_PROFILING DO{DEBUG,ASSERTS} SUPPORT_LD_DEBUG{,_EARLY} ; do
		sed -i -e "s:${def}=y:# ${def} is not set:" .config
	done

	for def in DO_C99_MATH UCLIBC_HAS_{RPC,CTYPE_CHECKED,WCHAR,HEXADECIMAL_FLOATS,GLIBC_CUSTOM_PRINTF,FOPEN_EXCLUSIVE_MODE,GLIBC_CUSTOM_STREAMS,PRINTF_M_SPEC,FTW} ; do
		sed -i -e "s:# ${def} is not set:${def}=y:" .config
	done
	echo "UCLIBC_HAS_FULL_RPC=n" >> .config

	#if use nls
	#then
	#	sed -i -e "s:# UCLIBC_HAS_LOCALE is not set:UCLIBC_HAS_LOCALE=y:" .config
	#	echo "UCLIBC_HAS_XLOCALE=n" >> .config
	#	echo "UCLIBC_HAS_GLIBC_DIGIT_GROUPING=y" >> .config
	#	echo "UCLIBC_HAS_SCANF_LENIENT_DIGIT_GROUPING=y" >> .config
	#	echo "UCLIBC_HAS_GETTEXT_AWARENESS=y" >> .config
	#	# on pax enabled kernels the locale files can't be built
	#	echo "UCLIBC_PREGENERATED_LOCALE_DATA=n" >> .config
	#fi
	# we disable LOCALE for any case, gettext has to be used
	echo "UCLIBC_HAS_LOCALE=n" >> .config

	use ipv6 && sed -i -e "s:# UCLIBC_HAS_IPV6 is not set:UCLIBC_HAS_IPV6=y:" .config

	if use hardened
	then
		if use x86
		then
			einfo "Enable Position Independent Executable support in ${P}"
			sed -i -e "s:# UCLIBC_PIE_SUPPORT.*:UCLIBC_PIE_SUPPORT=y:" .config
		fi

		einfo "Enable Stack Smashing Protections support in ${P}"
		sed -i -e "s:# UCLIBC_PROPOLICE.*:UCLIBC_PROPOLICE=y:" .config
		echo "PROPOLICE_BLOCK_ABRT=n" >> .config
		echo "PROPOLICE_BLOCK_SEGV=n" >> .config
		echo "PROPOLICE_BLOCK_KILL=y" >> .config
	fi

	# we are building against system installed kernel headers
	sed -i -e 's:KERNEL_SOURCE.*:KERNEL_SOURCE="/usr":' .config

	check_main_libc
	if [ "${SYS_LIBC}" = "uClibc" ]
	then
		sed -i -e 's:SHARED_LIB_LOADER_PREFIX=.*:SHARED_LIB_LOADER_PREFIX="/lib":' .config
		sed -i -e 's:DEVEL_PREFIX=.*:DEVEL_PREFIX="/usr":' .config
		sed -i -e 's:RUNTIME_PREFIX=.*:RUNTIME_PREFIX="/":' .config
	fi

	make -s oldconfig > /dev/null || die "could not make oldconfig"

	chmod +x extra/scripts/relative_path.sh

	cp .config myconfig

	emake clean >/dev/null || die "could not clean"
}

src_compile() {
	# running tests require this
	use build || addwrite /dev/ptmx
	mv myconfig .config

	#if use nls
	#then
	#	# these can be built only if the build system supports locales (as of 0.9.26)
	#	emake -j1 headers
	#	cd extra/locale
	#	make clean
	#	find ./charmaps -name "*.pairs" > codesets.txt
	#	cp LOCALES locales.txt
	#	emake -j1 || die "could not make locales"
	#	cd ../..
	#fi

	emake -j1 || die "could not make"
	if ! use build
	then
		if [ "${SYS_LIBC}" = "uClibc" ]
		then
			emake -j1 utils || die "could not make utils"
		fi
		# assert test fails on pax enabled kernels - normal
		# vfork test fails in sandbox
		cd test; make; cd ..
	fi
}

src_install() {
	emake PREFIX=${D} install || die "install failed"

	# remove files coming from kernel-headers
	# scsi is uclibc's own directory since cvs 20040212
	if [ "${SYS_LIBC}" = "uClibc" ]
	then
		rm -rf ${D}/usr/include/{asm,linux}
	fi

	rm -f ${D}/usr/lib/lib*_pic.a

	if ! use build
	then
		if [ "${SYS_LIBC}" = "uClibc" ]
		then
			emake PREFIX=${D} install_utils || die "install-utils failed"
			dodir /usr/bin
			exeinto /usr/bin
			doexe ${FILESDIR}/getent
		fi
		dodoc Changelog* README TODO docs/*.txt
		doman debian/*.1
	fi
}

#pkg_postinst() {
#if [ "${SYS_LIBC}" = "uClibc" ] ; then
#	if [ "${ROOT}" = "/" ] ; then
#		/sbin/ldconfig
#		[ ! -e /etc/TZ ] && echo UTC > /etc/TZ
#		# reload init?
#	fi
#else
#should we add the lib dir to ld.so.conf?
#fi
#}