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