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