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 --with-termlib=tinfo \
346 cd ncurses-$(NCURSES_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
347 cd ncurses-$(NCURSES_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
349 ncurses-$(NCURSES_VERSION).tgz:
351 wget -O $@-t ftp://invisible-island.net/ncurses/current/ncurses-$(NCURSES_VERSION).tgz
354 # Cross-compile bash.
355 stage3-chroot/bin/bash: bash-$(BASH_VERSION).tar.gz
357 cd bash-$(BASH_VERSION) && \
358 PATH=$(ROOT)/fixed-gcc:$$PATH \
359 ./configure --host=riscv64-unknown-linux-gnu \
360 --prefix=/usr --libdir=/usr/lib64
361 cd bash-$(BASH_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
362 cd bash-$(BASH_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
364 bash-$(BASH_VERSION).tar.gz:
366 wget -O $@-t ftp://ftp.gnu.org/gnu/bash/bash-$(BASH_VERSION).tar.gz
369 # Cross-compile coreutils. Bleah, coreutils cross-compilation is
370 # known-broken and upstream don't care, hence the 'touch' command.
372 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
374 stage3-chroot/bin/ls: coreutils-$(COREUTILS_VERSION).tar.xz
375 rm -rf coreutils-$(COREUTILS_VERSION)
377 cd coreutils-$(COREUTILS_VERSION) && \
378 PATH=$(ROOT)/fixed-gcc:$$PATH \
379 ./configure --host=riscv64-unknown-linux-gnu \
380 --prefix=/usr --libdir=/usr/lib64
381 -cd coreutils-$(COREUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
382 cd coreutils-$(COREUTILS_VERSION)/man && \
383 for f in $(COREUTILS_PROGRAMS); do touch $$f.1; done
384 cd coreutils-$(COREUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
385 cd coreutils-$(COREUTILS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
387 coreutils-$(COREUTILS_VERSION).tar.xz:
389 wget -O $@-t ftp://ftp.gnu.org/gnu/coreutils/coreutils-$(COREUTILS_VERSION).tar.xz
392 # Cross-compile binutils.
393 stage3-chroot/usr/bin/as: binutils-$(BINUTILS_X_VERSION).tar.gz
394 rm -rf riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)
396 mkdir riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build
397 cd riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build && \
398 PATH=$(ROOT)/fixed-gcc:$$PATH \
400 --host=riscv64-unknown-linux-gnu \
401 --prefix=/usr --libdir=/usr/lib64
402 cd riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build && PATH=$(ROOT)/fixed-gcc:$$PATH make
403 cd riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build && make DESTDIR=$(ROOT)/stage3-chroot install
405 binutils-$(BINUTILS_X_VERSION).tar.gz:
407 wget -O $@-t https://github.com/riscv/riscv-binutils-gdb/archive/riscv-binutils-$(BINUTILS_X_VERSION).tar.gz
410 # Cross-compile GMP, MPFR and MPC (deps of GCC).
411 stage3-chroot/usr/lib64/libgmp.so.10: gmp-$(GMP_VERSION).tar.lz
412 rm -rf gmp-$(GMP_VERSION)
413 tar --lzip -xf gmp-$(GMP_VERSION).tar.lz
414 cd gmp-$(GMP_VERSION) && \
415 PATH=$(ROOT)/fixed-gcc:$$PATH \
416 ./configure --host=riscv64-unknown-linux-gnu \
417 --prefix=/usr --libdir=/usr/lib64
418 cd gmp-$(GMP_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
419 cd gmp-$(GMP_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
420 cd stage3-chroot/usr/lib && ln -s ../lib64/libgmp.so
422 gmp-$(GMP_VERSION).tar.lz:
424 wget -O $@-t https://gmplib.org/download/gmp/gmp-$(GMP_VERSION).tar.lz
427 stage3-chroot/usr/lib64/libmpfr.so.4: mpfr-$(MPFR_VERSION).tar.gz
428 rm -rf mpfr-$(MPFR_VERSION)
429 tar -zxf mpfr-$(MPFR_VERSION).tar.gz
430 cd mpfr-$(MPFR_VERSION) && \
431 PATH=$(ROOT)/fixed-gcc:$$PATH \
432 ./configure --host=riscv64-unknown-linux-gnu \
433 --prefix=/usr --libdir=/usr/lib64 \
434 --with-gmp=$(ROOT)/stage3-chroot/usr
435 cd mpfr-$(MPFR_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
436 cd mpfr-$(MPFR_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
437 cd stage3-chroot/usr/lib && ln -s ../lib64/libmpfr.so
438 rm -f stage3-chroot/usr/lib64/*.la
440 mpfr-$(MPFR_VERSION).tar.gz:
442 wget -O $@-t http://www.mpfr.org/mpfr-current/mpfr-$(MPFR_VERSION).tar.gz
445 stage3-chroot/usr/lib64/libmpc.so.3: mpc-$(MPC_VERSION).tar.gz
446 rm -rf mpc-$(MPC_VERSION)
447 tar -zxf mpc-$(MPC_VERSION).tar.gz
448 cd mpc-$(MPC_VERSION) && \
449 PATH=$(ROOT)/fixed-gcc:$$PATH \
450 ./configure --host=riscv64-unknown-linux-gnu \
451 --prefix=/usr --libdir=/usr/lib64 \
452 --with-gmp=$(ROOT)/stage3-chroot/usr \
453 --with-mpfr=$(ROOT)/stage3-chroot/usr
454 cd mpc-$(MPC_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
455 cd mpc-$(MPC_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
456 cd stage3-chroot/usr/lib && ln -s ../lib64/libmpc.so
457 rm -f stage3-chroot/usr/lib64/*.la
459 mpc-$(MPC_VERSION).tar.gz:
461 wget -O $@-t ftp://ftp.gnu.org/gnu/mpc/mpc-$(MPC_VERSION).tar.gz
465 stage3-chroot/usr/bin/gcc: gcc-$(GCC_X_VERSION).tar.gz
466 rm -rf riscv-gcc-riscv-gcc-$(GCC_X_VERSION)
468 mkdir riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build
469 cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && \
470 PATH=$(ROOT)/fixed-gcc:$$PATH \
472 --host=riscv64-unknown-linux-gnu \
473 --prefix=/usr --libdir=/usr/lib64 \
476 --enable-languages=c,c++ \
477 --disable-libmudflap \
479 --disable-libquadmath \
482 # XXX use make all & make install here. However building libgcc
483 # fails, see 'broken-gcc.log'.
484 cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && PATH=$(ROOT)/fixed-gcc:$$PATH make all-gcc
485 cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && make install-gcc DESTDIR=$(ROOT)/stage3-chroot
487 gcc-$(GCC_X_VERSION).tar.gz:
489 wget -O $@-t https://github.com/riscv/riscv-gcc/archive/riscv-gcc-$(GCC_X_VERSION).tar.gz
492 # Cross-compile util-linux.
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 \
498 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
500 --host=riscv64-unknown-linux-gnu \
501 --prefix=/usr --libdir=/usr/lib64 \
504 --disable-makeinstall-chown \
505 --enable-static-programs=mount
506 cd util-linux-$(UTIL_LINUX_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
507 cd util-linux-$(UTIL_LINUX_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
508 rm -f stage3-chroot/usr/lib64/*.la
510 util-linux-$(UTIL_LINUX_VERSION).tar.xz:
512 wget -O $@-t ftp://ftp.kernel.org/pub/linux/utils/util-linux/v$(UTIL_LINUX_VERSION)/util-linux-$(UTIL_LINUX_VERSION).tar.xz
515 # Cross-compile GNU tar.
516 stage3-chroot/usr/bin/tar: tar-$(TAR_VERSION).tar.xz
517 rm -rf tar-$(TAR_VERSION)
519 cd tar-$(TAR_VERSION) && \
520 PATH=$(ROOT)/fixed-gcc:$$PATH \
522 --host=riscv64-unknown-linux-gnu \
523 --prefix=/usr --libdir=/usr/lib64
524 cd tar-$(TAR_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
525 cd tar-$(TAR_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
527 tar-$(TAR_VERSION).tar.xz:
529 wget -O $@-t https://ftp.gnu.org/gnu/tar/tar-$(TAR_VERSION).tar.xz
532 # Cross-compile GNU gzip.
533 stage3-chroot/usr/bin/gzip: gzip-$(GZIP_VERSION).tar.gz
534 rm -rf gzip-$(GZIP_VERSION)
536 cd gzip-$(GZIP_VERSION) && \
537 PATH=$(ROOT)/fixed-gcc:$$PATH \
539 --host=riscv64-unknown-linux-gnu \
540 --prefix=/usr --libdir=/usr/lib64
541 cd gzip-$(GZIP_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
542 cd gzip-$(GZIP_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
544 gzip-$(GZIP_VERSION).tar.gz:
546 wget -O $@-t https://ftp.gnu.org/gnu/gzip/gzip-$(GZIP_VERSION).tar.gz
549 # Cross-compile zlib.
550 stage3-chroot/usr/lib64/libz.so: zlib-$(ZLIB_VERSION).tar.gz
551 rm -rf zlib-$(ZLIB_VERSION)
553 cd zlib-$(ZLIB_VERSION) && \
554 PATH=$(ROOT)/fixed-gcc:$$PATH \
555 CC=riscv64-unknown-linux-gnu-gcc \
556 CFLAGS="-I$(ROOT)/stage3-chroot/usr/include -L$(ROOT)/stage3-chroot/usr/lib" \
558 --prefix=/usr --libdir=/usr/lib64
559 cd zlib-$(ZLIB_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make shared
560 cd zlib-$(ZLIB_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
562 zlib-$(ZLIB_VERSION).tar.gz:
564 wget -O $@-t http://zlib.net/zlib-$(ZLIB_VERSION).tar.gz
567 # Cross-compile file/libmagic.
568 stage3-chroot/usr/bin/file: file-$(FILE_VERSION).tar.gz
569 rm -rf file-$(FILE_VERSION)
571 cd file-$(FILE_VERSION) && \
572 PATH=$(ROOT)/fixed-gcc:$$PATH \
573 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
575 --host=riscv64-unknown-linux-gnu \
576 --prefix=/usr --libdir=/usr/lib64 \
577 --disable-static --enable-shared
578 cd file-$(FILE_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
579 cd file-$(FILE_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
580 rm -f stage3-chroot/usr/lib64/*.la
582 file-$(FILE_VERSION).tar.gz:
584 wget -O $@-t ftp://ftp.astron.com/pub/file/file-$(FILE_VERSION).tar.gz
587 # Cross-compile popt.
588 stage3-chroot/usr/lib64/libpopt.so: popt-$(POPT_VERSION).tar.gz
589 rm -rf popt-$(POPT_VERSION)
591 cd popt-$(POPT_VERSION) && \
592 PATH=$(ROOT)/fixed-gcc:$$PATH \
593 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
595 --host=riscv64-unknown-linux-gnu \
596 --prefix=/usr --libdir=/usr/lib64 \
597 --disable-static --enable-shared
598 cd popt-$(POPT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
599 cd popt-$(POPT_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
600 rm -f stage3-chroot/usr/lib64/*.la
602 popt-$(POPT_VERSION).tar.gz:
604 wget -O $@-t http://rpm5.org/files/popt/popt-$(POPT_VERSION).tar.gz
607 # Cross-compile beecrypt.
608 stage3-chroot/usr/lib64/libbeecrypt.so: beecrypt-$(BEECRYPT_VERSION).tar.gz
609 rm -rf beecrypt-$(BEECRYPT_VERSION)
611 cd beecrypt-$(BEECRYPT_VERSION) && patch -p0 < ../beecrypt-disable-cplusplus.patch
612 cd beecrypt-$(BEECRYPT_VERSION) && autoreconf -i
613 cd beecrypt-$(BEECRYPT_VERSION) && \
614 PATH=$(ROOT)/fixed-gcc:$$PATH \
615 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
617 --host=riscv64-unknown-linux-gnu \
618 --prefix=/usr --libdir=/usr/lib64 \
619 --without-cplusplus \
624 cd beecrypt-$(BEECRYPT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
625 cd beecrypt-$(BEECRYPT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot V=1
626 chrpath -d stage3-chroot/usr/lib64/libbeecrypt.so.*
627 rm -f stage3-chroot/usr/lib64/*.la
629 beecrypt-$(BEECRYPT_VERSION).tar.gz:
631 wget -O $@-t http://downloads.sourceforge.net/sourceforge/beecrypt/beecrypt-$(BEECRYPT_VERSION).tar.gz
634 # Cross-compile RPM / rpmbuild.
635 # We build this from a git commit, with a few hacks to the configure
637 stage3-chroot/usr/bin/rpm: rpm-$(RPM_SHORT_COMMIT).tar.gz db-$(BDB_VERSION).tar.gz
638 rm -rf rpm-$(RPM_SHORT_COMMIT)
639 tar -zxf rpm-$(RPM_SHORT_COMMIT).tar.gz
640 tar -zxf db-$(BDB_VERSION).tar.gz -C rpm-$(RPM_SHORT_COMMIT)
641 cd rpm-$(RPM_SHORT_COMMIT) && ln -s db-$(BDB_VERSION) db
642 cd rpm-$(RPM_SHORT_COMMIT) && patch -p1 < ../rpm-hacks.patch
643 cd rpm-$(RPM_SHORT_COMMIT) && autoreconf -i
644 cd rpm-$(RPM_SHORT_COMMIT) && \
645 PATH=$(ROOT)/fixed-gcc:$$PATH \
646 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
648 --host=riscv64-unknown-linux-gnu \
649 --prefix=/usr --libdir=/usr/lib64 \
651 --without-libarchive \
655 --without-external-db \
658 cd rpm-$(RPM_SHORT_COMMIT) && \
659 sed -i 's|^sys_lib_dlsearch_path_spec="/lib64|sys_lib_dlsearch_path_spec="$(ROOT)/stage3-chroot/usr/lib64 /lib64|g' libtool
660 cd rpm-$(RPM_SHORT_COMMIT) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
661 cd rpm-$(RPM_SHORT_COMMIT) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
662 rm -f stage3-chroot/usr/lib64/*.la
664 rpm-$(RPM_SHORT_COMMIT).tar.gz:
666 wget -O $@-t 'http://rpm.org/gitweb?p=rpm.git;a=snapshot;h=$(RPM_COMMIT);sf=tgz'
669 db-$(BDB_VERSION).tar.gz:
671 wget -O $@-t http://download.oracle.com/berkeley-db/db-$(BDB_VERSION).tar.gz
674 # Create an /init script.
675 stage3-chroot/init: init.sh
676 install -m 0755 $^ $@
678 # Create the stage3 disk image.
679 # Note `-s +...' adds spare space to the disk image.
680 stage3-disk.img: stage3-chroot
681 cd stage3-chroot && virt-make-fs . ../$@ -t ext2 -F raw -s +4G
683 # Upload the compressed disk image.
684 upload-stage3: stage3-disk.img.xz
685 scp $^ tick:public_html/riscv/
686 stage3-disk.img.xz: stage3-disk.img
690 # Helper which boots stage3 disk image in spike.
691 boot-stage3-in-spike: stage3-disk.img stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
692 spike +disk=stage3-disk.img \
693 /usr/bin/bbl stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
695 # Helper which boots stage3 disk image in qemu.
696 boot-stage3-in-qemu: stage3-disk.img stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
697 qemu-system-riscv -kernel /usr/bin/bbl \
698 -append ./stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux \
699 -drive file=stage3-disk.img,format=raw -nographic