1 # Refer to the README file to understand how Fedora on RISC-V is
4 # Absolute path to the current directory.
7 # Note these are chosen very specifically to ensure the different
8 # versions work together. Don't blindly update to the latest
10 # https://github.com/riscv/riscv-pk/issues/18#issuecomment-206115996
11 RISCV_QEMU_COMMIT = 94f5eb73091fb4fe272db3e943f173ecc0f78ffd
12 RISCV_QEMU_SHORTCOMMIT = 94f5eb73
13 RISCV_FESVR_COMMIT = 0f34d7ad311f78455a674224225f5b3056efba1d
14 RISCV_FESVR_SHORTCOMMIT = 0f34d7ad
15 RISCV_ISA_SIM_COMMIT = 3bfc00ef2a1b1f0b0472a39a866261b00f67027e
16 RISCV_ISA_SIM_SHORTCOMMIT = 3bfc00ef
17 RISCV_GNU_TOOLCHAIN_COMMIT = 728afcddcb0526a0f6560c4032da82805f054d58
18 RISCV_GNU_TOOLCHAIN_SHORTCOMMIT = 728afcdd
19 RISCV_PK_COMMIT = 85ae17aa149b9ea114bdd70cc30ea7e73813fb48
20 RISCV_PK_SHORTCOMMIT = 85ae17aa
22 # For the correct versions, see
23 # riscv-gnu-toolchain/Makefile.in *_version variables
24 BINUTILS_VERSION = 2.25.1
27 NEWLIB_VERSION = 2.2.0
29 # See linux-4.1.y-riscv branch of
30 # https://github.com/riscv/riscv-linux
31 KERNEL_VERSION = 4.1.26
33 # A local copy of Linux git repo so you don't have to keep downloading
34 # git commits (optional).
35 LOCAL_LINUX_GIT_COPY = $(HOME)/d/linux
37 # The root packages (plus their dependencies) that we want to
38 # cross-compile into the stage 3 chroot.
39 # beecrypt-devel is required to build RPM.
40 # Packages for usability: nano, grep, less
41 STAGE3_PACKAGES = gcc rpm-build beecrypt-devel nano grep less
43 # Versions of cross-compiled packages.
44 NCURSES_VERSION = 6.0-20160730
46 COREUTILS_VERSION = 8.25
50 BINUTILS_X_VERSION = 2.26
52 UTIL_LINUX_VERSION = 2.28
56 # Needs to match the version of 'file' installed (on host), otherwise:
57 # "Cannot use the installed version of file (xx) to cross-compile file yy"
58 # Also note that 5.25 is definitely broken (segfaults in libmagic:magic_close).
61 BEECRYPT_VERSION = 4.2.1
62 RPM_COMMIT = 95712183458748ea6cafebac1bdd5daa097d9bee
63 RPM_SHORT_COMMIT = 9571218
68 STRACE_COMMIT = f320e1897832fd07a62e18ed288e75d8e79f4c5b
69 STRACE_SHORT_COMMIT = f320e189
72 DIFFUTILS_VERSION = 3.4
73 FINDUTILS_VERSION = 4.6.0
76 HOSTNAME_VERSION = 3.15
77 GETTEXT_VERSION = 0.19
79 all: stage1 stage2 stage3 stage4
83 stage1: stage1-riscv-qemu/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz \
84 stage1-riscv-qemu/riscv-qemu.spec \
85 stamp-riscv-qemu-installed \
86 stage1-riscv-fesvr/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz \
87 stage1-riscv-fesvr/riscv-fesvr.spec \
88 stamp-riscv-fesvr-installed \
89 stage1-riscv-isa-sim/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz \
90 stage1-riscv-isa-sim/riscv-isa-sim.spec \
91 stamp-riscv-isa-sim-installed
93 stage1-riscv-qemu/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz:
95 wget -O $@-t 'https://github.com/riscv/riscv-qemu/archive/$(RISCV_QEMU_COMMIT)/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz'
98 stage1-riscv-qemu/riscv-qemu.spec: stage1-riscv-qemu/riscv-qemu.spec.in
99 sed -e 's/@COMMIT@/$(RISCV_QEMU_COMMIT)/g' \
100 -e 's/@SHORTCOMMIT@/$(RISCV_QEMU_SHORTCOMMIT)/g' \
104 stamp-riscv-qemu-installed:
106 @rpm -q riscv-qemu >/dev/null || { \
107 echo "ERROR: You must install riscv-qemu:"; \
109 echo " dnf copr enable rjones/riscv"; \
110 echo " dnf install riscv-qemu"; \
112 echo "OR: you can build it yourself from the stage1-riscv-qemu directory."; \
116 @qemu-system-riscv --version || { \
117 echo "ERROR: qemu-system-riscv is not working."; \
118 echo "Make sure you installed the riscv-qemu package."; \
123 stage1-riscv-fesvr/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz:
125 wget -O $@-t 'https://github.com/riscv/riscv-fesvr/archive/$(RISCV_FESVR_COMMIT)/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz'
128 stage1-riscv-fesvr/riscv-fesvr.spec: stage1-riscv-fesvr/riscv-fesvr.spec.in
129 sed -e 's/@COMMIT@/$(RISCV_FESVR_COMMIT)/g' \
130 -e 's/@SHORTCOMMIT@/$(RISCV_FESVR_SHORTCOMMIT)/g' \
134 stamp-riscv-fesvr-installed:
136 @rpm -q riscv-fesvr >/dev/null || { \
137 echo "ERROR: You must install riscv-fesvr:"; \
139 echo " dnf copr enable rjones/riscv"; \
140 echo " dnf install riscv-fesvr"; \
142 echo "OR: you can build it yourself from the stage1-riscv-fesvr directory."; \
148 stage1-riscv-isa-sim/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz:
150 wget -O $@-t 'https://github.com/riscv/riscv-isa-sim/archive/$(RISCV_ISA_SIM_COMMIT)/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz'
153 stage1-riscv-isa-sim/riscv-isa-sim.spec: stage1-riscv-isa-sim/riscv-isa-sim.spec.in
154 sed -e 's/@COMMIT@/$(RISCV_ISA_SIM_COMMIT)/g' \
155 -e 's/@SHORTCOMMIT@/$(RISCV_ISA_SIM_SHORTCOMMIT)/g' \
159 stamp-riscv-isa-sim-installed:
161 @rpm -q riscv-isa-sim >/dev/null || { \
162 echo "ERROR: You must install riscv-isa-sim:"; \
164 echo " dnf copr enable rjones/riscv"; \
165 echo " dnf install riscv-isa-sim"; \
167 echo "OR: you can build it yourself from the stage1-riscv-isa-sim directory."; \
175 stage2: stage2-riscv-gnu-toolchain/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz \
176 stage2-riscv-gnu-toolchain/binutils-$(BINUTILS_VERSION).tar.gz \
177 stage2-riscv-gnu-toolchain/gcc-$(GCC_VERSION).tar.gz \
178 stage2-riscv-gnu-toolchain/glibc-$(GLIBC_VERSION).tar.gz \
179 stage2-riscv-gnu-toolchain/newlib-$(NEWLIB_VERSION).tar.gz \
180 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec \
181 stamp-riscv-gnu-toolchain-installed \
182 stage2-riscv-pk/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz \
183 stage2-riscv-pk/riscv-pk.spec \
184 stamp-riscv-pk-installed
186 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz:
188 wget -O $@-t https://github.com/lowRISC/riscv-gnu-toolchain/archive/$(RISCV_GNU_TOOLCHAIN_COMMIT)/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz
191 stage2-riscv-gnu-toolchain/binutils-$(BINUTILS_VERSION).tar.gz:
193 wget -O $@-t http://mirrors.kernel.org/gnu/binutils/binutils-$(BINUTILS_VERSION).tar.gz
196 # GCC 5 no longer compiles with GCC 6 unless we patch it.
197 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69959
198 stage2-riscv-gnu-toolchain/gcc-$(GCC_VERSION).tar.gz:
200 wget -O $@-t http://mirrors.kernel.org/gnu/gcc/gcc-$(GCC_VERSION)/gcc-$(GCC_VERSION).tar.gz
202 cd gcc-$(GCC_VERSION) && patch -p0 < ../stage2-riscv-gnu-toolchain/gcc-5-fix-compilation-with-gcc-6.patch
203 tar zcf $@-t gcc-$(GCC_VERSION)
204 rm -r gcc-$(GCC_VERSION)
207 stage2-riscv-gnu-toolchain/glibc-$(GLIBC_VERSION).tar.gz:
209 wget -O $@-t http://mirrors.kernel.org/gnu/glibc/glibc-$(GLIBC_VERSION).tar.gz
212 stage2-riscv-gnu-toolchain/newlib-$(NEWLIB_VERSION).tar.gz:
214 wget -O $@-t ftp://sourceware.org/pub/newlib/newlib-$(NEWLIB_VERSION).tar.gz
217 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec: stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec.in
218 sed -e 's/@COMMIT@/$(RISCV_GNU_TOOLCHAIN_COMMIT)/g' \
219 -e 's/@SHORTCOMMIT@/$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT)/g' \
220 -e 's/@BINUTILS_VERSION@/$(BINUTILS_VERSION)/g' \
221 -e 's/@GCC_VERSION@/$(GCC_VERSION)/g' \
222 -e 's/@GLIBC_VERSION@/$(GLIBC_VERSION)/g' \
223 -e 's/@NEWLIB_VERSION@/$(NEWLIB_VERSION)/g' \
227 stamp-riscv-gnu-toolchain-installed:
229 @rpm -q riscv-gnu-toolchain >/dev/null || { \
230 echo "ERROR: You must install riscv-gnu-toolchain:"; \
232 echo " dnf copr enable rjones/riscv"; \
233 echo " dnf install riscv-gnu-toolchain"; \
235 echo "OR: you can build it yourself from the stage2-riscv-gnu-toolchain directory."; \
239 @riscv64-unknown-elf-gcc --version || { \
240 echo "ERROR: riscv64-unknown-elf-gcc (cross compiler) is not working."; \
241 echo "Make sure you installed the riscv-gnu-toolchain package."; \
246 stage2-riscv-pk/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz:
248 wget -O $@-t https://github.com/lowRISC/riscv-pk/archive/$(RISCV_PK_COMMIT)/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz
251 stage2-riscv-pk/riscv-pk.spec: stage2-riscv-pk/riscv-pk.spec.in
252 sed -e 's/@COMMIT@/$(RISCV_PK_COMMIT)/g' \
253 -e 's/@SHORTCOMMIT@/$(RISCV_PK_SHORTCOMMIT)/g' \
257 stamp-riscv-pk-installed:
259 @rpm -q riscv-pk >/dev/null || { \
260 echo "ERROR: You must install riscv-pk:"; \
262 echo " dnf copr enable rjones/riscv"; \
263 echo " dnf install riscv-pk"; \
265 echo "OR: you can build it yourself from the stage2-riscv-pk directory."; \
273 stage3: stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux \
274 stage3-chroot-original/etc/fedora-release \
275 stage3-chroot/etc/fedora-release \
276 stage3-chroot/lib64/libc.so.6 \
277 stage3-chroot/usr/bin/tic \
278 stage3-chroot/bin/bash \
279 stage3-chroot/bin/ls \
280 stage3-chroot/usr/lib64/libgmp.so.10 \
281 stage3-chroot/usr/lib64/libmpfr.so.4 \
282 stage3-chroot/usr/lib64/libmpc.so.3 \
283 stage3-chroot/usr/bin/as \
284 stage3-chroot/usr/bin/gcc \
285 stage3-chroot/usr/bin/mount \
286 stage3-chroot/usr/bin/tar \
287 stage3-chroot/usr/bin/gzip \
288 stage3-chroot/usr/lib64/libz.so \
289 stage3-chroot/usr/bin/file \
290 stage3-chroot/usr/lib64/libpopt.so \
291 stage3-chroot/usr/lib64/libbeecrypt.so \
292 stage3-chroot/usr/bin/nano \
293 stage3-chroot/usr/bin/grep \
294 stage3-chroot/usr/bin/less \
295 stage3-chroot/usr/bin/strace \
296 stage3-chroot/usr/bin/bzip2 \
297 stage3-chroot/usr/bin/make \
298 stage3-chroot/usr/bin/diff \
299 stage3-chroot/usr/bin/find \
300 stage3-chroot/usr/bin/sed \
301 stage3-chroot/usr/bin/patch \
302 stage3-chroot/usr/bin/hostname \
303 stage3-chroot/usr/bin/gettext \
304 stage3-chroot/usr/bin/rpm \
308 stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux:
309 rm -rf stage3-kernel/linux-$(KERNEL_VERSION)
310 cp -a $(LOCAL_LINUX_GIT_COPY) stage3-kernel/linux-$(KERNEL_VERSION) || { \
311 mkdir stage3-kernel/linux-$(KERNEL_VERSION) && \
312 cd stage3-kernel/linux-$(KERNEL_VERSION) && \
315 cd stage3-kernel/linux-$(KERNEL_VERSION) && \
316 git remote add riscv https://github.com/riscv/riscv-linux && \
318 git checkout -f linux-4.1.y-riscv && \
320 make ARCH=riscv defconfig
321 echo CONFIG_CMDLINE=\"root=/dev/htifblk0 init=/init\" >> stage3-kernel/linux-$(KERNEL_VERSION)/.config
322 echo CONFIG_CROSS_COMPILE=riscv64-unknown-elf- >> stage3-kernel/linux-$(KERNEL_VERSION)/.config
323 cd stage3-kernel/linux-$(KERNEL_VERSION) && \
324 make ARCH=riscv olddefconfig
325 cd stage3-kernel/linux-$(KERNEL_VERSION) && \
326 make ARCH=riscv vmlinux
329 # Build an original (x86-64) chroot using supermin. We then aim to
330 # rebuild (using cross-compiled versions) every ELF binary in this
332 stage3-chroot-original/etc/fedora-release:
333 rm -rf stage3-chroot-original tmp-supermin.d
334 supermin --prepare $(STAGE3_PACKAGES) -o tmp-supermin.d
335 supermin --build -f chroot tmp-supermin.d -o stage3-chroot-original
337 @echo -n "Total files in chroot: "
338 @find stage3-chroot-original -type f | wc -l
339 @echo -n "ELF files to be rebuilt: "
340 @find stage3-chroot-original -type f | xargs file -N | grep -E '\bELF.*LSB\b' | wc -l
342 # Copy the original chroot to the final chroot, remove all the ELF
344 stage3-chroot/etc/fedora-release: stage3-chroot-original/etc/fedora-release
346 cp -a stage3-chroot-original stage3-chroot
347 find stage3-chroot -type d | xargs chmod u+w
348 find stage3-chroot -type f | xargs chmod u+w
349 find stage3-chroot -type f | xargs file -N | grep -E '\bELF.*LSB\b' | awk -F: '{print $$1}' | xargs rm -f
350 rm -f stage3-chroot/lib64/libc.so.6
352 # Copy in compiled glibc from the riscv-gnu-toolchain sysroot. Only
353 # copy files and symlinks, leave the target directory structure
355 stage3-chroot/lib64/libc.so.6:
356 mkdir -p stage3-chroot/usr/lib/audit
357 mkdir -p stage3-chroot/usr/lib/gconv
358 for f in `cd /usr/sysroot && find -type f -o -type l`; do \
359 cp -d /usr/sysroot/$$f stage3-chroot/$$f; \
361 cd stage3-chroot/lib64 && for f in ../lib/*; do ln -sf $$f; done
363 # Cross-compile ncurses.
364 stage3-chroot/usr/bin/tic: ncurses-$(NCURSES_VERSION).tgz
366 cd ncurses-$(NCURSES_VERSION) && \
367 PATH=$(ROOT)/fixed-gcc:$$PATH \
368 ./configure --host=riscv64-unknown-linux-gnu \
369 --prefix=/usr --libdir=/usr/lib64 \
371 --with-termlib=tinfo \
373 cd ncurses-$(NCURSES_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
374 cd ncurses-$(NCURSES_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
376 ncurses-$(NCURSES_VERSION).tgz:
378 wget -O $@-t ftp://invisible-island.net/ncurses/current/ncurses-$(NCURSES_VERSION).tgz
381 # Cross-compile bash.
382 stage3-chroot/bin/bash: bash-$(BASH_VERSION).tar.gz
384 cd bash-$(BASH_VERSION) && \
385 PATH=$(ROOT)/fixed-gcc:$$PATH \
386 ./configure --host=riscv64-unknown-linux-gnu \
387 --prefix=/usr --libdir=/usr/lib64
388 cd bash-$(BASH_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
389 cd bash-$(BASH_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
391 bash-$(BASH_VERSION).tar.gz:
393 wget -O $@-t ftp://ftp.gnu.org/gnu/bash/bash-$(BASH_VERSION).tar.gz
396 # Cross-compile coreutils. Bleah, coreutils cross-compilation is
397 # known-broken and upstream don't care, hence the 'touch' command.
399 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
401 stage3-chroot/bin/ls: coreutils-$(COREUTILS_VERSION).tar.xz
402 rm -rf coreutils-$(COREUTILS_VERSION)
404 cd coreutils-$(COREUTILS_VERSION) && \
405 PATH=$(ROOT)/fixed-gcc:$$PATH \
406 ./configure --host=riscv64-unknown-linux-gnu \
407 --prefix=/usr --libdir=/usr/lib64
408 -cd coreutils-$(COREUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
409 cd coreutils-$(COREUTILS_VERSION)/man && \
410 for f in $(COREUTILS_PROGRAMS); do touch $$f.1; done
411 cd coreutils-$(COREUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
412 cd coreutils-$(COREUTILS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
414 coreutils-$(COREUTILS_VERSION).tar.xz:
416 wget -O $@-t ftp://ftp.gnu.org/gnu/coreutils/coreutils-$(COREUTILS_VERSION).tar.xz
419 # Cross-compile binutils.
420 stage3-chroot/usr/bin/as: binutils-$(BINUTILS_X_VERSION).tar.gz
421 rm -rf riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)
423 mkdir riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build
424 cd riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build && \
425 PATH=$(ROOT)/fixed-gcc:$$PATH \
427 --host=riscv64-unknown-linux-gnu \
428 --prefix=/usr --libdir=/usr/lib64
429 cd riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build && PATH=$(ROOT)/fixed-gcc:$$PATH make
430 cd riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build && make DESTDIR=$(ROOT)/stage3-chroot install
432 binutils-$(BINUTILS_X_VERSION).tar.gz:
434 wget -O $@-t https://github.com/riscv/riscv-binutils-gdb/archive/riscv-binutils-$(BINUTILS_X_VERSION).tar.gz
437 # Cross-compile GMP, MPFR and MPC (deps of GCC).
438 stage3-chroot/usr/lib64/libgmp.so.10: gmp-$(GMP_VERSION).tar.lz
439 rm -rf gmp-$(GMP_VERSION)
440 tar --lzip -xf gmp-$(GMP_VERSION).tar.lz
441 cd gmp-$(GMP_VERSION) && \
442 PATH=$(ROOT)/fixed-gcc:$$PATH \
443 ./configure --host=riscv64-unknown-linux-gnu \
444 --prefix=/usr --libdir=/usr/lib64
445 cd gmp-$(GMP_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
446 cd gmp-$(GMP_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
447 cd stage3-chroot/usr/lib && ln -s ../lib64/libgmp.so
449 gmp-$(GMP_VERSION).tar.lz:
451 wget -O $@-t https://gmplib.org/download/gmp/gmp-$(GMP_VERSION).tar.lz
454 stage3-chroot/usr/lib64/libmpfr.so.4: mpfr-$(MPFR_VERSION).tar.gz
455 rm -rf mpfr-$(MPFR_VERSION)
456 tar -zxf mpfr-$(MPFR_VERSION).tar.gz
457 cd mpfr-$(MPFR_VERSION) && \
458 PATH=$(ROOT)/fixed-gcc:$$PATH \
459 ./configure --host=riscv64-unknown-linux-gnu \
460 --prefix=/usr --libdir=/usr/lib64 \
461 --with-gmp=$(ROOT)/stage3-chroot/usr
462 cd mpfr-$(MPFR_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
463 cd mpfr-$(MPFR_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
464 cd stage3-chroot/usr/lib && ln -s ../lib64/libmpfr.so
465 rm -f stage3-chroot/usr/lib64/*.la
467 mpfr-$(MPFR_VERSION).tar.gz:
469 wget -O $@-t http://www.mpfr.org/mpfr-current/mpfr-$(MPFR_VERSION).tar.gz
472 stage3-chroot/usr/lib64/libmpc.so.3: mpc-$(MPC_VERSION).tar.gz
473 rm -rf mpc-$(MPC_VERSION)
474 tar -zxf mpc-$(MPC_VERSION).tar.gz
475 cd mpc-$(MPC_VERSION) && \
476 PATH=$(ROOT)/fixed-gcc:$$PATH \
477 ./configure --host=riscv64-unknown-linux-gnu \
478 --prefix=/usr --libdir=/usr/lib64 \
479 --with-gmp=$(ROOT)/stage3-chroot/usr \
480 --with-mpfr=$(ROOT)/stage3-chroot/usr
481 cd mpc-$(MPC_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
482 cd mpc-$(MPC_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
483 cd stage3-chroot/usr/lib && ln -s ../lib64/libmpc.so
484 rm -f stage3-chroot/usr/lib64/*.la
486 mpc-$(MPC_VERSION).tar.gz:
488 wget -O $@-t ftp://ftp.gnu.org/gnu/mpc/mpc-$(MPC_VERSION).tar.gz
492 stage3-chroot/usr/bin/gcc: gcc-$(GCC_X_VERSION).tar.gz
493 rm -rf riscv-gcc-riscv-gcc-$(GCC_X_VERSION)
495 cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION) && \
496 patch -p1 < ../0001-HACKS-TO-GET-GCC-TO-COMPILE.patch
497 mkdir riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build
498 cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && \
499 PATH=$(ROOT)/fixed-gcc:$$PATH \
501 --host=riscv64-unknown-linux-gnu \
502 --prefix=/usr --libdir=/usr/lib64 \
505 --enable-languages=c,c++ \
506 --disable-libmudflap \
508 --disable-libquadmath \
511 cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && PATH=$(ROOT)/fixed-gcc:$$PATH make
512 cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && make install DESTDIR=$(ROOT)/stage3-chroot
514 gcc-$(GCC_X_VERSION).tar.gz:
516 wget -O $@-t https://github.com/riscv/riscv-gcc/archive/riscv-gcc-$(GCC_X_VERSION).tar.gz
519 # Cross-compile util-linux.
520 stage3-chroot/usr/bin/mount: util-linux-$(UTIL_LINUX_VERSION).tar.xz
521 rm -rf util-linux-$(UTIL_LINUX_VERSION)
523 cd util-linux-$(UTIL_LINUX_VERSION) && \
524 PATH=$(ROOT)/fixed-gcc:$$PATH \
525 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
527 --host=riscv64-unknown-linux-gnu \
528 --prefix=/usr --libdir=/usr/lib64 \
531 --disable-makeinstall-chown \
532 --enable-static-programs=mount
533 cd util-linux-$(UTIL_LINUX_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
534 cd util-linux-$(UTIL_LINUX_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
535 rm -f stage3-chroot/usr/lib64/*.la
537 util-linux-$(UTIL_LINUX_VERSION).tar.xz:
539 wget -O $@-t ftp://ftp.kernel.org/pub/linux/utils/util-linux/v$(UTIL_LINUX_VERSION)/util-linux-$(UTIL_LINUX_VERSION).tar.xz
542 # Cross-compile GNU tar.
543 stage3-chroot/usr/bin/tar: tar-$(TAR_VERSION).tar.xz
544 rm -rf tar-$(TAR_VERSION)
546 cd tar-$(TAR_VERSION) && \
547 PATH=$(ROOT)/fixed-gcc:$$PATH \
549 --host=riscv64-unknown-linux-gnu \
550 --prefix=/usr --libdir=/usr/lib64
551 cd tar-$(TAR_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
552 cd tar-$(TAR_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
554 tar-$(TAR_VERSION).tar.xz:
556 wget -O $@-t https://ftp.gnu.org/gnu/tar/tar-$(TAR_VERSION).tar.xz
559 # Cross-compile GNU gzip.
560 stage3-chroot/usr/bin/gzip: gzip-$(GZIP_VERSION).tar.gz
561 rm -rf gzip-$(GZIP_VERSION)
563 cd gzip-$(GZIP_VERSION) && \
564 PATH=$(ROOT)/fixed-gcc:$$PATH \
566 --host=riscv64-unknown-linux-gnu \
567 --prefix=/usr --libdir=/usr/lib64
568 cd gzip-$(GZIP_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
569 cd gzip-$(GZIP_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
571 gzip-$(GZIP_VERSION).tar.gz:
573 wget -O $@-t https://ftp.gnu.org/gnu/gzip/gzip-$(GZIP_VERSION).tar.gz
576 # Cross-compile zlib.
577 stage3-chroot/usr/lib64/libz.so: zlib-$(ZLIB_VERSION).tar.gz
578 rm -rf zlib-$(ZLIB_VERSION)
580 cd zlib-$(ZLIB_VERSION) && \
581 PATH=$(ROOT)/fixed-gcc:$$PATH \
582 CC=riscv64-unknown-linux-gnu-gcc \
583 CFLAGS="-I$(ROOT)/stage3-chroot/usr/include -L$(ROOT)/stage3-chroot/usr/lib" \
585 --prefix=/usr --libdir=/usr/lib64
586 cd zlib-$(ZLIB_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make shared
587 cd zlib-$(ZLIB_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
589 zlib-$(ZLIB_VERSION).tar.gz:
591 wget -O $@-t http://zlib.net/zlib-$(ZLIB_VERSION).tar.gz
594 # Cross-compile file/libmagic.
595 stage3-chroot/usr/bin/file: file-$(FILE_VERSION).tar.gz
596 rm -rf file-$(FILE_VERSION)
598 cd file-$(FILE_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 file-$(FILE_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
606 cd file-$(FILE_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
607 rm -f stage3-chroot/usr/lib64/*.la
609 file-$(FILE_VERSION).tar.gz:
611 wget -O $@-t ftp://ftp.astron.com/pub/file/file-$(FILE_VERSION).tar.gz
614 # Cross-compile popt.
615 stage3-chroot/usr/lib64/libpopt.so: popt-$(POPT_VERSION).tar.gz
616 rm -rf popt-$(POPT_VERSION)
618 cd popt-$(POPT_VERSION) && \
619 PATH=$(ROOT)/fixed-gcc:$$PATH \
620 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
622 --host=riscv64-unknown-linux-gnu \
623 --prefix=/usr --libdir=/usr/lib64 \
624 --disable-static --enable-shared
625 cd popt-$(POPT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
626 cd popt-$(POPT_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
627 rm -f stage3-chroot/usr/lib64/*.la
629 popt-$(POPT_VERSION).tar.gz:
631 wget -O $@-t http://rpm5.org/files/popt/popt-$(POPT_VERSION).tar.gz
634 # Cross-compile beecrypt.
635 stage3-chroot/usr/lib64/libbeecrypt.so: beecrypt-$(BEECRYPT_VERSION).tar.gz
636 rm -rf beecrypt-$(BEECRYPT_VERSION)
638 cd beecrypt-$(BEECRYPT_VERSION) && patch -p0 < ../beecrypt-disable-cplusplus.patch
639 cd beecrypt-$(BEECRYPT_VERSION) && autoreconf -i
640 cd beecrypt-$(BEECRYPT_VERSION) && \
641 PATH=$(ROOT)/fixed-gcc:$$PATH \
642 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
644 --host=riscv64-unknown-linux-gnu \
645 --prefix=/usr --libdir=/usr/lib64 \
646 --without-cplusplus \
651 cd beecrypt-$(BEECRYPT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
652 cd beecrypt-$(BEECRYPT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot V=1
653 chrpath -d stage3-chroot/usr/lib64/libbeecrypt.so.*
654 rm -f stage3-chroot/usr/lib64/*.la
656 beecrypt-$(BEECRYPT_VERSION).tar.gz:
658 wget -O $@-t http://downloads.sourceforge.net/sourceforge/beecrypt/beecrypt-$(BEECRYPT_VERSION).tar.gz
661 # Cross-compile GNU nano (editor).
662 stage3-chroot/usr/bin/nano: nano-$(NANO_VERSION).tar.gz
663 rm -rf nano-$(NANO_VERSION)
665 cd nano-$(NANO_VERSION) && \
666 PATH=$(ROOT)/fixed-gcc:$$PATH \
667 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
669 --host=riscv64-unknown-linux-gnu \
670 --prefix=/usr --libdir=/usr/lib64
671 cd nano-$(NANO_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
672 cd nano-$(NANO_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
674 nano-$(NANO_VERSION).tar.gz:
676 wget -O $@-t https://www.nano-editor.org/dist/v2.6/nano-$(NANO_VERSION).tar.gz
679 # Cross-compile GNU grep.
680 stage3-chroot/usr/bin/grep: grep-$(GREP_VERSION).tar.xz
681 rm -rf grep-$(GREP_VERSION)
683 cd grep-$(GREP_VERSION) && \
684 PATH=$(ROOT)/fixed-gcc:$$PATH \
686 --host=riscv64-unknown-linux-gnu \
687 --prefix=/usr --libdir=/usr/lib64
688 cd grep-$(GREP_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
689 cd grep-$(GREP_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
691 grep-$(GREP_VERSION).tar.xz:
693 wget -O $@-t https://ftp.gnu.org/gnu/grep/grep-$(GREP_VERSION).tar.xz
696 # Cross-compile less.
697 stage3-chroot/usr/bin/less: less-$(LESS_VERSION).tar.gz
698 rm -rf less-$(LESS_VERSION)
700 cd less-$(LESS_VERSION) && \
701 PATH=$(ROOT)/fixed-gcc:$$PATH \
702 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
704 --host=riscv64-unknown-linux-gnu \
705 --prefix=/usr --libdir=/usr/lib64
706 cd less-$(LESS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
707 cd less-$(LESS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
709 less-$(LESS_VERSION).tar.gz:
711 wget -O $@-t http://www.greenwoodsoftware.com/less/less-$(LESS_VERSION).tar.gz
714 # Cross-compile strace.
715 # XXX This does not work.
716 stage3-chroot/usr/bin/strace: strace-$(STRACE_SHORT_COMMIT).tar.gz
717 rm -rf strace-$(STRACE_SHORT_COMMIT)
719 cd riscv-strace-$(STRACE_COMMIT) && patch -p1 < ../0001-Update-riscv_regs-for-ptrace.h-from-Linux-4.1.x.patch
720 cd riscv-strace-$(STRACE_COMMIT) && \
721 PATH=$(ROOT)/fixed-gcc:$$PATH \
722 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
724 --host=riscv64-unknown-linux-gnu \
725 --prefix=/usr --libdir=/usr/lib64
726 cd riscv-strace-$(STRACE_COMMIT) && PATH=$(ROOT)/fixed-gcc:$$PATH make
727 cd riscv-strace-$(STRACE_COMMIT) && make install DESTDIR=$(ROOT)/stage3-chroot
729 strace-$(STRACE_SHORT_COMMIT).tar.gz:
731 wget -O $@-t 'https://github.com/riscv/riscv-strace/archive/$(STRACE_COMMIT)/riscv-strace-$(STRACE_SHORTCOMMIT).tar.gz'
734 # Cross-compile bzip2.
735 stage3-chroot/usr/bin/bzip2: bzip2-$(BZIP2_VERSION).tar.gz
736 rm -rf bzip2-$(BZIP2_VERSION)
738 cd bzip2-$(BZIP2_VERSION) && \
739 PATH=$(ROOT)/fixed-gcc:$$PATH \
740 make libbz2.a bzip2 bzip2recover \
742 CC=riscv64-unknown-linux-gnu-gcc \
743 AR=riscv64-unknown-linux-gnu-ar \
744 RANLIB=riscv64-unknown-linux-gnu-ranlib \
745 CFLAGS="-Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -fPIC"
746 cd bzip2-$(BZIP2_VERSION) && \
747 make install PREFIX=$(ROOT)/stage3-chroot/usr
749 bzip2-$(BZIP2_VERSION).tar.gz:
751 wget -O $@-t http://www.bzip.org/1.0.6/bzip2-$(BZIP2_VERSION).tar.gz
754 # Cross-compile GNU make.
755 stage3-chroot/usr/bin/make: make-$(MAKE_VERSION).tar.gz
756 rm -rf make-$(MAKE_VERSION)
758 cd make-$(MAKE_VERSION) && \
759 PATH=$(ROOT)/fixed-gcc:$$PATH \
761 --host=riscv64-unknown-linux-gnu \
762 --prefix=/usr --libdir=/usr/lib64
763 cd make-$(MAKE_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
764 cd make-$(MAKE_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
766 make-$(MAKE_VERSION).tar.gz:
768 wget -O $@-t https://ftp.gnu.org/gnu/make/make-$(MAKE_VERSION).tar.gz
771 # Cross-compile GNU diffutils.
772 stage3-chroot/usr/bin/diff: diffutils-$(DIFFUTILS_VERSION).tar.xz
773 rm -rf diffutils-$(DIFFUTILS_VERSION)
775 cd diffutils-$(DIFFUTILS_VERSION) && \
776 PATH=$(ROOT)/fixed-gcc:$$PATH \
778 --host=riscv64-unknown-linux-gnu \
779 --prefix=/usr --libdir=/usr/lib64
780 cd diffutils-$(DIFFUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
781 cd diffutils-$(DIFFUTILS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
783 diffutils-$(DIFFUTILS_VERSION).tar.xz:
785 wget -O $@-t https://ftp.gnu.org/gnu/diffutils/diffutils-$(DIFFUTILS_VERSION).tar.xz
788 # Cross-compile GNU findutils.
789 stage3-chroot/usr/bin/find: findutils-$(FINDUTILS_VERSION).tar.gz
790 rm -rf findutils-$(FINDUTILS_VERSION)
792 cd findutils-$(FINDUTILS_VERSION) && \
793 PATH=$(ROOT)/fixed-gcc:$$PATH \
795 --host=riscv64-unknown-linux-gnu \
796 --prefix=/usr --libdir=/usr/lib64
797 cd findutils-$(FINDUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
798 cd findutils-$(FINDUTILS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
800 findutils-$(FINDUTILS_VERSION).tar.gz:
802 wget -O $@-t https://ftp.gnu.org/gnu/findutils/findutils-$(FINDUTILS_VERSION).tar.gz
805 # Cross-compile GNU sed.
806 stage3-chroot/usr/bin/sed: sed-$(SED_VERSION).tar.gz
807 rm -rf sed-$(SED_VERSION)
809 cd sed-$(SED_VERSION) && \
810 PATH=$(ROOT)/fixed-gcc:$$PATH \
812 --host=riscv64-unknown-linux-gnu \
813 --prefix=/usr --libdir=/usr/lib64
814 cd sed-$(SED_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
815 cd sed-$(SED_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
817 sed-$(SED_VERSION).tar.gz:
819 wget -O $@-t https://ftp.gnu.org/gnu/sed/sed-$(SED_VERSION).tar.gz
822 # Cross-compile patch.
823 stage3-chroot/usr/bin/patch: patch-$(PATCH_VERSION).tar.gz
824 rm -rf patch-$(PATCH_VERSION)
826 cd patch-$(PATCH_VERSION) && \
827 PATH=$(ROOT)/fixed-gcc:$$PATH \
829 --host=riscv64-unknown-linux-gnu \
830 --prefix=/usr --libdir=/usr/lib64
831 cd patch-$(PATCH_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
832 cd patch-$(PATCH_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
834 patch-$(PATCH_VERSION).tar.gz:
836 wget -O $@-t https://ftp.gnu.org/gnu/patch/patch-$(PATCH_VERSION).tar.gz
839 # Cross-compile hostname.
840 stage3-chroot/usr/bin/hostname: hostname-$(HOSTNAME_VERSION).tar.gz
841 rm -rf hostname-$(HOSTNAME_VERSION)
843 cd hostname && patch -p1 < ../hostname-rh.patch
845 PATH=$(ROOT)/fixed-gcc:$$PATH \
847 CC=riscv64-unknown-linux-gnu-gcc \
849 cd hostname && make install BASEDIR=$(ROOT)/stage3-chroot
851 hostname-$(HOSTNAME_VERSION).tar.gz:
853 wget -O $@-t http://ftp.de.debian.org/debian/pool/main/h/hostname/hostname_$(HOSTNAME_VERSION).tar.gz
856 # Cross-compile GNU gettext.
857 stage3-chroot/usr/bin/gettext: gettext-$(GETTEXT_VERSION).tar.gz
858 rm -rf gettext-$(GETTEXT_VERSION)
860 cd gettext-$(GETTEXT_VERSION) && \
861 PATH=$(ROOT)/fixed-gcc:$$PATH \
863 --host=riscv64-unknown-linux-gnu \
864 --prefix=/usr --libdir=/usr/lib64
865 cd gettext-$(GETTEXT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
866 cd gettext-$(GETTEXT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
867 rm -f stage3-chroot/usr/lib64/*.la
869 gettext-$(GETTEXT_VERSION).tar.gz:
871 wget -O $@-t https://ftp.gnu.org/gnu/gettext/gettext-$(GETTEXT_VERSION).tar.gz
874 # Cross-compile RPM / rpmbuild.
875 # We build this from a git commit, with a few hacks to the configure
877 stage3-chroot/usr/bin/rpm: rpm-$(RPM_SHORT_COMMIT).tar.gz db-$(BDB_VERSION).tar.gz
878 rm -rf rpm-$(RPM_SHORT_COMMIT)
879 tar -zxf rpm-$(RPM_SHORT_COMMIT).tar.gz
880 tar -zxf db-$(BDB_VERSION).tar.gz -C rpm-$(RPM_SHORT_COMMIT)
881 cd rpm-$(RPM_SHORT_COMMIT) && ln -s db-$(BDB_VERSION) db
882 cd rpm-$(RPM_SHORT_COMMIT) && \
883 patch -p1 < ../0001-RISCV-64-bit-riscv64-support.patch && \
884 patch -p1 < ../0002-build-fgetc-returns-int-not-char.patch && \
885 patch -p1 < ../0003-HACKS-TO-GET-RPM-TO-CROSS-COMPILE.patch
886 cd rpm-$(RPM_SHORT_COMMIT) && autoreconf -i
887 cd rpm-$(RPM_SHORT_COMMIT) && \
888 PATH=$(ROOT)/fixed-gcc:$$PATH \
889 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
891 --host=riscv64-unknown-linux-gnu \
892 --prefix=/usr --libdir=/usr/lib64 \
894 --without-libarchive \
898 --without-external-db \
901 cd rpm-$(RPM_SHORT_COMMIT) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
902 cd rpm-$(RPM_SHORT_COMMIT) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
903 rm -f stage3-chroot/usr/lib64/*.la
905 rpm-$(RPM_SHORT_COMMIT).tar.gz:
907 wget -O $@-t 'http://rpm.org/gitweb?p=rpm.git;a=snapshot;h=$(RPM_COMMIT);sf=tgz'
910 db-$(BDB_VERSION).tar.gz:
912 wget -O $@-t http://download.oracle.com/berkeley-db/db-$(BDB_VERSION).tar.gz
915 # Create an /init script.
916 stage3-chroot/init: init.sh
917 install -m 0755 $^ $@
919 # Create the stage3 disk image.
920 # Note `-s +...' adds spare space to the disk image.
921 stage3-disk.img: stage3-chroot
922 cd stage3-chroot && virt-make-fs . ../$@ -t ext2 -F raw -s +4G
924 # Upload the compressed disk image.
925 upload-stage3: stage3-disk.img.xz
926 scp $^ tick:public_html/riscv/
927 stage3-disk.img.xz: stage3-disk.img
931 # Helper which boots stage3 disk image in spike.
932 boot-stage3-in-spike: stage3-disk.img stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
933 spike +disk=stage3-disk.img \
934 /usr/bin/bbl stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
936 # Helper which boots stage3 disk image in qemu.
937 boot-stage3-in-qemu: stage3-disk.img stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
938 qemu-system-riscv -kernel /usr/bin/bbl \
939 -append ./stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux \
940 -drive file=stage3-disk.img,format=raw -nographic