--- /var/portage/sys-libs/newlib/newlib-9999.ebuild 2016-01-18 11:06:25.000000000 +0100 +++ /usr/local/portage/kim/cross-arm-none-eabi/newlib/newlib-9999-r1.ebuild 2016-06-13 10:45:17.934320364 +0200 @@ -29,10 +29,15 @@ LICENSE="NEWLIB LIBGLOSS GPL-2" SLOT="0" -IUSE="nls threads unicode crosscompile_opts_headers-only" +IUSE="nls threads unicode crosscompile_opts_headers-only newlib-nano newlib-supplied-syscalls" RESTRICT="strip" NEWLIBBUILD="${WORKDIR}/build" +NEWLIBNANOBUILD="${WORKDIR}/build.nano" +NEWLIBNANOTMPINSTALL="${WORKDIR}/nano_tmp_install" + +CFLAGS_FULL="-ffunction-sections -fdata-sections" +CFLAGS_NANO="-Os -ffunction-sections -fdata-sections" pkg_setup() { # Reject newlib-on-glibc type installs @@ -52,30 +57,86 @@ # we should fix this ... unset LDFLAGS CHOST=${CTARGET} strip-unsupported-flags + CCASFLAGS_ORIG="${CCASFLAGS}" + CFLAGS_ORIG="${CFLAGS}" local myconf="" [[ ${CTARGET} == "spu" ]] \ && myconf="${myconf} --disable-newlib-multithread" \ || myconf="${myconf} $(use_enable threads newlib-multithread)" + myconf="${myconf} $(use_enable newlib-supplied-syscalls)" mkdir -p "${NEWLIBBUILD}" cd "${NEWLIBBUILD}" - + export "CFLAGS_FOR_TARGET=${CFLAGS_ORIG} ${CFLAGS_FULL}" + export "CCASFLAGS=${CCASFLAGS_ORIG} ${CFLAGS_FULL}" ECONF_SOURCE=${S} \ econf \ $(use_enable unicode newlib-mb) \ $(use_enable nls) \ + --enable-newlib-io-long-long \ + --enable-newlib-register-fini \ ${myconf} + + # Build newlib-nano beside newlib (original) + # Based on https://tracker.debian.org/media/packages/n/newlib/rules-2.1.0%2Bgit20140818.1a8323b-2 + if use newlib-nano ; then + mkdir -p "${NEWLIBNANOBUILD}" + cd "${NEWLIBNANOBUILD}" + export "CFLAGS_FOR_TARGET=${CFLAGS_ORIG} ${CFLAGS_NANO}" + export "CCASFLAGS=${CCASFLAGS_ORIG} ${CFLAGS_NANO}" + ECONF_SOURCE=${S} \ + econf \ + $(use_enable unicode newlib-mb) \ + $(use_enable nls) \ + --enable-newlib-reent-small \ + --disable-newlib-fvwrite-in-streamio \ + --disable-newlib-fseek-optimization \ + --disable-newlib-wide-orient \ + --enable-newlib-nano-malloc \ + --disable-newlib-unbuf-stream-opt \ + --enable-lite-exit \ + --enable-newlib-global-atexit \ + --enable-newlib-nano-formatted-io \ + ${myconf} + fi } src_compile() { + export "CFLAGS_FOR_TARGET=${CFLAGS_ORIG} ${CFLAGS_FULL}" + export "CCASFLAGS=${CCASFLAGS_ORIG} ${CFLAGS_FULL}" emake -C "${NEWLIBBUILD}" + if use newlib-nano ; then + export "CFLAGS_FOR_TARGET=${CFLAGS_ORIG} ${CFLAGS_NANO}" + export "CCASFLAGS=${CCASFLAGS_ORIG} ${CFLAGS_NANO}" + emake -C "${NEWLIBNANOBUILD}" + fi } src_install() { cd "${NEWLIBBUILD}" emake -j1 DESTDIR="${D}" install # env -uRESTRICT CHOST=${CTARGET} prepallstrip + + if use newlib-nano ; then + cd "${NEWLIBNANOBUILD}" + emake -j1 DESTDIR="${NEWLIBNANOTMPINSTALL}" install + # Rename nano lib* files to lib*_nano and move to the real ${D} + # Avoid dependency on perl-rename by using a for loop instead. + local nanolibfiles="" + nanolibfiles=$(find "${NEWLIBNANOTMPINSTALL}" -regex ".*/lib\(c\|g\|rdimon\)\.a" -print) + for f in ${nanolibfiles}; do + local l="${f##${NEWLIBNANOTMPINSTALL}}" + echo mv "${f}" "${D}/${l%%\.a}_nano.a" + mv "${f}" "${D}/${l%%\.a}_nano.a" + done + # Move newlib-nano's version of newlib.h to newlib-nano/newlib.h + mkdir -p ${D}/usr/${CTARGET}/include/newlib-nano + mv ${NEWLIBNANOTMPINSTALL}/usr/${CTARGET}/include/newlib.h \ + ${D}/usr/${CTARGET}/include/newlib-nano/newlib.h + + fi + # minor hack to keep things clean rm -fR "${D}"/usr/share/info rm -fR "${D}"/usr/info