fd5968a123cdcd637d6ed5778e09de332744ad20
[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 # 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
42
43 # Versions of cross-compiled packages.
44 NCURSES_VERSION    = 6.0-20160730
45 BASH_VERSION       = 4.3
46 COREUTILS_VERSION  = 8.25
47 GMP_VERSION        = 6.1.1
48 MPFR_VERSION       = 3.1.4
49 MPC_VERSION        = 1.0.3
50 BINUTILS_X_VERSION = 2.26
51 GCC_X_VERSION      = 6.1.0
52 UTIL_LINUX_VERSION = 2.28
53 TAR_VERSION        = 1.29
54 GZIP_VERSION       = 1.8
55 ZLIB_VERSION       = 1.2.8
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).
59 FILE_VERSION       = 5.28
60 POPT_VERSION       = 1.16
61 BEECRYPT_VERSION   = 4.2.1
62 RPM_COMMIT         = 95712183458748ea6cafebac1bdd5daa097d9bee
63 RPM_SHORT_COMMIT   = 9571218
64 BDB_VERSION        = 4.5.20
65 NANO_VERSION       = 2.6.2
66 GREP_VERSION       = 2.25
67 LESS_VERSION       = 481
68 STRACE_COMMIT      = f320e1897832fd07a62e18ed288e75d8e79f4c5b
69 STRACE_SHORT_COMMIT = f320e189
70 BZIP2_VERSION      = 1.0.6
71 MAKE_VERSION       = 4.1
72 DIFFUTILS_VERSION  = 3.4
73 FINDUTILS_VERSION  = 4.6.0
74 SED_VERSION        = 4.2
75 PATCH_VERSION      = 2.7.5
76 HOSTNAME_VERSION   = 3.15
77
78 all: stage1 stage2 stage3 stage4
79
80 # Stage 1
81
82 stage1: stage1-riscv-qemu/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz \
83         stage1-riscv-qemu/riscv-qemu.spec \
84         stamp-riscv-qemu-installed \
85         stage1-riscv-fesvr/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz \
86         stage1-riscv-fesvr/riscv-fesvr.spec \
87         stamp-riscv-fesvr-installed \
88         stage1-riscv-isa-sim/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz \
89         stage1-riscv-isa-sim/riscv-isa-sim.spec \
90         stamp-riscv-isa-sim-installed
91
92 stage1-riscv-qemu/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz:
93         rm -f $@ $@-t
94         wget -O $@-t 'https://github.com/riscv/riscv-qemu/archive/$(RISCV_QEMU_COMMIT)/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz'
95         mv $@-t $@
96
97 stage1-riscv-qemu/riscv-qemu.spec: stage1-riscv-qemu/riscv-qemu.spec.in
98         sed -e 's/@COMMIT@/$(RISCV_QEMU_COMMIT)/g' \
99             -e 's/@SHORTCOMMIT@/$(RISCV_QEMU_SHORTCOMMIT)/g' \
100             < $^ > $@-t
101         mv $@-t $@
102
103 stamp-riscv-qemu-installed:
104         rm -f $@
105         @rpm -q riscv-qemu >/dev/null || { \
106           echo "ERROR: You must install riscv-qemu:"; \
107           echo; \
108           echo "       dnf copr enable rjones/riscv"; \
109           echo "       dnf install riscv-qemu"; \
110           echo; \
111           echo "OR: you can build it yourself from the stage1-riscv-qemu directory."; \
112           echo; \
113           exit 1; \
114         }
115         @qemu-system-riscv --version || { \
116           echo "ERROR: qemu-system-riscv is not working."; \
117           echo "Make sure you installed the riscv-qemu package."; \
118           exit 1; \
119         }
120         touch $@
121
122 stage1-riscv-fesvr/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz:
123         rm -f $@ $@-t
124         wget -O $@-t 'https://github.com/riscv/riscv-fesvr/archive/$(RISCV_FESVR_COMMIT)/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz'
125         mv $@-t $@
126
127 stage1-riscv-fesvr/riscv-fesvr.spec: stage1-riscv-fesvr/riscv-fesvr.spec.in
128         sed -e 's/@COMMIT@/$(RISCV_FESVR_COMMIT)/g' \
129             -e 's/@SHORTCOMMIT@/$(RISCV_FESVR_SHORTCOMMIT)/g' \
130             < $^ > $@-t
131         mv $@-t $@
132
133 stamp-riscv-fesvr-installed:
134         rm -f $@
135         @rpm -q riscv-fesvr >/dev/null || { \
136           echo "ERROR: You must install riscv-fesvr:"; \
137           echo; \
138           echo "       dnf copr enable rjones/riscv"; \
139           echo "       dnf install riscv-fesvr"; \
140           echo; \
141           echo "OR: you can build it yourself from the stage1-riscv-fesvr directory."; \
142           echo; \
143           exit 1; \
144         }
145         touch $@
146
147 stage1-riscv-isa-sim/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz:
148         rm -f $@ $@-t
149         wget -O $@-t 'https://github.com/riscv/riscv-isa-sim/archive/$(RISCV_ISA_SIM_COMMIT)/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz'
150         mv $@-t $@
151
152 stage1-riscv-isa-sim/riscv-isa-sim.spec: stage1-riscv-isa-sim/riscv-isa-sim.spec.in
153         sed -e 's/@COMMIT@/$(RISCV_ISA_SIM_COMMIT)/g' \
154             -e 's/@SHORTCOMMIT@/$(RISCV_ISA_SIM_SHORTCOMMIT)/g' \
155             < $^ > $@-t
156         mv $@-t $@
157
158 stamp-riscv-isa-sim-installed:
159         rm -f $@
160         @rpm -q riscv-isa-sim >/dev/null || { \
161           echo "ERROR: You must install riscv-isa-sim:"; \
162           echo; \
163           echo "       dnf copr enable rjones/riscv"; \
164           echo "       dnf install riscv-isa-sim"; \
165           echo; \
166           echo "OR: you can build it yourself from the stage1-riscv-isa-sim directory."; \
167           echo; \
168           exit 1; \
169         }
170         touch $@
171
172 # Stage 2
173
174 stage2: stage2-riscv-gnu-toolchain/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz \
175         stage2-riscv-gnu-toolchain/binutils-$(BINUTILS_VERSION).tar.gz \
176         stage2-riscv-gnu-toolchain/gcc-$(GCC_VERSION).tar.gz \
177         stage2-riscv-gnu-toolchain/glibc-$(GLIBC_VERSION).tar.gz \
178         stage2-riscv-gnu-toolchain/newlib-$(NEWLIB_VERSION).tar.gz \
179         stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec \
180         stamp-riscv-gnu-toolchain-installed \
181         stage2-riscv-pk/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz \
182         stage2-riscv-pk/riscv-pk.spec \
183         stamp-riscv-pk-installed
184
185 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz:
186         rm -f $@ $@-t
187         wget -O $@-t https://github.com/lowRISC/riscv-gnu-toolchain/archive/$(RISCV_GNU_TOOLCHAIN_COMMIT)/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz
188         mv $@-t $@
189
190 stage2-riscv-gnu-toolchain/binutils-$(BINUTILS_VERSION).tar.gz:
191         rm -f $@ $@-t
192         wget -O $@-t http://mirrors.kernel.org/gnu/binutils/binutils-$(BINUTILS_VERSION).tar.gz
193         mv $@-t $@
194
195 # GCC 5 no longer compiles with GCC 6 unless we patch it.
196 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69959
197 stage2-riscv-gnu-toolchain/gcc-$(GCC_VERSION).tar.gz:
198         rm -f $@ $@-t
199         wget -O $@-t http://mirrors.kernel.org/gnu/gcc/gcc-$(GCC_VERSION)/gcc-$(GCC_VERSION).tar.gz
200         zcat $@-t | tar xf -
201         cd gcc-$(GCC_VERSION) && patch -p0 < ../stage2-riscv-gnu-toolchain/gcc-5-fix-compilation-with-gcc-6.patch
202         tar zcf $@-t gcc-$(GCC_VERSION)
203         rm -r gcc-$(GCC_VERSION)
204         mv $@-t $@
205
206 stage2-riscv-gnu-toolchain/glibc-$(GLIBC_VERSION).tar.gz:
207         rm -f $@ $@-t
208         wget -O $@-t http://mirrors.kernel.org/gnu/glibc/glibc-$(GLIBC_VERSION).tar.gz
209         mv $@-t $@
210
211 stage2-riscv-gnu-toolchain/newlib-$(NEWLIB_VERSION).tar.gz:
212         rm -f $@ $@-t
213         wget -O $@-t ftp://sourceware.org/pub/newlib/newlib-$(NEWLIB_VERSION).tar.gz
214         mv $@-t $@
215
216 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec: stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec.in
217         sed -e 's/@COMMIT@/$(RISCV_GNU_TOOLCHAIN_COMMIT)/g' \
218             -e 's/@SHORTCOMMIT@/$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT)/g' \
219             -e 's/@BINUTILS_VERSION@/$(BINUTILS_VERSION)/g' \
220             -e 's/@GCC_VERSION@/$(GCC_VERSION)/g' \
221             -e 's/@GLIBC_VERSION@/$(GLIBC_VERSION)/g' \
222             -e 's/@NEWLIB_VERSION@/$(NEWLIB_VERSION)/g' \
223             < $^ > $@-t
224         mv $@-t $@
225
226 stamp-riscv-gnu-toolchain-installed:
227         rm -f $@
228         @rpm -q riscv-gnu-toolchain >/dev/null || { \
229           echo "ERROR: You must install riscv-gnu-toolchain:"; \
230           echo; \
231           echo "       dnf copr enable rjones/riscv"; \
232           echo "       dnf install riscv-gnu-toolchain"; \
233           echo; \
234           echo "OR: you can build it yourself from the stage2-riscv-gnu-toolchain directory."; \
235           echo; \
236           exit 1; \
237         }
238         @riscv64-unknown-elf-gcc --version || { \
239           echo "ERROR: riscv64-unknown-elf-gcc (cross compiler) is not working."; \
240           echo "Make sure you installed the riscv-gnu-toolchain package."; \
241           exit 1; \
242         }
243         touch $@
244
245 stage2-riscv-pk/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz:
246         rm -f $@ $@-t
247         wget -O $@-t https://github.com/lowRISC/riscv-pk/archive/$(RISCV_PK_COMMIT)/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz
248         mv $@-t $@
249
250 stage2-riscv-pk/riscv-pk.spec: stage2-riscv-pk/riscv-pk.spec.in
251         sed -e 's/@COMMIT@/$(RISCV_PK_COMMIT)/g' \
252             -e 's/@SHORTCOMMIT@/$(RISCV_PK_SHORTCOMMIT)/g' \
253             < $^ > $@-t
254         mv $@-t $@
255
256 stamp-riscv-pk-installed:
257         rm -f $@
258         @rpm -q riscv-pk >/dev/null || { \
259           echo "ERROR: You must install riscv-pk:"; \
260           echo; \
261           echo "       dnf copr enable rjones/riscv"; \
262           echo "       dnf install riscv-pk"; \
263           echo; \
264           echo "OR: you can build it yourself from the stage2-riscv-pk directory."; \
265           echo; \
266           exit 1; \
267         }
268         touch $@
269
270 # Stage 3
271
272 stage3: stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux \
273         stage3-chroot-original/etc/fedora-release \
274         stage3-chroot/etc/fedora-release \
275         stage3-chroot/lib64/libc.so.6 \
276         stage3-chroot/usr/bin/tic \
277         stage3-chroot/bin/bash \
278         stage3-chroot/bin/ls \
279         stage3-chroot/usr/lib64/libgmp.so.10 \
280         stage3-chroot/usr/lib64/libmpfr.so.4 \
281         stage3-chroot/usr/lib64/libmpc.so.3 \
282         stage3-chroot/usr/bin/as \
283         stage3-chroot/usr/bin/gcc \
284         stage3-chroot/usr/bin/mount \
285         stage3-chroot/usr/bin/tar \
286         stage3-chroot/usr/bin/gzip \
287         stage3-chroot/usr/lib64/libz.so \
288         stage3-chroot/usr/bin/file \
289         stage3-chroot/usr/lib64/libpopt.so \
290         stage3-chroot/usr/lib64/libbeecrypt.so \
291         stage3-chroot/usr/bin/nano \
292         stage3-chroot/usr/bin/grep \
293         stage3-chroot/usr/bin/less \
294         stage3-chroot/usr/bin/strace \
295         stage3-chroot/usr/bin/bzip2 \
296         stage3-chroot/usr/bin/make \
297         stage3-chroot/usr/bin/diff \
298         stage3-chroot/usr/bin/find \
299         stage3-chroot/usr/bin/sed \
300         stage3-chroot/usr/bin/patch \
301         stage3-chroot/usr/bin/hostname \
302         stage3-chroot/usr/bin/rpm \
303         stage3-chroot/init \
304         stage3-disk.img
305
306 stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux:
307         rm -rf stage3-kernel/linux-$(KERNEL_VERSION)
308         cp -a $(LOCAL_LINUX_GIT_COPY) stage3-kernel/linux-$(KERNEL_VERSION) || { \
309           mkdir stage3-kernel/linux-$(KERNEL_VERSION) && \
310           cd stage3-kernel/linux-$(KERNEL_VERSION) && \
311           git init; \
312         }
313         cd stage3-kernel/linux-$(KERNEL_VERSION) && \
314         git remote add riscv https://github.com/riscv/riscv-linux && \
315         git fetch riscv && \
316         git checkout -f linux-4.1.y-riscv && \
317         make mrproper && \
318         make ARCH=riscv defconfig
319         echo CONFIG_CMDLINE=\"root=/dev/htifblk0 init=/init\" >> stage3-kernel/linux-$(KERNEL_VERSION)/.config
320         echo CONFIG_CROSS_COMPILE=riscv64-unknown-elf- >> stage3-kernel/linux-$(KERNEL_VERSION)/.config
321         cd stage3-kernel/linux-$(KERNEL_VERSION) && \
322         make ARCH=riscv olddefconfig
323         cd stage3-kernel/linux-$(KERNEL_VERSION) && \
324         make ARCH=riscv vmlinux
325         ls -l $@
326
327 # Build an original (x86-64) chroot using supermin.  We then aim to
328 # rebuild (using cross-compiled versions) every ELF binary in this
329 # chroot.
330 stage3-chroot-original/etc/fedora-release:
331         rm -rf stage3-chroot-original tmp-supermin.d
332         supermin --prepare $(STAGE3_PACKAGES) -o tmp-supermin.d
333         supermin --build -f chroot tmp-supermin.d -o stage3-chroot-original
334         rm -r tmp-supermin.d
335         @echo -n "Total files in chroot: "
336         @find stage3-chroot-original -type f | wc -l
337         @echo -n "ELF files to be rebuilt: "
338         @find stage3-chroot-original -type f | xargs file -N | grep -E '\bELF.*LSB\b' | wc -l
339
340 # Copy the original chroot to the final chroot, remove all the ELF
341 # files.
342 stage3-chroot/etc/fedora-release: stage3-chroot-original/etc/fedora-release
343         rm -rf stage3-chroot
344         cp -a stage3-chroot-original stage3-chroot
345         find stage3-chroot -type d | xargs chmod u+w
346         find stage3-chroot -type f | xargs chmod u+w
347         find stage3-chroot -type f | xargs file -N | grep -E '\bELF.*LSB\b' | awk -F: '{print $$1}' | xargs rm -f
348         rm -f stage3-chroot/lib64/libc.so.6
349
350 # Copy in compiled glibc from the riscv-gnu-toolchain sysroot.  Only
351 # copy files and symlinks, leave the target directory structure
352 # intact.
353 stage3-chroot/lib64/libc.so.6:
354         mkdir -p stage3-chroot/usr/lib/audit
355         mkdir -p stage3-chroot/usr/lib/gconv
356         for f in `cd /usr/sysroot && find -type f -o -type l`; do \
357             cp -d /usr/sysroot/$$f stage3-chroot/$$f; \
358         done
359         cd stage3-chroot/lib64 && for f in ../lib/*; do ln -sf $$f; done
360
361 # Cross-compile ncurses.
362 stage3-chroot/usr/bin/tic: ncurses-$(NCURSES_VERSION).tgz
363         tar zxf $^
364         cd ncurses-$(NCURSES_VERSION) && \
365         PATH=$(ROOT)/fixed-gcc:$$PATH \
366         ./configure --host=riscv64-unknown-linux-gnu \
367             --prefix=/usr --libdir=/usr/lib64 \
368             --with-shared \
369             --with-termlib=tinfo \
370             --enable-widec
371         cd ncurses-$(NCURSES_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
372         cd ncurses-$(NCURSES_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
373
374 ncurses-$(NCURSES_VERSION).tgz:
375         rm -f $@ $@-t
376         wget -O $@-t ftp://invisible-island.net/ncurses/current/ncurses-$(NCURSES_VERSION).tgz
377         mv $@-t $@
378
379 # Cross-compile bash.
380 stage3-chroot/bin/bash: bash-$(BASH_VERSION).tar.gz
381         tar zxf $^
382         cd bash-$(BASH_VERSION) && \
383         PATH=$(ROOT)/fixed-gcc:$$PATH \
384         ./configure --host=riscv64-unknown-linux-gnu \
385             --prefix=/usr --libdir=/usr/lib64
386         cd bash-$(BASH_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
387         cd bash-$(BASH_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
388
389 bash-$(BASH_VERSION).tar.gz:
390         rm -f $@ $@-t
391         wget -O $@-t ftp://ftp.gnu.org/gnu/bash/bash-$(BASH_VERSION).tar.gz
392         mv $@-t $@
393
394 # Cross-compile coreutils.  Bleah, coreutils cross-compilation is
395 # known-broken and upstream don't care, hence the 'touch' command.
396
397 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
398
399 stage3-chroot/bin/ls: coreutils-$(COREUTILS_VERSION).tar.xz
400         rm -rf coreutils-$(COREUTILS_VERSION)
401         tar Jxf $^
402         cd coreutils-$(COREUTILS_VERSION) && \
403         PATH=$(ROOT)/fixed-gcc:$$PATH \
404         ./configure --host=riscv64-unknown-linux-gnu \
405             --prefix=/usr --libdir=/usr/lib64
406         -cd coreutils-$(COREUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
407         cd coreutils-$(COREUTILS_VERSION)/man && \
408         for f in $(COREUTILS_PROGRAMS); do touch $$f.1; done
409         cd coreutils-$(COREUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
410         cd coreutils-$(COREUTILS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
411
412 coreutils-$(COREUTILS_VERSION).tar.xz:
413         rm -f $@ $@-t
414         wget -O $@-t ftp://ftp.gnu.org/gnu/coreutils/coreutils-$(COREUTILS_VERSION).tar.xz
415         mv $@-t $@
416
417 # Cross-compile binutils.
418 stage3-chroot/usr/bin/as: binutils-$(BINUTILS_X_VERSION).tar.gz
419         rm -rf riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)
420         zcat $^ | tar xf -
421         mkdir riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build
422         cd riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build && \
423         PATH=$(ROOT)/fixed-gcc:$$PATH \
424         ../configure \
425             --host=riscv64-unknown-linux-gnu \
426             --prefix=/usr --libdir=/usr/lib64
427         cd riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build && PATH=$(ROOT)/fixed-gcc:$$PATH make
428         cd riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build && make DESTDIR=$(ROOT)/stage3-chroot install
429
430 binutils-$(BINUTILS_X_VERSION).tar.gz:
431         rm -f $@ $@-t
432         wget -O $@-t https://github.com/riscv/riscv-binutils-gdb/archive/riscv-binutils-$(BINUTILS_X_VERSION).tar.gz
433         mv $@-t $@
434
435 # Cross-compile GMP, MPFR and MPC (deps of GCC).
436 stage3-chroot/usr/lib64/libgmp.so.10: gmp-$(GMP_VERSION).tar.lz
437         rm -rf gmp-$(GMP_VERSION)
438         tar --lzip -xf gmp-$(GMP_VERSION).tar.lz
439         cd gmp-$(GMP_VERSION) && \
440         PATH=$(ROOT)/fixed-gcc:$$PATH \
441         ./configure --host=riscv64-unknown-linux-gnu \
442             --prefix=/usr --libdir=/usr/lib64
443         cd gmp-$(GMP_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
444         cd gmp-$(GMP_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
445         cd stage3-chroot/usr/lib && ln -s ../lib64/libgmp.so
446
447 gmp-$(GMP_VERSION).tar.lz:
448         rm -f $@ $@-t
449         wget -O $@-t https://gmplib.org/download/gmp/gmp-$(GMP_VERSION).tar.lz
450         mv $@-t $@
451
452 stage3-chroot/usr/lib64/libmpfr.so.4: mpfr-$(MPFR_VERSION).tar.gz
453         rm -rf mpfr-$(MPFR_VERSION)
454         tar -zxf mpfr-$(MPFR_VERSION).tar.gz
455         cd mpfr-$(MPFR_VERSION) && \
456         PATH=$(ROOT)/fixed-gcc:$$PATH \
457         ./configure --host=riscv64-unknown-linux-gnu \
458             --prefix=/usr --libdir=/usr/lib64 \
459             --with-gmp=$(ROOT)/stage3-chroot/usr
460         cd mpfr-$(MPFR_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
461         cd mpfr-$(MPFR_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
462         cd stage3-chroot/usr/lib && ln -s ../lib64/libmpfr.so
463         rm -f stage3-chroot/usr/lib64/*.la
464
465 mpfr-$(MPFR_VERSION).tar.gz:
466         rm -f $@ $@-t
467         wget -O $@-t http://www.mpfr.org/mpfr-current/mpfr-$(MPFR_VERSION).tar.gz
468         mv $@-t $@
469
470 stage3-chroot/usr/lib64/libmpc.so.3: mpc-$(MPC_VERSION).tar.gz
471         rm -rf mpc-$(MPC_VERSION)
472         tar -zxf mpc-$(MPC_VERSION).tar.gz
473         cd mpc-$(MPC_VERSION) && \
474         PATH=$(ROOT)/fixed-gcc:$$PATH \
475         ./configure --host=riscv64-unknown-linux-gnu \
476             --prefix=/usr --libdir=/usr/lib64 \
477             --with-gmp=$(ROOT)/stage3-chroot/usr \
478             --with-mpfr=$(ROOT)/stage3-chroot/usr
479         cd mpc-$(MPC_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
480         cd mpc-$(MPC_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
481         cd stage3-chroot/usr/lib && ln -s ../lib64/libmpc.so
482         rm -f stage3-chroot/usr/lib64/*.la
483
484 mpc-$(MPC_VERSION).tar.gz:
485         rm -f $@ $@-t
486         wget -O $@-t ftp://ftp.gnu.org/gnu/mpc/mpc-$(MPC_VERSION).tar.gz
487         mv $@-t $@
488
489 # Cross-compile GCC.
490 stage3-chroot/usr/bin/gcc: gcc-$(GCC_X_VERSION).tar.gz
491         rm -rf riscv-gcc-riscv-gcc-$(GCC_X_VERSION)
492         zcat $^ | tar xf -
493         mkdir riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build
494         cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && \
495         PATH=$(ROOT)/fixed-gcc:$$PATH \
496         ../configure \
497             --host=riscv64-unknown-linux-gnu \
498             --prefix=/usr --libdir=/usr/lib64 \
499             --enable-shared \
500             --enable-tls \
501             --enable-languages=c,c++ \
502             --disable-libmudflap \
503             --disable-libssp \
504             --disable-libquadmath \
505             --disable-nls \
506             --disable-multilib
507 # XXX use make all & make install here.  However building libgcc
508 # fails, see 'broken-gcc.log'.
509         cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && PATH=$(ROOT)/fixed-gcc:$$PATH make all-gcc
510         cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && make install-gcc DESTDIR=$(ROOT)/stage3-chroot
511
512 gcc-$(GCC_X_VERSION).tar.gz:
513         rm -f $@ $@-t
514         wget -O $@-t https://github.com/riscv/riscv-gcc/archive/riscv-gcc-$(GCC_X_VERSION).tar.gz
515         mv $@-t $@
516
517 # Cross-compile util-linux.
518 stage3-chroot/usr/bin/mount: util-linux-$(UTIL_LINUX_VERSION).tar.xz
519         rm -rf util-linux-$(UTIL_LINUX_VERSION)
520         tar -Jxf $^
521         cd util-linux-$(UTIL_LINUX_VERSION) && \
522         PATH=$(ROOT)/fixed-gcc:$$PATH \
523         LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
524         ./configure \
525             --host=riscv64-unknown-linux-gnu \
526             --prefix=/usr --libdir=/usr/lib64 \
527             --without-python \
528             --without-systemd \
529             --disable-makeinstall-chown \
530             --enable-static-programs=mount
531         cd util-linux-$(UTIL_LINUX_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
532         cd util-linux-$(UTIL_LINUX_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
533         rm -f stage3-chroot/usr/lib64/*.la
534
535 util-linux-$(UTIL_LINUX_VERSION).tar.xz:
536         rm -f $@ $@-t
537         wget -O $@-t ftp://ftp.kernel.org/pub/linux/utils/util-linux/v$(UTIL_LINUX_VERSION)/util-linux-$(UTIL_LINUX_VERSION).tar.xz
538         mv $@-t $@
539
540 # Cross-compile GNU tar.
541 stage3-chroot/usr/bin/tar: tar-$(TAR_VERSION).tar.xz
542         rm -rf tar-$(TAR_VERSION)
543         tar -Jxf $^
544         cd tar-$(TAR_VERSION) && \
545         PATH=$(ROOT)/fixed-gcc:$$PATH \
546         ./configure \
547             --host=riscv64-unknown-linux-gnu \
548             --prefix=/usr --libdir=/usr/lib64
549         cd tar-$(TAR_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
550         cd tar-$(TAR_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
551
552 tar-$(TAR_VERSION).tar.xz:
553         rm -f $@ $@-t
554         wget -O $@-t https://ftp.gnu.org/gnu/tar/tar-$(TAR_VERSION).tar.xz
555         mv $@-t $@
556
557 # Cross-compile GNU gzip.
558 stage3-chroot/usr/bin/gzip: gzip-$(GZIP_VERSION).tar.gz
559         rm -rf gzip-$(GZIP_VERSION)
560         tar -zxf $^
561         cd gzip-$(GZIP_VERSION) && \
562         PATH=$(ROOT)/fixed-gcc:$$PATH \
563         ./configure \
564             --host=riscv64-unknown-linux-gnu \
565             --prefix=/usr --libdir=/usr/lib64
566         cd gzip-$(GZIP_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
567         cd gzip-$(GZIP_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
568
569 gzip-$(GZIP_VERSION).tar.gz:
570         rm -f $@ $@-t
571         wget -O $@-t https://ftp.gnu.org/gnu/gzip/gzip-$(GZIP_VERSION).tar.gz
572         mv $@-t $@
573
574 # Cross-compile zlib.
575 stage3-chroot/usr/lib64/libz.so: zlib-$(ZLIB_VERSION).tar.gz
576         rm -rf zlib-$(ZLIB_VERSION)
577         tar -zxf $^
578         cd zlib-$(ZLIB_VERSION) && \
579         PATH=$(ROOT)/fixed-gcc:$$PATH \
580         CC=riscv64-unknown-linux-gnu-gcc \
581         CFLAGS="-I$(ROOT)/stage3-chroot/usr/include -L$(ROOT)/stage3-chroot/usr/lib" \
582         ./configure \
583             --prefix=/usr --libdir=/usr/lib64
584         cd zlib-$(ZLIB_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make shared
585         cd zlib-$(ZLIB_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
586
587 zlib-$(ZLIB_VERSION).tar.gz:
588         rm -f $@ $@-t
589         wget -O $@-t http://zlib.net/zlib-$(ZLIB_VERSION).tar.gz
590         mv $@-t $@
591
592 # Cross-compile file/libmagic.
593 stage3-chroot/usr/bin/file: file-$(FILE_VERSION).tar.gz
594         rm -rf file-$(FILE_VERSION)
595         tar -zxf $^
596         cd file-$(FILE_VERSION) && \
597         PATH=$(ROOT)/fixed-gcc:$$PATH \
598         LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
599         ./configure \
600             --host=riscv64-unknown-linux-gnu \
601             --prefix=/usr --libdir=/usr/lib64 \
602             --disable-static --enable-shared
603         cd file-$(FILE_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
604         cd file-$(FILE_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
605         rm -f stage3-chroot/usr/lib64/*.la
606
607 file-$(FILE_VERSION).tar.gz:
608         rm -f $@ $@-t
609         wget -O $@-t ftp://ftp.astron.com/pub/file/file-$(FILE_VERSION).tar.gz
610         mv $@-t $@
611
612 # Cross-compile popt.
613 stage3-chroot/usr/lib64/libpopt.so: popt-$(POPT_VERSION).tar.gz
614         rm -rf popt-$(POPT_VERSION)
615         tar -zxf $^
616         cd popt-$(POPT_VERSION) && \
617         PATH=$(ROOT)/fixed-gcc:$$PATH \
618         LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
619         ./configure \
620             --host=riscv64-unknown-linux-gnu \
621             --prefix=/usr --libdir=/usr/lib64 \
622             --disable-static --enable-shared
623         cd popt-$(POPT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
624         cd popt-$(POPT_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
625         rm -f stage3-chroot/usr/lib64/*.la
626
627 popt-$(POPT_VERSION).tar.gz:
628         rm -f $@ $@-t
629         wget -O $@-t http://rpm5.org/files/popt/popt-$(POPT_VERSION).tar.gz
630         mv $@-t $@
631
632 # Cross-compile beecrypt.
633 stage3-chroot/usr/lib64/libbeecrypt.so: beecrypt-$(BEECRYPT_VERSION).tar.gz
634         rm -rf beecrypt-$(BEECRYPT_VERSION)
635         tar -zxf $^
636         cd beecrypt-$(BEECRYPT_VERSION) && patch -p0 < ../beecrypt-disable-cplusplus.patch
637         cd beecrypt-$(BEECRYPT_VERSION) && autoreconf -i
638         cd beecrypt-$(BEECRYPT_VERSION) && \
639         PATH=$(ROOT)/fixed-gcc:$$PATH \
640         LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
641         ./configure \
642             --host=riscv64-unknown-linux-gnu \
643             --prefix=/usr --libdir=/usr/lib64 \
644             --without-cplusplus \
645             --without-java \
646             --disable-openmp \
647             --disable-static \
648             --enable-shared
649         cd beecrypt-$(BEECRYPT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
650         cd beecrypt-$(BEECRYPT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot V=1
651         chrpath -d stage3-chroot/usr/lib64/libbeecrypt.so.*
652         rm -f stage3-chroot/usr/lib64/*.la
653
654 beecrypt-$(BEECRYPT_VERSION).tar.gz:
655         rm -f $@ $@-t
656         wget -O $@-t http://downloads.sourceforge.net/sourceforge/beecrypt/beecrypt-$(BEECRYPT_VERSION).tar.gz
657         mv $@-t $@
658
659 # Cross-compile GNU nano (editor).
660 stage3-chroot/usr/bin/nano: nano-$(NANO_VERSION).tar.gz
661         rm -rf nano-$(NANO_VERSION)
662         tar -zxf $^
663         cd nano-$(NANO_VERSION) && \
664         PATH=$(ROOT)/fixed-gcc:$$PATH \
665         LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
666         ./configure \
667             --host=riscv64-unknown-linux-gnu \
668             --prefix=/usr --libdir=/usr/lib64
669         cd nano-$(NANO_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
670         cd nano-$(NANO_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
671
672 nano-$(NANO_VERSION).tar.gz:
673         rm -f $@ $@-t
674         wget -O $@-t https://www.nano-editor.org/dist/v2.6/nano-$(NANO_VERSION).tar.gz
675         mv $@-t $@
676
677 # Cross-compile GNU grep.
678 stage3-chroot/usr/bin/grep: grep-$(GREP_VERSION).tar.xz
679         rm -rf grep-$(GREP_VERSION)
680         tar -Jxf $^
681         cd grep-$(GREP_VERSION) && \
682         PATH=$(ROOT)/fixed-gcc:$$PATH \
683         ./configure \
684             --host=riscv64-unknown-linux-gnu \
685             --prefix=/usr --libdir=/usr/lib64
686         cd grep-$(GREP_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
687         cd grep-$(GREP_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
688
689 grep-$(GREP_VERSION).tar.xz:
690         rm -f $@ $@-t
691         wget -O $@-t https://ftp.gnu.org/gnu/grep/grep-$(GREP_VERSION).tar.xz
692         mv $@-t $@
693
694 # Cross-compile less.
695 stage3-chroot/usr/bin/less: less-$(LESS_VERSION).tar.gz
696         rm -rf less-$(LESS_VERSION)
697         tar -zxf $^
698         cd less-$(LESS_VERSION) && \
699         PATH=$(ROOT)/fixed-gcc:$$PATH \
700         LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
701         ./configure \
702             --host=riscv64-unknown-linux-gnu \
703             --prefix=/usr --libdir=/usr/lib64
704         cd less-$(LESS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
705         cd less-$(LESS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
706
707 less-$(LESS_VERSION).tar.gz:
708         rm -f $@ $@-t
709         wget -O $@-t http://www.greenwoodsoftware.com/less/less-$(LESS_VERSION).tar.gz
710         mv $@-t $@
711
712 # Cross-compile strace.
713 # XXX This does not work.
714 stage3-chroot/usr/bin/strace: strace-$(STRACE_SHORT_COMMIT).tar.gz
715         rm -rf strace-$(STRACE_SHORT_COMMIT)
716         tar -zxf $^
717         cd riscv-strace-$(STRACE_COMMIT) && patch -p1 < ../0001-Update-riscv_regs-for-ptrace.h-from-Linux-4.1.x.patch
718         cd riscv-strace-$(STRACE_COMMIT) && \
719         PATH=$(ROOT)/fixed-gcc:$$PATH \
720         LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
721         ./configure \
722             --host=riscv64-unknown-linux-gnu \
723             --prefix=/usr --libdir=/usr/lib64
724         cd riscv-strace-$(STRACE_COMMIT) && PATH=$(ROOT)/fixed-gcc:$$PATH make
725         cd riscv-strace-$(STRACE_COMMIT) && make install DESTDIR=$(ROOT)/stage3-chroot
726
727 strace-$(STRACE_SHORT_COMMIT).tar.gz:
728         rm -f $@ $@-t
729         wget -O $@-t 'https://github.com/riscv/riscv-strace/archive/$(STRACE_COMMIT)/riscv-strace-$(STRACE_SHORTCOMMIT).tar.gz'
730         mv $@-t $@
731
732 # Cross-compile bzip2.
733 stage3-chroot/usr/bin/bzip2: bzip2-$(BZIP2_VERSION).tar.gz
734         rm -rf bzip2-$(BZIP2_VERSION)
735         tar -zxf $^
736         cd bzip2-$(BZIP2_VERSION) && \
737         PATH=$(ROOT)/fixed-gcc:$$PATH \
738         make libbz2.a bzip2 bzip2recover \
739         PREFIX=/usr \
740         CC=riscv64-unknown-linux-gnu-gcc \
741         AR=riscv64-unknown-linux-gnu-ar \
742         RANLIB=riscv64-unknown-linux-gnu-ranlib \
743         CFLAGS="-Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -fPIC"
744         cd bzip2-$(BZIP2_VERSION) && \
745         make install PREFIX=$(ROOT)/stage3-chroot/usr
746
747 bzip2-$(BZIP2_VERSION).tar.gz:
748         rm -f $@ $@-t
749         wget -O $@-t http://www.bzip.org/1.0.6/bzip2-$(BZIP2_VERSION).tar.gz
750         mv $@-t $@
751
752 # Cross-compile GNU make.
753 stage3-chroot/usr/bin/make: make-$(MAKE_VERSION).tar.gz
754         rm -rf make-$(MAKE_VERSION)
755         tar -zxf $^
756         cd make-$(MAKE_VERSION) && \
757         PATH=$(ROOT)/fixed-gcc:$$PATH \
758         ./configure \
759             --host=riscv64-unknown-linux-gnu \
760             --prefix=/usr --libdir=/usr/lib64
761         cd make-$(MAKE_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
762         cd make-$(MAKE_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
763
764 make-$(MAKE_VERSION).tar.gz:
765         rm -f $@ $@-t
766         wget -O $@-t https://ftp.gnu.org/gnu/make/make-$(MAKE_VERSION).tar.gz
767         mv $@-t $@
768
769 # Cross-compile GNU diffutils.
770 stage3-chroot/usr/bin/diff: diffutils-$(DIFFUTILS_VERSION).tar.xz
771         rm -rf diffutils-$(DIFFUTILS_VERSION)
772         tar -Jxf $^
773         cd diffutils-$(DIFFUTILS_VERSION) && \
774         PATH=$(ROOT)/fixed-gcc:$$PATH \
775         ./configure \
776             --host=riscv64-unknown-linux-gnu \
777             --prefix=/usr --libdir=/usr/lib64
778         cd diffutils-$(DIFFUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
779         cd diffutils-$(DIFFUTILS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
780
781 diffutils-$(DIFFUTILS_VERSION).tar.xz:
782         rm -f $@ $@-t
783         wget -O $@-t https://ftp.gnu.org/gnu/diffutils/diffutils-$(DIFFUTILS_VERSION).tar.xz
784         mv $@-t $@
785
786 # Cross-compile GNU findutils.
787 stage3-chroot/usr/bin/find: findutils-$(FINDUTILS_VERSION).tar.gz
788         rm -rf findutils-$(FINDUTILS_VERSION)
789         tar -zxf $^
790         cd findutils-$(FINDUTILS_VERSION) && \
791         PATH=$(ROOT)/fixed-gcc:$$PATH \
792         ./configure \
793             --host=riscv64-unknown-linux-gnu \
794             --prefix=/usr --libdir=/usr/lib64
795         cd findutils-$(FINDUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
796         cd findutils-$(FINDUTILS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
797
798 findutils-$(FINDUTILS_VERSION).tar.gz:
799         rm -f $@ $@-t
800         wget -O $@-t https://ftp.gnu.org/gnu/findutils/findutils-$(FINDUTILS_VERSION).tar.gz
801         mv $@-t $@
802
803 # Cross-compile GNU sed.
804 stage3-chroot/usr/bin/sed: sed-$(SED_VERSION).tar.gz
805         rm -rf sed-$(SED_VERSION)
806         tar -zxf $^
807         cd sed-$(SED_VERSION) && \
808         PATH=$(ROOT)/fixed-gcc:$$PATH \
809         ./configure \
810             --host=riscv64-unknown-linux-gnu \
811             --prefix=/usr --libdir=/usr/lib64
812         cd sed-$(SED_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
813         cd sed-$(SED_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
814
815 sed-$(SED_VERSION).tar.gz:
816         rm -f $@ $@-t
817         wget -O $@-t https://ftp.gnu.org/gnu/sed/sed-$(SED_VERSION).tar.gz
818         mv $@-t $@
819
820 # Cross-compile patch.
821 stage3-chroot/usr/bin/patch: patch-$(PATCH_VERSION).tar.gz
822         rm -rf patch-$(PATCH_VERSION)
823         tar -zxf $^
824         cd patch-$(PATCH_VERSION) && \
825         PATH=$(ROOT)/fixed-gcc:$$PATH \
826         ./configure \
827             --host=riscv64-unknown-linux-gnu \
828             --prefix=/usr --libdir=/usr/lib64
829         cd patch-$(PATCH_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
830         cd patch-$(PATCH_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
831
832 patch-$(PATCH_VERSION).tar.gz:
833         rm -f $@ $@-t
834         wget -O $@-t https://ftp.gnu.org/gnu/patch/patch-$(PATCH_VERSION).tar.gz
835         mv $@-t $@
836
837 # Cross-compile hostname.
838 stage3-chroot/usr/bin/hostname: hostname-$(HOSTNAME_VERSION).tar.gz
839         rm -rf hostname-$(HOSTNAME_VERSION)
840         tar -zxf $^
841         cd hostname && patch -p1 < ../hostname-rh.patch
842         cd hostname && \
843         PATH=$(ROOT)/fixed-gcc:$$PATH \
844         make \
845         CC=riscv64-unknown-linux-gnu-gcc \
846         CFLAGS="-O2 -g"
847         cd hostname && make install BASEDIR=$(ROOT)/stage3-chroot
848
849 hostname-$(HOSTNAME_VERSION).tar.gz:
850         rm -f $@ $@-t
851         wget -O $@-t http://ftp.de.debian.org/debian/pool/main/h/hostname/hostname_$(HOSTNAME_VERSION).tar.gz
852         mv $@-t $@
853
854 # Cross-compile RPM / rpmbuild.
855 # We build this from a git commit, with a few hacks to the configure
856 # script.
857 stage3-chroot/usr/bin/rpm: rpm-$(RPM_SHORT_COMMIT).tar.gz db-$(BDB_VERSION).tar.gz
858         rm -rf rpm-$(RPM_SHORT_COMMIT)
859         tar -zxf rpm-$(RPM_SHORT_COMMIT).tar.gz
860         tar -zxf db-$(BDB_VERSION).tar.gz -C rpm-$(RPM_SHORT_COMMIT)
861         cd rpm-$(RPM_SHORT_COMMIT) && ln -s db-$(BDB_VERSION) db
862         cd rpm-$(RPM_SHORT_COMMIT) && \
863         patch -p1 < ../0001-RISCV-64-bit-riscv64-support.patch && \
864         patch -p1 < ../0002-build-fgetc-returns-int-not-char.patch && \
865         patch -p1 < ../0003-HACKS-TO-GET-RPM-TO-CROSS-COMPILE.patch
866         cd rpm-$(RPM_SHORT_COMMIT) && autoreconf -i
867         cd rpm-$(RPM_SHORT_COMMIT) && \
868         PATH=$(ROOT)/fixed-gcc:$$PATH \
869         LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
870         ./configure \
871             --host=riscv64-unknown-linux-gnu \
872             --prefix=/usr --libdir=/usr/lib64 \
873             --disable-rpath \
874             --without-libarchive \
875             --without-lua \
876             --with-beecrypt \
877             --without-archive \
878             --without-external-db \
879             --enable-ndb \
880             --disable-plugins
881         cd rpm-$(RPM_SHORT_COMMIT) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
882         cd rpm-$(RPM_SHORT_COMMIT) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
883         rm -f stage3-chroot/usr/lib64/*.la
884
885 rpm-$(RPM_SHORT_COMMIT).tar.gz:
886         rm -f $@ $@-t
887         wget -O $@-t 'http://rpm.org/gitweb?p=rpm.git;a=snapshot;h=$(RPM_COMMIT);sf=tgz'
888         mv $@-t $@
889
890 db-$(BDB_VERSION).tar.gz:
891         rm -f $@ $@-t
892         wget -O $@-t http://download.oracle.com/berkeley-db/db-$(BDB_VERSION).tar.gz
893         mv $@-t $@
894
895 # Create an /init script.
896 stage3-chroot/init: init.sh
897         install -m 0755 $^ $@
898
899 # Create the stage3 disk image.
900 # Note `-s +...' adds spare space to the disk image.
901 stage3-disk.img: stage3-chroot
902         cd stage3-chroot && virt-make-fs . ../$@ -t ext2 -F raw -s +4G
903
904 # Upload the compressed disk image.
905 upload-stage3: stage3-disk.img.xz
906         scp $^ tick:public_html/riscv/
907 stage3-disk.img.xz: stage3-disk.img
908         rm -f $@
909         xz --best $^
910
911 # Helper which boots stage3 disk image in spike.
912 boot-stage3-in-spike: stage3-disk.img stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
913         spike +disk=stage3-disk.img \
914             /usr/bin/bbl stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
915
916 # Helper which boots stage3 disk image in qemu.
917 boot-stage3-in-qemu: stage3-disk.img stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
918         qemu-system-riscv -kernel /usr/bin/bbl \
919             -append ./stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux \
920             -drive file=stage3-disk.img,format=raw -nographic
921
922 # Stage 4
923
924 stage4:
925         echo "XXX TO DO"
926         exit 1
927
928 .NOTPARALLEL: