+# Cross-compile GMP, MPFR and MPC (deps of GCC).
+stage3-chroot/usr/lib64/libgmp.so.10: gmp-$(GMP_VERSION).tar.lz
+ rm -rf gmp-$(GMP_VERSION)
+ tar --lzip -xf gmp-$(GMP_VERSION).tar.lz
+ cd gmp-$(GMP_VERSION) && \
+ PATH=$(ROOT)/fixed-gcc:$$PATH \
+ ./configure --host=riscv64-unknown-linux-gnu \
+ --prefix=/usr --libdir=/usr/lib64
+ cd gmp-$(GMP_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
+ cd gmp-$(GMP_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
+ cd stage3-chroot/usr/lib && ln -s ../lib64/libgmp.so
+
+gmp-$(GMP_VERSION).tar.lz:
+ rm -f $@ $@-t
+ wget -O $@-t https://gmplib.org/download/gmp/gmp-$(GMP_VERSION).tar.lz
+ mv $@-t $@
+
+stage3-chroot/usr/lib64/libmpfr.so.4: mpfr-$(MPFR_VERSION).tar.gz
+ rm -rf mpfr-$(MPFR_VERSION)
+ tar -zxf mpfr-$(MPFR_VERSION).tar.gz
+ cd mpfr-$(MPFR_VERSION) && \
+ PATH=$(ROOT)/fixed-gcc:$$PATH \
+ ./configure --host=riscv64-unknown-linux-gnu \
+ --prefix=/usr --libdir=/usr/lib64 \
+ --with-gmp=$(ROOT)/stage3-chroot/usr
+ cd mpfr-$(MPFR_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
+ cd mpfr-$(MPFR_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
+ cd stage3-chroot/usr/lib && ln -s ../lib64/libmpfr.so
+
+mpfr-$(MPFR_VERSION).tar.gz:
+ rm -f $@ $@-t
+ wget -O $@-t http://www.mpfr.org/mpfr-current/mpfr-$(MPFR_VERSION).tar.gz
+ mv $@-t $@
+
+stage3-chroot/usr/lib64/libmpc.so.3: mpc-$(MPC_VERSION).tar.gz
+ rm -rf mpc-$(MPC_VERSION)
+ tar -zxf mpc-$(MPC_VERSION).tar.gz
+ cd mpc-$(MPC_VERSION) && \
+ PATH=$(ROOT)/fixed-gcc:$$PATH \
+ ./configure --host=riscv64-unknown-linux-gnu \
+ --prefix=/usr --libdir=/usr/lib64 \
+ --with-gmp=$(ROOT)/stage3-chroot/usr \
+ --with-mpfr=$(ROOT)/stage3-chroot/usr
+ cd mpc-$(MPC_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
+ cd mpc-$(MPC_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
+ cd stage3-chroot/usr/lib && ln -s ../lib64/libmpc.so
+
+mpc-$(MPC_VERSION).tar.gz:
+ rm -f $@ $@-t
+ wget -O $@-t ftp://ftp.gnu.org/gnu/mpc/mpc-$(MPC_VERSION).tar.gz
+ mv $@-t $@
+
+# Cross-compile GCC.
+stage3-chroot/usr/bin/gcc: gcc-$(GCC_X_VERSION).tar.gz
+ rm -rf riscv-gcc-riscv-gcc-$(GCC_X_VERSION)
+ zcat $^ | tar xf -
+ mkdir riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build
+ cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && \
+ PATH=$(ROOT)/fixed-gcc:$$PATH \
+ ../configure \
+ --host=riscv64-unknown-linux-gnu \
+ --prefix=/usr --libdir=/usr/lib64 \
+ --enable-shared \
+ --enable-tls \
+ --enable-languages=c,c++ \
+ --disable-libmudflap \
+ --disable-libssp \
+ --disable-libquadmath \
+ --disable-nls \
+ --disable-multilib
+ 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
+
+gcc-$(GCC_X_VERSION).tar.gz:
+ rm -f $@ $@-t
+ wget -O $@-t https://github.com/riscv/riscv-gcc/archive/riscv-gcc-$(GCC_X_VERSION).tar.gz
+ mv $@-t $@
+