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 STAGE3_PACKAGES = gcc rpm-build beecrypt-devel
42 # Versions of cross-compiled packages.
43 NCURSES_VERSION = 6.0-20160730
45 COREUTILS_VERSION = 8.25
49 BINUTILS_X_VERSION = 2.26
51 UTIL_LINUX_VERSION = 2.28
55 # Needs to match the installed (on host) version, otherwise:
56 # "Cannot use the installed version of file (xx) to cross-compile file yy"
59 BEECRYPT_VERSION = 4.2.1
60 RPM_COMMIT = 95712183458748ea6cafebac1bdd5daa097d9bee
61 RPM_SHORT_COMMIT = 9571218
64 all: stage1 stage2 stage3 stage4
68 stage1: stage1-riscv-qemu/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz \
69 stage1-riscv-qemu/riscv-qemu.spec \
70 stamp-riscv-qemu-installed \
71 stage1-riscv-fesvr/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz \
72 stage1-riscv-fesvr/riscv-fesvr.spec \
73 stamp-riscv-fesvr-installed \
74 stage1-riscv-isa-sim/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz \
75 stage1-riscv-isa-sim/riscv-isa-sim.spec \
76 stamp-riscv-isa-sim-installed
78 stage1-riscv-qemu/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz:
80 wget -O $@-t 'https://github.com/riscv/riscv-qemu/archive/$(RISCV_QEMU_COMMIT)/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz'
83 stage1-riscv-qemu/riscv-qemu.spec: stage1-riscv-qemu/riscv-qemu.spec.in
84 sed -e 's/@COMMIT@/$(RISCV_QEMU_COMMIT)/g' \
85 -e 's/@SHORTCOMMIT@/$(RISCV_QEMU_SHORTCOMMIT)/g' \
89 stamp-riscv-qemu-installed:
91 @rpm -q riscv-qemu >/dev/null || { \
92 echo "ERROR: You must install riscv-qemu:"; \
94 echo " dnf copr enable rjones/riscv"; \
95 echo " dnf install riscv-qemu"; \
97 echo "OR: you can build it yourself from the stage1-riscv-qemu directory."; \
101 @qemu-system-riscv --version || { \
102 echo "ERROR: qemu-system-riscv is not working."; \
103 echo "Make sure you installed the riscv-qemu package."; \
108 stage1-riscv-fesvr/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz:
110 wget -O $@-t 'https://github.com/riscv/riscv-fesvr/archive/$(RISCV_FESVR_COMMIT)/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz'
113 stage1-riscv-fesvr/riscv-fesvr.spec: stage1-riscv-fesvr/riscv-fesvr.spec.in
114 sed -e 's/@COMMIT@/$(RISCV_FESVR_COMMIT)/g' \
115 -e 's/@SHORTCOMMIT@/$(RISCV_FESVR_SHORTCOMMIT)/g' \
119 stamp-riscv-fesvr-installed:
121 @rpm -q riscv-fesvr >/dev/null || { \
122 echo "ERROR: You must install riscv-fesvr:"; \
124 echo " dnf copr enable rjones/riscv"; \
125 echo " dnf install riscv-fesvr"; \
127 echo "OR: you can build it yourself from the stage1-riscv-fesvr directory."; \
133 stage1-riscv-isa-sim/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz:
135 wget -O $@-t 'https://github.com/riscv/riscv-isa-sim/archive/$(RISCV_ISA_SIM_COMMIT)/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz'
138 stage1-riscv-isa-sim/riscv-isa-sim.spec: stage1-riscv-isa-sim/riscv-isa-sim.spec.in
139 sed -e 's/@COMMIT@/$(RISCV_ISA_SIM_COMMIT)/g' \
140 -e 's/@SHORTCOMMIT@/$(RISCV_ISA_SIM_SHORTCOMMIT)/g' \
144 stamp-riscv-isa-sim-installed:
146 @rpm -q riscv-isa-sim >/dev/null || { \
147 echo "ERROR: You must install riscv-isa-sim:"; \
149 echo " dnf copr enable rjones/riscv"; \
150 echo " dnf install riscv-isa-sim"; \
152 echo "OR: you can build it yourself from the stage1-riscv-isa-sim directory."; \
160 stage2: stage2-riscv-gnu-toolchain/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz \
161 stage2-riscv-gnu-toolchain/binutils-$(BINUTILS_VERSION).tar.gz \
162 stage2-riscv-gnu-toolchain/gcc-$(GCC_VERSION).tar.gz \
163 stage2-riscv-gnu-toolchain/glibc-$(GLIBC_VERSION).tar.gz \
164 stage2-riscv-gnu-toolchain/newlib-$(NEWLIB_VERSION).tar.gz \
165 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec \
166 stamp-riscv-gnu-toolchain-installed \
167 stage2-riscv-pk/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz \
168 stage2-riscv-pk/riscv-pk.spec \
169 stamp-riscv-pk-installed
171 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz:
173 wget -O $@-t https://github.com/lowRISC/riscv-gnu-toolchain/archive/$(RISCV_GNU_TOOLCHAIN_COMMIT)/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz
176 stage2-riscv-gnu-toolchain/binutils-$(BINUTILS_VERSION).tar.gz:
178 wget -O $@-t http://mirrors.kernel.org/gnu/binutils/binutils-$(BINUTILS_VERSION).tar.gz
181 # GCC 5 no longer compiles with GCC 6 unless we patch it.
182 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69959
183 stage2-riscv-gnu-toolchain/gcc-$(GCC_VERSION).tar.gz:
185 wget -O $@-t http://mirrors.kernel.org/gnu/gcc/gcc-$(GCC_VERSION)/gcc-$(GCC_VERSION).tar.gz
187 cd gcc-$(GCC_VERSION) && patch -p0 < ../stage2-riscv-gnu-toolchain/gcc-5-fix-compilation-with-gcc-6.patch
188 tar zcf $@-t gcc-$(GCC_VERSION)
189 rm -r gcc-$(GCC_VERSION)
192 stage2-riscv-gnu-toolchain/glibc-$(GLIBC_VERSION).tar.gz:
194 wget -O $@-t http://mirrors.kernel.org/gnu/glibc/glibc-$(GLIBC_VERSION).tar.gz
197 stage2-riscv-gnu-toolchain/newlib-$(NEWLIB_VERSION).tar.gz:
199 wget -O $@-t ftp://sourceware.org/pub/newlib/newlib-$(NEWLIB_VERSION).tar.gz
202 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec: stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec.in
203 sed -e 's/@COMMIT@/$(RISCV_GNU_TOOLCHAIN_COMMIT)/g' \
204 -e 's/@SHORTCOMMIT@/$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT)/g' \
205 -e 's/@BINUTILS_VERSION@/$(BINUTILS_VERSION)/g' \
206 -e 's/@GCC_VERSION@/$(GCC_VERSION)/g' \
207 -e 's/@GLIBC_VERSION@/$(GLIBC_VERSION)/g' \
208 -e 's/@NEWLIB_VERSION@/$(NEWLIB_VERSION)/g' \
212 stamp-riscv-gnu-toolchain-installed:
214 @rpm -q riscv-gnu-toolchain >/dev/null || { \
215 echo "ERROR: You must install riscv-gnu-toolchain:"; \
217 echo " dnf copr enable rjones/riscv"; \
218 echo " dnf install riscv-gnu-toolchain"; \
220 echo "OR: you can build it yourself from the stage2-riscv-gnu-toolchain directory."; \
224 @riscv64-unknown-elf-gcc --version || { \
225 echo "ERROR: riscv64-unknown-elf-gcc (cross compiler) is not working."; \
226 echo "Make sure you installed the riscv-gnu-toolchain package."; \
231 stage2-riscv-pk/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz:
233 wget -O $@-t https://github.com/lowRISC/riscv-pk/archive/$(RISCV_PK_COMMIT)/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz
236 stage2-riscv-pk/riscv-pk.spec: stage2-riscv-pk/riscv-pk.spec.in
237 sed -e 's/@COMMIT@/$(RISCV_PK_COMMIT)/g' \
238 -e 's/@SHORTCOMMIT@/$(RISCV_PK_SHORTCOMMIT)/g' \
242 stamp-riscv-pk-installed:
244 @rpm -q riscv-pk >/dev/null || { \
245 echo "ERROR: You must install riscv-pk:"; \
247 echo " dnf copr enable rjones/riscv"; \
248 echo " dnf install riscv-pk"; \
250 echo "OR: you can build it yourself from the stage2-riscv-pk directory."; \
258 stage3: stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux \
259 stage3-chroot-original/etc/fedora-release \
260 stage3-chroot/etc/fedora-release \
261 stage3-chroot/lib64/libc.so.6 \
262 stage3-chroot/usr/bin/tic \
263 stage3-chroot/bin/bash \
264 stage3-chroot/bin/ls \
265 stage3-chroot/usr/lib64/libgmp.so.10 \
266 stage3-chroot/usr/lib64/libmpfr.so.4 \
267 stage3-chroot/usr/lib64/libmpc.so.3 \
268 stage3-chroot/usr/bin/as \
269 stage3-chroot/usr/bin/gcc \
270 stage3-chroot/usr/bin/mount \
271 stage3-chroot/usr/bin/tar \
272 stage3-chroot/usr/bin/gzip \
273 stage3-chroot/usr/lib64/libz.so \
274 stage3-chroot/usr/bin/file \
275 stage3-chroot/usr/lib64/libpopt.so \
276 stage3-chroot/usr/lib64/libbeecrypt.so \
277 stage3-chroot/usr/bin/rpm \
281 stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux:
282 rm -rf stage3-kernel/linux-$(KERNEL_VERSION)
283 cp -a $(LOCAL_LINUX_GIT_COPY) stage3-kernel/linux-$(KERNEL_VERSION) || { \
284 mkdir stage3-kernel/linux-$(KERNEL_VERSION) && \
285 cd stage3-kernel/linux-$(KERNEL_VERSION) && \
288 cd stage3-kernel/linux-$(KERNEL_VERSION) && \
289 git remote add riscv https://github.com/riscv/riscv-linux && \
291 git checkout -f linux-4.1.y-riscv && \
293 make ARCH=riscv defconfig
294 echo CONFIG_CMDLINE=\"root=/dev/htifblk0 init=/init\" >> stage3-kernel/linux-$(KERNEL_VERSION)/.config
295 echo CONFIG_CROSS_COMPILE=riscv64-unknown-elf- >> stage3-kernel/linux-$(KERNEL_VERSION)/.config
296 cd stage3-kernel/linux-$(KERNEL_VERSION) && \
297 make ARCH=riscv olddefconfig
298 cd stage3-kernel/linux-$(KERNEL_VERSION) && \
299 make ARCH=riscv vmlinux
302 # Build an original (x86-64) chroot using supermin. We then aim to
303 # rebuild (using cross-compiled versions) every ELF binary in this
305 stage3-chroot-original/etc/fedora-release:
306 rm -rf stage3-chroot-original tmp-supermin.d
307 supermin --prepare $(STAGE3_PACKAGES) -o tmp-supermin.d
308 supermin --build -f chroot tmp-supermin.d -o stage3-chroot-original
310 @echo -n "Total files in chroot: "
311 @find stage3-chroot-original -type f | wc -l
312 @echo -n "ELF files to be rebuilt: "
313 @find stage3-chroot-original -type f | xargs file -N | grep -E '\bELF.*LSB\b' | wc -l
315 # Copy the original chroot to the final chroot, remove all the ELF
317 stage3-chroot/etc/fedora-release: stage3-chroot-original/etc/fedora-release
319 cp -a stage3-chroot-original stage3-chroot
320 find stage3-chroot -type d | xargs chmod u+w
321 find stage3-chroot -type f | xargs chmod u+w
322 find stage3-chroot -type f | xargs file -N | grep -E '\bELF.*LSB\b' | awk -F: '{print $$1}' | xargs rm -f
323 rm -f stage3-chroot/lib64/libc.so.6
325 # Copy in compiled glibc from the riscv-gnu-toolchain sysroot. Only
326 # copy files and symlinks, leave the target directory structure
328 stage3-chroot/lib64/libc.so.6:
329 mkdir -p stage3-chroot/usr/lib/audit
330 mkdir -p stage3-chroot/usr/lib/gconv
331 for f in `cd /usr/sysroot && find -type f -o -type l`; do \
332 cp -d /usr/sysroot/$$f stage3-chroot/$$f; \
334 cd stage3-chroot/lib64 && for f in ../lib/*; do ln -sf $$f; done
336 # Cross-compile ncurses.
337 stage3-chroot/usr/bin/tic: ncurses-$(NCURSES_VERSION).tgz
339 cd ncurses-$(NCURSES_VERSION) && \
340 PATH=$(ROOT)/fixed-gcc:$$PATH \
341 ./configure --host=riscv64-unknown-linux-gnu \
342 --prefix=/usr --libdir=/usr/lib64 \
344 cd ncurses-$(NCURSES_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
345 cd ncurses-$(NCURSES_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
346 cd $(ROOT)/stage3-chroot/usr/lib64 && ln -sf libtinfo.so.6 libtinfo.so
348 ncurses-$(NCURSES_VERSION).tgz:
350 wget -O $@-t ftp://invisible-island.net/ncurses/current/ncurses-$(NCURSES_VERSION).tgz
353 # Cross-compile bash.
354 stage3-chroot/bin/bash: bash-$(BASH_VERSION).tar.gz
356 cd bash-$(BASH_VERSION) && \
357 PATH=$(ROOT)/fixed-gcc:$$PATH \
358 ./configure --host=riscv64-unknown-linux-gnu \
359 --prefix=/usr --libdir=/usr/lib64
360 cd bash-$(BASH_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
361 cd bash-$(BASH_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
363 bash-$(BASH_VERSION).tar.gz:
365 wget -O $@-t ftp://ftp.gnu.org/gnu/bash/bash-$(BASH_VERSION).tar.gz
368 # Cross-compile coreutils. Bleah, coreutils cross-compilation is
369 # known-broken and upstream don't care, hence the 'touch' command.
371 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
373 stage3-chroot/bin/ls: coreutils-$(COREUTILS_VERSION).tar.xz
374 rm -rf coreutils-$(COREUTILS_VERSION)
376 cd coreutils-$(COREUTILS_VERSION) && \
377 PATH=$(ROOT)/fixed-gcc:$$PATH \
378 ./configure --host=riscv64-unknown-linux-gnu \
379 --prefix=/usr --libdir=/usr/lib64
380 -cd coreutils-$(COREUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
381 cd coreutils-$(COREUTILS_VERSION)/man && \
382 for f in $(COREUTILS_PROGRAMS); do touch $$f.1; done
383 cd coreutils-$(COREUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
384 cd coreutils-$(COREUTILS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
386 coreutils-$(COREUTILS_VERSION).tar.xz:
388 wget -O $@-t ftp://ftp.gnu.org/gnu/coreutils/coreutils-$(COREUTILS_VERSION).tar.xz
391 # Cross-compile binutils.
392 stage3-chroot/usr/bin/as: binutils-$(BINUTILS_X_VERSION).tar.gz
393 rm -rf riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)
395 mkdir riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build
396 cd riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build && \
397 PATH=$(ROOT)/fixed-gcc:$$PATH \
399 --host=riscv64-unknown-linux-gnu \
400 --prefix=/usr --libdir=/usr/lib64
401 cd riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build && PATH=$(ROOT)/fixed-gcc:$$PATH make
402 cd riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build && make DESTDIR=$(ROOT)/stage3-chroot install
404 binutils-$(BINUTILS_X_VERSION).tar.gz:
406 wget -O $@-t https://github.com/riscv/riscv-binutils-gdb/archive/riscv-binutils-$(BINUTILS_X_VERSION).tar.gz
409 # Cross-compile GMP, MPFR and MPC (deps of GCC).
410 stage3-chroot/usr/lib64/libgmp.so.10: gmp-$(GMP_VERSION).tar.lz
411 rm -rf gmp-$(GMP_VERSION)
412 tar --lzip -xf gmp-$(GMP_VERSION).tar.lz
413 cd gmp-$(GMP_VERSION) && \
414 PATH=$(ROOT)/fixed-gcc:$$PATH \
415 ./configure --host=riscv64-unknown-linux-gnu \
416 --prefix=/usr --libdir=/usr/lib64
417 cd gmp-$(GMP_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
418 cd gmp-$(GMP_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
419 cd stage3-chroot/usr/lib && ln -s ../lib64/libgmp.so
421 gmp-$(GMP_VERSION).tar.lz:
423 wget -O $@-t https://gmplib.org/download/gmp/gmp-$(GMP_VERSION).tar.lz
426 stage3-chroot/usr/lib64/libmpfr.so.4: mpfr-$(MPFR_VERSION).tar.gz
427 rm -rf mpfr-$(MPFR_VERSION)
428 tar -zxf mpfr-$(MPFR_VERSION).tar.gz
429 cd mpfr-$(MPFR_VERSION) && \
430 PATH=$(ROOT)/fixed-gcc:$$PATH \
431 ./configure --host=riscv64-unknown-linux-gnu \
432 --prefix=/usr --libdir=/usr/lib64 \
433 --with-gmp=$(ROOT)/stage3-chroot/usr
434 cd mpfr-$(MPFR_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
435 cd mpfr-$(MPFR_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
436 cd stage3-chroot/usr/lib && ln -s ../lib64/libmpfr.so
437 rm -f stage3-chroot/usr/lib64/*.la
439 mpfr-$(MPFR_VERSION).tar.gz:
441 wget -O $@-t http://www.mpfr.org/mpfr-current/mpfr-$(MPFR_VERSION).tar.gz
444 stage3-chroot/usr/lib64/libmpc.so.3: mpc-$(MPC_VERSION).tar.gz
445 rm -rf mpc-$(MPC_VERSION)
446 tar -zxf mpc-$(MPC_VERSION).tar.gz
447 cd mpc-$(MPC_VERSION) && \
448 PATH=$(ROOT)/fixed-gcc:$$PATH \
449 ./configure --host=riscv64-unknown-linux-gnu \
450 --prefix=/usr --libdir=/usr/lib64 \
451 --with-gmp=$(ROOT)/stage3-chroot/usr \
452 --with-mpfr=$(ROOT)/stage3-chroot/usr
453 cd mpc-$(MPC_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
454 cd mpc-$(MPC_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
455 cd stage3-chroot/usr/lib && ln -s ../lib64/libmpc.so
456 rm -f stage3-chroot/usr/lib64/*.la
458 mpc-$(MPC_VERSION).tar.gz:
460 wget -O $@-t ftp://ftp.gnu.org/gnu/mpc/mpc-$(MPC_VERSION).tar.gz
464 stage3-chroot/usr/bin/gcc: gcc-$(GCC_X_VERSION).tar.gz
465 rm -rf riscv-gcc-riscv-gcc-$(GCC_X_VERSION)
467 mkdir riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build
468 cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && \
469 PATH=$(ROOT)/fixed-gcc:$$PATH \
471 --host=riscv64-unknown-linux-gnu \
472 --prefix=/usr --libdir=/usr/lib64 \
475 --enable-languages=c,c++ \
476 --disable-libmudflap \
478 --disable-libquadmath \
481 # XXX use make all & make install here. However building libgcc
482 # fails, see 'broken-gcc.log'.
483 cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && PATH=$(ROOT)/fixed-gcc:$$PATH make all-gcc
484 cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && make install-gcc DESTDIR=$(ROOT)/stage3-chroot
486 gcc-$(GCC_X_VERSION).tar.gz:
488 wget -O $@-t https://github.com/riscv/riscv-gcc/archive/riscv-gcc-$(GCC_X_VERSION).tar.gz
491 # Cross-compile util-linux.
492 # XXX Be nice to fix ncurses/tinfo support which in theory should work.
493 stage3-chroot/usr/bin/mount: util-linux-$(UTIL_LINUX_VERSION).tar.xz
494 rm -rf util-linux-$(UTIL_LINUX_VERSION)
496 cd util-linux-$(UTIL_LINUX_VERSION) && \
497 PATH=$(ROOT)/fixed-gcc:$$PATH \
499 --host=riscv64-unknown-linux-gnu \
500 --prefix=/usr --libdir=/usr/lib64 \
505 --disable-makeinstall-chown \
506 --enable-static-programs=mount
507 cd util-linux-$(UTIL_LINUX_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
508 cd util-linux-$(UTIL_LINUX_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
509 rm -f stage3-chroot/usr/lib64/*.la
511 util-linux-$(UTIL_LINUX_VERSION).tar.xz:
513 wget -O $@-t ftp://ftp.kernel.org/pub/linux/utils/util-linux/v$(UTIL_LINUX_VERSION)/util-linux-$(UTIL_LINUX_VERSION).tar.xz
516 # Cross-compile GNU tar.
517 stage3-chroot/usr/bin/tar: tar-$(TAR_VERSION).tar.xz
518 rm -rf tar-$(TAR_VERSION)
520 cd tar-$(TAR_VERSION) && \
521 PATH=$(ROOT)/fixed-gcc:$$PATH \
523 --host=riscv64-unknown-linux-gnu \
524 --prefix=/usr --libdir=/usr/lib64
525 cd tar-$(TAR_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
526 cd tar-$(TAR_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
528 tar-$(TAR_VERSION).tar.xz:
530 wget -O $@-t https://ftp.gnu.org/gnu/tar/tar-$(TAR_VERSION).tar.xz
533 # Cross-compile GNU gzip.
534 stage3-chroot/usr/bin/gzip: gzip-$(GZIP_VERSION).tar.gz
535 rm -rf gzip-$(GZIP_VERSION)
537 cd gzip-$(GZIP_VERSION) && \
538 PATH=$(ROOT)/fixed-gcc:$$PATH \
540 --host=riscv64-unknown-linux-gnu \
541 --prefix=/usr --libdir=/usr/lib64
542 cd gzip-$(GZIP_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
543 cd gzip-$(GZIP_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
545 gzip-$(GZIP_VERSION).tar.gz:
547 wget -O $@-t https://ftp.gnu.org/gnu/gzip/gzip-$(GZIP_VERSION).tar.gz
550 # Cross-compile zlib.
551 stage3-chroot/usr/lib64/libz.so: zlib-$(ZLIB_VERSION).tar.gz
552 rm -rf zlib-$(ZLIB_VERSION)
554 cd zlib-$(ZLIB_VERSION) && \
555 PATH=$(ROOT)/fixed-gcc:$$PATH \
556 CC=riscv64-unknown-linux-gnu-gcc \
557 CFLAGS="-I$(ROOT)/stage3-chroot/usr/include -L$(ROOT)/stage3-chroot/usr/lib" \
559 --prefix=/usr --libdir=/usr/lib64
560 cd zlib-$(ZLIB_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make shared
561 cd zlib-$(ZLIB_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
563 zlib-$(ZLIB_VERSION).tar.gz:
565 wget -O $@-t http://zlib.net/zlib-$(ZLIB_VERSION).tar.gz
568 # Cross-compile file/libmagic.
569 stage3-chroot/usr/bin/file: file-$(FILE_VERSION).tar.gz
570 rm -rf file-$(FILE_VERSION)
572 cd file-$(FILE_VERSION) && \
573 PATH=$(ROOT)/fixed-gcc:$$PATH \
574 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
576 --host=riscv64-unknown-linux-gnu \
577 --prefix=/usr --libdir=/usr/lib64 \
578 --disable-static --enable-shared
579 cd file-$(FILE_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
580 cd file-$(FILE_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
581 rm -f stage3-chroot/usr/lib64/*.la
583 file-$(FILE_VERSION).tar.gz:
585 wget -O $@-t ftp://ftp.astron.com/pub/file/file-$(FILE_VERSION).tar.gz
588 # Cross-compile popt.
589 stage3-chroot/usr/lib64/libpopt.so: popt-$(POPT_VERSION).tar.gz
590 rm -rf popt-$(POPT_VERSION)
592 cd popt-$(POPT_VERSION) && \
593 PATH=$(ROOT)/fixed-gcc:$$PATH \
594 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
596 --host=riscv64-unknown-linux-gnu \
597 --prefix=/usr --libdir=/usr/lib64 \
598 --disable-static --enable-shared
599 cd popt-$(POPT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
600 cd popt-$(POPT_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
601 rm -f stage3-chroot/usr/lib64/*.la
603 popt-$(POPT_VERSION).tar.gz:
605 wget -O $@-t http://rpm5.org/files/popt/popt-$(POPT_VERSION).tar.gz
608 # Cross-compile beecrypt.
609 stage3-chroot/usr/lib64/libbeecrypt.so: beecrypt-$(BEECRYPT_VERSION).tar.gz
610 rm -rf beecrypt-$(BEECRYPT_VERSION)
612 cd beecrypt-$(BEECRYPT_VERSION) && patch -p0 < ../beecrypt-disable-cplusplus.patch
613 cd beecrypt-$(BEECRYPT_VERSION) && autoreconf -i
614 cd beecrypt-$(BEECRYPT_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 --without-cplusplus \
625 cd beecrypt-$(BEECRYPT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
626 cd beecrypt-$(BEECRYPT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot V=1
627 chrpath -d stage3-chroot/usr/lib64/libbeecrypt.so.*
628 rm -f stage3-chroot/usr/lib64/*.la
630 beecrypt-$(BEECRYPT_VERSION).tar.gz:
632 wget -O $@-t http://downloads.sourceforge.net/sourceforge/beecrypt/beecrypt-$(BEECRYPT_VERSION).tar.gz
635 # Cross-compile RPM / rpmbuild.
636 # We build this from a git commit, with a few hacks to the configure
638 stage3-chroot/usr/bin/rpm: rpm-$(RPM_SHORT_COMMIT).tar.gz db-$(BDB_VERSION).tar.gz
639 rm -rf rpm-$(RPM_SHORT_COMMIT)
640 tar -zxf rpm-$(RPM_SHORT_COMMIT).tar.gz
641 tar -zxf db-$(BDB_VERSION).tar.gz -C rpm-$(RPM_SHORT_COMMIT)
642 cd rpm-$(RPM_SHORT_COMMIT) && ln -s db-$(BDB_VERSION) db
643 cd rpm-$(RPM_SHORT_COMMIT) && patch -p1 < ../rpm-hacks.patch
644 cd rpm-$(RPM_SHORT_COMMIT) && autoreconf -i
645 cd rpm-$(RPM_SHORT_COMMIT) && \
646 PATH=$(ROOT)/fixed-gcc:$$PATH \
647 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
649 --host=riscv64-unknown-linux-gnu \
650 --prefix=/usr --libdir=/usr/lib64 \
652 --without-libarchive \
656 --without-external-db \
659 cd rpm-$(RPM_SHORT_COMMIT) && \
660 sed -i 's|^sys_lib_dlsearch_path_spec="/lib64|sys_lib_dlsearch_path_spec="$(ROOT)/stage3-chroot/usr/lib64 /lib64|g' libtool
661 cd rpm-$(RPM_SHORT_COMMIT) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
662 cd rpm-$(RPM_SHORT_COMMIT) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
663 rm -f stage3-chroot/usr/lib64/*.la
665 rpm-$(RPM_SHORT_COMMIT).tar.gz:
667 wget -O $@-t 'http://rpm.org/gitweb?p=rpm.git;a=snapshot;h=$(RPM_COMMIT);sf=tgz'
670 db-$(BDB_VERSION).tar.gz:
672 wget -O $@-t http://download.oracle.com/berkeley-db/db-$(BDB_VERSION).tar.gz
675 # Create an /init script.
676 stage3-chroot/init: init.sh
677 install -m 0755 $^ $@
679 # Create the stage3 disk image.
680 # Note `-s +...' adds spare space to the disk image.
681 stage3-disk.img: stage3-chroot
682 cd stage3-chroot && virt-make-fs . ../$@ -t ext2 -F raw -s +4G
684 # Upload the compressed disk image.
685 upload-stage3: stage3-disk.img.xz
686 scp $^ tick:public_html/riscv/
687 stage3-disk.img.xz: stage3-disk.img
691 # Helper which boots stage3 disk image in spike.
692 boot-stage3-in-spike: stage3-disk.img stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
693 spike +disk=stage3-disk.img \
694 /usr/bin/bbl stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
696 # Helper which boots stage3 disk image in qemu.
697 boot-stage3-in-qemu: stage3-disk.img stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
698 qemu-system-riscv -kernel /usr/bin/bbl \
699 -append ./stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux \
700 -drive file=stage3-disk.img,format=raw -nographic