kde-apps/umbrello: Disable finding more packages
[gentoo.git] / sys-libs / newlib / newlib-3.1.0.ebuild
1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI="7"
5
6 inherit flag-o-matic toolchain-funcs
7
8 if [[ ${PV} == "9999" ]] ; then
9         EGIT_REPO_URI="git://sourceware.org/git/newlib-cygwin.git"
10         inherit git-r3
11 else
12         SRC_URI="ftp://sourceware.org/pub/newlib/${P}.tar.gz"
13         KEYWORDS="-* ~arm ~hppa ~m68k ~mips ~ppc ~ppc64 ~sh ~sparc ~x86"
14 fi
15
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-}
21         fi
22 fi
23
24 DESCRIPTION="Newlib is a C library intended for use on embedded systems"
25 HOMEPAGE="https://sourceware.org/newlib/"
26
27 LICENSE="NEWLIB LIBGLOSS GPL-2"
28 SLOT="0"
29 IUSE="nls threads unicode headers-only nano"
30 RESTRICT="strip"
31
32 NEWLIBBUILD="${WORKDIR}/build"
33 NEWLIBNANOBUILD="${WORKDIR}/build.nano"
34 NEWLIBNANOTMPINSTALL="${WORKDIR}/nano_tmp_install"
35
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
39 # is set.
40 CFLAGS_FULL="-ffunction-sections -fdata-sections -U_FORTIFY_SOURCE"
41 CFLAGS_NANO="-Os -ffunction-sections -fdata-sections -U_FORTIFY_SOURCE"
42
43 pkg_setup() {
44         # Reject newlib-on-glibc type installs
45         if [[ ${CTARGET} == ${CHOST} ]] ; then
46                 case ${CHOST} in
47                         *-newlib|*-elf) ;;
48                         *) die "Use sys-devel/crossdev to build a newlib toolchain" ;;
49                 esac
50         fi
51 }
52
53 src_configure() {
54         # we should fix this ...
55         unset LDFLAGS
56         CHOST=${CTARGET} strip-unsupported-flags
57         CCASFLAGS_ORIG="${CCASFLAGS}"
58         CFLAGS_ORIG="${CFLAGS}"
59
60         local myconf=(
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
65         )
66         [[ ${CTARGET} == "spu" ]] \
67                 && myconf+=( --disable-newlib-multithread ) \
68                 || myconf+=( $(use_enable threads newlib-multithread) )
69
70         mkdir -p "${NEWLIBBUILD}"
71         cd "${NEWLIBBUILD}"
72
73         export "CFLAGS_FOR_TARGET=${CFLAGS_ORIG} ${CFLAGS_FULL}"
74         export "CCASFLAGS=${CCASFLAGS_ORIG} ${CFLAGS_FULL}"
75         ECONF_SOURCE=${S} \
76         econf \
77                 $(use_enable unicode newlib-mb) \
78                 $(use_enable nls) \
79                 "${myconf[@]}"
80
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
83         if use nano ; then
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}"
88                 ECONF_SOURCE=${S} \
89                 econf \
90                         $(use_enable unicode newlib-mb) \
91                         $(use_enable nls) \
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 \
98                         --enable-lite-exit \
99                         --enable-newlib-global-atexit \
100                         --enable-newlib-nano-formatted-io \
101                         ${myconf}
102         fi
103 }
104
105 src_compile() {
106         export "CFLAGS_FOR_TARGET=${CFLAGS_ORIG} ${CFLAGS_FULL}"
107         export "CCASFLAGS=${CCASFLAGS_ORIG} ${CFLAGS_FULL}"
108         emake -C "${NEWLIBBUILD}"
109
110         if use nano ; then
111                 export "CFLAGS_FOR_TARGET=${CFLAGS_ORIG} ${CFLAGS_NANO}"
112                 export "CCASFLAGS=${CCASFLAGS_ORIG} ${CFLAGS_NANO}"
113                 emake -C "${NEWLIBNANOBUILD}"
114         fi
115 }
116
117 src_install() {
118         cd "${NEWLIBBUILD}" || die
119         emake -j1 DESTDIR="${D}" install
120
121         if use nano ; then
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
130                 done
131
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
136         fi
137
138         # minor hack to keep things clean
139         rm -rf "${D}"/usr/share/info || die
140         rm -rf "${D}"/usr/info || die
141 }