| 1 |
# Copyright 1999-2012 Gentoo Foundation
|
| 2 |
# Distributed under the terms of the GNU General Public License v2
|
| 3 |
# $Header: /var/cvsroot/gentoo-x86/sys-libs/uclibc/uclibc-0.9.33.2.ebuild,v 1.2 2012/06/01 04:22:53 zmedico Exp $
|
| 4 |
|
| 5 |
inherit eutils flag-o-matic multilib toolchain-funcs savedconfig
|
| 6 |
if [[ ${PV} == "9999" ]] ; then
|
| 7 |
EGIT_REPO_URI="git://git.busybox.net/uClibc"
|
| 8 |
inherit git-2
|
| 9 |
fi
|
| 10 |
|
| 11 |
export CBUILD=${CBUILD:-${CHOST}}
|
| 12 |
export CTARGET=${CTARGET:-${CHOST}}
|
| 13 |
if [[ ${CTARGET} == ${CHOST} ]] ; then
|
| 14 |
if [[ ${CATEGORY/cross-} != ${CATEGORY} ]] ; then
|
| 15 |
export CTARGET=${CATEGORY/cross-}
|
| 16 |
fi
|
| 17 |
fi
|
| 18 |
|
| 19 |
MY_P=uClibc-${PV}
|
| 20 |
DESCRIPTION="C library for developing embedded Linux systems"
|
| 21 |
HOMEPAGE="http://www.uclibc.org/"
|
| 22 |
if [[ ${PV} != "9999" ]] ; then
|
| 23 |
PATCH_VER="1"
|
| 24 |
SRC_URI="http://uclibc.org/downloads/${MY_P}.tar.bz2
|
| 25 |
${PATCH_VER:+mirror://gentoo/${MY_P}-patches-${PATCH_VER}.tar.bz2}"
|
| 26 |
KEYWORDS="-* amd64 arm ~m68k ~mips ppc ~sh sparc x86"
|
| 27 |
fi
|
| 28 |
|
| 29 |
LICENSE="LGPL-2"
|
| 30 |
SLOT="0"
|
| 31 |
IUSE="debug hardened iconv ipv6 nptl rpc ssp uclibc-compat wordexp crosscompile_opts_headers-only"
|
| 32 |
RESTRICT="strip"
|
| 33 |
|
| 34 |
S=${WORKDIR}/${MY_P}
|
| 35 |
|
| 36 |
is_crosscompile() {
|
| 37 |
[[ ${CHOST} != ${CTARGET} ]]
|
| 38 |
}
|
| 39 |
alt_build_kprefix() {
|
| 40 |
if [[ ${CBUILD} == ${CHOST} && ${CTARGET} == ${CHOST} ]] ; then
|
| 41 |
echo /usr/include
|
| 42 |
else
|
| 43 |
echo /usr/${CTARGET}/usr/include
|
| 44 |
fi
|
| 45 |
}
|
| 46 |
|
| 47 |
just_headers() {
|
| 48 |
use crosscompile_opts_headers-only && is_crosscompile
|
| 49 |
}
|
| 50 |
|
| 51 |
uclibc_endian() {
|
| 52 |
# XXX: this wont work for a toolchain which is bi-endian, but we
|
| 53 |
# dont have any such thing at the moment, so not a big deal
|
| 54 |
touch "${T}"/endian.s
|
| 55 |
$(tc-getAS ${CTARGET}) "${T}"/endian.s -o "${T}"/endian.o
|
| 56 |
case $(file "${T}"/endian.o) in
|
| 57 |
*" MSB "*) echo "BIG";;
|
| 58 |
*" LSB "*) echo "LITTLE";;
|
| 59 |
*) echo "NFC";;
|
| 60 |
esac
|
| 61 |
rm -f "${T}"/endian.{s,o}
|
| 62 |
}
|
| 63 |
|
| 64 |
pkg_setup() {
|
| 65 |
if [ ${CTARGET} == ${CHOST} ] ; then
|
| 66 |
case ${CHOST} in
|
| 67 |
*-uclinux*|*-uclibc*) ;;
|
| 68 |
*) die "Use sys-devel/crossdev to build a uclibc toolchain" ;;
|
| 69 |
esac
|
| 70 |
fi
|
| 71 |
}
|
| 72 |
|
| 73 |
# XXX: We should kill these off.
|
| 74 |
CPU_ALPHA=""
|
| 75 |
CPU_AMD64=""
|
| 76 |
CPU_ARM="GENERIC_ARM ARM{610,710,7TDMI,720T,920T,922T,926T,10T,1136JF_S,1176JZ{_,F_}S,_{SA110,SA1100,XSCALE,IWMMXT},_CORTEX_{M3,M1}}"
|
| 77 |
CPU_IA64=""
|
| 78 |
CPU_M68K=""
|
| 79 |
CPU_MIPS="MIPS_ISA_{1,2,3,4,MIPS{32{,R2},64}} MIPS_{N64,O32,N32}_ABI"
|
| 80 |
CPU_PPC=""
|
| 81 |
CPU_SH="SH{2,2A,3,4,5}"
|
| 82 |
CPU_SPARC="SPARC_V{7,8,9,9B}"
|
| 83 |
CPU_X86="GENERIC_386 {3,4,5,6}86 586MMX PENTIUM{II,III,4} K{6,7} ELAN CRUSOE WINCHIP{C6,2} CYRIXIII NEHEMIAH"
|
| 84 |
IUSE_UCLIBC_CPU="${CPU_ARM} ${CPU_MIPS} ${CPU_PPC} ${CPU_SH} ${CPU_SPARC} ${CPU_X86}"
|
| 85 |
|
| 86 |
check_cpu_opts() {
|
| 87 |
local cpu_var="CPU_$(echo $(tc-arch) | tr [a-z] [A-Z])"
|
| 88 |
[[ -z ${!cpu_var} ]] && return 0
|
| 89 |
|
| 90 |
if [[ -z ${UCLIBC_CPU} ]] ; then
|
| 91 |
ewarn "You really should consider setting UCLIBC_CPU"
|
| 92 |
ewarn "Otherwise, the build will be generic (read: slow)."
|
| 93 |
ewarn "Available CPU options:"
|
| 94 |
UCLIBC_CPU=$(eval echo ${!cpu_var})
|
| 95 |
echo ${UCLIBC_CPU}
|
| 96 |
case ${CTARGET} in
|
| 97 |
mips[1234]*) export UCLIBC_CPU="MIPS_ISA_${CTARGET:4:1}";;
|
| 98 |
sh[2345]*) export UCLIBC_CPU="SH${CTARGET:2:1}";;
|
| 99 |
i[456]86*) export UCLIBC_CPU="${CTARGET:1:1}86";;
|
| 100 |
*) export UCLIBC_CPU=${UCLIBC_CPU%% *};;
|
| 101 |
esac
|
| 102 |
else
|
| 103 |
local cpu found=0
|
| 104 |
for cpu in $(eval echo ${!cpu_var}) ; do
|
| 105 |
[[ ${UCLIBC_CPU} == "${cpu}" ]] && found=1 && break
|
| 106 |
done
|
| 107 |
if [[ ${found} -eq 0 ]] ; then
|
| 108 |
ewarn "UCLIBC_CPU choice '${UCLIBC_CPU}' not supported"
|
| 109 |
ewarn "Valid choices:"
|
| 110 |
eval echo ${!cpu_var}
|
| 111 |
die "pick a supported cpu type"
|
| 112 |
fi
|
| 113 |
fi
|
| 114 |
}
|
| 115 |
|
| 116 |
kconfig_q_opt() {
|
| 117 |
local flag=$1; shift
|
| 118 |
case ${flag} in
|
| 119 |
y|n) ;;
|
| 120 |
*) flag=$(usex ${flag} y n) ;;
|
| 121 |
esac
|
| 122 |
|
| 123 |
local var="defs_${flag}"
|
| 124 |
eval "${var}+=( $* )"
|
| 125 |
}
|
| 126 |
|
| 127 |
get_opt() {
|
| 128 |
(
|
| 129 |
unset ${1}
|
| 130 |
. ${2:-"${S}"/.config}
|
| 131 |
echo ${!1}
|
| 132 |
)
|
| 133 |
}
|
| 134 |
|
| 135 |
src_oldconfig() {
|
| 136 |
yes "" 2>/dev/null | emake -s oldconfig >/dev/null
|
| 137 |
}
|
| 138 |
src_config() {
|
| 139 |
restore_config .config
|
| 140 |
if [ -f .config ]; then
|
| 141 |
src_oldconfig
|
| 142 |
return 0
|
| 143 |
else
|
| 144 |
ewarn "Could not locate user configfile, so we will save a default one"
|
| 145 |
fi
|
| 146 |
|
| 147 |
emake ARCH=${target} defconfig >/dev/null || die
|
| 148 |
|
| 149 |
local defs_{y,n} defs
|
| 150 |
|
| 151 |
defs=(
|
| 152 |
DO{DEBUG_PT,ASSERTS}
|
| 153 |
SUPPORT_LD_DEBUG_EARLY
|
| 154 |
UCLIBC_HAS_PROFILING
|
| 155 |
)
|
| 156 |
kconfig_q_opt n "${defs[@]}"
|
| 157 |
kconfig_q_opt debug DODEBUG SUPPORT_LD_DEBUG
|
| 158 |
|
| 159 |
sed -i -e '/ARCH_.*_ENDIAN/d' .config
|
| 160 |
kconfig_q_opt y "ARCH_WANTS_$(uclibc_endian)_ENDIAN"
|
| 161 |
|
| 162 |
if [[ $(tc-is-softfloat) != "no" ]] ; then
|
| 163 |
kconfig_q_opt n UCLIBC_HAS_FPU
|
| 164 |
fi
|
| 165 |
|
| 166 |
if [[ ${CTARGET} == arm* ]] ; then
|
| 167 |
kconfig_q_opt n CONFIG_ARM_OABI
|
| 168 |
kconfig_q_opt y CONFIG_ARM_EABI
|
| 169 |
fi
|
| 170 |
|
| 171 |
defs=(
|
| 172 |
MALLOC_GLIBC_COMPAT
|
| 173 |
DO_C99_MATH
|
| 174 |
UCLIBC_HAS_{CTYPE_CHECKED,WCHAR,HEXADECIMAL_FLOATS,GLIBC_CUSTOM_PRINTF,FOPEN_EXCLUSIVE_MODE,GLIBC_CUSTOM_STREAMS,PRINTF_M_SPEC}
|
| 175 |
UCLIBC_HAS_FENV
|
| 176 |
UCLIBC_HAS_{N,}FTW
|
| 177 |
UCLIBC_HAS_GNU_GLOB
|
| 178 |
UCLIBC_HAS_LIBUTIL
|
| 179 |
UCLIBC_HAS_PROGRAM_INVOCATION_NAME
|
| 180 |
UCLIBC_HAS_RESOLVER_SUPPORT
|
| 181 |
UCLIBC_HAS_TZ_FILE_READ_MANY
|
| 182 |
UCLIBC_HAS_UTMPX
|
| 183 |
UCLIBC_SUSV3_LEGACY
|
| 184 |
UCLIBC_SUSV3_LEGACY_MACROS
|
| 185 |
UCLIBC_SUSV4_LEGACY
|
| 186 |
PTHREADS_DEBUG_SUPPORT
|
| 187 |
)
|
| 188 |
kconfig_q_opt y "${defs[@]}"
|
| 189 |
kconfig_q_opt n UCLIBC_HAS_CTYPE_UNSAFE
|
| 190 |
kconfig_q_opt n UCLIBC_HAS_LOCALE
|
| 191 |
kconfig_q_opt n HAS_NO_THREADS
|
| 192 |
kconfig_q_opt ipv6 UCLIBC_HAS_IPV6
|
| 193 |
kconfig_q_opt nptl UCLIBC_HAS_THREADS_NATIVE
|
| 194 |
kconfig_q_opt !nptl LINUXTHREADS_OLD
|
| 195 |
kconfig_q_opt rpc UCLIBC_HAS_{,{FULL,REENTRANT}_}RPC
|
| 196 |
kconfig_q_opt wordexp UCLIBC_HAS_WORDEXP
|
| 197 |
kconfig_q_opt uclibc-compat UCLIBC_HAS_LIB{NSL,RESOLV}_STUB COMPAT_ATEXIT
|
| 198 |
|
| 199 |
# we need to do it independently of hardened to get ssp.c built into libc
|
| 200 |
kconfig_q_opt y UCLIBC_HAS_SSP
|
| 201 |
kconfig_q_opt n UCLIBC_HAS_SSP_COMPAT
|
| 202 |
kconfig_q_opt y UCLIBC_HAS_ARC4RANDOM
|
| 203 |
kconfig_q_opt n PROPOLICE_BLOCK_ABRT
|
| 204 |
kconfig_q_opt y PROPOLICE_BLOCK_SEGV
|
| 205 |
|
| 206 |
# arm/mips do not emit PT_GNU_STACK, but if we enable this here
|
| 207 |
# it will be emitted as RWE, ppc has to be checked, x86 needs it
|
| 208 |
# this option should be used independently of hardened
|
| 209 |
if has $(tc-arch) x86 || has $(tc-arch) ppc ; then
|
| 210 |
kconfig_q_opt y UCLIBC_BUILD_NOEXECSTACK
|
| 211 |
else
|
| 212 |
kconfig_q_opt n UCLIBC_BUILD_NOEXECSTACK
|
| 213 |
fi
|
| 214 |
kconfig_q_opt y UCLIBC_BUILD_RELRO
|
| 215 |
kconfig_q_opt hardened UCLIBC_BUILD_PIE
|
| 216 |
kconfig_q_opt hardened UCLIBC_BUILD_NOW
|
| 217 |
kconfig_q_opt !ssp SSP_QUICK_CANARY
|
| 218 |
kconfig_q_opt ssp UCLIBC_BUILD_SSP
|
| 219 |
|
| 220 |
local def
|
| 221 |
for def in 1 2 ; do
|
| 222 |
# Run twice as some config opts depend on others being enabled first.
|
| 223 |
for def in ${defs_y[@]} ; do
|
| 224 |
sed -i -e "s:.*\<${def}\>.*set:${def}=y:g" .config
|
| 225 |
done
|
| 226 |
for def in ${defs_n[@]} ; do
|
| 227 |
sed -i -e "s:${def}=y:# ${def} is not set:g" .config
|
| 228 |
done
|
| 229 |
src_oldconfig
|
| 230 |
done
|
| 231 |
|
| 232 |
einfo "Enabled options:"
|
| 233 |
for def in ${defs_y[@]} ; do
|
| 234 |
einfo " " $(grep "^${def}=y" .config || echo "could not find ${def}")
|
| 235 |
done
|
| 236 |
einfo "Disabled options:"
|
| 237 |
for def in ${defs_n[@]} ; do
|
| 238 |
einfo " " $(grep "^# ${def} is not set" .config || echo "could not find ${def}")
|
| 239 |
done
|
| 240 |
|
| 241 |
# setup build and run paths
|
| 242 |
sed -i \
|
| 243 |
-e "/^CROSS_COMPILER_PREFIX/s:=.*:=\"${CTARGET}-\":" \
|
| 244 |
-e "/^KERNEL_HEADERS/s:=.*:=\"$(alt_build_kprefix)\":" \
|
| 245 |
-e "/^SHARED_LIB_LOADER_PREFIX/s:=.*:=\"/$(get_libdir)\":" \
|
| 246 |
-e "/^DEVEL_PREFIX/s:=.*:=\"/usr\":" \
|
| 247 |
-e "/^RUNTIME_PREFIX/s:=.*:=\"/\":" \
|
| 248 |
-e "/^UCLIBC_EXTRA_CFLAGS/s:=.*:=\"${UCLIBC_EXTRA_CFLAGS}\":" \
|
| 249 |
.config || die
|
| 250 |
|
| 251 |
src_oldconfig
|
| 252 |
}
|
| 253 |
|
| 254 |
src_unpack() {
|
| 255 |
if [[ ${PV} == "9999" ]] ; then
|
| 256 |
git-2_src_unpack
|
| 257 |
else
|
| 258 |
unpack ${A}
|
| 259 |
fi
|
| 260 |
cd "${S}"
|
| 261 |
if [[ -n ${PATCH_VER} ]] ; then
|
| 262 |
EPATCH_SUFFIX="patch" epatch "${WORKDIR}"/patch
|
| 263 |
fi
|
| 264 |
|
| 265 |
check_cpu_opts
|
| 266 |
|
| 267 |
echo
|
| 268 |
einfo "Runtime Prefix: /"
|
| 269 |
einfo "Devel Prefix: /usr"
|
| 270 |
einfo "Kernel Prefix: $(alt_build_kprefix)"
|
| 271 |
einfo "CBUILD: ${CBUILD}"
|
| 272 |
einfo "CHOST: ${CHOST}"
|
| 273 |
einfo "CTARGET: ${CTARGET}"
|
| 274 |
einfo "CPU: ${UCLIBC_CPU:-default}"
|
| 275 |
einfo "ENDIAN: $(uclibc_endian)"
|
| 276 |
echo
|
| 277 |
|
| 278 |
########## CPU SELECTION ##########
|
| 279 |
|
| 280 |
local target config_target
|
| 281 |
case $(tc-arch) in
|
| 282 |
alpha) target="alpha"; config_target="no cpu-specific options";;
|
| 283 |
amd64) target="x86_64"; config_target="no cpu-specific options";;
|
| 284 |
arm) target="arm"; config_target="GENERIC_ARM";;
|
| 285 |
avr) target="avr32"; config_target="no cpu-specific options";;
|
| 286 |
ia64) target="ia64"; config_target="no cpu-specific options";;
|
| 287 |
m68k) target="m68k"; config_target="no cpu-specific options";;
|
| 288 |
mips) target="mips"; config_target="MIPS_ISA_1";;
|
| 289 |
ppc) target="powerpc"; config_target="no cpu-specific options";;
|
| 290 |
sh) target="sh"; config_target="SH4";;
|
| 291 |
sparc) target="sparc"; config_target="no cpu-specific options";;
|
| 292 |
x86) target="i386"; config_target="GENERIC_386";;
|
| 293 |
*) die "$(tc-arch) lists no defaults :/";;
|
| 294 |
esac
|
| 295 |
sed -i -e "s:default CONFIG_${config_target}:default CONFIG_${UCLIBC_CPU:-${config_target}}:" \
|
| 296 |
extra/Configs/Config.${target}
|
| 297 |
sed -i -e "s:^HOSTCC.*=.*:HOSTCC=$(tc-getBUILD_CC):" Rules.mak
|
| 298 |
|
| 299 |
src_config
|
| 300 |
|
| 301 |
if use iconv ; then
|
| 302 |
# Run after make clean, otherwise files removed
|
| 303 |
find ./extra/locale/charmaps -name "*.pairs" > extra/locale/codesets.txt
|
| 304 |
if [[ ! -f /etc/locale.gen ]] ; then
|
| 305 |
# See ./extra/locale/LOCALES for examples
|
| 306 |
die "Please create an appropriate /etc/locale.gen for locale support"
|
| 307 |
fi
|
| 308 |
echo -e "@euro e\n@cyrillic c\n#---\nUTF-8 yes\n8-BIT yes\n#---\n\n" > ./extra/locale/locales.txt
|
| 309 |
cat /etc/locale.gen >> ./extra/locale/locales.txt
|
| 310 |
fi
|
| 311 |
}
|
| 312 |
|
| 313 |
src_compile() {
|
| 314 |
emake headers || die
|
| 315 |
just_headers && return 0
|
| 316 |
|
| 317 |
emake || die
|
| 318 |
if is_crosscompile ; then
|
| 319 |
emake -C utils hostutils || die
|
| 320 |
else
|
| 321 |
emake utils || die
|
| 322 |
fi
|
| 323 |
}
|
| 324 |
|
| 325 |
src_test() {
|
| 326 |
is_crosscompile && return 0
|
| 327 |
|
| 328 |
# assert test fails on pax/grsec enabled kernels - normal
|
| 329 |
# vfork test fails in sandbox (both glibc/uclibc)
|
| 330 |
emake UCLIBC_ONLY=1 check || die
|
| 331 |
}
|
| 332 |
|
| 333 |
src_install() {
|
| 334 |
local sysroot=${D}
|
| 335 |
is_crosscompile && sysroot+="/usr/${CTARGET}"
|
| 336 |
|
| 337 |
local target="install"
|
| 338 |
just_headers && target="install_headers"
|
| 339 |
emake DESTDIR="${sysroot}" ${target} || die
|
| 340 |
|
| 341 |
save_config .config
|
| 342 |
|
| 343 |
# remove files coming from kernel-headers
|
| 344 |
rm -rf "${sysroot}"/usr/include/{linux,asm*}
|
| 345 |
|
| 346 |
# Make sure we install the sys-include symlink so that when
|
| 347 |
# we build a 2nd stage cross-compiler, gcc finds the target
|
| 348 |
# system headers correctly. See gcc/doc/gccinstall.info
|
| 349 |
if is_crosscompile ; then
|
| 350 |
dosym usr/include /usr/${CTARGET}/sys-include
|
| 351 |
if ! just_headers && [[ -n $(get_opt HAVE_SHARED) ]] ; then
|
| 352 |
newbin utils/ldconfig.host ${CTARGET}-ldconfig || die
|
| 353 |
newbin utils/ldd.host ${CTARGET}-ldd || die
|
| 354 |
fi
|
| 355 |
return 0
|
| 356 |
fi
|
| 357 |
|
| 358 |
emake DESTDIR="${D}" install_utils || die
|
| 359 |
dobin extra/scripts/getent
|
| 360 |
dodoc Changelog* README TODO docs/*.txt DEDICATION.mjn3
|
| 361 |
}
|
| 362 |
|
| 363 |
pkg_postinst() {
|
| 364 |
is_crosscompile && return 0
|
| 365 |
|
| 366 |
if [ ! -e "${ROOT}"/etc/TZ ] ; then
|
| 367 |
ewarn "Please remember to set your timezone in /etc/TZ"
|
| 368 |
mkdir -p "${ROOT}"/etc
|
| 369 |
echo "UTC" > "${ROOT}"/etc/TZ
|
| 370 |
fi
|
| 371 |
[ "${ROOT}" != "/" ] && return 0
|
| 372 |
# update cache before reloading init
|
| 373 |
ldconfig
|
| 374 |
# reload init ...
|
| 375 |
/sbin/telinit U 2>/dev/null
|
| 376 |
}
|