+# Cross-compile GNU diffutils.
+stage3-chroot/usr/bin/diff: diffutils-$(DIFFUTILS_VERSION).tar.xz
+ rm -rf diffutils-$(DIFFUTILS_VERSION)
+ tar -Jxf $^
+ cd diffutils-$(DIFFUTILS_VERSION) && \
+ PATH=$(ROOT)/fixed-gcc:$$PATH \
+ ./configure \
+ --host=riscv64-unknown-linux-gnu \
+ --prefix=/usr --libdir=/usr/lib64
+ cd diffutils-$(DIFFUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
+ cd diffutils-$(DIFFUTILS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
+
+diffutils-$(DIFFUTILS_VERSION).tar.xz:
+ rm -f $@ $@-t
+ wget -O $@-t https://ftp.gnu.org/gnu/diffutils/diffutils-$(DIFFUTILS_VERSION).tar.xz
+ mv $@-t $@
+
+# Cross-compile GNU findutils.
+stage3-chroot/usr/bin/find: findutils-$(FINDUTILS_VERSION).tar.gz
+ rm -rf findutils-$(FINDUTILS_VERSION)
+ tar -zxf $^
+ cd findutils-$(FINDUTILS_VERSION) && \
+ PATH=$(ROOT)/fixed-gcc:$$PATH \
+ ./configure \
+ --host=riscv64-unknown-linux-gnu \
+ --prefix=/usr --libdir=/usr/lib64
+ cd findutils-$(FINDUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
+ cd findutils-$(FINDUTILS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
+
+findutils-$(FINDUTILS_VERSION).tar.gz:
+ rm -f $@ $@-t
+ wget -O $@-t https://ftp.gnu.org/gnu/findutils/findutils-$(FINDUTILS_VERSION).tar.gz
+ mv $@-t $@
+
+# Cross-compile GNU sed.
+stage3-chroot/usr/bin/sed: sed-$(SED_VERSION).tar.gz
+ rm -rf sed-$(SED_VERSION)
+ tar -zxf $^
+ cd sed-$(SED_VERSION) && \
+ PATH=$(ROOT)/fixed-gcc:$$PATH \
+ ./configure \
+ --host=riscv64-unknown-linux-gnu \
+ --prefix=/usr --libdir=/usr/lib64
+ cd sed-$(SED_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
+ cd sed-$(SED_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
+
+sed-$(SED_VERSION).tar.gz:
+ rm -f $@ $@-t
+ wget -O $@-t https://ftp.gnu.org/gnu/sed/sed-$(SED_VERSION).tar.gz
+ mv $@-t $@
+
+# Cross-compile patch.
+stage3-chroot/usr/bin/patch: patch-$(PATCH_VERSION).tar.gz
+ rm -rf patch-$(PATCH_VERSION)
+ tar -zxf $^
+ cd patch-$(PATCH_VERSION) && \
+ PATH=$(ROOT)/fixed-gcc:$$PATH \
+ ./configure \
+ --host=riscv64-unknown-linux-gnu \
+ --prefix=/usr --libdir=/usr/lib64
+ cd patch-$(PATCH_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
+ cd patch-$(PATCH_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
+
+patch-$(PATCH_VERSION).tar.gz:
+ rm -f $@ $@-t
+ wget -O $@-t https://ftp.gnu.org/gnu/patch/patch-$(PATCH_VERSION).tar.gz
+ mv $@-t $@
+
+# Cross-compile hostname.
+stage3-chroot/usr/bin/hostname: hostname-$(HOSTNAME_VERSION).tar.gz
+ rm -rf hostname-$(HOSTNAME_VERSION)
+ tar -zxf $^
+ cd hostname && patch -p1 < ../hostname-rh.patch
+ cd hostname && \
+ PATH=$(ROOT)/fixed-gcc:$$PATH \
+ make \
+ CC=riscv64-unknown-linux-gnu-gcc \
+ CFLAGS="-O2 -g"
+ cd hostname && make install BASEDIR=$(ROOT)/stage3-chroot
+
+hostname-$(HOSTNAME_VERSION).tar.gz:
+ rm -f $@ $@-t
+ wget -O $@-t http://ftp.de.debian.org/debian/pool/main/h/hostname/hostname_$(HOSTNAME_VERSION).tar.gz
+ mv $@-t $@
+
+# Cross-compile GNU gettext.
+stage3-chroot/usr/bin/gettext: gettext-$(GETTEXT_VERSION).tar.gz
+ rm -rf gettext-$(GETTEXT_VERSION)
+ tar -zxf $^
+ cd gettext-$(GETTEXT_VERSION) && \
+ PATH=$(ROOT)/fixed-gcc:$$PATH \
+ ./configure \
+ --host=riscv64-unknown-linux-gnu \
+ --prefix=/usr --libdir=/usr/lib64
+ cd gettext-$(GETTEXT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
+ cd gettext-$(GETTEXT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
+ rm -f stage3-chroot/usr/lib64/*.la
+
+gettext-$(GETTEXT_VERSION).tar.gz:
+ rm -f $@ $@-t
+ wget -O $@-t https://ftp.gnu.org/gnu/gettext/gettext-$(GETTEXT_VERSION).tar.gz
+ mv $@-t $@
+
+# Cross-compile lua.
+stage3-chroot/usr/bin/lua: lua-$(LUA_VERSION).tar.gz
+ rm -rf lua-$(LUA_VERSION)
+ tar -zxf $^
+ cd lua-$(LUA_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make PLAT=linux INSTALL_TOP=/usr CC=riscv64-unknown-linux-gnu-gcc AR="riscv64-unknown-linux-gnu-ar rcu" RANLIB="riscv64-unknown-linux-gnu-ranlib" MYLDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 MYLIBS=-ltinfo MYCFLAGS="-fPIC -DLUA_COMPAT_5_1"
+ cd lua-$(LUA_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install INSTALL_TOP=$(ROOT)/stage3-chroot/usr INSTALL_LIB=$(ROOT)/stage3-chroot/usr/lib64
+
+lua-$(LUA_VERSION).tar.gz:
+ rm -f $@ $@-t
+ wget -O $@-t https://www.lua.org/ftp/lua-$(LUA_VERSION).tar.gz
+ mv $@-t $@
+