Remove *.la files after gcc build.
[fedora-riscv.git] / Makefile
index e953bcb..7fe10ab 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -37,7 +37,8 @@ LOCAL_LINUX_GIT_COPY = $(HOME)/d/linux
 # The root packages (plus their dependencies) that we want to
 # cross-compile into the stage 3 chroot.
 # beecrypt-devel is required to build RPM.
-STAGE3_PACKAGES = gcc rpm-build beecrypt-devel
+# 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
@@ -52,14 +53,28 @@ UTIL_LINUX_VERSION = 2.28
 TAR_VERSION        = 1.29
 GZIP_VERSION       = 1.8
 ZLIB_VERSION       = 1.2.8
-# Needs to match the installed (on host) version, otherwise:
-# "Cannot use the installed version of file (xx) to cross-compile file yy"
-FILE_VERSION       = 5.25
+# Needs to match the version of 'file' installed (on host), otherwise:
+#   "Cannot use the installed version of file (xx) to cross-compile file yy"
+# Also note that 5.25 is definitely broken (segfaults in libmagic:magic_close).
+FILE_VERSION       = 5.28
 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
+MAKE_VERSION       = 4.1
+DIFFUTILS_VERSION  = 3.4
+FINDUTILS_VERSION  = 4.6.0
+SED_VERSION        = 4.2
+PATCH_VERSION      = 2.7.5
+HOSTNAME_VERSION   = 3.15
+GETTEXT_VERSION    = 0.19
 
 all: stage1 stage2 stage3 stage4
 
@@ -274,6 +289,18 @@ stage3: stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux \
        stage3-chroot/usr/bin/file \
        stage3-chroot/usr/lib64/libpopt.so \
        stage3-chroot/usr/lib64/libbeecrypt.so \
+       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/usr/bin/make \
+       stage3-chroot/usr/bin/diff \
+       stage3-chroot/usr/bin/find \
+       stage3-chroot/usr/bin/sed \
+       stage3-chroot/usr/bin/patch \
+       stage3-chroot/usr/bin/hostname \
+       stage3-chroot/usr/bin/gettext \
        stage3-chroot/usr/bin/rpm \
        stage3-chroot/init \
        stage3-disk.img
@@ -465,6 +492,8 @@ mpc-$(MPC_VERSION).tar.gz:
 stage3-chroot/usr/bin/gcc: gcc-$(GCC_X_VERSION).tar.gz
        rm -rf riscv-gcc-riscv-gcc-$(GCC_X_VERSION)
        zcat $^ | tar xf -
+       cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION) && \
+       patch -p1 < ../0001-HACKS-TO-GET-GCC-TO-COMPILE.patch
        mkdir riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build
        cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && \
        PATH=$(ROOT)/fixed-gcc:$$PATH \
@@ -479,10 +508,9 @@ stage3-chroot/usr/bin/gcc: gcc-$(GCC_X_VERSION).tar.gz
            --disable-libquadmath \
            --disable-nls \
            --disable-multilib
-# XXX use make all & make install here.  However building libgcc
-# fails, see 'broken-gcc.log'.
-       cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && PATH=$(ROOT)/fixed-gcc:$$PATH make all-gcc
-       cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && make install-gcc DESTDIR=$(ROOT)/stage3-chroot
+       cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && PATH=$(ROOT)/fixed-gcc:$$PATH make
+       cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && make install DESTDIR=$(ROOT)/stage3-chroot
+       rm -f stage3-chroot/usr/lib64/*.la
 
 gcc-$(GCC_X_VERSION).tar.gz:
        rm -f $@ $@-t
@@ -631,6 +659,219 @@ beecrypt-$(BEECRYPT_VERSION).tar.gz:
        wget -O $@-t http://downloads.sourceforge.net/sourceforge/beecrypt/beecrypt-$(BEECRYPT_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 \
+       CFLAGS="-Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -fPIC"
+       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 $@
+
+# Cross-compile GNU make.
+stage3-chroot/usr/bin/make: make-$(MAKE_VERSION).tar.gz
+       rm -rf make-$(MAKE_VERSION)
+       tar -zxf $^
+       cd make-$(MAKE_VERSION) && \
+       PATH=$(ROOT)/fixed-gcc:$$PATH \
+       ./configure \
+           --host=riscv64-unknown-linux-gnu \
+           --prefix=/usr --libdir=/usr/lib64
+       cd make-$(MAKE_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
+       cd make-$(MAKE_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
+
+make-$(MAKE_VERSION).tar.gz:
+       rm -f $@ $@-t
+       wget -O $@-t https://ftp.gnu.org/gnu/make/make-$(MAKE_VERSION).tar.gz
+       mv $@-t $@
+
+# 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 RPM / rpmbuild.
 # We build this from a git commit, with a few hacks to the configure
 # script.
@@ -639,8 +880,10 @@ stage3-chroot/usr/bin/rpm: rpm-$(RPM_SHORT_COMMIT).tar.gz db-$(BDB_VERSION).tar.
        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-HACKS-TO-GET-RPM-TO-CROSS-COMPILE.patch
-       cd rpm-$(RPM_SHORT_COMMIT) && patch -p1 < ../0002-RISCV-64-bit-riscv64-support.patch
+       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 \
@@ -656,8 +899,6 @@ stage3-chroot/usr/bin/rpm: rpm-$(RPM_SHORT_COMMIT).tar.gz db-$(BDB_VERSION).tar.
            --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