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 installed (on host) version, otherwise:
57 # "Cannot use the installed version of file (xx) to cross-compile file yy"
60 BEECRYPT_VERSION = 4.2.1
61 RPM_COMMIT = 95712183458748ea6cafebac1bdd5daa097d9bee
62 RPM_SHORT_COMMIT = 9571218
68 all: stage1 stage2 stage3 stage4
72 stage1: stage1-riscv-qemu/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz \
73 stage1-riscv-qemu/riscv-qemu.spec \
74 stamp-riscv-qemu-installed \
75 stage1-riscv-fesvr/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz \
76 stage1-riscv-fesvr/riscv-fesvr.spec \
77 stamp-riscv-fesvr-installed \
78 stage1-riscv-isa-sim/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz \
79 stage1-riscv-isa-sim/riscv-isa-sim.spec \
80 stamp-riscv-isa-sim-installed
82 stage1-riscv-qemu/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz:
84 wget -O $@-t 'https://github.com/riscv/riscv-qemu/archive/$(RISCV_QEMU_COMMIT)/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz'
87 stage1-riscv-qemu/riscv-qemu.spec: stage1-riscv-qemu/riscv-qemu.spec.in
88 sed -e 's/@COMMIT@/$(RISCV_QEMU_COMMIT)/g' \
89 -e 's/@SHORTCOMMIT@/$(RISCV_QEMU_SHORTCOMMIT)/g' \
93 stamp-riscv-qemu-installed:
95 @rpm -q riscv-qemu >/dev/null || { \
96 echo "ERROR: You must install riscv-qemu:"; \
98 echo " dnf copr enable rjones/riscv"; \
99 echo " dnf install riscv-qemu"; \
101 echo "OR: you can build it yourself from the stage1-riscv-qemu directory."; \
105 @qemu-system-riscv --version || { \
106 echo "ERROR: qemu-system-riscv is not working."; \
107 echo "Make sure you installed the riscv-qemu package."; \
112 stage1-riscv-fesvr/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz:
114 wget -O $@-t 'https://github.com/riscv/riscv-fesvr/archive/$(RISCV_FESVR_COMMIT)/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz'
117 stage1-riscv-fesvr/riscv-fesvr.spec: stage1-riscv-fesvr/riscv-fesvr.spec.in
118 sed -e 's/@COMMIT@/$(RISCV_FESVR_COMMIT)/g' \
119 -e 's/@SHORTCOMMIT@/$(RISCV_FESVR_SHORTCOMMIT)/g' \
123 stamp-riscv-fesvr-installed:
125 @rpm -q riscv-fesvr >/dev/null || { \
126 echo "ERROR: You must install riscv-fesvr:"; \
128 echo " dnf copr enable rjones/riscv"; \
129 echo " dnf install riscv-fesvr"; \
131 echo "OR: you can build it yourself from the stage1-riscv-fesvr directory."; \
137 stage1-riscv-isa-sim/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz:
139 wget -O $@-t 'https://github.com/riscv/riscv-isa-sim/archive/$(RISCV_ISA_SIM_COMMIT)/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz'
142 stage1-riscv-isa-sim/riscv-isa-sim.spec: stage1-riscv-isa-sim/riscv-isa-sim.spec.in
143 sed -e 's/@COMMIT@/$(RISCV_ISA_SIM_COMMIT)/g' \
144 -e 's/@SHORTCOMMIT@/$(RISCV_ISA_SIM_SHORTCOMMIT)/g' \
148 stamp-riscv-isa-sim-installed:
150 @rpm -q riscv-isa-sim >/dev/null || { \
151 echo "ERROR: You must install riscv-isa-sim:"; \
153 echo " dnf copr enable rjones/riscv"; \
154 echo " dnf install riscv-isa-sim"; \
156 echo "OR: you can build it yourself from the stage1-riscv-isa-sim directory."; \
164 stage2: stage2-riscv-gnu-toolchain/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz \
165 stage2-riscv-gnu-toolchain/binutils-$(BINUTILS_VERSION).tar.gz \
166 stage2-riscv-gnu-toolchain/gcc-$(GCC_VERSION).tar.gz \
167 stage2-riscv-gnu-toolchain/glibc-$(GLIBC_VERSION).tar.gz \
168 stage2-riscv-gnu-toolchain/newlib-$(NEWLIB_VERSION).tar.gz \
169 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec \
170 stamp-riscv-gnu-toolchain-installed \
171 stage2-riscv-pk/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz \
172 stage2-riscv-pk/riscv-pk.spec \
173 stamp-riscv-pk-installed
175 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz:
177 wget -O $@-t https://github.com/lowRISC/riscv-gnu-toolchain/archive/$(RISCV_GNU_TOOLCHAIN_COMMIT)/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz
180 stage2-riscv-gnu-toolchain/binutils-$(BINUTILS_VERSION).tar.gz:
182 wget -O $@-t http://mirrors.kernel.org/gnu/binutils/binutils-$(BINUTILS_VERSION).tar.gz
185 # GCC 5 no longer compiles with GCC 6 unless we patch it.
186 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69959
187 stage2-riscv-gnu-toolchain/gcc-$(GCC_VERSION).tar.gz:
189 wget -O $@-t http://mirrors.kernel.org/gnu/gcc/gcc-$(GCC_VERSION)/gcc-$(GCC_VERSION).tar.gz
191 cd gcc-$(GCC_VERSION) && patch -p0 < ../stage2-riscv-gnu-toolchain/gcc-5-fix-compilation-with-gcc-6.patch
192 tar zcf $@-t gcc-$(GCC_VERSION)
193 rm -r gcc-$(GCC_VERSION)
196 stage2-riscv-gnu-toolchain/glibc-$(GLIBC_VERSION).tar.gz:
198 wget -O $@-t http://mirrors.kernel.org/gnu/glibc/glibc-$(GLIBC_VERSION).tar.gz
201 stage2-riscv-gnu-toolchain/newlib-$(NEWLIB_VERSION).tar.gz:
203 wget -O $@-t ftp://sourceware.org/pub/newlib/newlib-$(NEWLIB_VERSION).tar.gz
206 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec: stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec.in
207 sed -e 's/@COMMIT@/$(RISCV_GNU_TOOLCHAIN_COMMIT)/g' \
208 -e 's/@SHORTCOMMIT@/$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT)/g' \
209 -e 's/@BINUTILS_VERSION@/$(BINUTILS_VERSION)/g' \
210 -e 's/@GCC_VERSION@/$(GCC_VERSION)/g' \
211 -e 's/@GLIBC_VERSION@/$(GLIBC_VERSION)/g' \
212 -e 's/@NEWLIB_VERSION@/$(NEWLIB_VERSION)/g' \
216 stamp-riscv-gnu-toolchain-installed:
218 @rpm -q riscv-gnu-toolchain >/dev/null || { \
219 echo "ERROR: You must install riscv-gnu-toolchain:"; \
221 echo " dnf copr enable rjones/riscv"; \
222 echo " dnf install riscv-gnu-toolchain"; \
224 echo "OR: you can build it yourself from the stage2-riscv-gnu-toolchain directory."; \
228 @riscv64-unknown-elf-gcc --version || { \
229 echo "ERROR: riscv64-unknown-elf-gcc (cross compiler) is not working."; \
230 echo "Make sure you installed the riscv-gnu-toolchain package."; \
235 stage2-riscv-pk/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz:
237 wget -O $@-t https://github.com/lowRISC/riscv-pk/archive/$(RISCV_PK_COMMIT)/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz
240 stage2-riscv-pk/riscv-pk.spec: stage2-riscv-pk/riscv-pk.spec.in
241 sed -e 's/@COMMIT@/$(RISCV_PK_COMMIT)/g' \
242 -e 's/@SHORTCOMMIT@/$(RISCV_PK_SHORTCOMMIT)/g' \
246 stamp-riscv-pk-installed:
248 @rpm -q riscv-pk >/dev/null || { \
249 echo "ERROR: You must install riscv-pk:"; \
251 echo " dnf copr enable rjones/riscv"; \
252 echo " dnf install riscv-pk"; \
254 echo "OR: you can build it yourself from the stage2-riscv-pk directory."; \
262 stage3: stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux \
263 stage3-chroot-original/etc/fedora-release \
264 stage3-chroot/etc/fedora-release \
265 stage3-chroot/lib64/libc.so.6 \
266 stage3-chroot/usr/bin/tic \
267 stage3-chroot/bin/bash \
268 stage3-chroot/bin/ls \
269 stage3-chroot/usr/lib64/libgmp.so.10 \
270 stage3-chroot/usr/lib64/libmpfr.so.4 \
271 stage3-chroot/usr/lib64/libmpc.so.3 \
272 stage3-chroot/usr/bin/as \
273 stage3-chroot/usr/bin/gcc \
274 stage3-chroot/usr/bin/mount \
275 stage3-chroot/usr/bin/tar \
276 stage3-chroot/usr/bin/gzip \
277 stage3-chroot/usr/lib64/libz.so \
278 stage3-chroot/usr/bin/file \
279 stage3-chroot/usr/lib64/libpopt.so \
280 stage3-chroot/usr/lib64/libbeecrypt.so \
281 stage3-chroot/usr/bin/rpm \
282 stage3-chroot/usr/bin/nano \
283 stage3-chroot/usr/bin/grep \
284 stage3-chroot/usr/bin/less \
288 stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux:
289 rm -rf stage3-kernel/linux-$(KERNEL_VERSION)
290 cp -a $(LOCAL_LINUX_GIT_COPY) stage3-kernel/linux-$(KERNEL_VERSION) || { \
291 mkdir stage3-kernel/linux-$(KERNEL_VERSION) && \
292 cd stage3-kernel/linux-$(KERNEL_VERSION) && \
295 cd stage3-kernel/linux-$(KERNEL_VERSION) && \
296 git remote add riscv https://github.com/riscv/riscv-linux && \
298 git checkout -f linux-4.1.y-riscv && \
300 make ARCH=riscv defconfig
301 echo CONFIG_CMDLINE=\"root=/dev/htifblk0 init=/init\" >> stage3-kernel/linux-$(KERNEL_VERSION)/.config
302 echo CONFIG_CROSS_COMPILE=riscv64-unknown-elf- >> stage3-kernel/linux-$(KERNEL_VERSION)/.config
303 cd stage3-kernel/linux-$(KERNEL_VERSION) && \
304 make ARCH=riscv olddefconfig
305 cd stage3-kernel/linux-$(KERNEL_VERSION) && \
306 make ARCH=riscv vmlinux
309 # Build an original (x86-64) chroot using supermin. We then aim to
310 # rebuild (using cross-compiled versions) every ELF binary in this
312 stage3-chroot-original/etc/fedora-release:
313 rm -rf stage3-chroot-original tmp-supermin.d
314 supermin --prepare $(STAGE3_PACKAGES) -o tmp-supermin.d
315 supermin --build -f chroot tmp-supermin.d -o stage3-chroot-original
317 @echo -n "Total files in chroot: "
318 @find stage3-chroot-original -type f | wc -l
319 @echo -n "ELF files to be rebuilt: "
320 @find stage3-chroot-original -type f | xargs file -N | grep -E '\bELF.*LSB\b' | wc -l
322 # Copy the original chroot to the final chroot, remove all the ELF
324 stage3-chroot/etc/fedora-release: stage3-chroot-original/etc/fedora-release
326 cp -a stage3-chroot-original stage3-chroot
327 find stage3-chroot -type d | xargs chmod u+w
328 find stage3-chroot -type f | xargs chmod u+w
329 find stage3-chroot -type f | xargs file -N | grep -E '\bELF.*LSB\b' | awk -F: '{print $$1}' | xargs rm -f
330 rm -f stage3-chroot/lib64/libc.so.6
332 # Copy in compiled glibc from the riscv-gnu-toolchain sysroot. Only
333 # copy files and symlinks, leave the target directory structure
335 stage3-chroot/lib64/libc.so.6:
336 mkdir -p stage3-chroot/usr/lib/audit
337 mkdir -p stage3-chroot/usr/lib/gconv
338 for f in `cd /usr/sysroot && find -type f -o -type l`; do \
339 cp -d /usr/sysroot/$$f stage3-chroot/$$f; \
341 cd stage3-chroot/lib64 && for f in ../lib/*; do ln -sf $$f; done
343 # Cross-compile ncurses.
344 stage3-chroot/usr/bin/tic: ncurses-$(NCURSES_VERSION).tgz
346 cd ncurses-$(NCURSES_VERSION) && \
347 PATH=$(ROOT)/fixed-gcc:$$PATH \
348 ./configure --host=riscv64-unknown-linux-gnu \
349 --prefix=/usr --libdir=/usr/lib64 \
351 --with-termlib=tinfo \
353 cd ncurses-$(NCURSES_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
354 cd ncurses-$(NCURSES_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
356 ncurses-$(NCURSES_VERSION).tgz:
358 wget -O $@-t ftp://invisible-island.net/ncurses/current/ncurses-$(NCURSES_VERSION).tgz
361 # Cross-compile bash.
362 stage3-chroot/bin/bash: bash-$(BASH_VERSION).tar.gz
364 cd bash-$(BASH_VERSION) && \
365 PATH=$(ROOT)/fixed-gcc:$$PATH \
366 ./configure --host=riscv64-unknown-linux-gnu \
367 --prefix=/usr --libdir=/usr/lib64
368 cd bash-$(BASH_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
369 cd bash-$(BASH_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
371 bash-$(BASH_VERSION).tar.gz:
373 wget -O $@-t ftp://ftp.gnu.org/gnu/bash/bash-$(BASH_VERSION).tar.gz
376 # Cross-compile coreutils. Bleah, coreutils cross-compilation is
377 # known-broken and upstream don't care, hence the 'touch' command.
379 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
381 stage3-chroot/bin/ls: coreutils-$(COREUTILS_VERSION).tar.xz
382 rm -rf coreutils-$(COREUTILS_VERSION)
384 cd coreutils-$(COREUTILS_VERSION) && \
385 PATH=$(ROOT)/fixed-gcc:$$PATH \
386 ./configure --host=riscv64-unknown-linux-gnu \
387 --prefix=/usr --libdir=/usr/lib64
388 -cd coreutils-$(COREUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
389 cd coreutils-$(COREUTILS_VERSION)/man && \
390 for f in $(COREUTILS_PROGRAMS); do touch $$f.1; done
391 cd coreutils-$(COREUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
392 cd coreutils-$(COREUTILS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
394 coreutils-$(COREUTILS_VERSION).tar.xz:
396 wget -O $@-t ftp://ftp.gnu.org/gnu/coreutils/coreutils-$(COREUTILS_VERSION).tar.xz
399 # Cross-compile binutils.
400 stage3-chroot/usr/bin/as: binutils-$(BINUTILS_X_VERSION).tar.gz
401 rm -rf riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)
403 mkdir riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build
404 cd riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build && \
405 PATH=$(ROOT)/fixed-gcc:$$PATH \
407 --host=riscv64-unknown-linux-gnu \
408 --prefix=/usr --libdir=/usr/lib64
409 cd riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build && PATH=$(ROOT)/fixed-gcc:$$PATH make
410 cd riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build && make DESTDIR=$(ROOT)/stage3-chroot install
412 binutils-$(BINUTILS_X_VERSION).tar.gz:
414 wget -O $@-t https://github.com/riscv/riscv-binutils-gdb/archive/riscv-binutils-$(BINUTILS_X_VERSION).tar.gz
417 # Cross-compile GMP, MPFR and MPC (deps of GCC).
418 stage3-chroot/usr/lib64/libgmp.so.10: gmp-$(GMP_VERSION).tar.lz
419 rm -rf gmp-$(GMP_VERSION)
420 tar --lzip -xf gmp-$(GMP_VERSION).tar.lz
421 cd gmp-$(GMP_VERSION) && \
422 PATH=$(ROOT)/fixed-gcc:$$PATH \
423 ./configure --host=riscv64-unknown-linux-gnu \
424 --prefix=/usr --libdir=/usr/lib64
425 cd gmp-$(GMP_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
426 cd gmp-$(GMP_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
427 cd stage3-chroot/usr/lib && ln -s ../lib64/libgmp.so
429 gmp-$(GMP_VERSION).tar.lz:
431 wget -O $@-t https://gmplib.org/download/gmp/gmp-$(GMP_VERSION).tar.lz
434 stage3-chroot/usr/lib64/libmpfr.so.4: mpfr-$(MPFR_VERSION).tar.gz
435 rm -rf mpfr-$(MPFR_VERSION)
436 tar -zxf mpfr-$(MPFR_VERSION).tar.gz
437 cd mpfr-$(MPFR_VERSION) && \
438 PATH=$(ROOT)/fixed-gcc:$$PATH \
439 ./configure --host=riscv64-unknown-linux-gnu \
440 --prefix=/usr --libdir=/usr/lib64 \
441 --with-gmp=$(ROOT)/stage3-chroot/usr
442 cd mpfr-$(MPFR_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
443 cd mpfr-$(MPFR_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
444 cd stage3-chroot/usr/lib && ln -s ../lib64/libmpfr.so
445 rm -f stage3-chroot/usr/lib64/*.la
447 mpfr-$(MPFR_VERSION).tar.gz:
449 wget -O $@-t http://www.mpfr.org/mpfr-current/mpfr-$(MPFR_VERSION).tar.gz
452 stage3-chroot/usr/lib64/libmpc.so.3: mpc-$(MPC_VERSION).tar.gz
453 rm -rf mpc-$(MPC_VERSION)
454 tar -zxf mpc-$(MPC_VERSION).tar.gz
455 cd mpc-$(MPC_VERSION) && \
456 PATH=$(ROOT)/fixed-gcc:$$PATH \
457 ./configure --host=riscv64-unknown-linux-gnu \
458 --prefix=/usr --libdir=/usr/lib64 \
459 --with-gmp=$(ROOT)/stage3-chroot/usr \
460 --with-mpfr=$(ROOT)/stage3-chroot/usr
461 cd mpc-$(MPC_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
462 cd mpc-$(MPC_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
463 cd stage3-chroot/usr/lib && ln -s ../lib64/libmpc.so
464 rm -f stage3-chroot/usr/lib64/*.la
466 mpc-$(MPC_VERSION).tar.gz:
468 wget -O $@-t ftp://ftp.gnu.org/gnu/mpc/mpc-$(MPC_VERSION).tar.gz
472 stage3-chroot/usr/bin/gcc: gcc-$(GCC_X_VERSION).tar.gz
473 rm -rf riscv-gcc-riscv-gcc-$(GCC_X_VERSION)
475 mkdir riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build
476 cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && \
477 PATH=$(ROOT)/fixed-gcc:$$PATH \
479 --host=riscv64-unknown-linux-gnu \
480 --prefix=/usr --libdir=/usr/lib64 \
483 --enable-languages=c,c++ \
484 --disable-libmudflap \
486 --disable-libquadmath \
489 # XXX use make all & make install here. However building libgcc
490 # fails, see 'broken-gcc.log'.
491 cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && PATH=$(ROOT)/fixed-gcc:$$PATH make all-gcc
492 cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && make install-gcc DESTDIR=$(ROOT)/stage3-chroot
494 gcc-$(GCC_X_VERSION).tar.gz:
496 wget -O $@-t https://github.com/riscv/riscv-gcc/archive/riscv-gcc-$(GCC_X_VERSION).tar.gz
499 # Cross-compile util-linux.
500 stage3-chroot/usr/bin/mount: util-linux-$(UTIL_LINUX_VERSION).tar.xz
501 rm -rf util-linux-$(UTIL_LINUX_VERSION)
503 cd util-linux-$(UTIL_LINUX_VERSION) && \
504 PATH=$(ROOT)/fixed-gcc:$$PATH \
505 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
507 --host=riscv64-unknown-linux-gnu \
508 --prefix=/usr --libdir=/usr/lib64 \
511 --disable-makeinstall-chown \
512 --enable-static-programs=mount
513 cd util-linux-$(UTIL_LINUX_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
514 cd util-linux-$(UTIL_LINUX_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
515 rm -f stage3-chroot/usr/lib64/*.la
517 util-linux-$(UTIL_LINUX_VERSION).tar.xz:
519 wget -O $@-t ftp://ftp.kernel.org/pub/linux/utils/util-linux/v$(UTIL_LINUX_VERSION)/util-linux-$(UTIL_LINUX_VERSION).tar.xz
522 # Cross-compile GNU tar.
523 stage3-chroot/usr/bin/tar: tar-$(TAR_VERSION).tar.xz
524 rm -rf tar-$(TAR_VERSION)
526 cd tar-$(TAR_VERSION) && \
527 PATH=$(ROOT)/fixed-gcc:$$PATH \
529 --host=riscv64-unknown-linux-gnu \
530 --prefix=/usr --libdir=/usr/lib64
531 cd tar-$(TAR_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
532 cd tar-$(TAR_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
534 tar-$(TAR_VERSION).tar.xz:
536 wget -O $@-t https://ftp.gnu.org/gnu/tar/tar-$(TAR_VERSION).tar.xz
539 # Cross-compile GNU gzip.
540 stage3-chroot/usr/bin/gzip: gzip-$(GZIP_VERSION).tar.gz
541 rm -rf gzip-$(GZIP_VERSION)
543 cd gzip-$(GZIP_VERSION) && \
544 PATH=$(ROOT)/fixed-gcc:$$PATH \
546 --host=riscv64-unknown-linux-gnu \
547 --prefix=/usr --libdir=/usr/lib64
548 cd gzip-$(GZIP_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
549 cd gzip-$(GZIP_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
551 gzip-$(GZIP_VERSION).tar.gz:
553 wget -O $@-t https://ftp.gnu.org/gnu/gzip/gzip-$(GZIP_VERSION).tar.gz
556 # Cross-compile zlib.
557 stage3-chroot/usr/lib64/libz.so: zlib-$(ZLIB_VERSION).tar.gz
558 rm -rf zlib-$(ZLIB_VERSION)
560 cd zlib-$(ZLIB_VERSION) && \
561 PATH=$(ROOT)/fixed-gcc:$$PATH \
562 CC=riscv64-unknown-linux-gnu-gcc \
563 CFLAGS="-I$(ROOT)/stage3-chroot/usr/include -L$(ROOT)/stage3-chroot/usr/lib" \
565 --prefix=/usr --libdir=/usr/lib64
566 cd zlib-$(ZLIB_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make shared
567 cd zlib-$(ZLIB_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
569 zlib-$(ZLIB_VERSION).tar.gz:
571 wget -O $@-t http://zlib.net/zlib-$(ZLIB_VERSION).tar.gz
574 # Cross-compile file/libmagic.
575 stage3-chroot/usr/bin/file: file-$(FILE_VERSION).tar.gz
576 rm -rf file-$(FILE_VERSION)
578 cd file-$(FILE_VERSION) && \
579 PATH=$(ROOT)/fixed-gcc:$$PATH \
580 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
582 --host=riscv64-unknown-linux-gnu \
583 --prefix=/usr --libdir=/usr/lib64 \
584 --disable-static --enable-shared
585 cd file-$(FILE_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
586 cd file-$(FILE_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
587 rm -f stage3-chroot/usr/lib64/*.la
589 file-$(FILE_VERSION).tar.gz:
591 wget -O $@-t ftp://ftp.astron.com/pub/file/file-$(FILE_VERSION).tar.gz
594 # Cross-compile popt.
595 stage3-chroot/usr/lib64/libpopt.so: popt-$(POPT_VERSION).tar.gz
596 rm -rf popt-$(POPT_VERSION)
598 cd popt-$(POPT_VERSION) && \
599 PATH=$(ROOT)/fixed-gcc:$$PATH \
600 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
602 --host=riscv64-unknown-linux-gnu \
603 --prefix=/usr --libdir=/usr/lib64 \
604 --disable-static --enable-shared
605 cd popt-$(POPT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
606 cd popt-$(POPT_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
607 rm -f stage3-chroot/usr/lib64/*.la
609 popt-$(POPT_VERSION).tar.gz:
611 wget -O $@-t http://rpm5.org/files/popt/popt-$(POPT_VERSION).tar.gz
614 # Cross-compile beecrypt.
615 stage3-chroot/usr/lib64/libbeecrypt.so: beecrypt-$(BEECRYPT_VERSION).tar.gz
616 rm -rf beecrypt-$(BEECRYPT_VERSION)
618 cd beecrypt-$(BEECRYPT_VERSION) && patch -p0 < ../beecrypt-disable-cplusplus.patch
619 cd beecrypt-$(BEECRYPT_VERSION) && autoreconf -i
620 cd beecrypt-$(BEECRYPT_VERSION) && \
621 PATH=$(ROOT)/fixed-gcc:$$PATH \
622 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
624 --host=riscv64-unknown-linux-gnu \
625 --prefix=/usr --libdir=/usr/lib64 \
626 --without-cplusplus \
631 cd beecrypt-$(BEECRYPT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
632 cd beecrypt-$(BEECRYPT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot V=1
633 chrpath -d stage3-chroot/usr/lib64/libbeecrypt.so.*
634 rm -f stage3-chroot/usr/lib64/*.la
636 beecrypt-$(BEECRYPT_VERSION).tar.gz:
638 wget -O $@-t http://downloads.sourceforge.net/sourceforge/beecrypt/beecrypt-$(BEECRYPT_VERSION).tar.gz
641 # Cross-compile RPM / rpmbuild.
642 # We build this from a git commit, with a few hacks to the configure
644 stage3-chroot/usr/bin/rpm: rpm-$(RPM_SHORT_COMMIT).tar.gz db-$(BDB_VERSION).tar.gz
645 rm -rf rpm-$(RPM_SHORT_COMMIT)
646 tar -zxf rpm-$(RPM_SHORT_COMMIT).tar.gz
647 tar -zxf db-$(BDB_VERSION).tar.gz -C rpm-$(RPM_SHORT_COMMIT)
648 cd rpm-$(RPM_SHORT_COMMIT) && ln -s db-$(BDB_VERSION) db
649 cd rpm-$(RPM_SHORT_COMMIT) && patch -p1 < ../0001-HACKS-TO-GET-RPM-TO-CROSS-COMPILE.patch
650 cd rpm-$(RPM_SHORT_COMMIT) && patch -p1 < ../0002-RISCV-64-bit-riscv64-support.patch
651 cd rpm-$(RPM_SHORT_COMMIT) && autoreconf -i
652 cd rpm-$(RPM_SHORT_COMMIT) && \
653 PATH=$(ROOT)/fixed-gcc:$$PATH \
654 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
656 --host=riscv64-unknown-linux-gnu \
657 --prefix=/usr --libdir=/usr/lib64 \
659 --without-libarchive \
663 --without-external-db \
666 cd rpm-$(RPM_SHORT_COMMIT) && \
667 sed -i 's|^sys_lib_dlsearch_path_spec="/lib64|sys_lib_dlsearch_path_spec="$(ROOT)/stage3-chroot/usr/lib64 /lib64|g' libtool
668 cd rpm-$(RPM_SHORT_COMMIT) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
669 cd rpm-$(RPM_SHORT_COMMIT) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
670 rm -f stage3-chroot/usr/lib64/*.la
672 rpm-$(RPM_SHORT_COMMIT).tar.gz:
674 wget -O $@-t 'http://rpm.org/gitweb?p=rpm.git;a=snapshot;h=$(RPM_COMMIT);sf=tgz'
677 db-$(BDB_VERSION).tar.gz:
679 wget -O $@-t http://download.oracle.com/berkeley-db/db-$(BDB_VERSION).tar.gz
682 # Cross-compile GNU nano (editor).
683 stage3-chroot/usr/bin/nano: nano-$(NANO_VERSION).tar.gz
684 rm -rf nano-$(NANO_VERSION)
686 cd nano-$(NANO_VERSION) && \
687 PATH=$(ROOT)/fixed-gcc:$$PATH \
688 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
690 --host=riscv64-unknown-linux-gnu \
691 --prefix=/usr --libdir=/usr/lib64
692 cd nano-$(NANO_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
693 cd nano-$(NANO_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
695 nano-$(NANO_VERSION).tar.gz:
697 wget -O $@-t https://www.nano-editor.org/dist/v2.6/nano-$(NANO_VERSION).tar.gz
700 # Cross-compile GNU grep.
701 stage3-chroot/usr/bin/grep: grep-$(GREP_VERSION).tar.xz
702 rm -rf grep-$(GREP_VERSION)
704 cd grep-$(GREP_VERSION) && \
705 PATH=$(ROOT)/fixed-gcc:$$PATH \
707 --host=riscv64-unknown-linux-gnu \
708 --prefix=/usr --libdir=/usr/lib64
709 cd grep-$(GREP_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
710 cd grep-$(GREP_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
712 grep-$(GREP_VERSION).tar.xz:
714 wget -O $@-t https://ftp.gnu.org/gnu/grep/grep-$(GREP_VERSION).tar.xz
717 # Cross-compile less.
718 stage3-chroot/usr/bin/less: less-$(LESS_VERSION).tar.gz
719 rm -rf less-$(LESS_VERSION)
721 cd less-$(LESS_VERSION) && \
722 PATH=$(ROOT)/fixed-gcc:$$PATH \
723 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
725 --host=riscv64-unknown-linux-gnu \
726 --prefix=/usr --libdir=/usr/lib64
727 cd less-$(LESS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
728 cd less-$(LESS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
730 less-$(LESS_VERSION).tar.gz:
732 wget -O $@-t http://www.greenwoodsoftware.com/less/less-$(LESS_VERSION).tar.gz
735 # Create an /init script.
736 stage3-chroot/init: init.sh
737 install -m 0755 $^ $@
739 # Create the stage3 disk image.
740 # Note `-s +...' adds spare space to the disk image.
741 stage3-disk.img: stage3-chroot
742 cd stage3-chroot && virt-make-fs . ../$@ -t ext2 -F raw -s +4G
744 # Upload the compressed disk image.
745 upload-stage3: stage3-disk.img.xz
746 scp $^ tick:public_html/riscv/
747 stage3-disk.img.xz: stage3-disk.img
751 # Helper which boots stage3 disk image in spike.
752 boot-stage3-in-spike: stage3-disk.img stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
753 spike +disk=stage3-disk.img \
754 /usr/bin/bbl stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
756 # Helper which boots stage3 disk image in qemu.
757 boot-stage3-in-qemu: stage3-disk.img stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
758 qemu-system-riscv -kernel /usr/bin/bbl \
759 -append ./stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux \
760 -drive file=stage3-disk.img,format=raw -nographic