Add bzip2 to the stage3 chroot.
[fedora-riscv.git] / Makefile
index 3a9a1fb..d69846e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -36,7 +36,9 @@ LOCAL_LINUX_GIT_COPY = $(HOME)/d/linux
 
 # 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.
+# Packages for usability: nano, grep, less
+STAGE3_PACKAGES = gcc rpm-build beecrypt-devel nano grep less
 
 # Versions of cross-compiled packages.
 NCURSES_VERSION    = 6.0-20160730
@@ -55,6 +57,16 @@ ZLIB_VERSION       = 1.2.8
 # "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
+NANO_VERSION       = 2.6.2
+GREP_VERSION       = 2.25
+LESS_VERSION       = 481
+STRACE_COMMIT      = f320e1897832fd07a62e18ed288e75d8e79f4c5b
+STRACE_SHORT_COMMIT = f320e189
+BZIP2_VERSION      = 1.0.6
 
 all: stage1 stage2 stage3 stage4
 
@@ -268,6 +280,13 @@ stage3: stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux \
        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/usr/bin/nano \
+       stage3-chroot/usr/bin/grep \
+       stage3-chroot/usr/bin/less \
+       stage3-chroot/usr/bin/strace \
+       stage3-chroot/usr/bin/bzip2 \
        stage3-chroot/init \
        stage3-disk.img
 
@@ -333,10 +352,11 @@ stage3-chroot/usr/bin/tic: ncurses-$(NCURSES_VERSION).tgz
        PATH=$(ROOT)/fixed-gcc:$$PATH \
        ./configure --host=riscv64-unknown-linux-gnu \
            --prefix=/usr --libdir=/usr/lib64 \
-           --with-shared
+           --with-shared \
+           --with-termlib=tinfo \
+           --enable-widec
        cd ncurses-$(NCURSES_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
        cd ncurses-$(NCURSES_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
-       cd $(ROOT)/stage3-chroot/usr/lib64 && ln -sf libtinfo.so.6 libtinfo.so
 
 ncurses-$(NCURSES_VERSION).tgz:
        rm -f $@ $@-t
@@ -482,23 +502,22 @@ gcc-$(GCC_X_VERSION).tar.gz:
        mv $@-t $@
 
 # Cross-compile util-linux.
-# XXX Be nice to fix ncurses/tinfo support which in theory should work.
 stage3-chroot/usr/bin/mount: util-linux-$(UTIL_LINUX_VERSION).tar.xz
        rm -rf util-linux-$(UTIL_LINUX_VERSION)
        tar -Jxf $^
        cd util-linux-$(UTIL_LINUX_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-python \
-           --without-tinfo \
-           --without-ncurses \
            --without-systemd \
-           --disable-makeinstall-chown
+           --disable-makeinstall-chown \
+           --enable-static-programs=mount
        cd util-linux-$(UTIL_LINUX_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
-#      libtool fucks something up here, ignore the failure and continue.
-       -cd util-linux-$(UTIL_LINUX_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot -j1 -k V=1
+       cd util-linux-$(UTIL_LINUX_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
+       rm -f stage3-chroot/usr/lib64/*.la
 
 util-linux-$(UTIL_LINUX_VERSION).tar.xz:
        rm -f $@ $@-t
@@ -597,6 +616,166 @@ popt-$(POPT_VERSION).tar.gz:
        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 < ../0001-RISCV-64-bit-riscv64-support.patch && \
+       patch -p1 < ../0002-build-fgetc-returns-int-not-char.patch && \
+       patch -p1 < ../0003-HACKS-TO-GET-RPM-TO-CROSS-COMPILE.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) && 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 $@
+
+# Cross-compile GNU nano (editor).
+stage3-chroot/usr/bin/nano: nano-$(NANO_VERSION).tar.gz
+       rm -rf nano-$(NANO_VERSION)
+       tar -zxf $^
+       cd nano-$(NANO_VERSION) && \
+       PATH=$(ROOT)/fixed-gcc:$$PATH \
+       LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
+       ./configure \
+           --host=riscv64-unknown-linux-gnu \
+           --prefix=/usr --libdir=/usr/lib64
+       cd nano-$(NANO_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
+       cd nano-$(NANO_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
+
+nano-$(NANO_VERSION).tar.gz:
+       rm -f $@ $@-t
+       wget -O $@-t https://www.nano-editor.org/dist/v2.6/nano-$(NANO_VERSION).tar.gz
+       mv $@-t $@
+
+# Cross-compile GNU grep.
+stage3-chroot/usr/bin/grep: grep-$(GREP_VERSION).tar.xz
+       rm -rf grep-$(GREP_VERSION)
+       tar -Jxf $^
+       cd grep-$(GREP_VERSION) && \
+       PATH=$(ROOT)/fixed-gcc:$$PATH \
+       ./configure \
+           --host=riscv64-unknown-linux-gnu \
+           --prefix=/usr --libdir=/usr/lib64
+       cd grep-$(GREP_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
+       cd grep-$(GREP_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
+
+grep-$(GREP_VERSION).tar.xz:
+       rm -f $@ $@-t
+       wget -O $@-t https://ftp.gnu.org/gnu/grep/grep-$(GREP_VERSION).tar.xz
+       mv $@-t $@
+
+# Cross-compile less.
+stage3-chroot/usr/bin/less: less-$(LESS_VERSION).tar.gz
+       rm -rf less-$(LESS_VERSION)
+       tar -zxf $^
+       cd less-$(LESS_VERSION) && \
+       PATH=$(ROOT)/fixed-gcc:$$PATH \
+       LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
+       ./configure \
+           --host=riscv64-unknown-linux-gnu \
+           --prefix=/usr --libdir=/usr/lib64
+       cd less-$(LESS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
+       cd less-$(LESS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
+
+less-$(LESS_VERSION).tar.gz:
+       rm -f $@ $@-t
+       wget -O $@-t http://www.greenwoodsoftware.com/less/less-$(LESS_VERSION).tar.gz
+       mv $@-t $@
+
+# Cross-compile strace.
+# XXX This does not work.
+stage3-chroot/usr/bin/strace: strace-$(STRACE_SHORT_COMMIT).tar.gz
+       rm -rf strace-$(STRACE_SHORT_COMMIT)
+       tar -zxf $^
+       cd riscv-strace-$(STRACE_COMMIT) && patch -p1 < ../0001-Update-riscv_regs-for-ptrace.h-from-Linux-4.1.x.patch
+       cd riscv-strace-$(STRACE_COMMIT) && \
+       PATH=$(ROOT)/fixed-gcc:$$PATH \
+       LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
+       ./configure \
+           --host=riscv64-unknown-linux-gnu \
+           --prefix=/usr --libdir=/usr/lib64
+       cd riscv-strace-$(STRACE_COMMIT) && PATH=$(ROOT)/fixed-gcc:$$PATH make
+       cd riscv-strace-$(STRACE_COMMIT) && make install DESTDIR=$(ROOT)/stage3-chroot
+
+strace-$(STRACE_SHORT_COMMIT).tar.gz:
+       rm -f $@ $@-t
+       wget -O $@-t 'https://github.com/riscv/riscv-strace/archive/$(STRACE_COMMIT)/riscv-strace-$(STRACE_SHORTCOMMIT).tar.gz'
+       mv $@-t $@
+
+# Cross-compile bzip2.
+stage3-chroot/usr/bin/bzip2: bzip2-$(BZIP2_VERSION).tar.gz
+       rm -rf bzip2-$(BZIP2_VERSION)
+       tar -zxf $^
+       cd bzip2-$(BZIP2_VERSION) && \
+       PATH=$(ROOT)/fixed-gcc:$$PATH \
+       make libbz2.a bzip2 bzip2recover \
+       PREFIX=/usr \
+       CC=riscv64-unknown-linux-gnu-gcc \
+       AR=riscv64-unknown-linux-gnu-ar \
+       RANLIB=riscv64-unknown-linux-gnu-ranlib
+       cd bzip2-$(BZIP2_VERSION) && \
+       make install PREFIX=$(ROOT)/stage3-chroot/usr
+
+bzip2-$(BZIP2_VERSION).tar.gz:
+       rm -f $@ $@-t
+       wget -O $@-t http://www.bzip.org/1.0.6/bzip2-$(BZIP2_VERSION).tar.gz
+       mv $@-t $@
+
 # Create an /init script.
 stage3-chroot/init: init.sh
        install -m 0755 $^ $@