1 # Refer to the README file to understand how Fedora on RISC-V is
4 # Absolute path to the current directory.
7 # Note these are chosen very specifically to ensure the different
8 # versions work together. Don't blindly update to the latest
10 # https://github.com/riscv/riscv-pk/issues/18#issuecomment-206115996
11 RISCV_QEMU_COMMIT = 94f5eb73091fb4fe272db3e943f173ecc0f78ffd
12 RISCV_QEMU_SHORTCOMMIT = 94f5eb73
13 RISCV_FESVR_COMMIT = 0f34d7ad311f78455a674224225f5b3056efba1d
14 RISCV_FESVR_SHORTCOMMIT = 0f34d7ad
15 RISCV_ISA_SIM_COMMIT = 3bfc00ef2a1b1f0b0472a39a866261b00f67027e
16 RISCV_ISA_SIM_SHORTCOMMIT = 3bfc00ef
17 RISCV_GNU_TOOLCHAIN_COMMIT = 728afcddcb0526a0f6560c4032da82805f054d58
18 RISCV_GNU_TOOLCHAIN_SHORTCOMMIT = 728afcdd
19 RISCV_PK_COMMIT = 85ae17aa149b9ea114bdd70cc30ea7e73813fb48
20 RISCV_PK_SHORTCOMMIT = 85ae17aa
22 # For the correct versions, see
23 # riscv-gnu-toolchain/Makefile.in *_version variables
24 BINUTILS_VERSION = 2.25.1
27 NEWLIB_VERSION = 2.2.0
29 # See linux-4.1.y-riscv branch of
30 # https://github.com/riscv/riscv-linux
31 KERNEL_VERSION = 4.1.26
33 # A local copy of Linux git repo so you don't have to keep downloading
34 # git commits (optional).
35 LOCAL_LINUX_GIT_COPY = $(HOME)/d/linux
37 # The root packages (plus their dependencies) that we want to
38 # cross-compile into the stage 3 chroot.
39 # beecrypt-devel is required to build RPM.
40 # Packages for usability: nano, grep, less
41 STAGE3_PACKAGES = gcc rpm-build beecrypt-devel nano grep less
43 # Versions of cross-compiled packages.
44 NCURSES_VERSION = 6.0-20160730
46 COREUTILS_VERSION = 8.25
50 BINUTILS_X_VERSION = 2.26
52 UTIL_LINUX_VERSION = 2.28
56 # Needs to match the version of 'file' installed (on host), otherwise:
57 # "Cannot use the installed version of file (xx) to cross-compile file yy"
58 # Also note that 5.25 is definitely broken (segfaults in libmagic:magic_close).
61 BEECRYPT_VERSION = 4.2.1
62 RPM_COMMIT = 95712183458748ea6cafebac1bdd5daa097d9bee
63 RPM_SHORT_COMMIT = 9571218
68 STRACE_COMMIT = f320e1897832fd07a62e18ed288e75d8e79f4c5b
69 STRACE_SHORT_COMMIT = f320e189
72 DIFFUTILS_VERSION = 3.4
73 FINDUTILS_VERSION = 4.6.0
77 all: stage1 stage2 stage3 stage4
81 stage1: stage1-riscv-qemu/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz \
82 stage1-riscv-qemu/riscv-qemu.spec \
83 stamp-riscv-qemu-installed \
84 stage1-riscv-fesvr/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz \
85 stage1-riscv-fesvr/riscv-fesvr.spec \
86 stamp-riscv-fesvr-installed \
87 stage1-riscv-isa-sim/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz \
88 stage1-riscv-isa-sim/riscv-isa-sim.spec \
89 stamp-riscv-isa-sim-installed
91 stage1-riscv-qemu/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz:
93 wget -O $@-t 'https://github.com/riscv/riscv-qemu/archive/$(RISCV_QEMU_COMMIT)/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz'
96 stage1-riscv-qemu/riscv-qemu.spec: stage1-riscv-qemu/riscv-qemu.spec.in
97 sed -e 's/@COMMIT@/$(RISCV_QEMU_COMMIT)/g' \
98 -e 's/@SHORTCOMMIT@/$(RISCV_QEMU_SHORTCOMMIT)/g' \
102 stamp-riscv-qemu-installed:
104 @rpm -q riscv-qemu >/dev/null || { \
105 echo "ERROR: You must install riscv-qemu:"; \
107 echo " dnf copr enable rjones/riscv"; \
108 echo " dnf install riscv-qemu"; \
110 echo "OR: you can build it yourself from the stage1-riscv-qemu directory."; \
114 @qemu-system-riscv --version || { \
115 echo "ERROR: qemu-system-riscv is not working."; \
116 echo "Make sure you installed the riscv-qemu package."; \
121 stage1-riscv-fesvr/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz:
123 wget -O $@-t 'https://github.com/riscv/riscv-fesvr/archive/$(RISCV_FESVR_COMMIT)/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz'
126 stage1-riscv-fesvr/riscv-fesvr.spec: stage1-riscv-fesvr/riscv-fesvr.spec.in
127 sed -e 's/@COMMIT@/$(RISCV_FESVR_COMMIT)/g' \
128 -e 's/@SHORTCOMMIT@/$(RISCV_FESVR_SHORTCOMMIT)/g' \
132 stamp-riscv-fesvr-installed:
134 @rpm -q riscv-fesvr >/dev/null || { \
135 echo "ERROR: You must install riscv-fesvr:"; \
137 echo " dnf copr enable rjones/riscv"; \
138 echo " dnf install riscv-fesvr"; \
140 echo "OR: you can build it yourself from the stage1-riscv-fesvr directory."; \
146 stage1-riscv-isa-sim/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz:
148 wget -O $@-t 'https://github.com/riscv/riscv-isa-sim/archive/$(RISCV_ISA_SIM_COMMIT)/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz'
151 stage1-riscv-isa-sim/riscv-isa-sim.spec: stage1-riscv-isa-sim/riscv-isa-sim.spec.in
152 sed -e 's/@COMMIT@/$(RISCV_ISA_SIM_COMMIT)/g' \
153 -e 's/@SHORTCOMMIT@/$(RISCV_ISA_SIM_SHORTCOMMIT)/g' \
157 stamp-riscv-isa-sim-installed:
159 @rpm -q riscv-isa-sim >/dev/null || { \
160 echo "ERROR: You must install riscv-isa-sim:"; \
162 echo " dnf copr enable rjones/riscv"; \
163 echo " dnf install riscv-isa-sim"; \
165 echo "OR: you can build it yourself from the stage1-riscv-isa-sim directory."; \
173 stage2: stage2-riscv-gnu-toolchain/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz \
174 stage2-riscv-gnu-toolchain/binutils-$(BINUTILS_VERSION).tar.gz \
175 stage2-riscv-gnu-toolchain/gcc-$(GCC_VERSION).tar.gz \
176 stage2-riscv-gnu-toolchain/glibc-$(GLIBC_VERSION).tar.gz \
177 stage2-riscv-gnu-toolchain/newlib-$(NEWLIB_VERSION).tar.gz \
178 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec \
179 stamp-riscv-gnu-toolchain-installed \
180 stage2-riscv-pk/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz \
181 stage2-riscv-pk/riscv-pk.spec \
182 stamp-riscv-pk-installed
184 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz:
186 wget -O $@-t https://github.com/lowRISC/riscv-gnu-toolchain/archive/$(RISCV_GNU_TOOLCHAIN_COMMIT)/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz
189 stage2-riscv-gnu-toolchain/binutils-$(BINUTILS_VERSION).tar.gz:
191 wget -O $@-t http://mirrors.kernel.org/gnu/binutils/binutils-$(BINUTILS_VERSION).tar.gz
194 # GCC 5 no longer compiles with GCC 6 unless we patch it.
195 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69959
196 stage2-riscv-gnu-toolchain/gcc-$(GCC_VERSION).tar.gz:
198 wget -O $@-t http://mirrors.kernel.org/gnu/gcc/gcc-$(GCC_VERSION)/gcc-$(GCC_VERSION).tar.gz
200 cd gcc-$(GCC_VERSION) && patch -p0 < ../stage2-riscv-gnu-toolchain/gcc-5-fix-compilation-with-gcc-6.patch
201 tar zcf $@-t gcc-$(GCC_VERSION)
202 rm -r gcc-$(GCC_VERSION)
205 stage2-riscv-gnu-toolchain/glibc-$(GLIBC_VERSION).tar.gz:
207 wget -O $@-t http://mirrors.kernel.org/gnu/glibc/glibc-$(GLIBC_VERSION).tar.gz
210 stage2-riscv-gnu-toolchain/newlib-$(NEWLIB_VERSION).tar.gz:
212 wget -O $@-t ftp://sourceware.org/pub/newlib/newlib-$(NEWLIB_VERSION).tar.gz
215 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec: stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec.in
216 sed -e 's/@COMMIT@/$(RISCV_GNU_TOOLCHAIN_COMMIT)/g' \
217 -e 's/@SHORTCOMMIT@/$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT)/g' \
218 -e 's/@BINUTILS_VERSION@/$(BINUTILS_VERSION)/g' \
219 -e 's/@GCC_VERSION@/$(GCC_VERSION)/g' \
220 -e 's/@GLIBC_VERSION@/$(GLIBC_VERSION)/g' \
221 -e 's/@NEWLIB_VERSION@/$(NEWLIB_VERSION)/g' \
225 stamp-riscv-gnu-toolchain-installed:
227 @rpm -q riscv-gnu-toolchain >/dev/null || { \
228 echo "ERROR: You must install riscv-gnu-toolchain:"; \
230 echo " dnf copr enable rjones/riscv"; \
231 echo " dnf install riscv-gnu-toolchain"; \
233 echo "OR: you can build it yourself from the stage2-riscv-gnu-toolchain directory."; \
237 @riscv64-unknown-elf-gcc --version || { \
238 echo "ERROR: riscv64-unknown-elf-gcc (cross compiler) is not working."; \
239 echo "Make sure you installed the riscv-gnu-toolchain package."; \
244 stage2-riscv-pk/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz:
246 wget -O $@-t https://github.com/lowRISC/riscv-pk/archive/$(RISCV_PK_COMMIT)/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz
249 stage2-riscv-pk/riscv-pk.spec: stage2-riscv-pk/riscv-pk.spec.in
250 sed -e 's/@COMMIT@/$(RISCV_PK_COMMIT)/g' \
251 -e 's/@SHORTCOMMIT@/$(RISCV_PK_SHORTCOMMIT)/g' \
255 stamp-riscv-pk-installed:
257 @rpm -q riscv-pk >/dev/null || { \
258 echo "ERROR: You must install riscv-pk:"; \
260 echo " dnf copr enable rjones/riscv"; \
261 echo " dnf install riscv-pk"; \
263 echo "OR: you can build it yourself from the stage2-riscv-pk directory."; \
271 stage3: stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux \
272 stage3-chroot-original/etc/fedora-release \
273 stage3-chroot/etc/fedora-release \
274 stage3-chroot/lib64/libc.so.6 \
275 stage3-chroot/usr/bin/tic \
276 stage3-chroot/bin/bash \
277 stage3-chroot/bin/ls \
278 stage3-chroot/usr/lib64/libgmp.so.10 \
279 stage3-chroot/usr/lib64/libmpfr.so.4 \
280 stage3-chroot/usr/lib64/libmpc.so.3 \
281 stage3-chroot/usr/bin/as \
282 stage3-chroot/usr/bin/gcc \
283 stage3-chroot/usr/bin/mount \
284 stage3-chroot/usr/bin/tar \
285 stage3-chroot/usr/bin/gzip \
286 stage3-chroot/usr/lib64/libz.so \
287 stage3-chroot/usr/bin/file \
288 stage3-chroot/usr/lib64/libpopt.so \
289 stage3-chroot/usr/lib64/libbeecrypt.so \
290 stage3-chroot/usr/bin/nano \
291 stage3-chroot/usr/bin/grep \
292 stage3-chroot/usr/bin/less \
293 stage3-chroot/usr/bin/strace \
294 stage3-chroot/usr/bin/bzip2 \
295 stage3-chroot/usr/bin/make \
296 stage3-chroot/usr/bin/diff \
297 stage3-chroot/usr/bin/find \
298 stage3-chroot/usr/bin/sed \
299 stage3-chroot/usr/bin/patch \
300 stage3-chroot/usr/bin/rpm \
304 stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux:
305 rm -rf stage3-kernel/linux-$(KERNEL_VERSION)
306 cp -a $(LOCAL_LINUX_GIT_COPY) stage3-kernel/linux-$(KERNEL_VERSION) || { \
307 mkdir stage3-kernel/linux-$(KERNEL_VERSION) && \
308 cd stage3-kernel/linux-$(KERNEL_VERSION) && \
311 cd stage3-kernel/linux-$(KERNEL_VERSION) && \
312 git remote add riscv https://github.com/riscv/riscv-linux && \
314 git checkout -f linux-4.1.y-riscv && \
316 make ARCH=riscv defconfig
317 echo CONFIG_CMDLINE=\"root=/dev/htifblk0 init=/init\" >> stage3-kernel/linux-$(KERNEL_VERSION)/.config
318 echo CONFIG_CROSS_COMPILE=riscv64-unknown-elf- >> stage3-kernel/linux-$(KERNEL_VERSION)/.config
319 cd stage3-kernel/linux-$(KERNEL_VERSION) && \
320 make ARCH=riscv olddefconfig
321 cd stage3-kernel/linux-$(KERNEL_VERSION) && \
322 make ARCH=riscv vmlinux
325 # Build an original (x86-64) chroot using supermin. We then aim to
326 # rebuild (using cross-compiled versions) every ELF binary in this
328 stage3-chroot-original/etc/fedora-release:
329 rm -rf stage3-chroot-original tmp-supermin.d
330 supermin --prepare $(STAGE3_PACKAGES) -o tmp-supermin.d
331 supermin --build -f chroot tmp-supermin.d -o stage3-chroot-original
333 @echo -n "Total files in chroot: "
334 @find stage3-chroot-original -type f | wc -l
335 @echo -n "ELF files to be rebuilt: "
336 @find stage3-chroot-original -type f | xargs file -N | grep -E '\bELF.*LSB\b' | wc -l
338 # Copy the original chroot to the final chroot, remove all the ELF
340 stage3-chroot/etc/fedora-release: stage3-chroot-original/etc/fedora-release
342 cp -a stage3-chroot-original stage3-chroot
343 find stage3-chroot -type d | xargs chmod u+w
344 find stage3-chroot -type f | xargs chmod u+w
345 find stage3-chroot -type f | xargs file -N | grep -E '\bELF.*LSB\b' | awk -F: '{print $$1}' | xargs rm -f
346 rm -f stage3-chroot/lib64/libc.so.6
348 # Copy in compiled glibc from the riscv-gnu-toolchain sysroot. Only
349 # copy files and symlinks, leave the target directory structure
351 stage3-chroot/lib64/libc.so.6:
352 mkdir -p stage3-chroot/usr/lib/audit
353 mkdir -p stage3-chroot/usr/lib/gconv
354 for f in `cd /usr/sysroot && find -type f -o -type l`; do \
355 cp -d /usr/sysroot/$$f stage3-chroot/$$f; \
357 cd stage3-chroot/lib64 && for f in ../lib/*; do ln -sf $$f; done
359 # Cross-compile ncurses.
360 stage3-chroot/usr/bin/tic: ncurses-$(NCURSES_VERSION).tgz
362 cd ncurses-$(NCURSES_VERSION) && \
363 PATH=$(ROOT)/fixed-gcc:$$PATH \
364 ./configure --host=riscv64-unknown-linux-gnu \
365 --prefix=/usr --libdir=/usr/lib64 \
367 --with-termlib=tinfo \
369 cd ncurses-$(NCURSES_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
370 cd ncurses-$(NCURSES_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
372 ncurses-$(NCURSES_VERSION).tgz:
374 wget -O $@-t ftp://invisible-island.net/ncurses/current/ncurses-$(NCURSES_VERSION).tgz
377 # Cross-compile bash.
378 stage3-chroot/bin/bash: bash-$(BASH_VERSION).tar.gz
380 cd bash-$(BASH_VERSION) && \
381 PATH=$(ROOT)/fixed-gcc:$$PATH \
382 ./configure --host=riscv64-unknown-linux-gnu \
383 --prefix=/usr --libdir=/usr/lib64
384 cd bash-$(BASH_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
385 cd bash-$(BASH_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
387 bash-$(BASH_VERSION).tar.gz:
389 wget -O $@-t ftp://ftp.gnu.org/gnu/bash/bash-$(BASH_VERSION).tar.gz
392 # Cross-compile coreutils. Bleah, coreutils cross-compilation is
393 # known-broken and upstream don't care, hence the 'touch' command.
395 COREUTILS_PROGRAMS = arch base32 base64 basename cat chcon chgrp chmod chown chroot cksum comm cp csplit cut date dd df dir dircolors dirname du echo env expand expr factor false fmt fold ginstall groups head hostid hostname id install join kill link ln logname ls md5sum mkdir mkfifo mknod mktemp mv nice nl nohup nproc numfmt od paste pathchk pinky pr printenv printf ptx pwd readlink realpath rm rmdir runcon seq sha1sum sha224sum sha256sum sha384sum sha512sum shred shuf sleep sort split stat stdbuf stty sum sync tac tail tee test timeout touch tr true truncate tsort tty uname unexpand uniq unlink uptime users vdir wc who whoami yes
397 stage3-chroot/bin/ls: coreutils-$(COREUTILS_VERSION).tar.xz
398 rm -rf coreutils-$(COREUTILS_VERSION)
400 cd coreutils-$(COREUTILS_VERSION) && \
401 PATH=$(ROOT)/fixed-gcc:$$PATH \
402 ./configure --host=riscv64-unknown-linux-gnu \
403 --prefix=/usr --libdir=/usr/lib64
404 -cd coreutils-$(COREUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
405 cd coreutils-$(COREUTILS_VERSION)/man && \
406 for f in $(COREUTILS_PROGRAMS); do touch $$f.1; done
407 cd coreutils-$(COREUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
408 cd coreutils-$(COREUTILS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
410 coreutils-$(COREUTILS_VERSION).tar.xz:
412 wget -O $@-t ftp://ftp.gnu.org/gnu/coreutils/coreutils-$(COREUTILS_VERSION).tar.xz
415 # Cross-compile binutils.
416 stage3-chroot/usr/bin/as: binutils-$(BINUTILS_X_VERSION).tar.gz
417 rm -rf riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)
419 mkdir riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build
420 cd riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build && \
421 PATH=$(ROOT)/fixed-gcc:$$PATH \
423 --host=riscv64-unknown-linux-gnu \
424 --prefix=/usr --libdir=/usr/lib64
425 cd riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build && PATH=$(ROOT)/fixed-gcc:$$PATH make
426 cd riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build && make DESTDIR=$(ROOT)/stage3-chroot install
428 binutils-$(BINUTILS_X_VERSION).tar.gz:
430 wget -O $@-t https://github.com/riscv/riscv-binutils-gdb/archive/riscv-binutils-$(BINUTILS_X_VERSION).tar.gz
433 # Cross-compile GMP, MPFR and MPC (deps of GCC).
434 stage3-chroot/usr/lib64/libgmp.so.10: gmp-$(GMP_VERSION).tar.lz
435 rm -rf gmp-$(GMP_VERSION)
436 tar --lzip -xf gmp-$(GMP_VERSION).tar.lz
437 cd gmp-$(GMP_VERSION) && \
438 PATH=$(ROOT)/fixed-gcc:$$PATH \
439 ./configure --host=riscv64-unknown-linux-gnu \
440 --prefix=/usr --libdir=/usr/lib64
441 cd gmp-$(GMP_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
442 cd gmp-$(GMP_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
443 cd stage3-chroot/usr/lib && ln -s ../lib64/libgmp.so
445 gmp-$(GMP_VERSION).tar.lz:
447 wget -O $@-t https://gmplib.org/download/gmp/gmp-$(GMP_VERSION).tar.lz
450 stage3-chroot/usr/lib64/libmpfr.so.4: mpfr-$(MPFR_VERSION).tar.gz
451 rm -rf mpfr-$(MPFR_VERSION)
452 tar -zxf mpfr-$(MPFR_VERSION).tar.gz
453 cd mpfr-$(MPFR_VERSION) && \
454 PATH=$(ROOT)/fixed-gcc:$$PATH \
455 ./configure --host=riscv64-unknown-linux-gnu \
456 --prefix=/usr --libdir=/usr/lib64 \
457 --with-gmp=$(ROOT)/stage3-chroot/usr
458 cd mpfr-$(MPFR_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
459 cd mpfr-$(MPFR_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
460 cd stage3-chroot/usr/lib && ln -s ../lib64/libmpfr.so
461 rm -f stage3-chroot/usr/lib64/*.la
463 mpfr-$(MPFR_VERSION).tar.gz:
465 wget -O $@-t http://www.mpfr.org/mpfr-current/mpfr-$(MPFR_VERSION).tar.gz
468 stage3-chroot/usr/lib64/libmpc.so.3: mpc-$(MPC_VERSION).tar.gz
469 rm -rf mpc-$(MPC_VERSION)
470 tar -zxf mpc-$(MPC_VERSION).tar.gz
471 cd mpc-$(MPC_VERSION) && \
472 PATH=$(ROOT)/fixed-gcc:$$PATH \
473 ./configure --host=riscv64-unknown-linux-gnu \
474 --prefix=/usr --libdir=/usr/lib64 \
475 --with-gmp=$(ROOT)/stage3-chroot/usr \
476 --with-mpfr=$(ROOT)/stage3-chroot/usr
477 cd mpc-$(MPC_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
478 cd mpc-$(MPC_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
479 cd stage3-chroot/usr/lib && ln -s ../lib64/libmpc.so
480 rm -f stage3-chroot/usr/lib64/*.la
482 mpc-$(MPC_VERSION).tar.gz:
484 wget -O $@-t ftp://ftp.gnu.org/gnu/mpc/mpc-$(MPC_VERSION).tar.gz
488 stage3-chroot/usr/bin/gcc: gcc-$(GCC_X_VERSION).tar.gz
489 rm -rf riscv-gcc-riscv-gcc-$(GCC_X_VERSION)
491 mkdir riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build
492 cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && \
493 PATH=$(ROOT)/fixed-gcc:$$PATH \
495 --host=riscv64-unknown-linux-gnu \
496 --prefix=/usr --libdir=/usr/lib64 \
499 --enable-languages=c,c++ \
500 --disable-libmudflap \
502 --disable-libquadmath \
505 # XXX use make all & make install here. However building libgcc
506 # fails, see 'broken-gcc.log'.
507 cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && PATH=$(ROOT)/fixed-gcc:$$PATH make all-gcc
508 cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && make install-gcc DESTDIR=$(ROOT)/stage3-chroot
510 gcc-$(GCC_X_VERSION).tar.gz:
512 wget -O $@-t https://github.com/riscv/riscv-gcc/archive/riscv-gcc-$(GCC_X_VERSION).tar.gz
515 # Cross-compile util-linux.
516 stage3-chroot/usr/bin/mount: util-linux-$(UTIL_LINUX_VERSION).tar.xz
517 rm -rf util-linux-$(UTIL_LINUX_VERSION)
519 cd util-linux-$(UTIL_LINUX_VERSION) && \
520 PATH=$(ROOT)/fixed-gcc:$$PATH \
521 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
523 --host=riscv64-unknown-linux-gnu \
524 --prefix=/usr --libdir=/usr/lib64 \
527 --disable-makeinstall-chown \
528 --enable-static-programs=mount
529 cd util-linux-$(UTIL_LINUX_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
530 cd util-linux-$(UTIL_LINUX_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
531 rm -f stage3-chroot/usr/lib64/*.la
533 util-linux-$(UTIL_LINUX_VERSION).tar.xz:
535 wget -O $@-t ftp://ftp.kernel.org/pub/linux/utils/util-linux/v$(UTIL_LINUX_VERSION)/util-linux-$(UTIL_LINUX_VERSION).tar.xz
538 # Cross-compile GNU tar.
539 stage3-chroot/usr/bin/tar: tar-$(TAR_VERSION).tar.xz
540 rm -rf tar-$(TAR_VERSION)
542 cd tar-$(TAR_VERSION) && \
543 PATH=$(ROOT)/fixed-gcc:$$PATH \
545 --host=riscv64-unknown-linux-gnu \
546 --prefix=/usr --libdir=/usr/lib64
547 cd tar-$(TAR_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
548 cd tar-$(TAR_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
550 tar-$(TAR_VERSION).tar.xz:
552 wget -O $@-t https://ftp.gnu.org/gnu/tar/tar-$(TAR_VERSION).tar.xz
555 # Cross-compile GNU gzip.
556 stage3-chroot/usr/bin/gzip: gzip-$(GZIP_VERSION).tar.gz
557 rm -rf gzip-$(GZIP_VERSION)
559 cd gzip-$(GZIP_VERSION) && \
560 PATH=$(ROOT)/fixed-gcc:$$PATH \
562 --host=riscv64-unknown-linux-gnu \
563 --prefix=/usr --libdir=/usr/lib64
564 cd gzip-$(GZIP_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
565 cd gzip-$(GZIP_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
567 gzip-$(GZIP_VERSION).tar.gz:
569 wget -O $@-t https://ftp.gnu.org/gnu/gzip/gzip-$(GZIP_VERSION).tar.gz
572 # Cross-compile zlib.
573 stage3-chroot/usr/lib64/libz.so: zlib-$(ZLIB_VERSION).tar.gz
574 rm -rf zlib-$(ZLIB_VERSION)
576 cd zlib-$(ZLIB_VERSION) && \
577 PATH=$(ROOT)/fixed-gcc:$$PATH \
578 CC=riscv64-unknown-linux-gnu-gcc \
579 CFLAGS="-I$(ROOT)/stage3-chroot/usr/include -L$(ROOT)/stage3-chroot/usr/lib" \
581 --prefix=/usr --libdir=/usr/lib64
582 cd zlib-$(ZLIB_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make shared
583 cd zlib-$(ZLIB_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
585 zlib-$(ZLIB_VERSION).tar.gz:
587 wget -O $@-t http://zlib.net/zlib-$(ZLIB_VERSION).tar.gz
590 # Cross-compile file/libmagic.
591 stage3-chroot/usr/bin/file: file-$(FILE_VERSION).tar.gz
592 rm -rf file-$(FILE_VERSION)
594 cd file-$(FILE_VERSION) && \
595 PATH=$(ROOT)/fixed-gcc:$$PATH \
596 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
598 --host=riscv64-unknown-linux-gnu \
599 --prefix=/usr --libdir=/usr/lib64 \
600 --disable-static --enable-shared
601 cd file-$(FILE_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
602 cd file-$(FILE_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
603 rm -f stage3-chroot/usr/lib64/*.la
605 file-$(FILE_VERSION).tar.gz:
607 wget -O $@-t ftp://ftp.astron.com/pub/file/file-$(FILE_VERSION).tar.gz
610 # Cross-compile popt.
611 stage3-chroot/usr/lib64/libpopt.so: popt-$(POPT_VERSION).tar.gz
612 rm -rf popt-$(POPT_VERSION)
614 cd popt-$(POPT_VERSION) && \
615 PATH=$(ROOT)/fixed-gcc:$$PATH \
616 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
618 --host=riscv64-unknown-linux-gnu \
619 --prefix=/usr --libdir=/usr/lib64 \
620 --disable-static --enable-shared
621 cd popt-$(POPT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
622 cd popt-$(POPT_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
623 rm -f stage3-chroot/usr/lib64/*.la
625 popt-$(POPT_VERSION).tar.gz:
627 wget -O $@-t http://rpm5.org/files/popt/popt-$(POPT_VERSION).tar.gz
630 # Cross-compile beecrypt.
631 stage3-chroot/usr/lib64/libbeecrypt.so: beecrypt-$(BEECRYPT_VERSION).tar.gz
632 rm -rf beecrypt-$(BEECRYPT_VERSION)
634 cd beecrypt-$(BEECRYPT_VERSION) && patch -p0 < ../beecrypt-disable-cplusplus.patch
635 cd beecrypt-$(BEECRYPT_VERSION) && autoreconf -i
636 cd beecrypt-$(BEECRYPT_VERSION) && \
637 PATH=$(ROOT)/fixed-gcc:$$PATH \
638 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
640 --host=riscv64-unknown-linux-gnu \
641 --prefix=/usr --libdir=/usr/lib64 \
642 --without-cplusplus \
647 cd beecrypt-$(BEECRYPT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
648 cd beecrypt-$(BEECRYPT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot V=1
649 chrpath -d stage3-chroot/usr/lib64/libbeecrypt.so.*
650 rm -f stage3-chroot/usr/lib64/*.la
652 beecrypt-$(BEECRYPT_VERSION).tar.gz:
654 wget -O $@-t http://downloads.sourceforge.net/sourceforge/beecrypt/beecrypt-$(BEECRYPT_VERSION).tar.gz
657 # Cross-compile GNU nano (editor).
658 stage3-chroot/usr/bin/nano: nano-$(NANO_VERSION).tar.gz
659 rm -rf nano-$(NANO_VERSION)
661 cd nano-$(NANO_VERSION) && \
662 PATH=$(ROOT)/fixed-gcc:$$PATH \
663 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
665 --host=riscv64-unknown-linux-gnu \
666 --prefix=/usr --libdir=/usr/lib64
667 cd nano-$(NANO_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
668 cd nano-$(NANO_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
670 nano-$(NANO_VERSION).tar.gz:
672 wget -O $@-t https://www.nano-editor.org/dist/v2.6/nano-$(NANO_VERSION).tar.gz
675 # Cross-compile GNU grep.
676 stage3-chroot/usr/bin/grep: grep-$(GREP_VERSION).tar.xz
677 rm -rf grep-$(GREP_VERSION)
679 cd grep-$(GREP_VERSION) && \
680 PATH=$(ROOT)/fixed-gcc:$$PATH \
682 --host=riscv64-unknown-linux-gnu \
683 --prefix=/usr --libdir=/usr/lib64
684 cd grep-$(GREP_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
685 cd grep-$(GREP_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
687 grep-$(GREP_VERSION).tar.xz:
689 wget -O $@-t https://ftp.gnu.org/gnu/grep/grep-$(GREP_VERSION).tar.xz
692 # Cross-compile less.
693 stage3-chroot/usr/bin/less: less-$(LESS_VERSION).tar.gz
694 rm -rf less-$(LESS_VERSION)
696 cd less-$(LESS_VERSION) && \
697 PATH=$(ROOT)/fixed-gcc:$$PATH \
698 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
700 --host=riscv64-unknown-linux-gnu \
701 --prefix=/usr --libdir=/usr/lib64
702 cd less-$(LESS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
703 cd less-$(LESS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
705 less-$(LESS_VERSION).tar.gz:
707 wget -O $@-t http://www.greenwoodsoftware.com/less/less-$(LESS_VERSION).tar.gz
710 # Cross-compile strace.
711 # XXX This does not work.
712 stage3-chroot/usr/bin/strace: strace-$(STRACE_SHORT_COMMIT).tar.gz
713 rm -rf strace-$(STRACE_SHORT_COMMIT)
715 cd riscv-strace-$(STRACE_COMMIT) && patch -p1 < ../0001-Update-riscv_regs-for-ptrace.h-from-Linux-4.1.x.patch
716 cd riscv-strace-$(STRACE_COMMIT) && \
717 PATH=$(ROOT)/fixed-gcc:$$PATH \
718 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
720 --host=riscv64-unknown-linux-gnu \
721 --prefix=/usr --libdir=/usr/lib64
722 cd riscv-strace-$(STRACE_COMMIT) && PATH=$(ROOT)/fixed-gcc:$$PATH make
723 cd riscv-strace-$(STRACE_COMMIT) && make install DESTDIR=$(ROOT)/stage3-chroot
725 strace-$(STRACE_SHORT_COMMIT).tar.gz:
727 wget -O $@-t 'https://github.com/riscv/riscv-strace/archive/$(STRACE_COMMIT)/riscv-strace-$(STRACE_SHORTCOMMIT).tar.gz'
730 # Cross-compile bzip2.
731 stage3-chroot/usr/bin/bzip2: bzip2-$(BZIP2_VERSION).tar.gz
732 rm -rf bzip2-$(BZIP2_VERSION)
734 cd bzip2-$(BZIP2_VERSION) && \
735 PATH=$(ROOT)/fixed-gcc:$$PATH \
736 make libbz2.a bzip2 bzip2recover \
738 CC=riscv64-unknown-linux-gnu-gcc \
739 AR=riscv64-unknown-linux-gnu-ar \
740 RANLIB=riscv64-unknown-linux-gnu-ranlib \
741 CFLAGS="-Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -fPIC"
742 cd bzip2-$(BZIP2_VERSION) && \
743 make install PREFIX=$(ROOT)/stage3-chroot/usr
745 bzip2-$(BZIP2_VERSION).tar.gz:
747 wget -O $@-t http://www.bzip.org/1.0.6/bzip2-$(BZIP2_VERSION).tar.gz
750 # Cross-compile GNU make.
751 stage3-chroot/usr/bin/make: make-$(MAKE_VERSION).tar.gz
752 rm -rf make-$(MAKE_VERSION)
754 cd make-$(MAKE_VERSION) && \
755 PATH=$(ROOT)/fixed-gcc:$$PATH \
757 --host=riscv64-unknown-linux-gnu \
758 --prefix=/usr --libdir=/usr/lib64
759 cd make-$(MAKE_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
760 cd make-$(MAKE_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
762 make-$(MAKE_VERSION).tar.gz:
764 wget -O $@-t https://ftp.gnu.org/gnu/make/make-$(MAKE_VERSION).tar.gz
767 # Cross-compile GNU diffutils.
768 stage3-chroot/usr/bin/diff: diffutils-$(DIFFUTILS_VERSION).tar.xz
769 rm -rf diffutils-$(DIFFUTILS_VERSION)
771 cd diffutils-$(DIFFUTILS_VERSION) && \
772 PATH=$(ROOT)/fixed-gcc:$$PATH \
774 --host=riscv64-unknown-linux-gnu \
775 --prefix=/usr --libdir=/usr/lib64
776 cd diffutils-$(DIFFUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
777 cd diffutils-$(DIFFUTILS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
779 diffutils-$(DIFFUTILS_VERSION).tar.xz:
781 wget -O $@-t https://ftp.gnu.org/gnu/diffutils/diffutils-$(DIFFUTILS_VERSION).tar.xz
784 # Cross-compile GNU findutils.
785 stage3-chroot/usr/bin/find: findutils-$(FINDUTILS_VERSION).tar.gz
786 rm -rf findutils-$(FINDUTILS_VERSION)
788 cd findutils-$(FINDUTILS_VERSION) && \
789 PATH=$(ROOT)/fixed-gcc:$$PATH \
791 --host=riscv64-unknown-linux-gnu \
792 --prefix=/usr --libdir=/usr/lib64
793 cd findutils-$(FINDUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
794 cd findutils-$(FINDUTILS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
796 findutils-$(FINDUTILS_VERSION).tar.gz:
798 wget -O $@-t https://ftp.gnu.org/gnu/findutils/findutils-$(FINDUTILS_VERSION).tar.gz
801 # Cross-compile GNU sed.
802 stage3-chroot/usr/bin/sed: sed-$(SED_VERSION).tar.gz
803 rm -rf sed-$(SED_VERSION)
805 cd sed-$(SED_VERSION) && \
806 PATH=$(ROOT)/fixed-gcc:$$PATH \
808 --host=riscv64-unknown-linux-gnu \
809 --prefix=/usr --libdir=/usr/lib64
810 cd sed-$(SED_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
811 cd sed-$(SED_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
813 sed-$(SED_VERSION).tar.gz:
815 wget -O $@-t https://ftp.gnu.org/gnu/sed/sed-$(SED_VERSION).tar.gz
818 # Cross-compile patch.
819 stage3-chroot/usr/bin/patch: patch-$(PATCH_VERSION).tar.gz
820 rm -rf patch-$(PATCH_VERSION)
822 cd patch-$(PATCH_VERSION) && \
823 PATH=$(ROOT)/fixed-gcc:$$PATH \
825 --host=riscv64-unknown-linux-gnu \
826 --prefix=/usr --libdir=/usr/lib64
827 cd patch-$(PATCH_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
828 cd patch-$(PATCH_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
830 patch-$(PATCH_VERSION).tar.gz:
832 wget -O $@-t https://ftp.gnu.org/gnu/patch/patch-$(PATCH_VERSION).tar.gz
835 # Cross-compile RPM / rpmbuild.
836 # We build this from a git commit, with a few hacks to the configure
838 stage3-chroot/usr/bin/rpm: rpm-$(RPM_SHORT_COMMIT).tar.gz db-$(BDB_VERSION).tar.gz
839 rm -rf rpm-$(RPM_SHORT_COMMIT)
840 tar -zxf rpm-$(RPM_SHORT_COMMIT).tar.gz
841 tar -zxf db-$(BDB_VERSION).tar.gz -C rpm-$(RPM_SHORT_COMMIT)
842 cd rpm-$(RPM_SHORT_COMMIT) && ln -s db-$(BDB_VERSION) db
843 cd rpm-$(RPM_SHORT_COMMIT) && \
844 patch -p1 < ../0001-RISCV-64-bit-riscv64-support.patch && \
845 patch -p1 < ../0002-build-fgetc-returns-int-not-char.patch && \
846 patch -p1 < ../0003-HACKS-TO-GET-RPM-TO-CROSS-COMPILE.patch
847 cd rpm-$(RPM_SHORT_COMMIT) && autoreconf -i
848 cd rpm-$(RPM_SHORT_COMMIT) && \
849 PATH=$(ROOT)/fixed-gcc:$$PATH \
850 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
852 --host=riscv64-unknown-linux-gnu \
853 --prefix=/usr --libdir=/usr/lib64 \
855 --without-libarchive \
859 --without-external-db \
862 cd rpm-$(RPM_SHORT_COMMIT) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
863 cd rpm-$(RPM_SHORT_COMMIT) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
864 rm -f stage3-chroot/usr/lib64/*.la
866 rpm-$(RPM_SHORT_COMMIT).tar.gz:
868 wget -O $@-t 'http://rpm.org/gitweb?p=rpm.git;a=snapshot;h=$(RPM_COMMIT);sf=tgz'
871 db-$(BDB_VERSION).tar.gz:
873 wget -O $@-t http://download.oracle.com/berkeley-db/db-$(BDB_VERSION).tar.gz
876 # Create an /init script.
877 stage3-chroot/init: init.sh
878 install -m 0755 $^ $@
880 # Create the stage3 disk image.
881 # Note `-s +...' adds spare space to the disk image.
882 stage3-disk.img: stage3-chroot
883 cd stage3-chroot && virt-make-fs . ../$@ -t ext2 -F raw -s +4G
885 # Upload the compressed disk image.
886 upload-stage3: stage3-disk.img.xz
887 scp $^ tick:public_html/riscv/
888 stage3-disk.img.xz: stage3-disk.img
892 # Helper which boots stage3 disk image in spike.
893 boot-stage3-in-spike: stage3-disk.img stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
894 spike +disk=stage3-disk.img \
895 /usr/bin/bbl stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
897 # Helper which boots stage3 disk image in qemu.
898 boot-stage3-in-qemu: stage3-disk.img stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
899 qemu-system-riscv -kernel /usr/bin/bbl \
900 -append ./stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux \
901 -drive file=stage3-disk.img,format=raw -nographic