File klibc.spec of Package klibc

%def_with static_utils

Name: klibc
Version: 2.0.4
Release: 14
Summary: A minimal libc subset for use with initramfs
License: BSD/GPL
Group: System/Libraries
URL: http://www.zytor.com/mailman/listinfo/%name
# git://git.kernel.org/pub/scm/libs/klibc/klibc
Source0: %name-%version.tar.xz
Source1: %name-find-provides
Source2: %name-find-requires
Patch0: %name-%version-git.patch
Patch1: klibc-2.0.4-released-next-version-is-2.0.5.patch
# klibc fixes
Patch05: %name-2.0.4-usleep.patch
Patch06: %name-asprintf.patch
Patch07: %name-i386-socketcall-compat.patch
Patch08: %name-O_TMPFILE.patch
# klibc features
Patch11: %name-2.0.4-glob.patch
Patch12: %name-2.0.4-feat-IF_NAMESIZE.patch
# utils fixes
Patch21: %name-readlink.patch
Patch22: %name-2.0.4-ln.patch
Patch23: %name-2.0.4-mknod.patch
Patch24: %name-2.0.4-mv.patch
Patch25: %name-2.0.4-pivot_root.patch
Patch26: %name-2.0.4-sleep.patch
Patch27: %name-2.0.4-umount.patch
Patch28: %name-2.0.4-uname.patch
# utils features
Patch31: %name-2.0.4-basename.patch
Patch32: %name-2.0.4-dirname.patch
# kinit fixes
Patch41: %name-2.0.4-kinit-capabilities.patch
Patch42: %name-2.0.4-kinit-nozlib.patch
Patch43: %name-2.0.4-ipconfig.patch
Patch44: %name-2.0.4-nfsmount.patch
# install fixes
Patch51: klibc-2.0.4-headers_install.patch

BuildRequires: fdupes

%define klibcdir %_libdir/%name
%define kernelsrcdir %(readlink -ev %_includedir/linux/../..)

# Use special scripts to find dependencies on klibc-*.so (default RPM scripts
# do not pick up these dependencies).
%define _use_internal_dependency_generator 0
%define __find_provides \\
%if 0%{?centos_version} && 0%{?centos_version} < 700
%define __find_provides env RPM_BUILD_ROOT="%buildroot" %_builddir/%name-%version/%name-find-provides
%else
%define __find_provides env %_builddir/%name-%version/%name-find-provides
%endif
%define __find_requires %_builddir/%name-%version/%name-find-requires

%description
%name is intended to be a minimalistic libc subset for use with initramfs.
It is deliberately written for small size, minimal entanglement, and portability,
not speed.


%package devel
Summary: Libraries and tools needed to compile applications against klibc
Group: Development/C
Requires: %name = %version-%release
AutoReq: nocpp
Provides: klcc = %version-%release
Provides: %name-devel-static = %version-%release

%description devel
This package contains the link libraries, header files, and gcc wrapper scripts
needed to compile applications against klibc.


%package utils
Summary: Small utilities built with klibc
Group: System/Kernel and hardware
Requires: %name = %version-%release

%description utils
This package contains a collection of programs that are linked against klibc.
These duplicate some of the functionality of a regular Linux toolset, but are
typically much smaller than their full-function counterparts. They are intended
for inclusion in initramfs images and embedded systems.


%prep
%setup -q
%patch -p1 -P 0
%patch -p1 -R -P 1
%patch -p1 -P 05 -P 06 -P 07 -P 08
%patch -p1 -P 11 -P 12
%patch -p1 -P21 -P 22 -P 23 -P 24 -P 25 -P 26 -P 27 -P 28
%patch -p1 -F 2 -P 31 -P 32
%patch -p1 -P 41 -P 42 -P 43 -P 44
%patch -p1 -F2 -P 51

find usr/include -type f -name '*.orig' -delete

install -p -m 0755 %{S:1} ./%name-find-provides
install -p -m 0755 %{S:2} ./%name-find-requires

cat > defconfig <<__EOF__
CONFIG_KLIBC=y
# CONFIG_KLIBC_ERRLIST is not set
# CONFIG_KLIBC_ZLIB is not set
# CONFIG_KLIBC_ZIP is not set
# i386 option
CONFIG_REGPARM=y
# ARM options
CONFIG_AEABI=y
# CONFIG_KLIBC_THUMB is not set
__EOF__


%build
%define optflags_debug %nil
make %{?_smp_mflags} \
	INSTALLROOT=%buildroot \
	KLIBCARCH=%_build_arch \
	prefix=%_prefix \
	KLIBCKERNELSRC=%kernelsrcdir \
	bindir=%_bindir \
	SHLIBDIR=/%_lib \
	mandir=%_mandir \
	INSTALLDIR=%klibcdir \
	V=1


%install
make \
	INSTALLROOT=%buildroot \
	KLIBCARCH=%_build_arch \
	prefix=%_prefix \
	KLIBCKERNELSRC=%kernelsrcdir \
	bindir=%_bindir \
	SHLIBDIR=/%_lib \
	mandir=%_mandir \
	INSTALLDIR=%klibcdir \
	V=1 \
	install

%if_with static_utils
# Install static utils
ls usr/{utils,kinit/*}/static/* | grep -v '\.g' | while read f; do
	[ -x $f ] || continue
	install -p -m 0755 $f %buildroot%klibcdir/bin/$(basename $f).static
done
install -p -m 0755 usr/dash/sh %buildroot%klibcdir/bin/sh.static
%endif

rm -f %buildroot%klibcdir/include/Kbuild

install -p -m 0755 %name-find-requires %buildroot%klibcdir/

# Install the docs
install -d -m 0755 %buildroot%_docdir/%name
install -p -m 0644 README usr/%name/{,arch/}README.%{name}* %buildroot%_docdir/%name/
for f in usr/{gzip/{COPYING,README},kinit{,/ipconfig}/README*}; do
	s="$(basename $(dirname $f))"
	install -p -m 0644 $f %buildroot%_docdir/%name/$(basename $f .$s).$s
done

ln -sf {/%_lib,%buildroot%klibcdir/lib}/$(basename %buildroot/%_lib/%name-*.so)

Symlinks()
{
	local s=$1
	shift
	local t
	for t in $*; do
		ln -sf $s %buildroot%klibcdir/bin/$t
	done
}

Symlinks gzip gunzip zcat
Symlinks halt poweroff reboot

%fdupes %buildroot%klibcdir

# This file must have normal symbols - they are used for linking
# (klibc does not use the dynamic symbol table).
export NO_BRP_STRIP_UNNEEDED=true


%files
/%_lib/%name-*.so


%files devel
%klibcdir
%exclude %klibcdir/bin
%_bindir/klcc
%_mandir/man1/*
%doc %dir %_docdir/%name
%doc %_docdir/%name/README
%doc %_docdir/%name/README.%{name}*


%files utils
%dir %klibcdir
%klibcdir/bin
%doc %dir %_docdir/%name
%doc %_docdir/%name/*
%exclude %_docdir/%name/README
%exclude %_docdir/%name/README.%{name}*


%changelog
openSUSE Build Service is sponsored by