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
513 rm -f stage3-chroot/usr/lib64/*.la
515 gcc-$(GCC_X_VERSION).tar.gz:
517 wget -O $@-t https://github.com/riscv/riscv-gcc/archive/riscv-gcc-$(GCC_X_VERSION).tar.gz
520 # Cross-compile util-linux.
521 stage3-chroot/usr/bin/mount: util-linux-$(UTIL_LINUX_VERSION).tar.xz
522 rm -rf util-linux-$(UTIL_LINUX_VERSION)
524 cd util-linux-$(UTIL_LINUX_VERSION) && \
525 PATH=$(ROOT)/fixed-gcc:$$PATH \
526 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
528 --host=riscv64-unknown-linux-gnu \
529 --prefix=/usr --libdir=/usr/lib64 \
532 --disable-makeinstall-chown \
533 --enable-static-programs=mount
534 cd util-linux-$(UTIL_LINUX_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
535 cd util-linux-$(UTIL_LINUX_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
536 rm -f stage3-chroot/usr/lib64/*.la
538 util-linux-$(UTIL_LINUX_VERSION).tar.xz:
540 wget -O $@-t ftp://ftp.kernel.org/pub/linux/utils/util-linux/v$(UTIL_LINUX_VERSION)/util-linux-$(UTIL_LINUX_VERSION).tar.xz
543 # Cross-compile GNU tar.
544 stage3-chroot/usr/bin/tar: tar-$(TAR_VERSION).tar.xz
545 rm -rf tar-$(TAR_VERSION)
547 cd tar-$(TAR_VERSION) && \
548 PATH=$(ROOT)/fixed-gcc:$$PATH \
550 --host=riscv64-unknown-linux-gnu \
551 --prefix=/usr --libdir=/usr/lib64
552 cd tar-$(TAR_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
553 cd tar-$(TAR_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
555 tar-$(TAR_VERSION).tar.xz:
557 wget -O $@-t https://ftp.gnu.org/gnu/tar/tar-$(TAR_VERSION).tar.xz
560 # Cross-compile GNU gzip.
561 stage3-chroot/usr/bin/gzip: gzip-$(GZIP_VERSION).tar.gz
562 rm -rf gzip-$(GZIP_VERSION)
564 cd gzip-$(GZIP_VERSION) && \
565 PATH=$(ROOT)/fixed-gcc:$$PATH \
567 --host=riscv64-unknown-linux-gnu \
568 --prefix=/usr --libdir=/usr/lib64
569 cd gzip-$(GZIP_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
570 cd gzip-$(GZIP_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
572 gzip-$(GZIP_VERSION).tar.gz:
574 wget -O $@-t https://ftp.gnu.org/gnu/gzip/gzip-$(GZIP_VERSION).tar.gz
577 # Cross-compile zlib.
578 stage3-chroot/usr/lib64/libz.so: zlib-$(ZLIB_VERSION).tar.gz
579 rm -rf zlib-$(ZLIB_VERSION)
581 cd zlib-$(ZLIB_VERSION) && \
582 PATH=$(ROOT)/fixed-gcc:$$PATH \
583 CC=riscv64-unknown-linux-gnu-gcc \
584 CFLAGS="-I$(ROOT)/stage3-chroot/usr/include -L$(ROOT)/stage3-chroot/usr/lib" \
586 --prefix=/usr --libdir=/usr/lib64
587 cd zlib-$(ZLIB_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make shared
588 cd zlib-$(ZLIB_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
590 zlib-$(ZLIB_VERSION).tar.gz:
592 wget -O $@-t http://zlib.net/zlib-$(ZLIB_VERSION).tar.gz
595 # Cross-compile file/libmagic.
596 stage3-chroot/usr/bin/file: file-$(FILE_VERSION).tar.gz
597 rm -rf file-$(FILE_VERSION)
599 cd file-$(FILE_VERSION) && \
600 PATH=$(ROOT)/fixed-gcc:$$PATH \
601 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
603 --host=riscv64-unknown-linux-gnu \
604 --prefix=/usr --libdir=/usr/lib64 \
605 --disable-static --enable-shared
606 cd file-$(FILE_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
607 cd file-$(FILE_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
608 rm -f stage3-chroot/usr/lib64/*.la
610 file-$(FILE_VERSION).tar.gz:
612 wget -O $@-t ftp://ftp.astron.com/pub/file/file-$(FILE_VERSION).tar.gz
615 # Cross-compile popt.
616 stage3-chroot/usr/lib64/libpopt.so: popt-$(POPT_VERSION).tar.gz
617 rm -rf popt-$(POPT_VERSION)
619 cd popt-$(POPT_VERSION) && \
620 PATH=$(ROOT)/fixed-gcc:$$PATH \
621 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
623 --host=riscv64-unknown-linux-gnu \
624 --prefix=/usr --libdir=/usr/lib64 \
625 --disable-static --enable-shared
626 cd popt-$(POPT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
627 cd popt-$(POPT_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
628 rm -f stage3-chroot/usr/lib64/*.la
630 popt-$(POPT_VERSION).tar.gz:
632 wget -O $@-t http://rpm5.org/files/popt/popt-$(POPT_VERSION).tar.gz
635 # Cross-compile beecrypt.
636 stage3-chroot/usr/lib64/libbeecrypt.so: beecrypt-$(BEECRYPT_VERSION).tar.gz
637 rm -rf beecrypt-$(BEECRYPT_VERSION)
639 cd beecrypt-$(BEECRYPT_VERSION) && patch -p0 < ../beecrypt-disable-cplusplus.patch
640 cd beecrypt-$(BEECRYPT_VERSION) && autoreconf -i
641 cd beecrypt-$(BEECRYPT_VERSION) && \
642 PATH=$(ROOT)/fixed-gcc:$$PATH \
643 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
645 --host=riscv64-unknown-linux-gnu \
646 --prefix=/usr --libdir=/usr/lib64 \
647 --without-cplusplus \
652 cd beecrypt-$(BEECRYPT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
653 cd beecrypt-$(BEECRYPT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot V=1
654 chrpath -d stage3-chroot/usr/lib64/libbeecrypt.so.*
655 rm -f stage3-chroot/usr/lib64/*.la
657 beecrypt-$(BEECRYPT_VERSION).tar.gz:
659 wget -O $@-t http://downloads.sourceforge.net/sourceforge/beecrypt/beecrypt-$(BEECRYPT_VERSION).tar.gz
662 # Cross-compile GNU nano (editor).
663 stage3-chroot/usr/bin/nano: nano-$(NANO_VERSION).tar.gz
664 rm -rf nano-$(NANO_VERSION)
666 cd nano-$(NANO_VERSION) && \
667 PATH=$(ROOT)/fixed-gcc:$$PATH \
668 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
670 --host=riscv64-unknown-linux-gnu \
671 --prefix=/usr --libdir=/usr/lib64
672 cd nano-$(NANO_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
673 cd nano-$(NANO_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
675 nano-$(NANO_VERSION).tar.gz:
677 wget -O $@-t https://www.nano-editor.org/dist/v2.6/nano-$(NANO_VERSION).tar.gz
680 # Cross-compile GNU grep.
681 stage3-chroot/usr/bin/grep: grep-$(GREP_VERSION).tar.xz
682 rm -rf grep-$(GREP_VERSION)
684 cd grep-$(GREP_VERSION) && \
685 PATH=$(ROOT)/fixed-gcc:$$PATH \
687 --host=riscv64-unknown-linux-gnu \
688 --prefix=/usr --libdir=/usr/lib64
689 cd grep-$(GREP_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
690 cd grep-$(GREP_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
692 grep-$(GREP_VERSION).tar.xz:
694 wget -O $@-t https://ftp.gnu.org/gnu/grep/grep-$(GREP_VERSION).tar.xz
697 # Cross-compile less.
698 stage3-chroot/usr/bin/less: less-$(LESS_VERSION).tar.gz
699 rm -rf less-$(LESS_VERSION)
701 cd less-$(LESS_VERSION) && \
702 PATH=$(ROOT)/fixed-gcc:$$PATH \
703 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
705 --host=riscv64-unknown-linux-gnu \
706 --prefix=/usr --libdir=/usr/lib64
707 cd less-$(LESS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
708 cd less-$(LESS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
710 less-$(LESS_VERSION).tar.gz:
712 wget -O $@-t http://www.greenwoodsoftware.com/less/less-$(LESS_VERSION).tar.gz
715 # Cross-compile strace.
716 # XXX This does not work.
717 stage3-chroot/usr/bin/strace: strace-$(STRACE_SHORT_COMMIT).tar.gz
718 rm -rf strace-$(STRACE_SHORT_COMMIT)
720 cd riscv-strace-$(STRACE_COMMIT) && patch -p1 < ../0001-Update-riscv_regs-for-ptrace.h-from-Linux-4.1.x.patch
721 cd riscv-strace-$(STRACE_COMMIT) && \
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 riscv-strace-$(STRACE_COMMIT) && PATH=$(ROOT)/fixed-gcc:$$PATH make
728 cd riscv-strace-$(STRACE_COMMIT) && make install DESTDIR=$(ROOT)/stage3-chroot
730 strace-$(STRACE_SHORT_COMMIT).tar.gz:
732 wget -O $@-t 'https://github.com/riscv/riscv-strace/archive/$(STRACE_COMMIT)/riscv-strace-$(STRACE_SHORTCOMMIT).tar.gz'
735 # Cross-compile bzip2.
736 stage3-chroot/usr/bin/bzip2: bzip2-$(BZIP2_VERSION).tar.gz
737 rm -rf bzip2-$(BZIP2_VERSION)
739 cd bzip2-$(BZIP2_VERSION) && \
740 PATH=$(ROOT)/fixed-gcc:$$PATH \
741 make libbz2.a bzip2 bzip2recover \
743 CC=riscv64-unknown-linux-gnu-gcc \
744 AR=riscv64-unknown-linux-gnu-ar \
745 RANLIB=riscv64-unknown-linux-gnu-ranlib \
746 CFLAGS="-Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -fPIC"
747 cd bzip2-$(BZIP2_VERSION) && \
748 make install PREFIX=$(ROOT)/stage3-chroot/usr
750 bzip2-$(BZIP2_VERSION).tar.gz:
752 wget -O $@-t http://www.bzip.org/1.0.6/bzip2-$(BZIP2_VERSION).tar.gz
755 # Cross-compile GNU make.
756 stage3-chroot/usr/bin/make: make-$(MAKE_VERSION).tar.gz
757 rm -rf make-$(MAKE_VERSION)
759 cd make-$(MAKE_VERSION) && \
760 PATH=$(ROOT)/fixed-gcc:$$PATH \
762 --host=riscv64-unknown-linux-gnu \
763 --prefix=/usr --libdir=/usr/lib64
764 cd make-$(MAKE_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
765 cd make-$(MAKE_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
767 make-$(MAKE_VERSION).tar.gz:
769 wget -O $@-t https://ftp.gnu.org/gnu/make/make-$(MAKE_VERSION).tar.gz
772 # Cross-compile GNU diffutils.
773 stage3-chroot/usr/bin/diff: diffutils-$(DIFFUTILS_VERSION).tar.xz
774 rm -rf diffutils-$(DIFFUTILS_VERSION)
776 cd diffutils-$(DIFFUTILS_VERSION) && \
777 PATH=$(ROOT)/fixed-gcc:$$PATH \
779 --host=riscv64-unknown-linux-gnu \
780 --prefix=/usr --libdir=/usr/lib64
781 cd diffutils-$(DIFFUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
782 cd diffutils-$(DIFFUTILS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
784 diffutils-$(DIFFUTILS_VERSION).tar.xz:
786 wget -O $@-t https://ftp.gnu.org/gnu/diffutils/diffutils-$(DIFFUTILS_VERSION).tar.xz
789 # Cross-compile GNU findutils.
790 stage3-chroot/usr/bin/find: findutils-$(FINDUTILS_VERSION).tar.gz
791 rm -rf findutils-$(FINDUTILS_VERSION)
793 cd findutils-$(FINDUTILS_VERSION) && \
794 PATH=$(ROOT)/fixed-gcc:$$PATH \
796 --host=riscv64-unknown-linux-gnu \
797 --prefix=/usr --libdir=/usr/lib64
798 cd findutils-$(FINDUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
799 cd findutils-$(FINDUTILS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
801 findutils-$(FINDUTILS_VERSION).tar.gz:
803 wget -O $@-t https://ftp.gnu.org/gnu/findutils/findutils-$(FINDUTILS_VERSION).tar.gz
806 # Cross-compile GNU sed.
807 stage3-chroot/usr/bin/sed: sed-$(SED_VERSION).tar.gz
808 rm -rf sed-$(SED_VERSION)
810 cd sed-$(SED_VERSION) && \
811 PATH=$(ROOT)/fixed-gcc:$$PATH \
813 --host=riscv64-unknown-linux-gnu \
814 --prefix=/usr --libdir=/usr/lib64
815 cd sed-$(SED_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
816 cd sed-$(SED_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
818 sed-$(SED_VERSION).tar.gz:
820 wget -O $@-t https://ftp.gnu.org/gnu/sed/sed-$(SED_VERSION).tar.gz
823 # Cross-compile patch.
824 stage3-chroot/usr/bin/patch: patch-$(PATCH_VERSION).tar.gz
825 rm -rf patch-$(PATCH_VERSION)
827 cd patch-$(PATCH_VERSION) && \
828 PATH=$(ROOT)/fixed-gcc:$$PATH \
830 --host=riscv64-unknown-linux-gnu \
831 --prefix=/usr --libdir=/usr/lib64
832 cd patch-$(PATCH_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
833 cd patch-$(PATCH_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
835 patch-$(PATCH_VERSION).tar.gz:
837 wget -O $@-t https://ftp.gnu.org/gnu/patch/patch-$(PATCH_VERSION).tar.gz
840 # Cross-compile hostname.
841 stage3-chroot/usr/bin/hostname: hostname-$(HOSTNAME_VERSION).tar.gz
842 rm -rf hostname-$(HOSTNAME_VERSION)
844 cd hostname && patch -p1 < ../hostname-rh.patch
846 PATH=$(ROOT)/fixed-gcc:$$PATH \
848 CC=riscv64-unknown-linux-gnu-gcc \
850 cd hostname && make install BASEDIR=$(ROOT)/stage3-chroot
852 hostname-$(HOSTNAME_VERSION).tar.gz:
854 wget -O $@-t http://ftp.de.debian.org/debian/pool/main/h/hostname/hostname_$(HOSTNAME_VERSION).tar.gz
857 # Cross-compile GNU gettext.
858 stage3-chroot/usr/bin/gettext: gettext-$(GETTEXT_VERSION).tar.gz
859 rm -rf gettext-$(GETTEXT_VERSION)
861 cd gettext-$(GETTEXT_VERSION) && \
862 PATH=$(ROOT)/fixed-gcc:$$PATH \
864 --host=riscv64-unknown-linux-gnu \
865 --prefix=/usr --libdir=/usr/lib64
866 cd gettext-$(GETTEXT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
867 cd gettext-$(GETTEXT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
868 rm -f stage3-chroot/usr/lib64/*.la
870 gettext-$(GETTEXT_VERSION).tar.gz:
872 wget -O $@-t https://ftp.gnu.org/gnu/gettext/gettext-$(GETTEXT_VERSION).tar.gz
875 # Cross-compile RPM / rpmbuild.
876 # We build this from a git commit, with a few hacks to the configure
878 stage3-chroot/usr/bin/rpm: rpm-$(RPM_SHORT_COMMIT).tar.gz db-$(BDB_VERSION).tar.gz
879 rm -rf rpm-$(RPM_SHORT_COMMIT)
880 tar -zxf rpm-$(RPM_SHORT_COMMIT).tar.gz
881 tar -zxf db-$(BDB_VERSION).tar.gz -C rpm-$(RPM_SHORT_COMMIT)
882 cd rpm-$(RPM_SHORT_COMMIT) && ln -s db-$(BDB_VERSION) db
883 cd rpm-$(RPM_SHORT_COMMIT) && \
884 patch -p1 < ../0001-RISCV-64-bit-riscv64-support.patch && \
885 patch -p1 < ../0002-build-fgetc-returns-int-not-char.patch && \
886 patch -p1 < ../0003-HACKS-TO-GET-RPM-TO-CROSS-COMPILE.patch
887 cd rpm-$(RPM_SHORT_COMMIT) && autoreconf -i
888 cd rpm-$(RPM_SHORT_COMMIT) && \
889 PATH=$(ROOT)/fixed-gcc:$$PATH \
890 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
892 --host=riscv64-unknown-linux-gnu \
893 --prefix=/usr --libdir=/usr/lib64 \
895 --without-libarchive \
899 --without-external-db \
902 cd rpm-$(RPM_SHORT_COMMIT) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
903 cd rpm-$(RPM_SHORT_COMMIT) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
904 rm -f stage3-chroot/usr/lib64/*.la
906 rpm-$(RPM_SHORT_COMMIT).tar.gz:
908 wget -O $@-t 'http://rpm.org/gitweb?p=rpm.git;a=snapshot;h=$(RPM_COMMIT);sf=tgz'
911 db-$(BDB_VERSION).tar.gz:
913 wget -O $@-t http://download.oracle.com/berkeley-db/db-$(BDB_VERSION).tar.gz
916 # Create an /init script.
917 stage3-chroot/init: init.sh
918 install -m 0755 $^ $@
920 # Create the stage3 disk image.
921 # Note `-s +...' adds spare space to the disk image.
922 stage3-disk.img: stage3-chroot
923 cd stage3-chroot && virt-make-fs . ../$@ -t ext2 -F raw -s +4G
925 # Upload the compressed disk image.
926 upload-stage3: stage3-disk.img.xz
927 scp $^ tick:public_html/riscv/
928 stage3-disk.img.xz: stage3-disk.img
932 # Helper which boots stage3 disk image in spike.
933 boot-stage3-in-spike: stage3-disk.img stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
934 spike +disk=stage3-disk.img \
935 /usr/bin/bbl stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
937 # Helper which boots stage3 disk image in qemu.
938 boot-stage3-in-qemu: stage3-disk.img stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
939 qemu-system-riscv -kernel /usr/bin/bbl \
940 -append ./stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux \
941 -drive file=stage3-disk.img,format=raw -nographic