1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
6 inherit flag-o-matic multilib savedconfig toolchain-funcs versionator
8 if [[ ${PV} == "9999" ]] ; then
9 EGIT_REPO_URI="git://uclibc-ng.org/git/uclibc-ng"
16 DESCRIPTION="C library for developing embedded Linux systems"
17 HOMEPAGE="http://www.uclibc-ng.org/"
18 if [[ ${PV} != "9999" ]] ; then
20 SRC_URI="http://downloads.uclibc-ng.org/releases/${PV}/${MY_P}.tar.bz2"
21 KEYWORDS="-* amd64 arm ~mips ppc x86"
26 IUSE="debug hardened iconv ipv6 rpc crosscompile_opts_headers-only"
29 # 1) We can't upgrade from uclibc to uclibc-ng via a soft blocker since portage
30 # will delete the ld.so sym link prematurely and break the system. So we
31 # will hard block and give manual migration instructions.
32 # 2) Currently uclibc and uclibc-ng's iconv are in bad shape. We've been using
33 # the breakout library. The disadvantage here is that we have to sprinkle
34 # LDFAGS=-liconv on build systems that need to link against libiconv.
37 iconv? ( dev-libs/libiconv )"
41 export CBUILD=${CBUILD:-${CHOST}}
42 export CTARGET=${CTARGET:-${CHOST}}
43 if [[ ${CHOST} == ${CTARGET} ]] ; then
44 if [[ ${CATEGORY} == cross-* ]] ; then
45 export CTARGET=${CATEGORY#cross-}
50 [[ ${CHOST} != ${CTARGET} ]]
54 if [[ ${CBUILD} == ${CHOST} && ${CHOST} == ${CTARGET} ]] ; then
57 echo /usr/${CTARGET}/usr/include
62 use crosscompile_opts_headers-only && is_crosscompile
66 # XXX: this wont work for a toolchain which is bi-endian, but we
67 # dont have any such thing at the moment, so not a big deal
69 $(tc-getAS ${CTARGET}) "${T}"/endian.s -o "${T}"/endian.o
70 case $(file "${T}"/endian.o) in
71 *" MSB "*) echo "BIG";;
72 *" LSB "*) echo "LITTLE";;
75 rm -f "${T}"/endian.{s,o}
82 *) flag=$(usex ${flag} y n) ;;
85 local var="defs_${flag}"
92 . ${2:-"${S}"/.config}
98 yes "" 2>/dev/null | emake -s oldconfig >/dev/null
102 restore_config .config
103 if [ -f .config ]; then
107 ewarn "Could not locate user configfile, so we will save a default one"
110 emake ARCH=$1 defconfig >/dev/null
114 # These are forced off
121 SUPPORT_LD_DEBUG_EARLY
122 UCLIBC_HAS_CTYPE_UNSAFE
124 UCLIBC_HAS_SSP_COMPAT
127 # These are forced on
132 FORCE_SHAREABLE_TEXT_SEGMENTS
133 LDSO_GNU_HASH_SUPPORT
135 LDSO_PRELOAD_FILE_SUPPORT
136 LDSO_RUNPATH_OF_EXECUTABLE
137 LDSO_STANDALONE_SUPPORT
140 PTHREADS_DEBUG_SUPPORT
141 UCLIBC_HAS_ARC4RANDOM
143 UCLIBC_HAS_BSD_RES_CLOSE
144 UCLIBC_HAS_CONTEXT_FUNCS
145 UCLIBC_HAS_CTYPE_CHECKED
146 UCLIBC_HAS_EXTRA_COMPAT_RES_STATE
148 UCLIBC_HAS_FOPEN_CLOSEEXEC_MODE
149 UCLIBC_HAS_FOPEN_EXCLUSIVE_MODE
150 UCLIBC_HAS_FOPEN_LARGEFILE_MODE
154 UCLIBC_HAS_GLIBC_CUSTOM_PRINTF
155 UCLIBC_HAS_GLIBC_CUSTOM_STREAMS
157 UCLIBC_HAS_HEXADECIMAL_FLOATS
158 UCLIBC_HAS_LIBNSL_STUB
159 UCLIBC_HAS_LIBRESOLV_STUB
162 UCLIBC_HAS_OBSOLETE_BSD_SIGNAL
164 UCLIBC_HAS_PRINTF_M_SPEC
165 UCLIBC_HAS_PROGRAM_INVOCATION_NAME
166 UCLIBC_HAS_RESOLVER_SUPPORT
167 UCLIBC_HAS_SHA256_CRYPT_IMPL
168 UCLIBC_HAS_SHA512_CRYPT_IMPL
171 UCLIBC_HAS_SYS_ERRLIST
172 UCLIBC_HAS_SYS_SIGLIST
173 UCLIBC_HAS_THREADS_NATIVE
174 UCLIBC_HAS_TZ_FILE_READ_MANY
180 UCLIBC_SUPPORT_AI_ADDRCONFIG
183 UCLIBC_SUSV3_LEGACY_MACROS
188 sed -i -e '/ARCH_.*_ENDIAN/d' .config
189 kconfig_q_opt y "ARCH_WANTS_$(uclibc_endian)_ENDIAN"
191 kconfig_q_opt debug DODEBUG
192 kconfig_q_opt debug SUPPORT_LD_DEBUG
193 kconfig_q_opt debug UCLIBC_HAS_PROFILING
195 kconfig_q_opt ipv6 UCLIBC_HAS_IPV6
197 kconfig_q_opt rpc UCLIBC_HAS_RPC
198 kconfig_q_opt rpc UCLIBC_HAS_FULL_RPC
199 kconfig_q_opt rpc UCLIBC_HAS_REENTRANT_RPC
201 kconfig_q_opt hardened UCLIBC_BUILD_NOEXECSTACK
202 kconfig_q_opt hardened UCLIBC_BUILD_NOW
203 kconfig_q_opt hardened UCLIBC_BUILD_PIE
204 kconfig_q_opt hardened UCLIBC_BUILD_RELRO
205 kconfig_q_opt hardened UCLIBC_BUILD_SSP
208 for count in 1 2 ; do
209 # Run twice as some config opts depend on others being enabled first.
210 for def in ${defs_y[@]} ; do
211 sed -i -e "s|.*\<${def}\>.*set|${def}=y|g" .config
213 for def in ${defs_n[@]} ; do
214 sed -i -e "s|${def}=y|# ${def} is not set|g" .config
219 einfo "Enabled options:"
220 for def in ${defs_y[@]} ; do
221 einfo " " $(grep "^${def}=y" .config || echo "could not find ${def}")
223 einfo "Disabled options:"
224 for def in ${defs_n[@]} ; do
225 einfo " " $(grep "^# ${def} is not set" .config || echo "could not find ${def}")
228 # setup build and run paths
230 -e "/^CROSS_COMPILER_PREFIX/s|=.*|=\"${CTARGET}-\"|" \
231 -e "/^KERNEL_HEADERS/s|=.*|=\"$(alt_build_kprefix)\"|" \
232 -e "/^SHARED_LIB_LOADER_PREFIX/s|=.*|=\"/$(get_libdir)\"|" \
233 -e "/^DEVEL_PREFIX/s|=.*|=\"/usr\"|" \
234 -e "/^RUNTIME_PREFIX/s|=.*|=\"/\"|" \
235 -e "/^UCLIBC_EXTRA_CFLAGS/s|=.*|=\"${UCLIBC_EXTRA_CFLAGS}\"|" \
242 # Make sure our CHOST is a uclibc toolchain for native compiling
243 if [[ ${CHOST} == ${CTARGET} ]]; then
245 *-uclinux*|*-uclibc*) ;;
246 *) die "Use sys-devel/crossdev to build a uclibc toolchain" ;;
250 # uClibc-ng doesn't carry old Linux threads, and since we force
251 # threading our only choice is NPTL which requires i486 and later.
252 [[ ${CTARGET} == i386* ]] && die "i386 can't support Native Posix Threads (NPTL)."
256 local version subversion extraversion
258 # uclibc-ng tries to create a two sym link with ld.so,
259 # ld-uClibc.so.{0,MAJOR_VERSION} -> ld-uClibc-<version>.so
260 # where MAJOR_VERSION != 0 indicates the ABI verison.
261 # We want to get rid of this and just have ABI = 0.
262 eapply "${FILESDIR}"/uclibc-compat-r1.patch
264 # We need to change the major.minor.sublevel of uclibc-ng.
265 # Upstream sets MAJOR_VERSION = 1 which breaks runtime linking.
266 # If we really want the ABI bump, we'll have to hack the gcc
267 # spec file and change the '*link:' rule.
268 version=( $(get_version_components) )
269 if [[ -z ${version[1]} ]]; then
273 subversion=${version[1]}
274 if [[ -z ${version[2]} ]]; then
277 extraversion=.${version[2]}
282 -e "/^MAJOR_VERSION/s|:=.*|:= 0|" \
283 -e "/^MINOR_VERSION/s|:=.*|:= ${version[0]}|" \
284 -e "/^SUBLEVEL/s|:=.*|:= ${subversion}|" \
285 -e "/^EXTRAVERSION/s|:=.*|:= ${extraversion}|" \
292 # Map our toolchain arch name to the name expected by uClibc-ng.
293 local target=$(tc-arch)
295 amd64) target="x86_64";;
297 mips) target="mips";;
298 ppc) target="powerpc";;
302 # Do arch specific configuration by changing the defaults in
303 # extra/Configs/Config.<arch>. If these are not overridden
304 # by an save .config, they will be selected by default.
306 # For i386, i486, i586 and i686
308 if [[ ${target} == "i386" ]]; then
309 [[ ${CTARGET} == i[456]86* ]] && cpu="${CTARGET:1:1}86"
310 sed -i -e "s|default CONFIG_686|default CONFIG_${cpu:-486}|" \
311 extra/Configs/Config.i386 || die
315 if [[ ${target} == "arm" ]]; then
316 sed -i -e '/Build for EABI/a \\tdefault y' extra/Configs/Config.arm
319 # We set HOSTCC to the proper tuple rather than just 'gcc'
320 sed -i -e "s|^HOSTCC.*=.*|HOSTCC=$(tc-getBUILD_CC)|" Rules.mak
322 make_config ${target}
325 einfo "Runtime Prefix: /"
326 einfo "Devel Prefix: /usr"
327 einfo "Kernel Prefix: $(alt_build_kprefix)"
328 einfo "CBUILD: ${CBUILD}"
329 einfo "CHOST: ${CHOST}"
330 einfo "CTARGET: ${CTARGET}"
332 einfo "ENDIAN: $(uclibc_endian)"
338 just_headers && return 0
341 if is_crosscompile ; then
342 emake -C utils hostutils
349 is_crosscompile && return 0
351 # assert test fails on pax/grsec enabled kernels
352 # normal vfork test fails in sandbox (both glibc/uclibc)
353 emake UCLIBC_ONLY=1 check
358 is_crosscompile && sysroot+="/usr/${CTARGET}"
360 local target="install"
361 just_headers && target="install_headers"
362 emake DESTDIR="${sysroot}" ${target}
366 # remove files coming from kernel-headers
367 rm -rf "${sysroot}"/usr/include/{linux,asm*}
369 # Make sure we install the sys-include symlink so that when
370 # we build a 2nd stage cross-compiler, gcc finds the target
371 # system headers correctly. See gcc/doc/gccinstall.info
372 if is_crosscompile ; then
373 dosym usr/include /usr/${CTARGET}/sys-include
374 if ! just_headers && [[ -n $(get_opt HAVE_SHARED) ]] ; then
375 newbin utils/ldconfig.host ${CTARGET}-ldconfig
376 newbin utils/ldd.host ${CTARGET}-ldd
381 dosym libc.so.0 "${DESTDIR}"/lib/libcrypt.so.0
382 dosym libc.so.0 "${DESTDIR}"/lib/libdl.so.0
383 dosym libc.so.0 "${DESTDIR}"/lib/libm.so.0
384 dosym libc.so.0 "${DESTDIR}"/lib/libpthread.so.0
385 dosym libc.so.0 "${DESTDIR}"/lib/librt.so.0
386 dosym libc.so.0 "${DESTDIR}"/lib/libresolv.so.0
387 dosym libc.so.0 "${DESTDIR}"/lib/libubacktrace.so.0
388 dosym libc.so.0 "${DESTDIR}"/lib/libutil.so.0
390 emake DESTDIR="${D}" install_utils
391 dobin extra/scripts/getent
392 dodoc README docs/*.txt
396 is_crosscompile && return 0
398 if [ ! -e "${ROOT}"/etc/TZ ] ; then
399 ewarn "Please remember to set your timezone in /etc/TZ"
400 mkdir -p "${ROOT}"/etc
401 echo "UTC" > "${ROOT}"/etc/TZ
403 [ "${ROOT}" != "/" ] && return 0
404 # update cache before reloading init
407 /sbin/telinit U 2>/dev/null