eceb9aeaa93dd9fa794c346944cdd8269314198a
[fedora-riscv.git] / Makefile
1 # Refer to the README file to understand how Fedora on RISC-V is
2 # bootstrapped.
3
4 # Absolute path to the current directory.
5 ROOT := $(shell pwd)
6
7 # Note these are chosen very specifically to ensure the different
8 # versions work together.  Don't blindly update to the latest
9 # versions.  See also:
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
21
22 # For the correct versions, see
23 # riscv-gnu-toolchain/Makefile.in *_version variables
24 BINUTILS_VERSION = 2.25.1
25 GLIBC_VERSION    = 2.22
26 GCC_VERSION      = 5.3.0
27 NEWLIB_VERSION   = 2.2.0
28
29 # See linux-4.1.y-riscv branch of
30 # https://github.com/riscv/riscv-linux
31 KERNEL_VERSION   = 4.1.26
32
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
36
37 # The root packages (plus their dependencies) that we want to
38 # cross-compile into the stage 3 chroot.
39 STAGE3_PACKAGES = gcc rpm-build
40
41 # Versions of cross-compiled packages.
42 BASH_VERSION      = 4.3
43 COREUTILS_VERSION = 8.25
44 GMP_VERSION       = 6.1.1
45 MPFR_VERSION      = 3.1.4
46 MPC_VERSION       = 1.0.3
47 GCC_X_VERSION     = 6.1.0
48
49 all: stage1 stage2 stage3 stage4
50
51 # Stage 1
52
53 stage1: stage1-riscv-qemu/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz \
54         stage1-riscv-qemu/riscv-qemu.spec \
55         stamp-riscv-qemu-installed \
56         stage1-riscv-fesvr/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz \
57         stage1-riscv-fesvr/riscv-fesvr.spec \
58         stamp-riscv-fesvr-installed \
59         stage1-riscv-isa-sim/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz \
60         stage1-riscv-isa-sim/riscv-isa-sim.spec \
61         stamp-riscv-isa-sim-installed
62
63 stage1-riscv-qemu/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz:
64         rm -f $@ $@-t
65         wget -O $@-t 'https://github.com/riscv/riscv-qemu/archive/$(RISCV_QEMU_COMMIT)/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz'
66         mv $@-t $@
67
68 stage1-riscv-qemu/riscv-qemu.spec: stage1-riscv-qemu/riscv-qemu.spec.in
69         sed -e 's/@COMMIT@/$(RISCV_QEMU_COMMIT)/g' \
70             -e 's/@SHORTCOMMIT@/$(RISCV_QEMU_SHORTCOMMIT)/g' \
71             < $^ > $@-t
72         mv $@-t $@
73
74 stamp-riscv-qemu-installed:
75         rm -f $@
76         @rpm -q riscv-qemu >/dev/null || { \
77           echo "ERROR: You must install riscv-qemu:"; \
78           echo; \
79           echo "       dnf copr enable rjones/riscv"; \
80           echo "       dnf install riscv-qemu"; \
81           echo; \
82           echo "OR: you can build it yourself from the stage1-riscv-qemu directory."; \
83           echo; \
84           exit 1; \
85         }
86         @qemu-system-riscv --version || { \
87           echo "ERROR: qemu-system-riscv is not working."; \
88           echo "Make sure you installed the riscv-qemu package."; \
89           exit 1; \
90         }
91         touch $@
92
93 stage1-riscv-fesvr/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz:
94         rm -f $@ $@-t
95         wget -O $@-t 'https://github.com/riscv/riscv-fesvr/archive/$(RISCV_FESVR_COMMIT)/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz'
96         mv $@-t $@
97
98 stage1-riscv-fesvr/riscv-fesvr.spec: stage1-riscv-fesvr/riscv-fesvr.spec.in
99         sed -e 's/@COMMIT@/$(RISCV_FESVR_COMMIT)/g' \
100             -e 's/@SHORTCOMMIT@/$(RISCV_FESVR_SHORTCOMMIT)/g' \
101             < $^ > $@-t
102         mv $@-t $@
103
104 stamp-riscv-fesvr-installed:
105         rm -f $@
106         @rpm -q riscv-fesvr >/dev/null || { \
107           echo "ERROR: You must install riscv-fesvr:"; \
108           echo; \
109           echo "       dnf copr enable rjones/riscv"; \
110           echo "       dnf install riscv-fesvr"; \
111           echo; \
112           echo "OR: you can build it yourself from the stage1-riscv-fesvr directory."; \
113           echo; \
114           exit 1; \
115         }
116         touch $@
117
118 stage1-riscv-isa-sim/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz:
119         rm -f $@ $@-t
120         wget -O $@-t 'https://github.com/riscv/riscv-isa-sim/archive/$(RISCV_ISA_SIM_COMMIT)/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz'
121         mv $@-t $@
122
123 stage1-riscv-isa-sim/riscv-isa-sim.spec: stage1-riscv-isa-sim/riscv-isa-sim.spec.in
124         sed -e 's/@COMMIT@/$(RISCV_ISA_SIM_COMMIT)/g' \
125             -e 's/@SHORTCOMMIT@/$(RISCV_ISA_SIM_SHORTCOMMIT)/g' \
126             < $^ > $@-t
127         mv $@-t $@
128
129 stamp-riscv-isa-sim-installed:
130         rm -f $@
131         @rpm -q riscv-isa-sim >/dev/null || { \
132           echo "ERROR: You must install riscv-isa-sim:"; \
133           echo; \
134           echo "       dnf copr enable rjones/riscv"; \
135           echo "       dnf install riscv-isa-sim"; \
136           echo; \
137           echo "OR: you can build it yourself from the stage1-riscv-isa-sim directory."; \
138           echo; \
139           exit 1; \
140         }
141         touch $@
142
143 # Stage 2
144
145 stage2: stage2-riscv-gnu-toolchain/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz \
146         stage2-riscv-gnu-toolchain/binutils-$(BINUTILS_VERSION).tar.gz \
147         stage2-riscv-gnu-toolchain/gcc-$(GCC_VERSION).tar.gz \
148         stage2-riscv-gnu-toolchain/glibc-$(GLIBC_VERSION).tar.gz \
149         stage2-riscv-gnu-toolchain/newlib-$(NEWLIB_VERSION).tar.gz \
150         stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec \
151         stamp-riscv-gnu-toolchain-installed \
152         stage2-riscv-pk/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz \
153         stage2-riscv-pk/riscv-pk.spec \
154         stamp-riscv-pk-installed
155
156 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz:
157         rm -f $@ $@-t
158         wget -O $@-t https://github.com/lowRISC/riscv-gnu-toolchain/archive/$(RISCV_GNU_TOOLCHAIN_COMMIT)/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz
159         mv $@-t $@
160
161 stage2-riscv-gnu-toolchain/binutils-$(BINUTILS_VERSION).tar.gz:
162         rm -f $@ $@-t
163         wget -O $@-t http://mirrors.kernel.org/gnu/binutils/binutils-$(BINUTILS_VERSION).tar.gz
164         mv $@-t $@
165
166 # GCC 5 no longer compiles with GCC 6 unless we patch it.
167 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69959
168 stage2-riscv-gnu-toolchain/gcc-$(GCC_VERSION).tar.gz:
169         rm -f $@ $@-t
170         wget -O $@-t http://mirrors.kernel.org/gnu/gcc/gcc-$(GCC_VERSION)/gcc-$(GCC_VERSION).tar.gz
171         zcat $@-t | tar xf -
172         cd gcc-$(GCC_VERSION) && patch -p0 < ../stage2-riscv-gnu-toolchain/gcc-5-fix-compilation-with-gcc-6.patch
173         tar zcf $@-t gcc-$(GCC_VERSION)
174         rm -r gcc-$(GCC_VERSION)
175         mv $@-t $@
176
177 stage2-riscv-gnu-toolchain/glibc-$(GLIBC_VERSION).tar.gz:
178         rm -f $@ $@-t
179         wget -O $@-t http://mirrors.kernel.org/gnu/glibc/glibc-$(GLIBC_VERSION).tar.gz
180         mv $@-t $@
181
182 stage2-riscv-gnu-toolchain/newlib-$(NEWLIB_VERSION).tar.gz:
183         rm -f $@ $@-t
184         wget -O $@-t ftp://sourceware.org/pub/newlib/newlib-$(NEWLIB_VERSION).tar.gz
185         mv $@-t $@
186
187 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec: stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec.in
188         sed -e 's/@COMMIT@/$(RISCV_GNU_TOOLCHAIN_COMMIT)/g' \
189             -e 's/@SHORTCOMMIT@/$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT)/g' \
190             -e 's/@BINUTILS_VERSION@/$(BINUTILS_VERSION)/g' \
191             -e 's/@GCC_VERSION@/$(GCC_VERSION)/g' \
192             -e 's/@GLIBC_VERSION@/$(GLIBC_VERSION)/g' \
193             -e 's/@NEWLIB_VERSION@/$(NEWLIB_VERSION)/g' \
194             < $^ > $@-t
195         mv $@-t $@
196
197 stamp-riscv-gnu-toolchain-installed:
198         rm -f $@
199         @rpm -q riscv-gnu-toolchain >/dev/null || { \
200           echo "ERROR: You must install riscv-gnu-toolchain:"; \
201           echo; \
202           echo "       dnf copr enable rjones/riscv"; \
203           echo "       dnf install riscv-gnu-toolchain"; \
204           echo; \
205           echo "OR: you can build it yourself from the stage2-riscv-gnu-toolchain directory."; \
206           echo; \
207           exit 1; \
208         }
209         @riscv64-unknown-elf-gcc --version || { \
210           echo "ERROR: riscv64-unknown-elf-gcc (cross compiler) is not working."; \
211           echo "Make sure you installed the riscv-gnu-toolchain package."; \
212           exit 1; \
213         }
214         touch $@
215
216 stage2-riscv-pk/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz:
217         rm -f $@ $@-t
218         wget -O $@-t https://github.com/lowRISC/riscv-pk/archive/$(RISCV_PK_COMMIT)/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz
219         mv $@-t $@
220
221 stage2-riscv-pk/riscv-pk.spec: stage2-riscv-pk/riscv-pk.spec.in
222         sed -e 's/@COMMIT@/$(RISCV_PK_COMMIT)/g' \
223             -e 's/@SHORTCOMMIT@/$(RISCV_PK_SHORTCOMMIT)/g' \
224             < $^ > $@-t
225         mv $@-t $@
226
227 stamp-riscv-pk-installed:
228         rm -f $@
229         @rpm -q riscv-pk >/dev/null || { \
230           echo "ERROR: You must install riscv-pk:"; \
231           echo; \
232           echo "       dnf copr enable rjones/riscv"; \
233           echo "       dnf install riscv-pk"; \
234           echo; \
235           echo "OR: you can build it yourself from the stage2-riscv-pk directory."; \
236           echo; \
237           exit 1; \
238         }
239         touch $@
240
241 # Stage 3
242
243 stage3: stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux \
244         stage3-chroot-original/etc/fedora-release \
245         stage3-chroot/etc/fedora-release \
246         stage3-chroot/lib64/libc.so.6 \
247         stage3-chroot/bin/bash \
248         stage3-chroot/bin/ls \
249         stage3-chroot/usr/lib64/libgmp.so.10 \
250         stage3-chroot/usr/lib64/libmpfr.so.4 \
251         stage3-chroot/usr/lib64/libmpc.so.3 \
252         stage3-chroot/usr/bin/gcc \
253         stage3-chroot/init \
254         stage3-disk.img
255
256 stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux:
257         rm -rf stage3-kernel/linux-$(KERNEL_VERSION)
258         cp -a $(LOCAL_LINUX_GIT_COPY) stage3-kernel/linux-$(KERNEL_VERSION) || { \
259           mkdir stage3-kernel/linux-$(KERNEL_VERSION) && \
260           cd stage3-kernel/linux-$(KERNEL_VERSION) && \
261           git init; \
262         }
263         cd stage3-kernel/linux-$(KERNEL_VERSION) && \
264         git remote add riscv https://github.com/riscv/riscv-linux && \
265         git fetch riscv && \
266         git checkout -f linux-4.1.y-riscv && \
267         make mrproper && \
268         make ARCH=riscv defconfig
269         echo CONFIG_CMDLINE=\"root=/dev/htifblk0 init=/init\" >> stage3-kernel/linux-$(KERNEL_VERSION)/.config
270         echo CONFIG_CROSS_COMPILE=riscv64-unknown-elf- >> stage3-kernel/linux-$(KERNEL_VERSION)/.config
271         cd stage3-kernel/linux-$(KERNEL_VERSION) && \
272         make ARCH=riscv olddefconfig
273         cd stage3-kernel/linux-$(KERNEL_VERSION) && \
274         make ARCH=riscv vmlinux
275         ls -l $@
276
277 # Build an original (x86-64) chroot using supermin.  We then aim to
278 # rebuild (using cross-compiled versions) every ELF binary in this
279 # chroot.
280 stage3-chroot-original/etc/fedora-release:
281         rm -rf stage3-chroot-original tmp-supermin.d
282         supermin --prepare $(STAGE3_PACKAGES) -o tmp-supermin.d
283         supermin --build -f chroot tmp-supermin.d -o stage3-chroot-original
284         rm -r tmp-supermin.d
285         @echo -n "Total files in chroot: "
286         @find stage3-chroot-original -type f | wc -l
287         @echo -n "ELF files to be rebuilt: "
288         @find stage3-chroot-original -type f | xargs file -N | grep -E '\bELF.*LSB\b' | wc -l
289
290 # Copy the original chroot to the final chroot, remove all the ELF
291 # files.
292 stage3-chroot/etc/fedora-release: stage3-chroot-original/etc/fedora-release
293         rm -rf stage3-chroot
294         cp -a stage3-chroot-original stage3-chroot
295         find stage3-chroot -type d | xargs chmod u+w
296         find stage3-chroot -type f | xargs chmod u+w
297         find stage3-chroot -type f | xargs file -N | grep -E '\bELF.*LSB\b' | awk -F: '{print $$1}' | xargs rm -f
298         rm -f stage3-chroot/lib64/libc.so.6
299
300 # Copy in compiled glibc from the riscv-gnu-toolchain sysroot.  Only
301 # copy files and symlinks, leave the target directory structure
302 # intact.
303 stage3-chroot/lib64/libc.so.6:
304         mkdir -p stage3-chroot/usr/lib/audit
305         mkdir -p stage3-chroot/usr/lib/gconv
306         for f in `cd /usr/sysroot && find -type f -o -type l`; do \
307             cp -d /usr/sysroot/$$f stage3-chroot/$$f; \
308         done
309         cd stage3-chroot/lib64 && for f in ../lib/*; do ln -sf $$f; done
310
311 # Cross-compile bash.
312 stage3-chroot/bin/bash: bash-$(BASH_VERSION).tar.gz
313         tar zxf $^
314         cd bash-$(BASH_VERSION) && \
315         PATH=$(ROOT)/fixed-gcc:$$PATH \
316         ./configure --host=riscv64-unknown-linux-gnu \
317             --prefix=/usr --libdir=/usr/lib64
318         cd bash-$(BASH_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
319         cd bash-$(BASH_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
320
321 bash-$(BASH_VERSION).tar.gz:
322         rm -f $@ $@-t
323         wget -O $@-t ftp://ftp.gnu.org/gnu/bash/bash-$(BASH_VERSION).tar.gz
324         mv $@-t $@
325
326 # Cross-compile coreutils.  Bleah, coreutils cross-compilation is
327 # known-broken and upstream don't care, hence the 'touch' command.
328
329 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
330
331 stage3-chroot/bin/ls: coreutils-$(COREUTILS_VERSION).tar.xz
332         rm -rf coreutils-$(COREUTILS_VERSION)
333         tar Jxf $^
334         cd coreutils-$(COREUTILS_VERSION) && \
335         PATH=$(ROOT)/fixed-gcc:$$PATH \
336         ./configure --host=riscv64-unknown-linux-gnu \
337             --prefix=/usr --libdir=/usr/lib64
338         -cd coreutils-$(COREUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
339         cd coreutils-$(COREUTILS_VERSION)/man && \
340         for f in $(COREUTILS_PROGRAMS); do touch $$f.1; done
341         cd coreutils-$(COREUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
342         cd coreutils-$(COREUTILS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
343
344 coreutils-$(COREUTILS_VERSION).tar.xz:
345         rm -f $@ $@-t
346         wget -O $@-t ftp://ftp.gnu.org/gnu/coreutils/coreutils-$(COREUTILS_VERSION).tar.xz
347         mv $@-t $@
348
349 # Cross-compile GMP, MPFR and MPC (deps of GCC).
350 stage3-chroot/usr/lib64/libgmp.so.10: gmp-$(GMP_VERSION).tar.lz
351         rm -rf gmp-$(GMP_VERSION)
352         tar --lzip -xf gmp-$(GMP_VERSION).tar.lz
353         cd gmp-$(GMP_VERSION) && \
354         PATH=$(ROOT)/fixed-gcc:$$PATH \
355         ./configure --host=riscv64-unknown-linux-gnu \
356             --prefix=/usr --libdir=/usr/lib64
357         cd gmp-$(GMP_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
358         cd gmp-$(GMP_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
359         cd stage3-chroot/usr/lib && ln -s ../lib64/libgmp.so
360
361 gmp-$(GMP_VERSION).tar.lz:
362         rm -f $@ $@-t
363         wget -O $@-t https://gmplib.org/download/gmp/gmp-$(GMP_VERSION).tar.lz
364         mv $@-t $@
365
366 stage3-chroot/usr/lib64/libmpfr.so.4: mpfr-$(MPFR_VERSION).tar.gz
367         rm -rf mpfr-$(MPFR_VERSION)
368         tar -zxf mpfr-$(MPFR_VERSION).tar.gz
369         cd mpfr-$(MPFR_VERSION) && \
370         PATH=$(ROOT)/fixed-gcc:$$PATH \
371         ./configure --host=riscv64-unknown-linux-gnu \
372             --prefix=/usr --libdir=/usr/lib64 \
373             --with-gmp=$(ROOT)/stage3-chroot/usr
374         cd mpfr-$(MPFR_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
375         cd mpfr-$(MPFR_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
376         cd stage3-chroot/usr/lib && ln -s ../lib64/libmpfr.so
377
378 mpfr-$(MPFR_VERSION).tar.gz:
379         rm -f $@ $@-t
380         wget -O $@-t http://www.mpfr.org/mpfr-current/mpfr-$(MPFR_VERSION).tar.gz
381         mv $@-t $@
382
383 stage3-chroot/usr/lib64/libmpc.so.3: mpc-$(MPC_VERSION).tar.gz
384         rm -rf mpc-$(MPC_VERSION)
385         tar -zxf mpc-$(MPC_VERSION).tar.gz
386         cd mpc-$(MPC_VERSION) && \
387         PATH=$(ROOT)/fixed-gcc:$$PATH \
388         ./configure --host=riscv64-unknown-linux-gnu \
389             --prefix=/usr --libdir=/usr/lib64 \
390             --with-gmp=$(ROOT)/stage3-chroot/usr \
391             --with-mpfr=$(ROOT)/stage3-chroot/usr
392         cd mpc-$(MPC_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
393         cd mpc-$(MPC_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
394         cd stage3-chroot/usr/lib && ln -s ../lib64/libmpc.so
395
396 mpc-$(MPC_VERSION).tar.gz:
397         rm -f $@ $@-t
398         wget -O $@-t ftp://ftp.gnu.org/gnu/mpc/mpc-$(MPC_VERSION).tar.gz
399         mv $@-t $@
400
401 # Cross-compile GCC.
402 stage3-chroot/usr/bin/gcc: gcc-$(GCC_X_VERSION).tar.gz
403         rm -rf riscv-gcc-riscv-gcc-$(GCC_X_VERSION)
404         zcat $^ | tar xf -
405         mkdir riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build
406         cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && \
407         PATH=$(ROOT)/fixed-gcc:$$PATH \
408         ../configure \
409             --host=riscv64-unknown-linux-gnu \
410             --prefix=/usr --libdir=/usr/lib64 \
411             --enable-shared \
412             --enable-tls \
413             --enable-languages=c,c++ \
414             --disable-libmudflap \
415             --disable-libssp \
416             --disable-libquadmath \
417             --disable-nls \
418             --disable-multilib
419         cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && PATH=$(ROOT)/fixed-gcc:$$PATH make all-gcc
420         cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && make install-gcc DESTDIR=$(ROOT)/stage3-chroot
421
422 gcc-$(GCC_X_VERSION).tar.gz:
423         rm -f $@ $@-t
424         wget -O $@-t https://github.com/riscv/riscv-gcc/archive/riscv-gcc-$(GCC_X_VERSION).tar.gz
425         mv $@-t $@
426
427 # Create an /init script.
428 stage3-chroot/init: init.sh
429         install -m 0755 $^ $@
430
431 # Create the stage3 disk image.
432 # Note `-s +...' adds spare space to the disk image.
433 stage3-disk.img: stage3-chroot
434         cd stage3-chroot && virt-make-fs . ../$@ -t ext2 -F raw -s +4G
435
436 # Upload the compressed disk image.
437 upload-stage3: stage3-disk.img.xz
438         scp $^ tick:public_html/riscv/
439 stage3-disk.img.xz: stage3-disk.img
440         rm -f $@
441         xz --best $^
442
443 # Helper which boots stage3 disk image in spike.
444 boot-stage3-in-spike: stage3-disk.img stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
445         spike +disk=stage3-disk.img \
446             /usr/bin/bbl stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
447
448 # Helper which boots stage3 disk image in qemu.
449 boot-stage3-in-qemu: stage3-disk.img stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
450         qemu-system-riscv -kernel /usr/bin/bbl \
451             -append ./stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux \
452             -drive file=stage3-disk.img,format=raw -nographic
453
454 # Stage 4
455
456 stage4:
457         echo "XXX TO DO"
458         exit 1
459
460 .NOTPARALLEL: