-
-#
-# _with_altconfig <name> - alternative busybox config file (replaces default one)
-# you should define cfgfile macro, i.e.
+# TODO:
+# - review patch 3. Updated to 1.17.3, but the code changed so much it's unclear
+# if it still serves a purpose
+# - sparc64 modules support in sparc(32), x86_64 modules support in i386 version
+# - make internal commands work even if busybox is not in /bin/busybox (initrd)
+# or when /proc is not mounted (static / normal)
#
-# rpm --rebuild busybox.*.src.rpm --with altconfig --define "cfgfile bb-emb-config.h"
+# Conditional build:
+# alternative busybox config file (replaces default one) you should
+# define cfgfile macro, i.e.
#
+# rpm --rebuild busybox.*.src.rpm --with altconfig --define "cfgfile bb-emb-config.h"
#
-# _with_linkfl - creates links to busybox binary and puts them into file list;
-#
+%bcond_with altconfig # use alternative config (defined by cfgfile)
+%bcond_with linkfl # creates links to busybox binary and puts them into file list
+%bcond_without dynamic # don't build dynamic (base) version
+%bcond_without static # don't build static version
+%bcond_without initrd # don't build initrd version
+%bcond_with dietlibc # build dietlibc-based initrd and static versions
+%bcond_with glibc # build glibc-based initrd and static versions
+%bcond_without verbose # verbose build
# Options below are useful, when you want fileutils and grep providing.
# For example, ash package requires fileutils and grep.
-#
-# _with_fileutl_prov - adds fileutils providing
-# _with_grep_prov - adds grep providing
-#
-#
+%bcond_with fileutl_prov # adds fileutils providing
+%bcond_with grep_prov # adds grep providing
# Option below is useful, when busybox is built with shell support.
-#
-# _with_sh_prov - adds /bin/sh providing
-#
-#
-# WARNING! Shell, filetuils and grep providing may depend on config file!
+%bcond_with sh_prov # adds /bin/sh providing
+# WARNING! Shell, fileutils and grep providing may depend on config file!
# Fileutils, grep and shell provided with busybox have not such
# functionality as their GNU countenders.
#
-#
-# _without_static - don't build static version
-#
-
-Summary: Set of common unix utils for embeded systems
-Summary(pl): Zestaw narzêdzi uniksowych dla systemów wbudowanych
-Summary(pt_BR): BusyBox é um conjunto de utilitários UNIX em um único binário
+%ifnarch %{ix86} %{x8664} ppc
+%define with_glibc 1
+%endif
+%ifarch x32
+# until uClibc builds on x32
+%undefine with_static
+%endif
+Summary: Set of common Unix utilities for embeded systems
+Summary(pl.UTF-8): Zestaw narzędzi uniksowych dla systemów wbudowanych
+Summary(pt_BR.UTF-8): BusyBox é um conjunto de utilitários UNIX em um único binário
Name: busybox
-Version: 0.60.2
-Release: 7
-License: GPL
+# stable line only
+Version: 1.24.2
+Release: 1
+License: GPL v2
Group: Applications
-Source0: ftp://ftp.lineo.com/pub/busybox/%{name}-%{version}.tar.gz
-%{!?_with_altconfig:Source1: %{name}-config.h}
-%{?_with_altconfig:Source1: %{cfgfile}}
-Patch0: %{name}-logconsole.patch
-Patch1: %{name}-tee.patch
-Patch3: %{name}-printf-gettext.patch
-Patch4: %{name}-loadfont.patch
-Patch5: %{name}-cread.patch
-Patch6: %{name}-malloc.patch
-Patch7: %{name}-pivot_root.patch
-URL: http://busybox.lineo.com/
-%{?_with_fileutl_prov:Provides: fileutils}
-%{?_with_grep_prov:Provides: grep}
-%{?_with_sh_prov:Provides: /bin/sh}
-%{!?_without_static:BuildRequires: glibc-static}
+Source0: http://www.busybox.net/downloads/%{name}-%{version}.tar.bz2
+# Source0-md5: 2eaae519cac1143bcf583636a745381f
+Source1: %{name}.config
+Source2: %{name}-initrd.config
+%{?with_altconfig:Source3: %{cfgfile}}
+Patch100: https://busybox.net/downloads/fixes-1.24.2/busybox-1.24.2-CVE-2016-2147.patch
+# Patch100-md5: c45a85f5ced712743efbb683900f8c1d
+Patch101: https://busybox.net/downloads/fixes-1.24.2/busybox-1.24.2-CVE-2016-2148.patch
+# Patch101-md5: 850a57ca2871e370b4916161a0320a3f
+Patch102: https://busybox.net/downloads/fixes-1.24.2/busybox-1.24.2-ash-recursive-heredocs.patch
+# Patch102-md5: b59eb7536609db1ab5215de860d9e558
+Patch0: x32.patch
+Patch1: %{name}-logconsole.patch
+Patch2: %{name}-printf-gettext.patch
+Patch3: %{name}-loadfont.patch
+Patch4: %{name}-kernel_headers.patch
+Patch5: %{name}-insmod-morearchs.patch
+Patch6: %{name}-dhcp.patch
+Patch7: %{name}-fix_64_archs.patch
+Patch9: %{name}-ash-export-PATH.patch
+URL: http://www.busybox.net/
+BuildRequires: gcc >= 3.2
+BuildRequires: perl-tools-pod
+BuildRequires: rpmbuild(macros) >= 1.652
+%if %{with initrd} || %{with static}
+ %if %{with dietlibc}
+BuildRequires: dietlibc-static
+ %else
+ %if %{with glibc}
+BuildRequires: glibc-static
+ %else
+%if "%{_target_base_arch}" != "%{_host_base_arch}"
+BuildRequires: cross%{_target_base_arch}-uClibc-static
+%else
+ %ifarch ppc %{x8664}
+BuildRequires: uClibc-static >= 3:0.9.30.1
+ %else
+BuildRequires: uClibc-static >= 3:0.9.30.1
+ %endif
+%endif
+ %endif
+ %endif
+%endif
+%{?with_sh_prov:Provides: /bin/sh}
+%{?with_fileutl_prov:Provides: fileutils}
+%{?with_grep_prov:Provides: grep}
BuildRoot: %{tmpdir}/%{name}-%{version}-root-%(id -u -n)
+%define _bindir /bin
+
+%if "%{_target_base_arch}" != "%{_host_base_arch}"
+ %define CrossOpts CROSS="%{_target_cpu}-pld-linux-"
+%else
+ %define CrossOpts %{nil}
+%endif
+
+%define filterout_ld -Wl,-z,(combreloc|relro)
+
%description
BusyBox combines tiny versions of many common UNIX utilities into a
single small executable. It provides minimalist replacements for most
a kernel, a shell (such as ash), and an editor (such as elvis-tiny or
ae).
-%description -l pl
-BusyBox sk³ada ma³e wersje wielu narzêdzi uniksowych w jeden ma³y plik
-wykonywalny. Zapewnia minimalne zastêpniki wiêkszo¶ci narzêdzi
+%description -l pl.UTF-8
+BusyBox składa małe wersje wielu narzędzi uniksowych w jeden mały plik
+wykonywalny. Zapewnia minimalne zastępniki większości narzędzi
zawartych w pakietach fileutils, shellutils, findutils, grep, gzip,
-tar itp. BusyBox daje w miarê kompletne ¶rodowisko POSIX dla ma³ych
-lub wbudowanych systemów. Narzêdzia maj± mniej opcji ni¿ ich pe³ne
-odpowiedniki GNU, ale maj± podstawow± funkcjonalno¶æ. Do dzia³aj±cego
+tar itp. BusyBox daje w miarę kompletne środowisko POSIX dla małych
+lub wbudowanych systemów. Narzędzia mają mniej opcji niż ich pełne
+odpowiedniki GNU, ale mają podstawową funkcjonalność. Do działającego
systemu potrzeba jeszcze tylko kernela, shella (np. ash) oraz edytora
(np. elvis-tiny albo ae).
-%description -l pt_BR
-BusyBox combina versões reduzidas de muitos utilitários UNIX num único
-executável, fornecendo substitutos minimalistas para muitos dos
-executáveis encontrados em pacotes como fileutils, shellutils,
-findutils, textutils, grep, gzip, tar, etc. Os utilitários do BusyBox
-em geral têm menos opções que os utilitários GNU, mas as opções
+%description -l pt_BR.UTF-8
+BusyBox combina versões reduzidas de muitos utilitários UNIX num único
+executável, fornecendo substitutos minimalistas para muitos dos
+executáveis encontrados em pacotes como fileutils, shellutils,
+findutils, textutils, grep, gzip, tar, etc. Os utilitários do BusyBox
+em geral têm menos opções que os utilitários GNU, mas as opções
implementadas comportam-se de maneira similar aos equivalentes GNU.
%package static
Summary: Static busybox
-Summary(pl): Statycznie linkowany busybox
+Summary(pl.UTF-8): Statycznie skonsolidowany busybox
Group: Applications
%description static
Static busybox.
-%description static -l pl
-Statycznie linkowany busybox.
+%description static -l pl.UTF-8
+Statycznie skonsolidowany busybox.
+
+%package initrd
+Summary: Static busybox for initrd
+Summary(pl.UTF-8): Statycznie skonsolidowany busybox dla initrd
+Group: Base
+Conflicts: geninitrd < 10000.20
+
+%description initrd
+Static busybox for initrd.
+
+%description initrd -l pl.UTF-8
+Statycznie skonsolidowany busybox dla initrd.
%prep
%setup -q
+%patch100 -p1
+%patch101 -p1
+%patch102 -p1
+
%patch0 -p1
%patch1 -p1
-%patch3 -p1
+%patch2 -p1
+#%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1
%patch7 -p1
+%patch9 -p1
%build
-cp -f %{SOURCE1} Config.h
+install -d built
+%if %{with initrd}
+install %{SOURCE2} .config
+%{__make} oldconfig
+%{__make} \
+ %{?with_verbose:V=1} \
+ CROSS_CFLAGS="%{rpmcflags} -Os -D_BSD_SOURCE" \
+ LDFLAGS="%{rpmldflags} -static" \
+%if %{with dietlibc}
+ LIBRARIES="-lrpc" \
+ CC="diet %{__cc}"
+%else
+%if %{with glibc}
+ %{CrossOpts} \
+ CC="%{__cc}"
+%else
+ %if "%{_target_base_arch}" != "%{_host_base_arch}"
+ CROSS="%{_target_cpu}-uclibc-" \
+ %endif
+ CC="%{_target_cpu}-uclibc-gcc"
+%endif
+%endif
+
+mv -f busybox built/busybox.initrd
+%{__make} clean
+%endif
+
+%if %{with altconfig}
+install %{SOURCE3} .config
+%else
+install %{SOURCE1} .config
+%endif
-%if %{?_without_static:0}%{!?_without_static:1}
+%if %{with static}
+%{__make} oldconfig
%{__make} \
- CFLAGS_EXTRA="%{rpmcflags}" \
- LDFLAGS="%{rpmldflags} -static"
-mv -f busybox busybox.static
+ %{?with_verbose:V=1} \
+ CROSS_CFLAGS="%{rpmcflags} -Os -D_BSD_SOURCE" \
+ LDFLAGS="%{rpmldflags} -static" \
+%if %{with dietlibc}
+ LIBRARIES="-lrpc" \
+ CC="diet %{__cc}"
+%else
+%if %{with glibc}
+ %{CrossOpts} \
+ CC="%{__cc}"
+%else
+ %if "%{_target_base_arch}" != "%{_host_base_arch}"
+ CROSS="%{_target_cpu}-uclibc-" \
+ %endif
+ CC="%{_target_cpu}-uclibc-gcc"
+%endif
+%endif
+
+mv -f busybox built/busybox.static
%{__make} clean
%endif
+%if %{with dynamic}
+%{__make} oldconfig
%{__make} \
+ %{?with_verbose:V=1} \
+ %{CrossOpts} \
CFLAGS_EXTRA="%{rpmcflags}" \
LDFLAGS="%{rpmldflags}" \
CC="%{__cc}"
+%{__make} busybox.links docs/busybox.1
+%endif
%install
rm -rf $RPM_BUILD_ROOT
-install -d $RPM_BUILD_ROOT{%{_bindir},%{_mandir}/man1,%{_libdir}/busybox}
-%{!?_without_static:install busybox.static $RPM_BUILD_ROOT%{_bindir}}
+%if %{with static}
+install -d $RPM_BUILD_ROOT%{_bindir}
+install built/busybox.static $RPM_BUILD_ROOT%{_bindir}
+%endif
+
+%if %{with initrd}
+install -d $RPM_BUILD_ROOT%{_libdir}/initrd
+install built/busybox.initrd $RPM_BUILD_ROOT%{_libdir}/initrd/busybox
+%endif
-%{?!_with_linkfl:install busybox $RPM_BUILD_ROOT%{_bindir}}
+%if %{with dynamic}
+install -d $RPM_BUILD_ROOT{%{_bindir},%{_mandir}/man1,%{_libdir}/busybox}
install busybox.links $RPM_BUILD_ROOT%{_libdir}/busybox
-install docs/BusyBox.1 $RPM_BUILD_ROOT%{_mandir}/man1
-echo ".so BusyBox.1" > $RPM_BUILD_ROOT%{_mandir}/man1/busybox.1
+install docs/busybox.1 $RPM_BUILD_ROOT%{_mandir}/man1
# install links to busybox binary, when linkfl is defined
-%{?_with_linkfl:make install PREFIX=$RPM_BUILD_ROOT}
-
-gzip -9nf AUTHORS TODO Changelog README
+%if %{with linkfl}
+%{__make} install \
+ PREFIX=$RPM_BUILD_ROOT
+%else
+install busybox $RPM_BUILD_ROOT%{_bindir}
+%endif
+%endif
%clean
rm -rf $RPM_BUILD_ROOT
+%if %{with dynamic}
%files
%defattr(644,root,root,755)
-%doc *.gz
-
-%{?!_with_linkfl: %attr(755,root,root) %{_bindir}/busybox}
+%doc AUTHORS README .config
-%if %{?_with_linkfl:1}%{?!_with_linkfl:0}
+%if %{with linkfl}
%attr(755,root,root) /bin/*
%attr(755,root,root) /sbin/*
%attr(755,root,root) %{_bindir}/*
%attr(755,root,root) %{_sbindir}/*
+%else
+%attr(755,root,root) %{_bindir}/busybox
%endif
%{_libdir}/busybox
-%{_mandir}/man1/*
+%{_mandir}/man1/busybox.1*
+%endif
-%if %{?_without_static:0}%{!?_without_static:1}
+%if %{with static}
%files static
%defattr(644,root,root,755)
%attr(755,root,root) %{_bindir}/busybox.static
%endif
+
+%if %{with initrd}
+%files initrd
+%defattr(644,root,root,755)
+%attr(755,root,root) %{_libdir}/initrd/busybox
+%endif