# The root packages (plus their dependencies) that we want to
# cross-compile into the stage 3 chroot.
-STAGE3_PACKAGES = gcc rpm-build
+# beecrypt-devel is required to build RPM.
+STAGE3_PACKAGES = gcc rpm-build beecrypt-devel
# Versions of cross-compiled packages.
NCURSES_VERSION = 6.0-20160730
# "Cannot use the installed version of file (xx) to cross-compile file yy"
FILE_VERSION = 5.25
POPT_VERSION = 1.16
+BEECRYPT_VERSION = 4.2.1
+RPM_COMMIT = 95712183458748ea6cafebac1bdd5daa097d9bee
+RPM_SHORT_COMMIT = 9571218
+BDB_VERSION = 4.5.20
all: stage1 stage2 stage3 stage4
stage3-chroot/usr/lib64/libz.so \
stage3-chroot/usr/bin/file \
stage3-chroot/usr/lib64/libpopt.so \
+ stage3-chroot/usr/lib64/libbeecrypt.so \
+ stage3-chroot/usr/bin/rpm \
stage3-chroot/init \
stage3-disk.img
wget -O $@-t http://rpm5.org/files/popt/popt-$(POPT_VERSION).tar.gz
mv $@-t $@
+# Cross-compile beecrypt.
+stage3-chroot/usr/lib64/libbeecrypt.so: beecrypt-$(BEECRYPT_VERSION).tar.gz
+ rm -rf beecrypt-$(BEECRYPT_VERSION)
+ tar -zxf $^
+ cd beecrypt-$(BEECRYPT_VERSION) && patch -p0 < ../beecrypt-disable-cplusplus.patch
+ cd beecrypt-$(BEECRYPT_VERSION) && autoreconf -i
+ cd beecrypt-$(BEECRYPT_VERSION) && \
+ PATH=$(ROOT)/fixed-gcc:$$PATH \
+ LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
+ ./configure \
+ --host=riscv64-unknown-linux-gnu \
+ --prefix=/usr --libdir=/usr/lib64 \
+ --without-cplusplus \
+ --without-java \
+ --disable-openmp \
+ --disable-static \
+ --enable-shared
+ cd beecrypt-$(BEECRYPT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
+ cd beecrypt-$(BEECRYPT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot V=1
+ chrpath -d stage3-chroot/usr/lib64/libbeecrypt.so.*
+ rm -f stage3-chroot/usr/lib64/*.la
+
+beecrypt-$(BEECRYPT_VERSION).tar.gz:
+ rm -f $@ $@-t
+ wget -O $@-t http://downloads.sourceforge.net/sourceforge/beecrypt/beecrypt-$(BEECRYPT_VERSION).tar.gz
+ mv $@-t $@
+
+# Cross-compile RPM / rpmbuild.
+# We build this from a git commit, with a few hacks to the configure
+# script.
+stage3-chroot/usr/bin/rpm: rpm-$(RPM_SHORT_COMMIT).tar.gz db-$(BDB_VERSION).tar.gz
+ rm -rf rpm-$(RPM_SHORT_COMMIT)
+ tar -zxf rpm-$(RPM_SHORT_COMMIT).tar.gz
+ tar -zxf db-$(BDB_VERSION).tar.gz -C rpm-$(RPM_SHORT_COMMIT)
+ cd rpm-$(RPM_SHORT_COMMIT) && ln -s db-$(BDB_VERSION) db
+ cd rpm-$(RPM_SHORT_COMMIT) && patch -p1 < ../rpm-hacks.patch
+ cd rpm-$(RPM_SHORT_COMMIT) && autoreconf -i
+ cd rpm-$(RPM_SHORT_COMMIT) && \
+ PATH=$(ROOT)/fixed-gcc:$$PATH \
+ LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
+ ./configure \
+ --host=riscv64-unknown-linux-gnu \
+ --prefix=/usr --libdir=/usr/lib64 \
+ --disable-rpath \
+ --without-libarchive \
+ --without-lua \
+ --with-beecrypt \
+ --without-archive \
+ --without-external-db \
+ --enable-ndb \
+ --disable-plugins
+ cd rpm-$(RPM_SHORT_COMMIT) && \
+ sed -i 's|^sys_lib_dlsearch_path_spec="/lib64|sys_lib_dlsearch_path_spec="$(ROOT)/stage3-chroot/usr/lib64 /lib64|g' libtool
+ cd rpm-$(RPM_SHORT_COMMIT) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
+ cd rpm-$(RPM_SHORT_COMMIT) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
+ rm -f stage3-chroot/usr/lib64/*.la
+
+rpm-$(RPM_SHORT_COMMIT).tar.gz:
+ rm -f $@ $@-t
+ wget -O $@-t 'http://rpm.org/gitweb?p=rpm.git;a=snapshot;h=$(RPM_COMMIT);sf=tgz'
+ mv $@-t $@
+
+db-$(BDB_VERSION).tar.gz:
+ rm -f $@ $@-t
+ wget -O $@-t http://download.oracle.com/berkeley-db/db-$(BDB_VERSION).tar.gz
+ mv $@-t $@
+
# Create an /init script.
stage3-chroot/init: init.sh
install -m 0755 $^ $@
--- /dev/null
+The act of linking to any C++ file causes libbeecrypt to be linked to
+libstdc++ etc. We don't need any of that so kill it.
+
+--- Makefile.am~ 2009-07-08 19:56:18.000000000 +0100
++++ Makefile.am 2016-08-09 15:31:40.039891644 +0100
+@@ -62,7 +62,7 @@
+
+ lib_LTLIBRARIES = libbeecrypt.la
+
+-libbeecrypt_la_SOURCES = aes.c base64.c beecrypt.c blockmode.c blockpad.c blowfish.c dhies.c dldp.c dlkp.c dlpk.c dlsvdp-dh.c dsa.c elgamal.c endianness.c entropy.c fips186.c hmac.c hmacmd5.c hmacsha1.c hmacsha224.c hmacsha256.c md4.c md5.c hmacsha384.c hmacsha512.c memchunk.c mp.c mpbarrett.c mpnumber.c mpprime.c mtprng.c pkcs1.c pkcs12.c ripemd128.c ripemd160.c ripemd256.c ripemd320.c rsa.c rsakp.c rsapk.c sha1.c sha224.c sha256.c sha384.c sha512.c sha2k32.c sha2k64.c timestamp.c cppglue.cxx
++libbeecrypt_la_SOURCES = aes.c base64.c beecrypt.c blockmode.c blockpad.c blowfish.c dhies.c dldp.c dlkp.c dlpk.c dlsvdp-dh.c dsa.c elgamal.c endianness.c entropy.c fips186.c hmac.c hmacmd5.c hmacsha1.c hmacsha224.c hmacsha256.c md4.c md5.c hmacsha384.c hmacsha512.c memchunk.c mp.c mpbarrett.c mpnumber.c mpprime.c mtprng.c pkcs1.c pkcs12.c ripemd128.c ripemd160.c ripemd256.c ripemd320.c rsa.c rsakp.c rsapk.c sha1.c sha224.c sha256.c sha384.c sha512.c sha2k32.c sha2k64.c timestamp.c
+ libbeecrypt_la_DEPENDENCIES = $(BEECRYPT_OBJECTS)
+ libbeecrypt_la_LIBADD = blowfishopt.lo mpopt.lo sha1opt.lo $(OPENMP_LIBS)
+ libbeecrypt_la_LDFLAGS = -no-undefined -version-info $(LIBBEECRYPT_LT_CURRENT):$(LIBBEECRYPT_LT_REVISION):$(LIBBEECRYPT_LT_AGE)
--- /dev/null
+diff --git a/configure.ac b/configure.ac
+index e2d5ec3..3f94742 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -309,6 +309,8 @@ AC_SUBST(WITH_NSS_LIB)
+ WITH_MAGIC_INCLUDE=
+ WITH_MAGIC_LIB=
+
++old_LIBS="$LIBS"
++LIBS="-lz"
+ AC_CHECK_HEADER([magic.h], [
+ AC_CHECK_LIB(magic, magic_open, [
+ WITH_MAGIC_INCLUDE=
+@@ -319,6 +321,7 @@ AC_CHECK_HEADER([magic.h], [
+ ],[
+ AC_MSG_ERROR([missing required header magic.h])
+ ])
++LIBS="$old_LIBS"
+
+ AC_SUBST(WITH_MAGIC_INCLUDE)
+ AC_SUBST(WITH_MAGIC_LIB)
+@@ -369,18 +372,19 @@ AM_CONDITIONAL(WITH_ARCHIVE,[test "$with_archive" = yes])
+
+ #=================
+ # Check for elfutils libdw library with dwelf_elf_gnu_build_id.
+-AS_IF([test "$WITH_LIBELF" = yes],[
+- AC_CHECK_HEADERS([elfutils/libdwelf.h],[
+- AC_CHECK_LIB(dw, dwelf_elf_gnu_build_id, [
+- AC_DEFINE(HAVE_LIBDW, 1,
+- [Define to 1 if you have elfutils libdw library])
+- WITH_LIBDW_LIB="-ldw"
+- WITH_LIBDW=yes
+- ])
+- ])
+- AC_SUBST(WITH_LIBDW_LIB)
+- AM_CONDITIONAL(LIBDW,[test "$WITH_LIBDW" = yes])
+-])
++dnl AS_IF([test "$WITH_LIBELF" = yes],[
++dnl AC_CHECK_HEADERS([elfutils/libdwelf.h],[
++dnl AC_CHECK_LIB(dw, dwelf_elf_gnu_build_id, [
++dnl AC_DEFINE(HAVE_LIBDW, 1,
++dnl [Define to 1 if you have elfutils libdw library])
++dnl WITH_LIBDW_LIB="-ldw"
++dnl WITH_LIBDW=yes
++dnl ])
++dnl ])
++dnl AC_SUBST(WITH_LIBDW_LIB)
++dnl AM_CONDITIONAL(LIBDW,[test "$WITH_LIBDW" = yes])
++dnl ])
++AM_CONDITIONAL(LIBDW,[false])
+
+ #=================
+ # Process --with/without-external-db