sys-cluster/kubectl: Remove old
[gentoo.git] / sys-libs / uclibc-ng / uclibc-ng-1.0.19.ebuild
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI="6"
5
6 inherit flag-o-matic multilib savedconfig toolchain-funcs versionator
7
8 if [[ ${PV} == "9999" ]] ; then
9         EGIT_REPO_URI="git://uclibc-ng.org/git/uclibc-ng"
10         inherit git-r3
11         MY_P=uclibc-ng-${PV}
12 else
13         MY_P=uClibc-ng-${PV}
14 fi
15
16 DESCRIPTION="C library for developing embedded Linux systems"
17 HOMEPAGE="http://www.uclibc-ng.org/"
18 if [[ ${PV} != "9999" ]] ; then
19         PATCH_VER=""
20         SRC_URI="http://downloads.uclibc-ng.org/releases/${PV}/${MY_P}.tar.bz2"
21         KEYWORDS="-* amd64 arm ~mips ppc x86"
22 fi
23
24 LICENSE="LGPL-2"
25 SLOT="0"
26 IUSE="debug hardened iconv ipv6 rpc crosscompile_opts_headers-only"
27 RESTRICT="strip"
28
29 # 1) We can't upgrade from uclibc to uclibc-ng via a soft blocker since portage
30 #    will delete the ld.so sym link prematurely and break the system. So we
31 #    will hard block and give manual migration instructions.
32 # 2) Currently uclibc and uclibc-ng's iconv are in bad shape.  We've been using
33 #    the breakout library.  The disadvantage here is that we have to sprinkle
34 #    LDFAGS=-liconv on build systems that need to link against libiconv.
35 RDEPEND="
36         !!sys-libs/uclibc
37         iconv? ( dev-libs/libiconv )"
38
39 S=${WORKDIR}/${MY_P}
40
41 export CBUILD=${CBUILD:-${CHOST}}
42 export CTARGET=${CTARGET:-${CHOST}}
43 if [[ ${CHOST} == ${CTARGET} ]] ; then
44         if [[ ${CATEGORY} == cross-* ]] ; then
45                 export CTARGET=${CATEGORY#cross-}
46         fi
47 fi
48
49 is_crosscompile() {
50         [[ ${CHOST} != ${CTARGET} ]]
51 }
52
53 alt_build_kprefix() {
54         if [[ ${CBUILD} == ${CHOST} && ${CHOST} == ${CTARGET} ]] ; then
55                 echo /usr/include
56         else
57                 echo /usr/${CTARGET}/usr/include
58         fi
59 }
60
61 just_headers() {
62         use crosscompile_opts_headers-only && is_crosscompile
63 }
64
65 uclibc_endian() {
66         # XXX: this wont work for a toolchain which is bi-endian, but we
67         #      dont have any such thing at the moment, so not a big deal
68         touch "${T}"/endian.s
69         $(tc-getAS ${CTARGET}) "${T}"/endian.s -o "${T}"/endian.o
70         case $(file "${T}"/endian.o) in
71                 *" MSB "*) echo "BIG";;
72                 *" LSB "*) echo "LITTLE";;
73                 *)         echo "NFC";;
74         esac
75         rm -f "${T}"/endian.{s,o}
76 }
77
78 kconfig_q_opt() {
79         local flag=$1; shift
80         case ${flag} in
81                 y|n) ;;
82                 *) flag=$(usex ${flag} y n) ;;
83         esac
84
85         local var="defs_${flag}"
86         eval "${var}+=( $* )"
87 }
88
89 get_opt() {
90         (
91         unset ${1}
92         . ${2:-"${S}"/.config}
93         echo ${!1}
94         )
95 }
96
97 make_oldconfig() {
98         yes "" 2>/dev/null | emake -s oldconfig >/dev/null
99 }
100
101 make_config() {
102         restore_config .config
103         if [ -f .config ]; then
104                 make_oldconfig
105                 return 0
106         else
107                 ewarn "Could not locate user configfile, so we will save a default one"
108         fi
109
110         emake ARCH=$1 defconfig >/dev/null
111
112         local defs_{y,n}
113
114         # These are forced off
115         defs_n=(
116                 DOASSERTS
117                 DODEBUG_PT
118                 HAS_NO_THREADS
119                 PROPOLICE_BLOCK_ABRT
120                 SSP_QUICK_CANARY
121                 SUPPORT_LD_DEBUG_EARLY
122                 UCLIBC_HAS_CTYPE_UNSAFE
123                 UCLIBC_HAS_LOCALE
124                 UCLIBC_HAS_SSP_COMPAT
125         )
126
127         # These are forced on
128         defs_y=(
129                 COMPAT_ATEXIT
130                 DO_C99_MATH
131                 DO_XSI_MATH
132                 FORCE_SHAREABLE_TEXT_SEGMENTS
133                 LDSO_GNU_HASH_SUPPORT
134                 LDSO_PRELINK_SUPPORT
135                 LDSO_PRELOAD_FILE_SUPPORT
136                 LDSO_RUNPATH_OF_EXECUTABLE
137                 LDSO_STANDALONE_SUPPORT
138                 MALLOC_GLIBC_COMPAT
139                 PROPOLICE_BLOCK_SEGV
140                 PTHREADS_DEBUG_SUPPORT
141                 UCLIBC_HAS_ARC4RANDOM
142                 UCLIBC_HAS_BACKTRACE
143                 UCLIBC_HAS_BSD_RES_CLOSE
144                 UCLIBC_HAS_CONTEXT_FUNCS
145                 UCLIBC_HAS_CTYPE_CHECKED
146                 UCLIBC_HAS_EXTRA_COMPAT_RES_STATE
147                 UCLIBC_HAS_FENV
148                 UCLIBC_HAS_FOPEN_CLOSEEXEC_MODE
149                 UCLIBC_HAS_FOPEN_EXCLUSIVE_MODE
150                 UCLIBC_HAS_FOPEN_LARGEFILE_MODE
151                 UCLIBC_HAS_FTS
152                 UCLIBC_HAS_FTW
153                 UCLIBC_HAS_GETPT
154                 UCLIBC_HAS_GLIBC_CUSTOM_PRINTF
155                 UCLIBC_HAS_GLIBC_CUSTOM_STREAMS
156                 UCLIBC_HAS_GNU_GLOB
157                 UCLIBC_HAS_HEXADECIMAL_FLOATS
158                 UCLIBC_HAS_LIBNSL_STUB
159                 UCLIBC_HAS_LIBRESOLV_STUB
160                 UCLIBC_HAS_LIBUTIL
161                 UCLIBC_HAS_NFTW
162                 UCLIBC_HAS_OBSOLETE_BSD_SIGNAL
163                 UCLIBC_HAS_OBSTACK
164                 UCLIBC_HAS_PRINTF_M_SPEC
165                 UCLIBC_HAS_PROGRAM_INVOCATION_NAME
166                 UCLIBC_HAS_RESOLVER_SUPPORT
167                 UCLIBC_HAS_SHA256_CRYPT_IMPL
168                 UCLIBC_HAS_SHA512_CRYPT_IMPL
169                 UCLIBC_HAS_SSP
170                 UCLIBC_HAS_STUBS
171                 UCLIBC_HAS_SYS_ERRLIST
172                 UCLIBC_HAS_SYS_SIGLIST
173                 UCLIBC_HAS_THREADS_NATIVE
174                 UCLIBC_HAS_TZ_FILE_READ_MANY
175                 UCLIBC_HAS_UTMP
176                 UCLIBC_HAS_UTMPX
177                 UCLIBC_HAS_WCHAR
178                 UCLIBC_HAS_WORDEXP
179                 UCLIBC_NTP_LEGACY
180                 UCLIBC_SUPPORT_AI_ADDRCONFIG
181                 UCLIBC_SUSV2_LEGACY
182                 UCLIBC_SUSV3_LEGACY
183                 UCLIBC_SUSV3_LEGACY_MACROS
184                 UCLIBC_SUSV4_LEGACY
185                 UCLIBC_USE_NETLINK
186         )
187
188         sed -i -e '/ARCH_.*_ENDIAN/d' .config
189         kconfig_q_opt y "ARCH_WANTS_$(uclibc_endian)_ENDIAN"
190
191         kconfig_q_opt debug DODEBUG
192         kconfig_q_opt debug SUPPORT_LD_DEBUG
193         kconfig_q_opt debug UCLIBC_HAS_PROFILING
194
195         kconfig_q_opt ipv6 UCLIBC_HAS_IPV6
196
197         kconfig_q_opt rpc UCLIBC_HAS_RPC
198         kconfig_q_opt rpc UCLIBC_HAS_FULL_RPC
199         kconfig_q_opt rpc UCLIBC_HAS_REENTRANT_RPC
200
201         kconfig_q_opt hardened UCLIBC_BUILD_NOEXECSTACK
202         kconfig_q_opt hardened UCLIBC_BUILD_NOW
203         kconfig_q_opt hardened UCLIBC_BUILD_PIE
204         kconfig_q_opt hardened UCLIBC_BUILD_RELRO
205         kconfig_q_opt hardened UCLIBC_BUILD_SSP
206
207         local count def
208         for count in 1 2 ; do
209                 # Run twice as some config opts depend on others being enabled first.
210                 for def in ${defs_y[@]} ; do
211                         sed -i -e "s|.*\<${def}\>.*set|${def}=y|g" .config
212                 done
213                 for def in ${defs_n[@]} ; do
214                         sed -i -e "s|${def}=y|# ${def} is not set|g" .config
215                 done
216                 make_oldconfig
217         done
218
219         einfo "Enabled options:"
220         for def in ${defs_y[@]} ; do
221                 einfo " " $(grep "^${def}=y" .config || echo "could not find ${def}")
222         done
223         einfo "Disabled options:"
224         for def in ${defs_n[@]} ; do
225                 einfo " " $(grep "^# ${def} is not set" .config || echo "could not find ${def}")
226         done
227
228         # setup build and run paths
229         sed -i \
230                 -e "/^CROSS_COMPILER_PREFIX/s|=.*|=\"${CTARGET}-\"|" \
231                 -e "/^KERNEL_HEADERS/s|=.*|=\"$(alt_build_kprefix)\"|" \
232                 -e "/^SHARED_LIB_LOADER_PREFIX/s|=.*|=\"/$(get_libdir)\"|" \
233                 -e "/^DEVEL_PREFIX/s|=.*|=\"/usr\"|" \
234                 -e "/^RUNTIME_PREFIX/s|=.*|=\"/\"|" \
235                 -e "/^UCLIBC_EXTRA_CFLAGS/s|=.*|=\"${UCLIBC_EXTRA_CFLAGS}\"|" \
236                 .config || die
237
238         make_oldconfig
239 }
240
241 pkg_setup() {
242         # Make sure our CHOST is a uclibc toolchain for native compiling
243         if [[ ${CHOST} == ${CTARGET} ]]; then
244                 case ${CHOST} in
245                         *-uclinux*|*-uclibc*) ;;
246                         *) die "Use sys-devel/crossdev to build a uclibc toolchain" ;;
247                 esac
248         fi
249
250         # uClibc-ng doesn't carry old Linux threads, and since we force
251         # threading our only choice is NPTL which requires i486 and later.
252         [[ ${CTARGET} == i386* ]] && die "i386 can't support Native Posix Threads (NPTL)."
253 }
254
255 src_prepare() {
256         local version subversion extraversion
257
258         # uclibc-ng tries to create a two sym link with ld.so,
259         # ld-uClibc.so.{0,MAJOR_VERSION} -> ld-uClibc-<version>.so
260         # where MAJOR_VERSION != 0 indicates the ABI verison.
261         # We want to get rid of this and just have ABI = 0.
262         eapply "${FILESDIR}"/uclibc-compat-r1.patch
263
264         # We need to change the major.minor.sublevel of uclibc-ng.
265         # Upstream sets MAJOR_VERSION = 1 which breaks runtime linking.
266         # If we really want the ABI bump, we'll have to hack the gcc
267         # spec file and change the '*link:' rule.
268         version=( $(get_version_components) )
269         if [[ -z ${version[1]} ]]; then
270                 subversion=0
271                 extraversion=0
272         else
273                 subversion=${version[1]}
274                 if [[ -z ${version[2]} ]]; then
275                         extraversion=0
276                 else
277                         extraversion=.${version[2]}
278                 fi
279         fi
280
281         sed -i \
282                 -e "/^MAJOR_VERSION/s|:=.*|:= 0|" \
283                 -e "/^MINOR_VERSION/s|:=.*|:= ${version[0]}|" \
284                 -e "/^SUBLEVEL/s|:=.*|:= ${subversion}|" \
285                 -e "/^EXTRAVERSION/s|:=.*|:= ${extraversion}|" \
286                 Rules.mak || die
287
288         eapply_user
289 }
290
291 src_configure() {
292         # Map our toolchain arch name to the name expected by uClibc-ng.
293         local target=$(tc-arch)
294         case ${target} in
295                 amd64) target="x86_64";;
296                 arm)   target="arm";;
297                 mips)  target="mips";;
298                 ppc)   target="powerpc";;
299                 x86)   target="i386";;
300         esac
301
302         # Do arch specific configuration by changing the defaults in
303         # extra/Configs/Config.<arch>.  If these are not overridden
304         # by an save .config, they will be selected by default.
305
306         # For i386, i486, i586 and i686
307         local cpu
308         if [[ ${target} == "i386" ]]; then
309                 [[ ${CTARGET} == i[456]86* ]] && cpu="${CTARGET:1:1}86"
310                 sed -i -e "s|default CONFIG_686|default CONFIG_${cpu:-486}|" \
311                         extra/Configs/Config.i386 || die
312         fi
313
314         # For arm
315         if [[ ${target} == "arm" ]]; then
316                 sed -i -e '/Build for EABI/a \\tdefault y' extra/Configs/Config.arm
317         fi
318
319         # We set HOSTCC to the proper tuple rather than just 'gcc'
320         sed -i -e "s|^HOSTCC.*=.*|HOSTCC=$(tc-getBUILD_CC)|" Rules.mak
321
322         make_config ${target}
323
324         einfo
325         einfo "Runtime Prefix: /"
326         einfo "Devel Prefix:   /usr"
327         einfo "Kernel Prefix:  $(alt_build_kprefix)"
328         einfo "CBUILD:         ${CBUILD}"
329         einfo "CHOST:          ${CHOST}"
330         einfo "CTARGET:        ${CTARGET}"
331         einfo "ABI:            ${ABI}"
332         einfo "ENDIAN:         $(uclibc_endian)"
333         einfo
334 }
335
336 src_compile() {
337         emake headers
338         just_headers && return 0
339
340         emake
341         if is_crosscompile ; then
342                 emake -C utils hostutils
343         else
344                 emake utils
345         fi
346 }
347
348 src_test() {
349         is_crosscompile && return 0
350
351         # assert test fails on pax/grsec enabled kernels
352         # normal vfork test fails in sandbox (both glibc/uclibc)
353         emake UCLIBC_ONLY=1 check
354 }
355
356 src_install() {
357         local sysroot=${D}
358         is_crosscompile && sysroot+="/usr/${CTARGET}"
359
360         local target="install"
361         just_headers && target="install_headers"
362         emake DESTDIR="${sysroot}" ${target}
363
364         save_config .config
365
366         # remove files coming from kernel-headers
367         rm -rf "${sysroot}"/usr/include/{linux,asm*}
368
369         # Make sure we install the sys-include symlink so that when
370         # we build a 2nd stage cross-compiler, gcc finds the target
371         # system headers correctly.  See gcc/doc/gccinstall.info
372         if is_crosscompile ; then
373                 dosym usr/include /usr/${CTARGET}/sys-include
374                 if ! just_headers && [[ -n $(get_opt HAVE_SHARED) ]] ; then
375                         newbin utils/ldconfig.host ${CTARGET}-ldconfig
376                         newbin utils/ldd.host ${CTARGET}-ldd
377                 fi
378                 return 0
379         fi
380
381         dosym libc.so.0 "${DESTDIR}"/lib/libcrypt.so.0
382         dosym libc.so.0 "${DESTDIR}"/lib/libdl.so.0
383         dosym libc.so.0 "${DESTDIR}"/lib/libm.so.0
384         dosym libc.so.0 "${DESTDIR}"/lib/libpthread.so.0
385         dosym libc.so.0 "${DESTDIR}"/lib/librt.so.0
386         dosym libc.so.0 "${DESTDIR}"/lib/libresolv.so.0
387         dosym libc.so.0 "${DESTDIR}"/lib/libubacktrace.so.0
388         dosym libc.so.0 "${DESTDIR}"/lib/libutil.so.0
389
390         emake DESTDIR="${D}" install_utils
391         dobin extra/scripts/getent
392         dodoc README docs/*.txt
393 }
394
395 pkg_postinst() {
396         is_crosscompile && return 0
397
398         if [ ! -e "${ROOT}"/etc/TZ ] ; then
399                 ewarn "Please remember to set your timezone in /etc/TZ"
400                 mkdir -p "${ROOT}"/etc
401                 echo "UTC" > "${ROOT}"/etc/TZ
402         fi
403         [ "${ROOT}" != "/" ] && return 0
404         # update cache before reloading init
405         ldconfig
406         # reload init ...
407         /sbin/telinit U 2>/dev/null
408 }