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