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 in the
38 # stage 3 chroot. This must include all the cross-compiled packages
39 # below, and may also include any noarch package we like.
40 STAGE3_PACKAGES = ncurses-devel bash coreutils gmp-devel \
41 mpfr-devel mpc-devel binutils gcc gcc-c++ util-linux tar \
42 gzip zlib-devel file-devel popt-devel beecrypt-devel \
43 rpm rpm-build rpm-devel libdb-utils libdb-devel nano \
44 grep less strace bzip2-devel make diffutils findutils \
45 sed patch hostname gettext-devel
47 # Versions of cross-compiled packages.
48 NCURSES_VERSION = 6.0-20160730
50 COREUTILS_VERSION = 8.25
54 BINUTILS_X_VERSION = 2.26
56 UTIL_LINUX_VERSION = 2.28
60 # Needs to match the version of 'file' installed (on host), otherwise:
61 # "Cannot use the installed version of file (xx) to cross-compile file yy"
62 # Also note that 5.25 is definitely broken (segfaults in libmagic:magic_close).
65 BEECRYPT_VERSION = 4.2.1
66 RPM_COMMIT = 95712183458748ea6cafebac1bdd5daa097d9bee
67 RPM_SHORT_COMMIT = 9571218
72 STRACE_COMMIT = f320e1897832fd07a62e18ed288e75d8e79f4c5b
73 STRACE_SHORT_COMMIT = f320e189
76 DIFFUTILS_VERSION = 3.4
77 FINDUTILS_VERSION = 4.6.0
80 HOSTNAME_VERSION = 3.15
81 GETTEXT_VERSION = 0.19
83 all: stage1 stage2 stage3 stage4
87 stage1: stage1-riscv-qemu/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz \
88 stage1-riscv-qemu/riscv-qemu.spec \
89 stamp-riscv-qemu-installed \
90 stage1-riscv-fesvr/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz \
91 stage1-riscv-fesvr/riscv-fesvr.spec \
92 stamp-riscv-fesvr-installed \
93 stage1-riscv-isa-sim/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz \
94 stage1-riscv-isa-sim/riscv-isa-sim.spec \
95 stamp-riscv-isa-sim-installed
97 stage1-riscv-qemu/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz:
99 wget -O $@-t 'https://github.com/riscv/riscv-qemu/archive/$(RISCV_QEMU_COMMIT)/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz'
102 stage1-riscv-qemu/riscv-qemu.spec: stage1-riscv-qemu/riscv-qemu.spec.in
103 sed -e 's/@COMMIT@/$(RISCV_QEMU_COMMIT)/g' \
104 -e 's/@SHORTCOMMIT@/$(RISCV_QEMU_SHORTCOMMIT)/g' \
108 stamp-riscv-qemu-installed:
110 @rpm -q riscv-qemu >/dev/null || { \
111 echo "ERROR: You must install riscv-qemu:"; \
113 echo " dnf copr enable rjones/riscv"; \
114 echo " dnf install riscv-qemu"; \
116 echo "OR: you can build it yourself from the stage1-riscv-qemu directory."; \
120 @qemu-system-riscv --version || { \
121 echo "ERROR: qemu-system-riscv is not working."; \
122 echo "Make sure you installed the riscv-qemu package."; \
127 stage1-riscv-fesvr/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz:
129 wget -O $@-t 'https://github.com/riscv/riscv-fesvr/archive/$(RISCV_FESVR_COMMIT)/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz'
132 stage1-riscv-fesvr/riscv-fesvr.spec: stage1-riscv-fesvr/riscv-fesvr.spec.in
133 sed -e 's/@COMMIT@/$(RISCV_FESVR_COMMIT)/g' \
134 -e 's/@SHORTCOMMIT@/$(RISCV_FESVR_SHORTCOMMIT)/g' \
138 stamp-riscv-fesvr-installed:
140 @rpm -q riscv-fesvr >/dev/null || { \
141 echo "ERROR: You must install riscv-fesvr:"; \
143 echo " dnf copr enable rjones/riscv"; \
144 echo " dnf install riscv-fesvr"; \
146 echo "OR: you can build it yourself from the stage1-riscv-fesvr directory."; \
152 stage1-riscv-isa-sim/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz:
154 wget -O $@-t 'https://github.com/riscv/riscv-isa-sim/archive/$(RISCV_ISA_SIM_COMMIT)/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz'
157 stage1-riscv-isa-sim/riscv-isa-sim.spec: stage1-riscv-isa-sim/riscv-isa-sim.spec.in
158 sed -e 's/@COMMIT@/$(RISCV_ISA_SIM_COMMIT)/g' \
159 -e 's/@SHORTCOMMIT@/$(RISCV_ISA_SIM_SHORTCOMMIT)/g' \
163 stamp-riscv-isa-sim-installed:
165 @rpm -q riscv-isa-sim >/dev/null || { \
166 echo "ERROR: You must install riscv-isa-sim:"; \
168 echo " dnf copr enable rjones/riscv"; \
169 echo " dnf install riscv-isa-sim"; \
171 echo "OR: you can build it yourself from the stage1-riscv-isa-sim directory."; \
179 stage2: stage2-riscv-gnu-toolchain/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz \
180 stage2-riscv-gnu-toolchain/binutils-$(BINUTILS_VERSION).tar.gz \
181 stage2-riscv-gnu-toolchain/gcc-$(GCC_VERSION).tar.gz \
182 stage2-riscv-gnu-toolchain/glibc-$(GLIBC_VERSION).tar.gz \
183 stage2-riscv-gnu-toolchain/newlib-$(NEWLIB_VERSION).tar.gz \
184 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec \
185 stamp-riscv-gnu-toolchain-installed \
186 stage2-riscv-pk/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz \
187 stage2-riscv-pk/riscv-pk.spec \
188 stamp-riscv-pk-installed
190 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz:
192 wget -O $@-t https://github.com/lowRISC/riscv-gnu-toolchain/archive/$(RISCV_GNU_TOOLCHAIN_COMMIT)/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz
195 stage2-riscv-gnu-toolchain/binutils-$(BINUTILS_VERSION).tar.gz:
197 wget -O $@-t http://mirrors.kernel.org/gnu/binutils/binutils-$(BINUTILS_VERSION).tar.gz
200 # GCC 5 no longer compiles with GCC 6 unless we patch it.
201 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69959
202 stage2-riscv-gnu-toolchain/gcc-$(GCC_VERSION).tar.gz:
204 wget -O $@-t http://mirrors.kernel.org/gnu/gcc/gcc-$(GCC_VERSION)/gcc-$(GCC_VERSION).tar.gz
206 cd gcc-$(GCC_VERSION) && patch -p0 < ../stage2-riscv-gnu-toolchain/gcc-5-fix-compilation-with-gcc-6.patch
207 tar zcf $@-t gcc-$(GCC_VERSION)
208 rm -r gcc-$(GCC_VERSION)
211 stage2-riscv-gnu-toolchain/glibc-$(GLIBC_VERSION).tar.gz:
213 wget -O $@-t http://mirrors.kernel.org/gnu/glibc/glibc-$(GLIBC_VERSION).tar.gz
216 stage2-riscv-gnu-toolchain/newlib-$(NEWLIB_VERSION).tar.gz:
218 wget -O $@-t ftp://sourceware.org/pub/newlib/newlib-$(NEWLIB_VERSION).tar.gz
221 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec: stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec.in
222 sed -e 's/@COMMIT@/$(RISCV_GNU_TOOLCHAIN_COMMIT)/g' \
223 -e 's/@SHORTCOMMIT@/$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT)/g' \
224 -e 's/@BINUTILS_VERSION@/$(BINUTILS_VERSION)/g' \
225 -e 's/@GCC_VERSION@/$(GCC_VERSION)/g' \
226 -e 's/@GLIBC_VERSION@/$(GLIBC_VERSION)/g' \
227 -e 's/@NEWLIB_VERSION@/$(NEWLIB_VERSION)/g' \
231 stamp-riscv-gnu-toolchain-installed:
233 @rpm -q riscv-gnu-toolchain >/dev/null || { \
234 echo "ERROR: You must install riscv-gnu-toolchain:"; \
236 echo " dnf copr enable rjones/riscv"; \
237 echo " dnf install riscv-gnu-toolchain"; \
239 echo "OR: you can build it yourself from the stage2-riscv-gnu-toolchain directory."; \
243 @riscv64-unknown-elf-gcc --version || { \
244 echo "ERROR: riscv64-unknown-elf-gcc (cross compiler) is not working."; \
245 echo "Make sure you installed the riscv-gnu-toolchain package."; \
250 stage2-riscv-pk/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz:
252 wget -O $@-t https://github.com/lowRISC/riscv-pk/archive/$(RISCV_PK_COMMIT)/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz
255 stage2-riscv-pk/riscv-pk.spec: stage2-riscv-pk/riscv-pk.spec.in
256 sed -e 's/@COMMIT@/$(RISCV_PK_COMMIT)/g' \
257 -e 's/@SHORTCOMMIT@/$(RISCV_PK_SHORTCOMMIT)/g' \
261 stamp-riscv-pk-installed:
263 @rpm -q riscv-pk >/dev/null || { \
264 echo "ERROR: You must install riscv-pk:"; \
266 echo " dnf copr enable rjones/riscv"; \
267 echo " dnf install riscv-pk"; \
269 echo "OR: you can build it yourself from the stage2-riscv-pk directory."; \
277 stage3: stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux \
278 stage3-chroot-original/etc/fedora-release \
279 stage3-chroot/etc/fedora-release \
280 stage3-chroot/lib64/libc.so.6 \
281 stage3-chroot/usr/bin/tic \
282 stage3-chroot/bin/bash \
283 stage3-chroot/bin/ls \
284 stage3-chroot/usr/lib64/libgmp.so.10 \
285 stage3-chroot/usr/lib64/libmpfr.so.4 \
286 stage3-chroot/usr/lib64/libmpc.so.3 \
287 stage3-chroot/usr/bin/as \
288 stage3-chroot/usr/bin/gcc \
289 stage3-chroot/usr/bin/mount \
290 stage3-chroot/usr/bin/tar \
291 stage3-chroot/usr/bin/gzip \
292 stage3-chroot/usr/lib64/libz.so \
293 stage3-chroot/usr/bin/file \
294 stage3-chroot/usr/lib64/libpopt.so \
295 stage3-chroot/usr/lib64/libbeecrypt.so \
296 stage3-chroot/usr/bin/nano \
297 stage3-chroot/usr/bin/grep \
298 stage3-chroot/usr/bin/less \
299 stage3-chroot/usr/bin/strace \
300 stage3-chroot/usr/bin/bzip2 \
301 stage3-chroot/usr/bin/make \
302 stage3-chroot/usr/bin/diff \
303 stage3-chroot/usr/bin/find \
304 stage3-chroot/usr/bin/sed \
305 stage3-chroot/usr/bin/patch \
306 stage3-chroot/usr/bin/hostname \
307 stage3-chroot/usr/bin/gettext \
308 stage3-chroot/usr/bin/rpm \
312 stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux:
313 rm -rf stage3-kernel/linux-$(KERNEL_VERSION)
314 cp -a $(LOCAL_LINUX_GIT_COPY) stage3-kernel/linux-$(KERNEL_VERSION) || { \
315 mkdir stage3-kernel/linux-$(KERNEL_VERSION) && \
316 cd stage3-kernel/linux-$(KERNEL_VERSION) && \
319 cd stage3-kernel/linux-$(KERNEL_VERSION) && \
320 git remote add riscv https://github.com/riscv/riscv-linux && \
322 git checkout -f linux-4.1.y-riscv && \
324 make ARCH=riscv defconfig
325 echo CONFIG_CMDLINE=\"root=/dev/htifblk0 init=/init\" >> stage3-kernel/linux-$(KERNEL_VERSION)/.config
326 echo CONFIG_CROSS_COMPILE=riscv64-unknown-elf- >> stage3-kernel/linux-$(KERNEL_VERSION)/.config
327 cd stage3-kernel/linux-$(KERNEL_VERSION) && \
328 make ARCH=riscv olddefconfig
329 cd stage3-kernel/linux-$(KERNEL_VERSION) && \
330 make ARCH=riscv vmlinux
333 # Build an original (x86-64) chroot using supermin. We then aim to
334 # rebuild (using cross-compiled versions) every ELF binary in this
336 stage3-chroot-original/etc/fedora-release:
337 rm -rf stage3-chroot-original tmp-supermin.d
338 supermin --prepare $(STAGE3_PACKAGES) -o tmp-supermin.d
339 supermin --build -f chroot tmp-supermin.d -o stage3-chroot-original
341 @echo -n "Total files in chroot: "
342 @find stage3-chroot-original -type f | wc -l
343 @echo -n "ELF files to be rebuilt: "
344 @find stage3-chroot-original -type f | xargs file -N | grep -E '\bELF.*LSB\b' | wc -l
346 # Copy the original chroot to the final chroot, remove all the ELF
348 stage3-chroot/etc/fedora-release: stage3-chroot-original/etc/fedora-release
350 cp -a stage3-chroot-original stage3-chroot
351 find stage3-chroot -type d -print0 | xargs -0 chmod u+w
352 find stage3-chroot -type f -print0 | xargs -0 chmod u+w
353 find stage3-chroot -type f -print0 | xargs -0 file -N | grep -E '\bELF.*LSB\b' | awk -F: '{print $$1}' | xargs rm -f
354 rm -f stage3-chroot/lib64/libc.so.6
356 # Copy in compiled glibc from the riscv-gnu-toolchain sysroot. Only
357 # copy files and symlinks, leave the target directory structure
359 stage3-chroot/lib64/libc.so.6:
360 mkdir -p stage3-chroot/usr/lib/audit
361 mkdir -p stage3-chroot/usr/lib/gconv
362 for f in `cd /usr/sysroot && find -type f -o -type l`; do \
363 cp -d /usr/sysroot/$$f stage3-chroot/$$f; \
365 cd stage3-chroot/lib64 && for f in ../lib/*; do ln -sf $$f; done
367 # Cross-compile ncurses.
368 stage3-chroot/usr/bin/tic: ncurses-$(NCURSES_VERSION).tgz
370 cd ncurses-$(NCURSES_VERSION) && \
371 PATH=$(ROOT)/fixed-gcc:$$PATH \
372 ./configure --host=riscv64-unknown-linux-gnu \
373 --prefix=/usr --libdir=/usr/lib64 \
375 --with-termlib=tinfo \
377 cd ncurses-$(NCURSES_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
378 cd ncurses-$(NCURSES_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
380 ncurses-$(NCURSES_VERSION).tgz:
382 wget -O $@-t ftp://invisible-island.net/ncurses/current/ncurses-$(NCURSES_VERSION).tgz
385 # Cross-compile bash.
386 stage3-chroot/bin/bash: bash-$(BASH_VERSION).tar.gz
388 cd bash-$(BASH_VERSION) && \
389 PATH=$(ROOT)/fixed-gcc:$$PATH \
390 ./configure --host=riscv64-unknown-linux-gnu \
391 --prefix=/usr --libdir=/usr/lib64
392 cd bash-$(BASH_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
393 cd bash-$(BASH_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
395 bash-$(BASH_VERSION).tar.gz:
397 wget -O $@-t ftp://ftp.gnu.org/gnu/bash/bash-$(BASH_VERSION).tar.gz
400 # Cross-compile coreutils. Bleah, coreutils cross-compilation is
401 # known-broken and upstream don't care, hence the 'touch' command.
403 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
405 stage3-chroot/bin/ls: coreutils-$(COREUTILS_VERSION).tar.xz
406 rm -rf coreutils-$(COREUTILS_VERSION)
408 cd coreutils-$(COREUTILS_VERSION) && \
409 PATH=$(ROOT)/fixed-gcc:$$PATH \
410 ./configure --host=riscv64-unknown-linux-gnu \
411 --prefix=/usr --libdir=/usr/lib64
412 -cd coreutils-$(COREUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
413 cd coreutils-$(COREUTILS_VERSION)/man && \
414 for f in $(COREUTILS_PROGRAMS); do touch $$f.1; done
415 cd coreutils-$(COREUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
416 cd coreutils-$(COREUTILS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
418 coreutils-$(COREUTILS_VERSION).tar.xz:
420 wget -O $@-t ftp://ftp.gnu.org/gnu/coreutils/coreutils-$(COREUTILS_VERSION).tar.xz
423 # Cross-compile binutils.
424 stage3-chroot/usr/bin/as: binutils-$(BINUTILS_X_VERSION).tar.gz
425 rm -rf riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)
427 mkdir riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build
428 cd riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build && \
429 PATH=$(ROOT)/fixed-gcc:$$PATH \
431 --host=riscv64-unknown-linux-gnu \
432 --prefix=/usr --libdir=/usr/lib64
433 cd riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build && PATH=$(ROOT)/fixed-gcc:$$PATH make
434 cd riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build && make DESTDIR=$(ROOT)/stage3-chroot install
436 binutils-$(BINUTILS_X_VERSION).tar.gz:
438 wget -O $@-t https://github.com/riscv/riscv-binutils-gdb/archive/riscv-binutils-$(BINUTILS_X_VERSION).tar.gz
441 # Cross-compile GMP, MPFR and MPC (deps of GCC).
442 stage3-chroot/usr/lib64/libgmp.so.10: gmp-$(GMP_VERSION).tar.lz
443 rm -rf gmp-$(GMP_VERSION)
444 tar --lzip -xf gmp-$(GMP_VERSION).tar.lz
445 cd gmp-$(GMP_VERSION) && \
446 PATH=$(ROOT)/fixed-gcc:$$PATH \
447 ./configure --host=riscv64-unknown-linux-gnu \
448 --prefix=/usr --libdir=/usr/lib64
449 cd gmp-$(GMP_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
450 cd gmp-$(GMP_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
451 cd stage3-chroot/usr/lib && ln -s ../lib64/libgmp.so
453 gmp-$(GMP_VERSION).tar.lz:
455 wget -O $@-t https://gmplib.org/download/gmp/gmp-$(GMP_VERSION).tar.lz
458 stage3-chroot/usr/lib64/libmpfr.so.4: mpfr-$(MPFR_VERSION).tar.gz
459 rm -rf mpfr-$(MPFR_VERSION)
460 tar -zxf mpfr-$(MPFR_VERSION).tar.gz
461 cd mpfr-$(MPFR_VERSION) && \
462 PATH=$(ROOT)/fixed-gcc:$$PATH \
463 ./configure --host=riscv64-unknown-linux-gnu \
464 --prefix=/usr --libdir=/usr/lib64 \
465 --with-gmp=$(ROOT)/stage3-chroot/usr
466 cd mpfr-$(MPFR_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
467 cd mpfr-$(MPFR_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
468 cd stage3-chroot/usr/lib && ln -s ../lib64/libmpfr.so
469 rm -f stage3-chroot/usr/lib64/*.la
471 mpfr-$(MPFR_VERSION).tar.gz:
473 wget -O $@-t http://www.mpfr.org/mpfr-current/mpfr-$(MPFR_VERSION).tar.gz
476 stage3-chroot/usr/lib64/libmpc.so.3: mpc-$(MPC_VERSION).tar.gz
477 rm -rf mpc-$(MPC_VERSION)
478 tar -zxf mpc-$(MPC_VERSION).tar.gz
479 cd mpc-$(MPC_VERSION) && \
480 PATH=$(ROOT)/fixed-gcc:$$PATH \
481 ./configure --host=riscv64-unknown-linux-gnu \
482 --prefix=/usr --libdir=/usr/lib64 \
483 --with-gmp=$(ROOT)/stage3-chroot/usr \
484 --with-mpfr=$(ROOT)/stage3-chroot/usr
485 cd mpc-$(MPC_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
486 cd mpc-$(MPC_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
487 cd stage3-chroot/usr/lib && ln -s ../lib64/libmpc.so
488 rm -f stage3-chroot/usr/lib64/*.la
490 mpc-$(MPC_VERSION).tar.gz:
492 wget -O $@-t ftp://ftp.gnu.org/gnu/mpc/mpc-$(MPC_VERSION).tar.gz
496 stage3-chroot/usr/bin/gcc: gcc-$(GCC_X_VERSION).tar.gz
497 rm -rf riscv-gcc-riscv-gcc-$(GCC_X_VERSION)
499 cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION) && \
500 patch -p1 < ../0001-HACKS-TO-GET-GCC-TO-COMPILE.patch
501 mkdir riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build
502 cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && \
503 PATH=$(ROOT)/fixed-gcc:$$PATH \
505 --host=riscv64-unknown-linux-gnu \
506 --prefix=/usr --libdir=/usr/lib64 \
509 --enable-languages=c,c++ \
510 --disable-libmudflap \
512 --disable-libquadmath \
515 cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && PATH=$(ROOT)/fixed-gcc:$$PATH make
516 cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && make install DESTDIR=$(ROOT)/stage3-chroot
517 rm -f stage3-chroot/usr/lib64/*.la
519 gcc-$(GCC_X_VERSION).tar.gz:
521 wget -O $@-t https://github.com/riscv/riscv-gcc/archive/riscv-gcc-$(GCC_X_VERSION).tar.gz
524 # Cross-compile util-linux.
525 stage3-chroot/usr/bin/mount: util-linux-$(UTIL_LINUX_VERSION).tar.xz
526 rm -rf util-linux-$(UTIL_LINUX_VERSION)
528 cd util-linux-$(UTIL_LINUX_VERSION) && \
529 PATH=$(ROOT)/fixed-gcc:$$PATH \
530 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
532 --host=riscv64-unknown-linux-gnu \
533 --prefix=/usr --libdir=/usr/lib64 \
536 --disable-makeinstall-chown \
537 --enable-static-programs=mount
538 cd util-linux-$(UTIL_LINUX_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
539 cd util-linux-$(UTIL_LINUX_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
540 rm -f stage3-chroot/usr/lib64/*.la
542 util-linux-$(UTIL_LINUX_VERSION).tar.xz:
544 wget -O $@-t ftp://ftp.kernel.org/pub/linux/utils/util-linux/v$(UTIL_LINUX_VERSION)/util-linux-$(UTIL_LINUX_VERSION).tar.xz
547 # Cross-compile GNU tar.
548 stage3-chroot/usr/bin/tar: tar-$(TAR_VERSION).tar.xz
549 rm -rf tar-$(TAR_VERSION)
551 cd tar-$(TAR_VERSION) && \
552 PATH=$(ROOT)/fixed-gcc:$$PATH \
554 --host=riscv64-unknown-linux-gnu \
555 --prefix=/usr --libdir=/usr/lib64
556 cd tar-$(TAR_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
557 cd tar-$(TAR_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
559 tar-$(TAR_VERSION).tar.xz:
561 wget -O $@-t https://ftp.gnu.org/gnu/tar/tar-$(TAR_VERSION).tar.xz
564 # Cross-compile GNU gzip.
565 stage3-chroot/usr/bin/gzip: gzip-$(GZIP_VERSION).tar.gz
566 rm -rf gzip-$(GZIP_VERSION)
568 cd gzip-$(GZIP_VERSION) && \
569 PATH=$(ROOT)/fixed-gcc:$$PATH \
571 --host=riscv64-unknown-linux-gnu \
572 --prefix=/usr --libdir=/usr/lib64
573 cd gzip-$(GZIP_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
574 cd gzip-$(GZIP_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
576 gzip-$(GZIP_VERSION).tar.gz:
578 wget -O $@-t https://ftp.gnu.org/gnu/gzip/gzip-$(GZIP_VERSION).tar.gz
581 # Cross-compile zlib.
582 stage3-chroot/usr/lib64/libz.so: zlib-$(ZLIB_VERSION).tar.gz
583 rm -rf zlib-$(ZLIB_VERSION)
585 cd zlib-$(ZLIB_VERSION) && \
586 PATH=$(ROOT)/fixed-gcc:$$PATH \
587 CC=riscv64-unknown-linux-gnu-gcc \
588 CFLAGS="-I$(ROOT)/stage3-chroot/usr/include -L$(ROOT)/stage3-chroot/usr/lib" \
590 --prefix=/usr --libdir=/usr/lib64
591 cd zlib-$(ZLIB_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make shared
592 cd zlib-$(ZLIB_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
594 zlib-$(ZLIB_VERSION).tar.gz:
596 wget -O $@-t http://zlib.net/zlib-$(ZLIB_VERSION).tar.gz
599 # Cross-compile file/libmagic.
600 stage3-chroot/usr/bin/file: file-$(FILE_VERSION).tar.gz
601 rm -rf file-$(FILE_VERSION)
603 cd file-$(FILE_VERSION) && \
604 PATH=$(ROOT)/fixed-gcc:$$PATH \
605 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
607 --host=riscv64-unknown-linux-gnu \
608 --prefix=/usr --libdir=/usr/lib64 \
609 --disable-static --enable-shared
610 cd file-$(FILE_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
611 cd file-$(FILE_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
612 rm -f stage3-chroot/usr/lib64/*.la
614 file-$(FILE_VERSION).tar.gz:
616 wget -O $@-t ftp://ftp.astron.com/pub/file/file-$(FILE_VERSION).tar.gz
619 # Cross-compile popt.
620 stage3-chroot/usr/lib64/libpopt.so: popt-$(POPT_VERSION).tar.gz
621 rm -rf popt-$(POPT_VERSION)
623 cd popt-$(POPT_VERSION) && \
624 PATH=$(ROOT)/fixed-gcc:$$PATH \
625 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
627 --host=riscv64-unknown-linux-gnu \
628 --prefix=/usr --libdir=/usr/lib64 \
629 --disable-static --enable-shared
630 cd popt-$(POPT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
631 cd popt-$(POPT_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
632 rm -f stage3-chroot/usr/lib64/*.la
634 popt-$(POPT_VERSION).tar.gz:
636 wget -O $@-t http://rpm5.org/files/popt/popt-$(POPT_VERSION).tar.gz
639 # Cross-compile beecrypt.
640 stage3-chroot/usr/lib64/libbeecrypt.so: beecrypt-$(BEECRYPT_VERSION).tar.gz
641 rm -rf beecrypt-$(BEECRYPT_VERSION)
643 cd beecrypt-$(BEECRYPT_VERSION) && patch -p0 < ../beecrypt-disable-cplusplus.patch
644 cd beecrypt-$(BEECRYPT_VERSION) && autoreconf -i
645 cd beecrypt-$(BEECRYPT_VERSION) && \
646 PATH=$(ROOT)/fixed-gcc:$$PATH \
647 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
649 --host=riscv64-unknown-linux-gnu \
650 --prefix=/usr --libdir=/usr/lib64 \
651 --without-cplusplus \
656 cd beecrypt-$(BEECRYPT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
657 cd beecrypt-$(BEECRYPT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot V=1
658 chrpath -d stage3-chroot/usr/lib64/libbeecrypt.so.*
659 rm -f stage3-chroot/usr/lib64/*.la
661 beecrypt-$(BEECRYPT_VERSION).tar.gz:
663 wget -O $@-t http://downloads.sourceforge.net/sourceforge/beecrypt/beecrypt-$(BEECRYPT_VERSION).tar.gz
666 # Cross-compile GNU nano (editor).
667 stage3-chroot/usr/bin/nano: nano-$(NANO_VERSION).tar.gz
668 rm -rf nano-$(NANO_VERSION)
670 cd nano-$(NANO_VERSION) && \
671 PATH=$(ROOT)/fixed-gcc:$$PATH \
672 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
674 --host=riscv64-unknown-linux-gnu \
675 --prefix=/usr --libdir=/usr/lib64
676 cd nano-$(NANO_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
677 cd nano-$(NANO_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
679 nano-$(NANO_VERSION).tar.gz:
681 wget -O $@-t https://www.nano-editor.org/dist/v2.6/nano-$(NANO_VERSION).tar.gz
684 # Cross-compile GNU grep.
685 stage3-chroot/usr/bin/grep: grep-$(GREP_VERSION).tar.xz
686 rm -rf grep-$(GREP_VERSION)
688 cd grep-$(GREP_VERSION) && \
689 PATH=$(ROOT)/fixed-gcc:$$PATH \
691 --host=riscv64-unknown-linux-gnu \
692 --prefix=/usr --libdir=/usr/lib64
693 cd grep-$(GREP_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
694 cd grep-$(GREP_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
696 grep-$(GREP_VERSION).tar.xz:
698 wget -O $@-t https://ftp.gnu.org/gnu/grep/grep-$(GREP_VERSION).tar.xz
701 # Cross-compile less.
702 stage3-chroot/usr/bin/less: less-$(LESS_VERSION).tar.gz
703 rm -rf less-$(LESS_VERSION)
705 cd less-$(LESS_VERSION) && \
706 PATH=$(ROOT)/fixed-gcc:$$PATH \
707 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
709 --host=riscv64-unknown-linux-gnu \
710 --prefix=/usr --libdir=/usr/lib64
711 cd less-$(LESS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
712 cd less-$(LESS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
714 less-$(LESS_VERSION).tar.gz:
716 wget -O $@-t http://www.greenwoodsoftware.com/less/less-$(LESS_VERSION).tar.gz
719 # Cross-compile strace.
720 # XXX This does not work.
721 stage3-chroot/usr/bin/strace: strace-$(STRACE_SHORT_COMMIT).tar.gz
722 rm -rf strace-$(STRACE_SHORT_COMMIT)
724 cd riscv-strace-$(STRACE_COMMIT) && patch -p1 < ../0001-Update-riscv_regs-for-ptrace.h-from-Linux-4.1.x.patch
725 cd riscv-strace-$(STRACE_COMMIT) && \
726 PATH=$(ROOT)/fixed-gcc:$$PATH \
727 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
729 --host=riscv64-unknown-linux-gnu \
730 --prefix=/usr --libdir=/usr/lib64
731 cd riscv-strace-$(STRACE_COMMIT) && PATH=$(ROOT)/fixed-gcc:$$PATH make
732 cd riscv-strace-$(STRACE_COMMIT) && make install DESTDIR=$(ROOT)/stage3-chroot
734 strace-$(STRACE_SHORT_COMMIT).tar.gz:
736 wget -O $@-t 'https://github.com/riscv/riscv-strace/archive/$(STRACE_COMMIT)/riscv-strace-$(STRACE_SHORTCOMMIT).tar.gz'
739 # Cross-compile bzip2.
740 stage3-chroot/usr/bin/bzip2: bzip2-$(BZIP2_VERSION).tar.gz
741 rm -rf bzip2-$(BZIP2_VERSION)
743 cd bzip2-$(BZIP2_VERSION) && \
744 PATH=$(ROOT)/fixed-gcc:$$PATH \
745 make libbz2.a bzip2 bzip2recover \
747 CC=riscv64-unknown-linux-gnu-gcc \
748 AR=riscv64-unknown-linux-gnu-ar \
749 RANLIB=riscv64-unknown-linux-gnu-ranlib \
750 CFLAGS="-Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -fPIC"
751 cd bzip2-$(BZIP2_VERSION) && \
752 make install PREFIX=$(ROOT)/stage3-chroot/usr
754 bzip2-$(BZIP2_VERSION).tar.gz:
756 wget -O $@-t http://www.bzip.org/1.0.6/bzip2-$(BZIP2_VERSION).tar.gz
759 # Cross-compile GNU make.
760 stage3-chroot/usr/bin/make: make-$(MAKE_VERSION).tar.gz
761 rm -rf make-$(MAKE_VERSION)
763 cd make-$(MAKE_VERSION) && \
764 PATH=$(ROOT)/fixed-gcc:$$PATH \
766 --host=riscv64-unknown-linux-gnu \
767 --prefix=/usr --libdir=/usr/lib64
768 cd make-$(MAKE_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
769 cd make-$(MAKE_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
771 make-$(MAKE_VERSION).tar.gz:
773 wget -O $@-t https://ftp.gnu.org/gnu/make/make-$(MAKE_VERSION).tar.gz
776 # Cross-compile GNU diffutils.
777 stage3-chroot/usr/bin/diff: diffutils-$(DIFFUTILS_VERSION).tar.xz
778 rm -rf diffutils-$(DIFFUTILS_VERSION)
780 cd diffutils-$(DIFFUTILS_VERSION) && \
781 PATH=$(ROOT)/fixed-gcc:$$PATH \
783 --host=riscv64-unknown-linux-gnu \
784 --prefix=/usr --libdir=/usr/lib64
785 cd diffutils-$(DIFFUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
786 cd diffutils-$(DIFFUTILS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
788 diffutils-$(DIFFUTILS_VERSION).tar.xz:
790 wget -O $@-t https://ftp.gnu.org/gnu/diffutils/diffutils-$(DIFFUTILS_VERSION).tar.xz
793 # Cross-compile GNU findutils.
794 stage3-chroot/usr/bin/find: findutils-$(FINDUTILS_VERSION).tar.gz
795 rm -rf findutils-$(FINDUTILS_VERSION)
797 cd findutils-$(FINDUTILS_VERSION) && \
798 PATH=$(ROOT)/fixed-gcc:$$PATH \
800 --host=riscv64-unknown-linux-gnu \
801 --prefix=/usr --libdir=/usr/lib64
802 cd findutils-$(FINDUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
803 cd findutils-$(FINDUTILS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
805 findutils-$(FINDUTILS_VERSION).tar.gz:
807 wget -O $@-t https://ftp.gnu.org/gnu/findutils/findutils-$(FINDUTILS_VERSION).tar.gz
810 # Cross-compile GNU sed.
811 stage3-chroot/usr/bin/sed: sed-$(SED_VERSION).tar.gz
812 rm -rf sed-$(SED_VERSION)
814 cd sed-$(SED_VERSION) && \
815 PATH=$(ROOT)/fixed-gcc:$$PATH \
817 --host=riscv64-unknown-linux-gnu \
818 --prefix=/usr --libdir=/usr/lib64
819 cd sed-$(SED_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
820 cd sed-$(SED_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
822 sed-$(SED_VERSION).tar.gz:
824 wget -O $@-t https://ftp.gnu.org/gnu/sed/sed-$(SED_VERSION).tar.gz
827 # Cross-compile patch.
828 stage3-chroot/usr/bin/patch: patch-$(PATCH_VERSION).tar.gz
829 rm -rf patch-$(PATCH_VERSION)
831 cd patch-$(PATCH_VERSION) && \
832 PATH=$(ROOT)/fixed-gcc:$$PATH \
834 --host=riscv64-unknown-linux-gnu \
835 --prefix=/usr --libdir=/usr/lib64
836 cd patch-$(PATCH_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
837 cd patch-$(PATCH_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
839 patch-$(PATCH_VERSION).tar.gz:
841 wget -O $@-t https://ftp.gnu.org/gnu/patch/patch-$(PATCH_VERSION).tar.gz
844 # Cross-compile hostname.
845 stage3-chroot/usr/bin/hostname: hostname-$(HOSTNAME_VERSION).tar.gz
846 rm -rf hostname-$(HOSTNAME_VERSION)
848 cd hostname && patch -p1 < ../hostname-rh.patch
850 PATH=$(ROOT)/fixed-gcc:$$PATH \
852 CC=riscv64-unknown-linux-gnu-gcc \
854 cd hostname && make install BASEDIR=$(ROOT)/stage3-chroot
856 hostname-$(HOSTNAME_VERSION).tar.gz:
858 wget -O $@-t http://ftp.de.debian.org/debian/pool/main/h/hostname/hostname_$(HOSTNAME_VERSION).tar.gz
861 # Cross-compile GNU gettext.
862 stage3-chroot/usr/bin/gettext: gettext-$(GETTEXT_VERSION).tar.gz
863 rm -rf gettext-$(GETTEXT_VERSION)
865 cd gettext-$(GETTEXT_VERSION) && \
866 PATH=$(ROOT)/fixed-gcc:$$PATH \
868 --host=riscv64-unknown-linux-gnu \
869 --prefix=/usr --libdir=/usr/lib64
870 cd gettext-$(GETTEXT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
871 cd gettext-$(GETTEXT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
872 rm -f stage3-chroot/usr/lib64/*.la
874 gettext-$(GETTEXT_VERSION).tar.gz:
876 wget -O $@-t https://ftp.gnu.org/gnu/gettext/gettext-$(GETTEXT_VERSION).tar.gz
879 # Cross-compile RPM / rpmbuild.
880 # We build this from a git commit, with a few hacks to the configure
882 stage3-chroot/usr/bin/rpm: rpm-$(RPM_SHORT_COMMIT).tar.gz db-$(BDB_VERSION).tar.gz
883 rm -rf rpm-$(RPM_SHORT_COMMIT)
884 tar -zxf rpm-$(RPM_SHORT_COMMIT).tar.gz
885 tar -zxf db-$(BDB_VERSION).tar.gz -C rpm-$(RPM_SHORT_COMMIT)
886 cd rpm-$(RPM_SHORT_COMMIT) && ln -s db-$(BDB_VERSION) db
887 cd rpm-$(RPM_SHORT_COMMIT) && \
888 patch -p1 < ../0001-RISCV-64-bit-riscv64-support.patch && \
889 patch -p1 < ../0002-build-fgetc-returns-int-not-char.patch && \
890 patch -p1 < ../0003-HACKS-TO-GET-RPM-TO-CROSS-COMPILE.patch
891 cd rpm-$(RPM_SHORT_COMMIT) && autoreconf -i
892 cd rpm-$(RPM_SHORT_COMMIT) && \
893 PATH=$(ROOT)/fixed-gcc:$$PATH \
894 LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
896 --host=riscv64-unknown-linux-gnu \
897 --prefix=/usr --libdir=/usr/lib64 \
899 --without-libarchive \
903 --without-external-db \
906 cd rpm-$(RPM_SHORT_COMMIT) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
907 cd rpm-$(RPM_SHORT_COMMIT) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
908 rm -f stage3-chroot/usr/lib64/*.la
910 rpm-$(RPM_SHORT_COMMIT).tar.gz:
912 wget -O $@-t 'http://rpm.org/gitweb?p=rpm.git;a=snapshot;h=$(RPM_COMMIT);sf=tgz'
915 db-$(BDB_VERSION).tar.gz:
917 wget -O $@-t http://download.oracle.com/berkeley-db/db-$(BDB_VERSION).tar.gz
920 # Create an /init script.
921 stage3-chroot/init: init.sh
922 install -m 0755 $^ $@
924 # Create the stage3 disk image.
925 # Note `-s +...' adds spare space to the disk image.
926 stage3-disk.img: stage3-chroot
927 cd stage3-chroot && virt-make-fs . ../$@ -t ext2 -F raw -s +4G
929 # Upload the compressed disk image.
930 upload-stage3: stage3-disk.img.xz
931 scp $^ tick:public_html/riscv/
932 stage3-disk.img.xz: stage3-disk.img
936 # Helper which boots stage3 disk image in spike.
937 boot-stage3-in-spike: stage3-disk.img stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
938 spike +disk=stage3-disk.img \
939 /usr/bin/bbl stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
941 # Helper which boots stage3 disk image in qemu.
942 boot-stage3-in-qemu: stage3-disk.img stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
943 qemu-system-riscv -kernel /usr/bin/bbl \
944 -append ./stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux \
945 -drive file=stage3-disk.img,format=raw -nographic