--- dev-libs/klibc/klibc-1.5.15.ebuild_orig 2009-09-14 12:25:13.000000000 -0400 +++ dev-libs/klibc/klibc-1.5.15.ebuild 2009-09-14 12:27:37.000000000 -0400 @@ -16,7 +16,7 @@ # This will be able to go away once the klibc author updates his code # to build again the headers provided by the kernel's 'headers_install' target. -inherit eutils multilib toolchain-funcs +inherit eutils multilib toolchain-funcs savedconfig DESCRIPTION="A minimal libc subset for use with initramfs." HOMEPAGE="http://www.zytor.com/mailman/listinfo/klibc" @@ -37,9 +37,9 @@ ${KERNEL_URI}" LICENSE="|| ( GPL-2 LGPL-2 )" -KEYWORDS="~amd64 -mips ~ppc ~sparc ~x86" +KEYWORDS="~amd64 ~arm -mips ~ppc ~sparc ~x86" SLOT="0" -IUSE="debug n32" +IUSE="debug n32 savedconfig" DEPEND="dev-lang/perl" RDEPEND="${DEPEND}" @@ -51,7 +51,60 @@ # Do not strip RESTRICT="strip" +SAVED_DEFCONFIG_SRC="${PORTAGE_CONFIGROOT}etc/portage/savedconfig/${CATEGORY}/${PF}" + +kernel_asm_arch() { + a="${1:${ARCH}}" + case ${a} in + # Merged arches + x86|amd64) echo x86 ;; + ppc*) echo powerpc ;; + arm*) echo arm ;; + # Non-merged + alphaia64|m68k|mips|sh|sparc*) echo ${1} ;; + *) die "TODO: Update the code for your asm-ARCH symlink" ;; + esac +} + +savedconfig_dst() { + local a="$(kernel_asm_arch ${ARCH})" + echo "${KS}/arch/${a}/configs/savedconfig_defconfig" +} + +# for non-standardized defconfigs (e.g. arm*) +require_savedconfig() { + case ${ARCH} in + arm*) return 0 ;; + *) return 1 ;; + esac +} + src_unpack() { + # do first to avoid wasting time or resources + if require_savedconfig ; then + if ! use savedconfig ; then + eerror "Your ARCH requires a saved defconfig located at" + eerror "${SAVED_DEFCONFIG_SRC}" + eerror "Please create the file using linux-${OKV}, and then add" + eerror "\"dev-libs/klibc savedconfig\" to " + eerror "${PORTAGE_CONFIGROOT}etc/portage/package.use" + die "USE=\"savedconfig\" is required for ARCH=${ARCH}" + else + if [ ! -f "${SAVED_DEFCONFIG_SRC}" ]; then + eerror "Your savedconfig file does not exist at" + eerror "${SAVED_DEFCONFIG_SRC}" + eerror "Please create the file using linux-${OKV}." + die "${SAVED_DEFCONFIG_SRC}: No such file or directory." + fi + fi + else + if use savedconfig ; then + ewarn "Using a saved defconfig with ARCH=${ARCH} is discouraged and also completely" + ewarn "unsupported. You have been warned." + epause + fi + fi + unpack linux-${OKV}.tar.bz2 ${P}.tar.bz2 [ -n "${PKV}" ] && EPATCH_OPTS="-d ${KS} -p1" epatch "${DISTDIR}"/patch-${PKV}.bz2 cd "${S}" @@ -77,6 +130,20 @@ # bug 229525, usr/include/arch/x86_64/sys/io.h has undefined variables epatch "${FILESDIR}"/${PN}-1.5.11-x86_64-io.h-return.diff + + [[ ${ARCH} =~ arm.* ]] && [[ ${CHOST} =~ .*eabi ]] && + sed -i -e "s/# CONFIG_AEABI is not set/CONFIG_AEABI=y/" \ + defconfig + + for i in dash_readopt losetup klibc_kexecsyscall \ + klibc-1.5.15/wc klibc-1.5.15/modprobe \ + klibc-1.5.15/fstype-sane-vfat-and-jffs2-for-1.5; do + epatch "${FILESDIR}"/oe/${i}.patch || die "" + done + + if use savedconfig ; then + restore_config "$(savedconfig_dst)" || die + fi } # For a given Gentoo ARCH, @@ -87,7 +154,8 @@ case ${a} in ppc64) echo ppc64_defconfig ;; ppc) echo pmac32_defconfig ;; - arm*|sh*) die "TODO: Your arch is not supported by the klibc ebuild. Please suggest a defconfig in a bug." ;; + arm*) echo $(basename $(savedconfig_dst)) ;; + sh*) die "TODO: Your arch is not supported by the klibc ebuild. Please suggest a defconfig in a bug." ;; *) echo defconfig ;; esac } @@ -106,71 +174,64 @@ esac } -kernel_asm_arch() { - a="${1:${ARCH}}" - case ${a} in - # Merged arches - x86|amd64) echo x86 ;; - ppc*) echo powerpc ;; - # Non-merged - alpha|arm|ia64|m68k|mips|sh|sparc*) echo ${1} ;; - *) die "TODO: Update the code for your asm-ARCH symlink" ;; - esac +tc-get-toolchain-prefix() { + echo "${CHOST}-" } src_compile() { - local myargs="all" - local myARCH="${ARCH}" myABI="${ABI}" - # TODO: For cross-compiling - # You should set ARCH and ABI here - CC="$(tc-getCC)" - HOSTCC="$(tc-getBUILD_CC)" - KLIBCARCH="$(klibc_arch ${ARCH})" - KLIBCASMARCH="$(kernel_asm_arch ${ARCH})" - libdir="$(get_libdir)" + +# +# for both linux and klibc +# + local xopts + tc-is-cross-compiler && \ + xopts="ARCH=${ARCH} CROSS_COMPILE=$(tc-get-toolchain-prefix)" +# +# for linux +# + # This should be the defconfig corresponding to your userspace! # NOT your kernel. PPC64-32ul would choose 'ppc' for example. - defconfig=$(kernel_defconfig ${ARCH}) - unset ABI ARCH # Unset these, because they interfere - unset KBUILD_OUTPUT # we are using a private copy + local defconfig=$(kernel_defconfig ${ARCH}) cd "${KS}" - emake ${defconfig} CC="${CC}" HOSTCC="${HOSTCC}" || die "No defconfig" - emake prepare CC="${CC}" HOSTCC="${HOSTCC}" || die "Failed to prepare kernel sources for header usage" + emake ${xopts} ${myopts} ${defconfig} &> /dev/null || \ + die "no defconfig" + emake prepare ${xopts} ${myopts} &> /dev/null || \ + die "make prepare failed" + +# +# for klibc +# + +# unset ABI ARCH # Unset these, because they interfere + unset KBUILD_OUTPUT # we are using a private copy cd "${S}" + local myargs="all" + local libdir="$(get_libdir)" + + [[ ! -z "$(tc-get-abi)" ]] && \ + echo "CONFIG_$(tc-get-abi)=y" >> .config use debug && myargs="${myargs} V=1" has test $FEATURES && myargs="${myargs} test" emake \ - EXTRA_KLIBCAFLAGS="-Wa,--noexecstack" \ - EXTRA_KLIBCLDFLAGS="-z,noexecstack" \ - HOSTCC="${HOSTCC}" CC="${CC}" \ + KLIBCARCH="$(klibc_arch ${ARCH})" \ + KLIBCASMARCH="$(kernel_asm_arch ${ARCH})" \ INSTALLDIR="/usr/${libdir}/klibc" \ - KLIBCARCH=${KLIBCARCH} \ - KLIBCASMARCH=${KLIBCASMARCH} \ SHLIBDIR="/${libdir}" \ libdir="/usr/${libdir}" \ mandir="/usr/share/man" \ - T="${T}" \ - ${myargs} || die "Compile failed!" - - #SHLIBDIR="/${libdir}" \ - - ARCH="${myARCH}" ABI="${myABI}" + ${xopts} \ + ${myargs} &> /dev/null || die "Compile failed!" } src_install() { local myargs - local myARCH="${ARCH}" myABI="${ABI}" - # TODO: For cross-compiling - # You should set ARCH and ABI here - CC="$(tc-getCC)" - HOSTCC="$(tc-getBUILD_CC)" - KLIBCARCH="$(klibc_arch ${ARCH})" - KLIBCASMARCH="$(kernel_asm_arch ${ARCH})" libdir="$(get_libdir)" + # This should be the defconfig corresponding to your userspace! # NOT your kernel. PPC64-32ul would choose 'ppc' for example. defconfig=$(kernel_defconfig ${ARCH}) @@ -183,25 +244,26 @@ else klibc_prefix=$("${S}/klcc/klcc" -print-klibc-prefix) fi + local xopts + tc-is-cross-compiler && \ + xopts="CROSS_COMPILE=$(tc-get-toolchain-prefix) ARCH=${ARCH}" - unset ABI ARCH # Unset these, because they interfere +# unset ABI ARCH # Unset these, because they interfere ... really?? unset KBUILD_OUTPUT # we are using a private copy emake \ EXTRA_KLIBCAFLAGS="-Wa,--noexecstack" \ EXTRA_KLIBCLDFLAGS="-z,noexecstack" \ - HOSTCC="${HOSTCC}" CC="${CC}" \ INSTALLDIR="/usr/${libdir}/klibc" \ INSTALLROOT="${D}" \ - KLIBCARCH=${KLIBCARCH} \ - KLIBCASMARCH=${KLIBCASMARCH} \ + KLIBCARCH="$(klibc_arch ${ARCH})" \ + KLIBCASMARCH="$(kernel_asm_arch ${ARCH})" \ SHLIBDIR="/${libdir}" \ libdir="/usr/${libdir}" \ mandir="/usr/share/man" \ ${myargs} \ - install || die "Install failed!" - - #SHLIBDIR="/${libdir}" \ + ${xopts} \ + install &> /dev/null || die "Install failed!" # klibc doesn't support prelinking, so we need to mask it cat > "${T}/70klibc" <<-EOF