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 STAGE3_PACKAGES = gcc rpm-build
41 # Versions of cross-compiled packages.
42 NCURSES_VERSION = 6.0-20160730
44 COREUTILS_VERSION = 8.25
48 BINUTILS_X_VERSION = 2.26
50 UTIL_LINUX_VERSION = 2.28
55 all: stage1 stage2 stage3 stage4
59 stage1: stage1-riscv-qemu/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz \
60 stage1-riscv-qemu/riscv-qemu.spec \
61 stamp-riscv-qemu-installed \
62 stage1-riscv-fesvr/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz \
63 stage1-riscv-fesvr/riscv-fesvr.spec \
64 stamp-riscv-fesvr-installed \
65 stage1-riscv-isa-sim/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz \
66 stage1-riscv-isa-sim/riscv-isa-sim.spec \
67 stamp-riscv-isa-sim-installed
69 stage1-riscv-qemu/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz:
71 wget -O $@-t 'https://github.com/riscv/riscv-qemu/archive/$(RISCV_QEMU_COMMIT)/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz'
74 stage1-riscv-qemu/riscv-qemu.spec: stage1-riscv-qemu/riscv-qemu.spec.in
75 sed -e 's/@COMMIT@/$(RISCV_QEMU_COMMIT)/g' \
76 -e 's/@SHORTCOMMIT@/$(RISCV_QEMU_SHORTCOMMIT)/g' \
80 stamp-riscv-qemu-installed:
82 @rpm -q riscv-qemu >/dev/null || { \
83 echo "ERROR: You must install riscv-qemu:"; \
85 echo " dnf copr enable rjones/riscv"; \
86 echo " dnf install riscv-qemu"; \
88 echo "OR: you can build it yourself from the stage1-riscv-qemu directory."; \
92 @qemu-system-riscv --version || { \
93 echo "ERROR: qemu-system-riscv is not working."; \
94 echo "Make sure you installed the riscv-qemu package."; \
99 stage1-riscv-fesvr/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz:
101 wget -O $@-t 'https://github.com/riscv/riscv-fesvr/archive/$(RISCV_FESVR_COMMIT)/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz'
104 stage1-riscv-fesvr/riscv-fesvr.spec: stage1-riscv-fesvr/riscv-fesvr.spec.in
105 sed -e 's/@COMMIT@/$(RISCV_FESVR_COMMIT)/g' \
106 -e 's/@SHORTCOMMIT@/$(RISCV_FESVR_SHORTCOMMIT)/g' \
110 stamp-riscv-fesvr-installed:
112 @rpm -q riscv-fesvr >/dev/null || { \
113 echo "ERROR: You must install riscv-fesvr:"; \
115 echo " dnf copr enable rjones/riscv"; \
116 echo " dnf install riscv-fesvr"; \
118 echo "OR: you can build it yourself from the stage1-riscv-fesvr directory."; \
124 stage1-riscv-isa-sim/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz:
126 wget -O $@-t 'https://github.com/riscv/riscv-isa-sim/archive/$(RISCV_ISA_SIM_COMMIT)/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz'
129 stage1-riscv-isa-sim/riscv-isa-sim.spec: stage1-riscv-isa-sim/riscv-isa-sim.spec.in
130 sed -e 's/@COMMIT@/$(RISCV_ISA_SIM_COMMIT)/g' \
131 -e 's/@SHORTCOMMIT@/$(RISCV_ISA_SIM_SHORTCOMMIT)/g' \
135 stamp-riscv-isa-sim-installed:
137 @rpm -q riscv-isa-sim >/dev/null || { \
138 echo "ERROR: You must install riscv-isa-sim:"; \
140 echo " dnf copr enable rjones/riscv"; \
141 echo " dnf install riscv-isa-sim"; \
143 echo "OR: you can build it yourself from the stage1-riscv-isa-sim directory."; \
151 stage2: stage2-riscv-gnu-toolchain/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz \
152 stage2-riscv-gnu-toolchain/binutils-$(BINUTILS_VERSION).tar.gz \
153 stage2-riscv-gnu-toolchain/gcc-$(GCC_VERSION).tar.gz \
154 stage2-riscv-gnu-toolchain/glibc-$(GLIBC_VERSION).tar.gz \
155 stage2-riscv-gnu-toolchain/newlib-$(NEWLIB_VERSION).tar.gz \
156 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec \
157 stamp-riscv-gnu-toolchain-installed \
158 stage2-riscv-pk/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz \
159 stage2-riscv-pk/riscv-pk.spec \
160 stamp-riscv-pk-installed
162 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz:
164 wget -O $@-t https://github.com/lowRISC/riscv-gnu-toolchain/archive/$(RISCV_GNU_TOOLCHAIN_COMMIT)/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz
167 stage2-riscv-gnu-toolchain/binutils-$(BINUTILS_VERSION).tar.gz:
169 wget -O $@-t http://mirrors.kernel.org/gnu/binutils/binutils-$(BINUTILS_VERSION).tar.gz
172 # GCC 5 no longer compiles with GCC 6 unless we patch it.
173 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69959
174 stage2-riscv-gnu-toolchain/gcc-$(GCC_VERSION).tar.gz:
176 wget -O $@-t http://mirrors.kernel.org/gnu/gcc/gcc-$(GCC_VERSION)/gcc-$(GCC_VERSION).tar.gz
178 cd gcc-$(GCC_VERSION) && patch -p0 < ../stage2-riscv-gnu-toolchain/gcc-5-fix-compilation-with-gcc-6.patch
179 tar zcf $@-t gcc-$(GCC_VERSION)
180 rm -r gcc-$(GCC_VERSION)
183 stage2-riscv-gnu-toolchain/glibc-$(GLIBC_VERSION).tar.gz:
185 wget -O $@-t http://mirrors.kernel.org/gnu/glibc/glibc-$(GLIBC_VERSION).tar.gz
188 stage2-riscv-gnu-toolchain/newlib-$(NEWLIB_VERSION).tar.gz:
190 wget -O $@-t ftp://sourceware.org/pub/newlib/newlib-$(NEWLIB_VERSION).tar.gz
193 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec: stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec.in
194 sed -e 's/@COMMIT@/$(RISCV_GNU_TOOLCHAIN_COMMIT)/g' \
195 -e 's/@SHORTCOMMIT@/$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT)/g' \
196 -e 's/@BINUTILS_VERSION@/$(BINUTILS_VERSION)/g' \
197 -e 's/@GCC_VERSION@/$(GCC_VERSION)/g' \
198 -e 's/@GLIBC_VERSION@/$(GLIBC_VERSION)/g' \
199 -e 's/@NEWLIB_VERSION@/$(NEWLIB_VERSION)/g' \
203 stamp-riscv-gnu-toolchain-installed:
205 @rpm -q riscv-gnu-toolchain >/dev/null || { \
206 echo "ERROR: You must install riscv-gnu-toolchain:"; \
208 echo " dnf copr enable rjones/riscv"; \
209 echo " dnf install riscv-gnu-toolchain"; \
211 echo "OR: you can build it yourself from the stage2-riscv-gnu-toolchain directory."; \
215 @riscv64-unknown-elf-gcc --version || { \
216 echo "ERROR: riscv64-unknown-elf-gcc (cross compiler) is not working."; \
217 echo "Make sure you installed the riscv-gnu-toolchain package."; \
222 stage2-riscv-pk/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz:
224 wget -O $@-t https://github.com/lowRISC/riscv-pk/archive/$(RISCV_PK_COMMIT)/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz
227 stage2-riscv-pk/riscv-pk.spec: stage2-riscv-pk/riscv-pk.spec.in
228 sed -e 's/@COMMIT@/$(RISCV_PK_COMMIT)/g' \
229 -e 's/@SHORTCOMMIT@/$(RISCV_PK_SHORTCOMMIT)/g' \
233 stamp-riscv-pk-installed:
235 @rpm -q riscv-pk >/dev/null || { \
236 echo "ERROR: You must install riscv-pk:"; \
238 echo " dnf copr enable rjones/riscv"; \
239 echo " dnf install riscv-pk"; \
241 echo "OR: you can build it yourself from the stage2-riscv-pk directory."; \
249 stage3: stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux \
250 stage3-chroot-original/etc/fedora-release \
251 stage3-chroot/etc/fedora-release \
252 stage3-chroot/lib64/libc.so.6 \
253 stage3-chroot/usr/bin/tic \
254 stage3-chroot/bin/bash \
255 stage3-chroot/bin/ls \
256 stage3-chroot/usr/lib64/libgmp.so.10 \
257 stage3-chroot/usr/lib64/libmpfr.so.4 \
258 stage3-chroot/usr/lib64/libmpc.so.3 \
259 stage3-chroot/usr/bin/as \
260 stage3-chroot/usr/bin/gcc \
261 stage3-chroot/usr/bin/mount \
262 stage3-chroot/usr/bin/tar \
263 stage3-chroot/usr/bin/gzip \
264 stage3-chroot/usr/lib64/libz.so \
268 stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux:
269 rm -rf stage3-kernel/linux-$(KERNEL_VERSION)
270 cp -a $(LOCAL_LINUX_GIT_COPY) stage3-kernel/linux-$(KERNEL_VERSION) || { \
271 mkdir stage3-kernel/linux-$(KERNEL_VERSION) && \
272 cd stage3-kernel/linux-$(KERNEL_VERSION) && \
275 cd stage3-kernel/linux-$(KERNEL_VERSION) && \
276 git remote add riscv https://github.com/riscv/riscv-linux && \
278 git checkout -f linux-4.1.y-riscv && \
280 make ARCH=riscv defconfig
281 echo CONFIG_CMDLINE=\"root=/dev/htifblk0 init=/init\" >> stage3-kernel/linux-$(KERNEL_VERSION)/.config
282 echo CONFIG_CROSS_COMPILE=riscv64-unknown-elf- >> stage3-kernel/linux-$(KERNEL_VERSION)/.config
283 cd stage3-kernel/linux-$(KERNEL_VERSION) && \
284 make ARCH=riscv olddefconfig
285 cd stage3-kernel/linux-$(KERNEL_VERSION) && \
286 make ARCH=riscv vmlinux
289 # Build an original (x86-64) chroot using supermin. We then aim to
290 # rebuild (using cross-compiled versions) every ELF binary in this
292 stage3-chroot-original/etc/fedora-release:
293 rm -rf stage3-chroot-original tmp-supermin.d
294 supermin --prepare $(STAGE3_PACKAGES) -o tmp-supermin.d
295 supermin --build -f chroot tmp-supermin.d -o stage3-chroot-original
297 @echo -n "Total files in chroot: "
298 @find stage3-chroot-original -type f | wc -l
299 @echo -n "ELF files to be rebuilt: "
300 @find stage3-chroot-original -type f | xargs file -N | grep -E '\bELF.*LSB\b' | wc -l
302 # Copy the original chroot to the final chroot, remove all the ELF
304 stage3-chroot/etc/fedora-release: stage3-chroot-original/etc/fedora-release
306 cp -a stage3-chroot-original stage3-chroot
307 find stage3-chroot -type d | xargs chmod u+w
308 find stage3-chroot -type f | xargs chmod u+w
309 find stage3-chroot -type f | xargs file -N | grep -E '\bELF.*LSB\b' | awk -F: '{print $$1}' | xargs rm -f
310 rm -f stage3-chroot/lib64/libc.so.6
312 # Copy in compiled glibc from the riscv-gnu-toolchain sysroot. Only
313 # copy files and symlinks, leave the target directory structure
315 stage3-chroot/lib64/libc.so.6:
316 mkdir -p stage3-chroot/usr/lib/audit
317 mkdir -p stage3-chroot/usr/lib/gconv
318 for f in `cd /usr/sysroot && find -type f -o -type l`; do \
319 cp -d /usr/sysroot/$$f stage3-chroot/$$f; \
321 cd stage3-chroot/lib64 && for f in ../lib/*; do ln -sf $$f; done
323 # Cross-compile ncurses.
324 stage3-chroot/usr/bin/tic: ncurses-$(NCURSES_VERSION).tgz
326 cd ncurses-$(NCURSES_VERSION) && \
327 PATH=$(ROOT)/fixed-gcc:$$PATH \
328 ./configure --host=riscv64-unknown-linux-gnu \
329 --prefix=/usr --libdir=/usr/lib64 \
331 cd ncurses-$(NCURSES_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
332 cd ncurses-$(NCURSES_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
333 cd $(ROOT)/stage3-chroot/usr/lib64 && ln -sf libtinfo.so.6 libtinfo.so
335 ncurses-$(NCURSES_VERSION).tgz:
337 wget -O $@-t ftp://invisible-island.net/ncurses/current/ncurses-$(NCURSES_VERSION).tgz
340 # Cross-compile bash.
341 stage3-chroot/bin/bash: bash-$(BASH_VERSION).tar.gz
343 cd bash-$(BASH_VERSION) && \
344 PATH=$(ROOT)/fixed-gcc:$$PATH \
345 ./configure --host=riscv64-unknown-linux-gnu \
346 --prefix=/usr --libdir=/usr/lib64
347 cd bash-$(BASH_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
348 cd bash-$(BASH_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
350 bash-$(BASH_VERSION).tar.gz:
352 wget -O $@-t ftp://ftp.gnu.org/gnu/bash/bash-$(BASH_VERSION).tar.gz
355 # Cross-compile coreutils. Bleah, coreutils cross-compilation is
356 # known-broken and upstream don't care, hence the 'touch' command.
358 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
360 stage3-chroot/bin/ls: coreutils-$(COREUTILS_VERSION).tar.xz
361 rm -rf coreutils-$(COREUTILS_VERSION)
363 cd coreutils-$(COREUTILS_VERSION) && \
364 PATH=$(ROOT)/fixed-gcc:$$PATH \
365 ./configure --host=riscv64-unknown-linux-gnu \
366 --prefix=/usr --libdir=/usr/lib64
367 -cd coreutils-$(COREUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
368 cd coreutils-$(COREUTILS_VERSION)/man && \
369 for f in $(COREUTILS_PROGRAMS); do touch $$f.1; done
370 cd coreutils-$(COREUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
371 cd coreutils-$(COREUTILS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
373 coreutils-$(COREUTILS_VERSION).tar.xz:
375 wget -O $@-t ftp://ftp.gnu.org/gnu/coreutils/coreutils-$(COREUTILS_VERSION).tar.xz
378 # Cross-compile binutils.
379 stage3-chroot/usr/bin/as: binutils-$(BINUTILS_X_VERSION).tar.gz
380 rm -rf binutils-$(BINUTILS_X_VERSION)
382 mkdir riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build
383 cd riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build && \
384 PATH=$(ROOT)/fixed-gcc:$$PATH \
386 --host=riscv64-unknown-linux-gnu \
387 --prefix=/usr --libdir=/usr/lib64
388 cd riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build && PATH=$(ROOT)/fixed-gcc:$$PATH make
389 cd riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build && make DESTDIR=$(ROOT)/stage3-chroot install
391 binutils-$(BINUTILS_X_VERSION).tar.gz:
393 wget -O $@-t https://github.com/riscv/riscv-binutils-gdb/archive/riscv-binutils-$(BINUTILS_X_VERSION).tar.gz
396 # Cross-compile GMP, MPFR and MPC (deps of GCC).
397 stage3-chroot/usr/lib64/libgmp.so.10: gmp-$(GMP_VERSION).tar.lz
398 rm -rf gmp-$(GMP_VERSION)
399 tar --lzip -xf gmp-$(GMP_VERSION).tar.lz
400 cd gmp-$(GMP_VERSION) && \
401 PATH=$(ROOT)/fixed-gcc:$$PATH \
402 ./configure --host=riscv64-unknown-linux-gnu \
403 --prefix=/usr --libdir=/usr/lib64
404 cd gmp-$(GMP_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
405 cd gmp-$(GMP_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
406 cd stage3-chroot/usr/lib && ln -s ../lib64/libgmp.so
408 gmp-$(GMP_VERSION).tar.lz:
410 wget -O $@-t https://gmplib.org/download/gmp/gmp-$(GMP_VERSION).tar.lz
413 stage3-chroot/usr/lib64/libmpfr.so.4: mpfr-$(MPFR_VERSION).tar.gz
414 rm -rf mpfr-$(MPFR_VERSION)
415 tar -zxf mpfr-$(MPFR_VERSION).tar.gz
416 cd mpfr-$(MPFR_VERSION) && \
417 PATH=$(ROOT)/fixed-gcc:$$PATH \
418 ./configure --host=riscv64-unknown-linux-gnu \
419 --prefix=/usr --libdir=/usr/lib64 \
420 --with-gmp=$(ROOT)/stage3-chroot/usr
421 cd mpfr-$(MPFR_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
422 cd mpfr-$(MPFR_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
423 cd stage3-chroot/usr/lib && ln -s ../lib64/libmpfr.so
425 mpfr-$(MPFR_VERSION).tar.gz:
427 wget -O $@-t http://www.mpfr.org/mpfr-current/mpfr-$(MPFR_VERSION).tar.gz
430 stage3-chroot/usr/lib64/libmpc.so.3: mpc-$(MPC_VERSION).tar.gz
431 rm -rf mpc-$(MPC_VERSION)
432 tar -zxf mpc-$(MPC_VERSION).tar.gz
433 cd mpc-$(MPC_VERSION) && \
434 PATH=$(ROOT)/fixed-gcc:$$PATH \
435 ./configure --host=riscv64-unknown-linux-gnu \
436 --prefix=/usr --libdir=/usr/lib64 \
437 --with-gmp=$(ROOT)/stage3-chroot/usr \
438 --with-mpfr=$(ROOT)/stage3-chroot/usr
439 cd mpc-$(MPC_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
440 cd mpc-$(MPC_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
441 cd stage3-chroot/usr/lib && ln -s ../lib64/libmpc.so
443 mpc-$(MPC_VERSION).tar.gz:
445 wget -O $@-t ftp://ftp.gnu.org/gnu/mpc/mpc-$(MPC_VERSION).tar.gz
449 stage3-chroot/usr/bin/gcc: gcc-$(GCC_X_VERSION).tar.gz
450 rm -rf riscv-gcc-riscv-gcc-$(GCC_X_VERSION)
452 mkdir riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build
453 cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && \
454 PATH=$(ROOT)/fixed-gcc:$$PATH \
456 --host=riscv64-unknown-linux-gnu \
457 --prefix=/usr --libdir=/usr/lib64 \
460 --enable-languages=c,c++ \
461 --disable-libmudflap \
463 --disable-libquadmath \
466 # XXX use make all & make install here. However building libgcc
467 # fails, see 'broken-gcc.log'.
468 cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && PATH=$(ROOT)/fixed-gcc:$$PATH make all-gcc
469 cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && make install-gcc DESTDIR=$(ROOT)/stage3-chroot
471 gcc-$(GCC_X_VERSION).tar.gz:
473 wget -O $@-t https://github.com/riscv/riscv-gcc/archive/riscv-gcc-$(GCC_X_VERSION).tar.gz
476 # Cross-compile util-linux.
477 # XXX Be nice to fix ncurses/tinfo support which in theory should work.
478 stage3-chroot/usr/bin/mount: util-linux-$(UTIL_LINUX_VERSION).tar.xz
479 rm -rf util-linux-$(UTIL_LINUX_VERSION)
481 cd util-linux-$(UTIL_LINUX_VERSION) && \
482 PATH=$(ROOT)/fixed-gcc:$$PATH \
484 --host=riscv64-unknown-linux-gnu \
485 --prefix=/usr --libdir=/usr/lib64 \
490 --disable-makeinstall-chown
491 cd util-linux-$(UTIL_LINUX_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
492 # libtool fucks something up here, ignore the failure and continue.
493 -cd util-linux-$(UTIL_LINUX_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot -j1 -k V=1
495 util-linux-$(UTIL_LINUX_VERSION).tar.xz:
497 wget -O $@-t ftp://ftp.kernel.org/pub/linux/utils/util-linux/v$(UTIL_LINUX_VERSION)/util-linux-$(UTIL_LINUX_VERSION).tar.xz
500 # Cross-compile GNU tar.
501 stage3-chroot/usr/bin/tar: tar-$(TAR_VERSION).tar.xz
502 rm -rf tar-$(TAR_VERSION)
504 cd tar-$(TAR_VERSION) && \
505 PATH=$(ROOT)/fixed-gcc:$$PATH \
507 --host=riscv64-unknown-linux-gnu \
508 --prefix=/usr --libdir=/usr/lib64
509 cd tar-$(TAR_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
510 cd tar-$(TAR_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
512 tar-$(TAR_VERSION).tar.xz:
514 wget -O $@-t https://ftp.gnu.org/gnu/tar/tar-$(TAR_VERSION).tar.xz
517 # Cross-compile GNU gzip.
518 stage3-chroot/usr/bin/gzip: gzip-$(GZIP_VERSION).tar.gz
519 rm -rf gzip-$(GZIP_VERSION)
521 cd gzip-$(GZIP_VERSION) && \
522 PATH=$(ROOT)/fixed-gcc:$$PATH \
524 --host=riscv64-unknown-linux-gnu \
525 --prefix=/usr --libdir=/usr/lib64
526 cd gzip-$(GZIP_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
527 cd gzip-$(GZIP_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
529 gzip-$(GZIP_VERSION).tar.gz:
531 wget -O $@-t https://ftp.gnu.org/gnu/gzip/gzip-$(GZIP_VERSION).tar.gz
534 # Cross-compile zlib.
535 stage3-chroot/usr/lib64/libz.so: zlib-$(ZLIB_VERSION).tar.gz
536 rm -rf zlib-$(ZLIB_VERSION)
538 cd zlib-$(ZLIB_VERSION) && \
539 PATH=$(ROOT)/fixed-gcc:$$PATH \
540 CC=riscv64-unknown-linux-gnu-gcc \
541 CFLAGS="-I/home/rjones/d/fedora-riscv/stage3-chroot/usr/include -L/home/rjones/d/fedora-riscv/stage3-chroot/usr/lib" \
543 --prefix=/usr --libdir=/usr/lib64
544 cd zlib-$(ZLIB_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make shared
545 cd zlib-$(ZLIB_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
547 zlib-$(ZLIB_VERSION).tar.gz:
549 wget -O $@-t http://zlib.net/zlib-$(ZLIB_VERSION).tar.gz
552 # Create an /init script.
553 stage3-chroot/init: init.sh
554 install -m 0755 $^ $@
556 # Create the stage3 disk image.
557 # Note `-s +...' adds spare space to the disk image.
558 stage3-disk.img: stage3-chroot
559 cd stage3-chroot && virt-make-fs . ../$@ -t ext2 -F raw -s +4G
561 # Upload the compressed disk image.
562 upload-stage3: stage3-disk.img.xz
563 scp $^ tick:public_html/riscv/
564 stage3-disk.img.xz: stage3-disk.img
568 # Helper which boots stage3 disk image in spike.
569 boot-stage3-in-spike: stage3-disk.img stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
570 spike +disk=stage3-disk.img \
571 /usr/bin/bbl stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
573 # Helper which boots stage3 disk image in qemu.
574 boot-stage3-in-qemu: stage3-disk.img stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
575 qemu-system-riscv -kernel /usr/bin/bbl \
576 -append ./stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux \
577 -drive file=stage3-disk.img,format=raw -nographic