1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 inherit flag-o-matic toolchain-funcs
8 if [[ ${PV} == "9999" ]] ; then
9 EGIT_REPO_URI="git://sourceware.org/git/newlib-cygwin.git"
12 SRC_URI="ftp://sourceware.org/pub/newlib/${P}.tar.gz"
13 KEYWORDS="-* ~arm ~hppa ~m68k ~mips ~ppc ~ppc64 ~sh ~sparc ~x86"
16 export CBUILD=${CBUILD:-${CHOST}}
17 export CTARGET=${CTARGET:-${CHOST}}
18 if [[ ${CTARGET} == ${CHOST} ]] ; then
19 if [[ ${CATEGORY} == cross-* ]] ; then
20 export CTARGET=${CATEGORY#cross-}
24 DESCRIPTION="Newlib is a C library intended for use on embedded systems"
25 HOMEPAGE="https://sourceware.org/newlib/"
27 LICENSE="NEWLIB LIBGLOSS GPL-2"
29 IUSE="nls threads unicode headers-only nano"
32 NEWLIBBUILD="${WORKDIR}/build"
33 NEWLIBNANOBUILD="${WORKDIR}/build.nano"
34 NEWLIBNANOTMPINSTALL="${WORKDIR}/nano_tmp_install"
36 # Adding -U_FORTIFY_SOURCE to counter the effect of Gentoo's
37 # auto-addition of _FORTIFY_SOURCE at gcc site: bug #656018#c4
38 # Currently newlib can't be built itself when _FORTIFY_SOURCE
40 CFLAGS_FULL="-ffunction-sections -fdata-sections -U_FORTIFY_SOURCE"
41 CFLAGS_NANO="-Os -ffunction-sections -fdata-sections -U_FORTIFY_SOURCE"
44 # Reject newlib-on-glibc type installs
45 if [[ ${CTARGET} == ${CHOST} ]] ; then
48 *) die "Use sys-devel/crossdev to build a newlib toolchain" ;;
54 # we should fix this ...
56 CHOST=${CTARGET} strip-unsupported-flags
57 CCASFLAGS_ORIG="${CCASFLAGS}"
58 CFLAGS_ORIG="${CFLAGS}"
61 # Disable legacy syscall stub code in newlib. These have been
62 # moved to libgloss for a long time now, so the code in newlib
63 # itself just gets in the way.
64 --disable-newlib-supplied-syscalls
66 [[ ${CTARGET} == "spu" ]] \
67 && myconf+=( --disable-newlib-multithread ) \
68 || myconf+=( $(use_enable threads newlib-multithread) )
70 mkdir -p "${NEWLIBBUILD}"
73 export "CFLAGS_FOR_TARGET=${CFLAGS_ORIG} ${CFLAGS_FULL}"
74 export "CCASFLAGS=${CCASFLAGS_ORIG} ${CFLAGS_FULL}"
77 $(use_enable unicode newlib-mb) \
81 # Build newlib-nano beside newlib (original)
82 # Based on https://tracker.debian.org/media/packages/n/newlib/rules-2.1.0%2Bgit20140818.1a8323b-2
84 mkdir -p "${NEWLIBNANOBUILD}" || die
85 cd "${NEWLIBNANOBUILD}" || die
86 export "CFLAGS_FOR_TARGET=${CFLAGS_ORIG} ${CFLAGS_NANO}"
87 export "CCASFLAGS=${CCASFLAGS_ORIG} ${CFLAGS_NANO}"
90 $(use_enable unicode newlib-mb) \
92 --enable-newlib-reent-small \
93 --disable-newlib-fvwrite-in-streamio \
94 --disable-newlib-fseek-optimization \
95 --disable-newlib-wide-orient \
96 --enable-newlib-nano-malloc \
97 --disable-newlib-unbuf-stream-opt \
99 --enable-newlib-global-atexit \
100 --enable-newlib-nano-formatted-io \
106 export "CFLAGS_FOR_TARGET=${CFLAGS_ORIG} ${CFLAGS_FULL}"
107 export "CCASFLAGS=${CCASFLAGS_ORIG} ${CFLAGS_FULL}"
108 emake -C "${NEWLIBBUILD}"
111 export "CFLAGS_FOR_TARGET=${CFLAGS_ORIG} ${CFLAGS_NANO}"
112 export "CCASFLAGS=${CCASFLAGS_ORIG} ${CFLAGS_NANO}"
113 emake -C "${NEWLIBNANOBUILD}"
118 cd "${NEWLIBBUILD}" || die
119 emake -j1 DESTDIR="${D}" install
122 cd "${NEWLIBNANOBUILD}" || die
123 emake -j1 DESTDIR="${NEWLIBNANOTMPINSTALL}" install
124 # Rename nano lib* files to lib*_nano and move to the real ${D}
125 local nanolibfiles=""
126 nanolibfiles=$(find "${NEWLIBNANOTMPINSTALL}" -regex ".*/lib\(c\|g\|rdimon\)\.a" -print)
127 for f in ${nanolibfiles}; do
128 local l="${f##${NEWLIBNANOTMPINSTALL}}"
129 mv -v "${f}" "${D}/${l%%\.a}_nano.a" || die
132 # Move newlib-nano's version of newlib.h to newlib-nano/newlib.h
133 mkdir -p "${D}/usr/${CTARGET}/include/newlib-nano" || die
134 mv "${NEWLIBNANOTMPINSTALL}/usr/${CTARGET}/include/newlib.h" \
135 "${D}/usr/${CTARGET}/include/newlib-nano/newlib.h" || die
138 # minor hack to keep things clean
139 rm -rf "${D}"/usr/share/info || die
140 rm -rf "${D}"/usr/info || die