Religiously remove *.la files from chroot.
[fedora-riscv.git] / Makefile
1 # Refer to the README file to understand how Fedora on RISC-V is
2 # bootstrapped.
3
4 # Absolute path to the current directory.
5 ROOT := $(shell pwd)
6
7 # Note these are chosen very specifically to ensure the different
8 # versions work together.  Don't blindly update to the latest
9 # versions.  See also:
10 # https://github.com/riscv/riscv-pk/issues/18#issuecomment-206115996
11 RISCV_QEMU_COMMIT               = 94f5eb73091fb4fe272db3e943f173ecc0f78ffd
12 RISCV_QEMU_SHORTCOMMIT          = 94f5eb73
13 RISCV_FESVR_COMMIT              = 0f34d7ad311f78455a674224225f5b3056efba1d
14 RISCV_FESVR_SHORTCOMMIT         = 0f34d7ad
15 RISCV_ISA_SIM_COMMIT            = 3bfc00ef2a1b1f0b0472a39a866261b00f67027e
16 RISCV_ISA_SIM_SHORTCOMMIT       = 3bfc00ef
17 RISCV_GNU_TOOLCHAIN_COMMIT      = 728afcddcb0526a0f6560c4032da82805f054d58
18 RISCV_GNU_TOOLCHAIN_SHORTCOMMIT = 728afcdd
19 RISCV_PK_COMMIT                 = 85ae17aa149b9ea114bdd70cc30ea7e73813fb48
20 RISCV_PK_SHORTCOMMIT            = 85ae17aa
21
22 # For the correct versions, see
23 # riscv-gnu-toolchain/Makefile.in *_version variables
24 BINUTILS_VERSION = 2.25.1
25 GLIBC_VERSION    = 2.22
26 GCC_VERSION      = 5.3.0
27 NEWLIB_VERSION   = 2.2.0
28
29 # See linux-4.1.y-riscv branch of
30 # https://github.com/riscv/riscv-linux
31 KERNEL_VERSION   = 4.1.26
32
33 # A local copy of Linux git repo so you don't have to keep downloading
34 # git commits (optional).
35 LOCAL_LINUX_GIT_COPY = $(HOME)/d/linux
36
37 # The root packages (plus their dependencies) that we want to
38 # cross-compile into the stage 3 chroot.
39 STAGE3_PACKAGES = gcc rpm-build
40
41 # Versions of cross-compiled packages.
42 NCURSES_VERSION    = 6.0-20160730
43 BASH_VERSION       = 4.3
44 COREUTILS_VERSION  = 8.25
45 GMP_VERSION        = 6.1.1
46 MPFR_VERSION       = 3.1.4
47 MPC_VERSION        = 1.0.3
48 BINUTILS_X_VERSION = 2.26
49 GCC_X_VERSION      = 6.1.0
50 UTIL_LINUX_VERSION = 2.28
51 TAR_VERSION        = 1.29
52 GZIP_VERSION       = 1.8
53 ZLIB_VERSION       = 1.2.8
54 # Needs to match the installed (on host) version, otherwise:
55 # "Cannot use the installed version of file (xx) to cross-compile file yy"
56 FILE_VERSION       = 5.25
57 POPT_VERSION       = 1.16
58
59 all: stage1 stage2 stage3 stage4
60
61 # Stage 1
62
63 stage1: stage1-riscv-qemu/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz \
64         stage1-riscv-qemu/riscv-qemu.spec \
65         stamp-riscv-qemu-installed \
66         stage1-riscv-fesvr/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz \
67         stage1-riscv-fesvr/riscv-fesvr.spec \
68         stamp-riscv-fesvr-installed \
69         stage1-riscv-isa-sim/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz \
70         stage1-riscv-isa-sim/riscv-isa-sim.spec \
71         stamp-riscv-isa-sim-installed
72
73 stage1-riscv-qemu/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz:
74         rm -f $@ $@-t
75         wget -O $@-t 'https://github.com/riscv/riscv-qemu/archive/$(RISCV_QEMU_COMMIT)/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz'
76         mv $@-t $@
77
78 stage1-riscv-qemu/riscv-qemu.spec: stage1-riscv-qemu/riscv-qemu.spec.in
79         sed -e 's/@COMMIT@/$(RISCV_QEMU_COMMIT)/g' \
80             -e 's/@SHORTCOMMIT@/$(RISCV_QEMU_SHORTCOMMIT)/g' \
81             < $^ > $@-t
82         mv $@-t $@
83
84 stamp-riscv-qemu-installed:
85         rm -f $@
86         @rpm -q riscv-qemu >/dev/null || { \
87           echo "ERROR: You must install riscv-qemu:"; \
88           echo; \
89           echo "       dnf copr enable rjones/riscv"; \
90           echo "       dnf install riscv-qemu"; \
91           echo; \
92           echo "OR: you can build it yourself from the stage1-riscv-qemu directory."; \
93           echo; \
94           exit 1; \
95         }
96         @qemu-system-riscv --version || { \
97           echo "ERROR: qemu-system-riscv is not working."; \
98           echo "Make sure you installed the riscv-qemu package."; \
99           exit 1; \
100         }
101         touch $@
102
103 stage1-riscv-fesvr/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz:
104         rm -f $@ $@-t
105         wget -O $@-t 'https://github.com/riscv/riscv-fesvr/archive/$(RISCV_FESVR_COMMIT)/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz'
106         mv $@-t $@
107
108 stage1-riscv-fesvr/riscv-fesvr.spec: stage1-riscv-fesvr/riscv-fesvr.spec.in
109         sed -e 's/@COMMIT@/$(RISCV_FESVR_COMMIT)/g' \
110             -e 's/@SHORTCOMMIT@/$(RISCV_FESVR_SHORTCOMMIT)/g' \
111             < $^ > $@-t
112         mv $@-t $@
113
114 stamp-riscv-fesvr-installed:
115         rm -f $@
116         @rpm -q riscv-fesvr >/dev/null || { \
117           echo "ERROR: You must install riscv-fesvr:"; \
118           echo; \
119           echo "       dnf copr enable rjones/riscv"; \
120           echo "       dnf install riscv-fesvr"; \
121           echo; \
122           echo "OR: you can build it yourself from the stage1-riscv-fesvr directory."; \
123           echo; \
124           exit 1; \
125         }
126         touch $@
127
128 stage1-riscv-isa-sim/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz:
129         rm -f $@ $@-t
130         wget -O $@-t 'https://github.com/riscv/riscv-isa-sim/archive/$(RISCV_ISA_SIM_COMMIT)/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz'
131         mv $@-t $@
132
133 stage1-riscv-isa-sim/riscv-isa-sim.spec: stage1-riscv-isa-sim/riscv-isa-sim.spec.in
134         sed -e 's/@COMMIT@/$(RISCV_ISA_SIM_COMMIT)/g' \
135             -e 's/@SHORTCOMMIT@/$(RISCV_ISA_SIM_SHORTCOMMIT)/g' \
136             < $^ > $@-t
137         mv $@-t $@
138
139 stamp-riscv-isa-sim-installed:
140         rm -f $@
141         @rpm -q riscv-isa-sim >/dev/null || { \
142           echo "ERROR: You must install riscv-isa-sim:"; \
143           echo; \
144           echo "       dnf copr enable rjones/riscv"; \
145           echo "       dnf install riscv-isa-sim"; \
146           echo; \
147           echo "OR: you can build it yourself from the stage1-riscv-isa-sim directory."; \
148           echo; \
149           exit 1; \
150         }
151         touch $@
152
153 # Stage 2
154
155 stage2: stage2-riscv-gnu-toolchain/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz \
156         stage2-riscv-gnu-toolchain/binutils-$(BINUTILS_VERSION).tar.gz \
157         stage2-riscv-gnu-toolchain/gcc-$(GCC_VERSION).tar.gz \
158         stage2-riscv-gnu-toolchain/glibc-$(GLIBC_VERSION).tar.gz \
159         stage2-riscv-gnu-toolchain/newlib-$(NEWLIB_VERSION).tar.gz \
160         stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec \
161         stamp-riscv-gnu-toolchain-installed \
162         stage2-riscv-pk/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz \
163         stage2-riscv-pk/riscv-pk.spec \
164         stamp-riscv-pk-installed
165
166 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz:
167         rm -f $@ $@-t
168         wget -O $@-t https://github.com/lowRISC/riscv-gnu-toolchain/archive/$(RISCV_GNU_TOOLCHAIN_COMMIT)/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz
169         mv $@-t $@
170
171 stage2-riscv-gnu-toolchain/binutils-$(BINUTILS_VERSION).tar.gz:
172         rm -f $@ $@-t
173         wget -O $@-t http://mirrors.kernel.org/gnu/binutils/binutils-$(BINUTILS_VERSION).tar.gz
174         mv $@-t $@
175
176 # GCC 5 no longer compiles with GCC 6 unless we patch it.
177 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69959
178 stage2-riscv-gnu-toolchain/gcc-$(GCC_VERSION).tar.gz:
179         rm -f $@ $@-t
180         wget -O $@-t http://mirrors.kernel.org/gnu/gcc/gcc-$(GCC_VERSION)/gcc-$(GCC_VERSION).tar.gz
181         zcat $@-t | tar xf -
182         cd gcc-$(GCC_VERSION) && patch -p0 < ../stage2-riscv-gnu-toolchain/gcc-5-fix-compilation-with-gcc-6.patch
183         tar zcf $@-t gcc-$(GCC_VERSION)
184         rm -r gcc-$(GCC_VERSION)
185         mv $@-t $@
186
187 stage2-riscv-gnu-toolchain/glibc-$(GLIBC_VERSION).tar.gz:
188         rm -f $@ $@-t
189         wget -O $@-t http://mirrors.kernel.org/gnu/glibc/glibc-$(GLIBC_VERSION).tar.gz
190         mv $@-t $@
191
192 stage2-riscv-gnu-toolchain/newlib-$(NEWLIB_VERSION).tar.gz:
193         rm -f $@ $@-t
194         wget -O $@-t ftp://sourceware.org/pub/newlib/newlib-$(NEWLIB_VERSION).tar.gz
195         mv $@-t $@
196
197 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec: stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec.in
198         sed -e 's/@COMMIT@/$(RISCV_GNU_TOOLCHAIN_COMMIT)/g' \
199             -e 's/@SHORTCOMMIT@/$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT)/g' \
200             -e 's/@BINUTILS_VERSION@/$(BINUTILS_VERSION)/g' \
201             -e 's/@GCC_VERSION@/$(GCC_VERSION)/g' \
202             -e 's/@GLIBC_VERSION@/$(GLIBC_VERSION)/g' \
203             -e 's/@NEWLIB_VERSION@/$(NEWLIB_VERSION)/g' \
204             < $^ > $@-t
205         mv $@-t $@
206
207 stamp-riscv-gnu-toolchain-installed:
208         rm -f $@
209         @rpm -q riscv-gnu-toolchain >/dev/null || { \
210           echo "ERROR: You must install riscv-gnu-toolchain:"; \
211           echo; \
212           echo "       dnf copr enable rjones/riscv"; \
213           echo "       dnf install riscv-gnu-toolchain"; \
214           echo; \
215           echo "OR: you can build it yourself from the stage2-riscv-gnu-toolchain directory."; \
216           echo; \
217           exit 1; \
218         }
219         @riscv64-unknown-elf-gcc --version || { \
220           echo "ERROR: riscv64-unknown-elf-gcc (cross compiler) is not working."; \
221           echo "Make sure you installed the riscv-gnu-toolchain package."; \
222           exit 1; \
223         }
224         touch $@
225
226 stage2-riscv-pk/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz:
227         rm -f $@ $@-t
228         wget -O $@-t https://github.com/lowRISC/riscv-pk/archive/$(RISCV_PK_COMMIT)/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz
229         mv $@-t $@
230
231 stage2-riscv-pk/riscv-pk.spec: stage2-riscv-pk/riscv-pk.spec.in
232         sed -e 's/@COMMIT@/$(RISCV_PK_COMMIT)/g' \
233             -e 's/@SHORTCOMMIT@/$(RISCV_PK_SHORTCOMMIT)/g' \
234             < $^ > $@-t
235         mv $@-t $@
236
237 stamp-riscv-pk-installed:
238         rm -f $@
239         @rpm -q riscv-pk >/dev/null || { \
240           echo "ERROR: You must install riscv-pk:"; \
241           echo; \
242           echo "       dnf copr enable rjones/riscv"; \
243           echo "       dnf install riscv-pk"; \
244           echo; \
245           echo "OR: you can build it yourself from the stage2-riscv-pk directory."; \
246           echo; \
247           exit 1; \
248         }
249         touch $@
250
251 # Stage 3
252
253 stage3: stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux \
254         stage3-chroot-original/etc/fedora-release \
255         stage3-chroot/etc/fedora-release \
256         stage3-chroot/lib64/libc.so.6 \
257         stage3-chroot/usr/bin/tic \
258         stage3-chroot/bin/bash \
259         stage3-chroot/bin/ls \
260         stage3-chroot/usr/lib64/libgmp.so.10 \
261         stage3-chroot/usr/lib64/libmpfr.so.4 \
262         stage3-chroot/usr/lib64/libmpc.so.3 \
263         stage3-chroot/usr/bin/as \
264         stage3-chroot/usr/bin/gcc \
265         stage3-chroot/usr/bin/mount \
266         stage3-chroot/usr/bin/tar \
267         stage3-chroot/usr/bin/gzip \
268         stage3-chroot/usr/lib64/libz.so \
269         stage3-chroot/usr/bin/file \
270         stage3-chroot/usr/lib64/libpopt.so \
271         stage3-chroot/init \
272         stage3-disk.img
273
274 stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux:
275         rm -rf stage3-kernel/linux-$(KERNEL_VERSION)
276         cp -a $(LOCAL_LINUX_GIT_COPY) stage3-kernel/linux-$(KERNEL_VERSION) || { \
277           mkdir stage3-kernel/linux-$(KERNEL_VERSION) && \
278           cd stage3-kernel/linux-$(KERNEL_VERSION) && \
279           git init; \
280         }
281         cd stage3-kernel/linux-$(KERNEL_VERSION) && \
282         git remote add riscv https://github.com/riscv/riscv-linux && \
283         git fetch riscv && \
284         git checkout -f linux-4.1.y-riscv && \
285         make mrproper && \
286         make ARCH=riscv defconfig
287         echo CONFIG_CMDLINE=\"root=/dev/htifblk0 init=/init\" >> stage3-kernel/linux-$(KERNEL_VERSION)/.config
288         echo CONFIG_CROSS_COMPILE=riscv64-unknown-elf- >> stage3-kernel/linux-$(KERNEL_VERSION)/.config
289         cd stage3-kernel/linux-$(KERNEL_VERSION) && \
290         make ARCH=riscv olddefconfig
291         cd stage3-kernel/linux-$(KERNEL_VERSION) && \
292         make ARCH=riscv vmlinux
293         ls -l $@
294
295 # Build an original (x86-64) chroot using supermin.  We then aim to
296 # rebuild (using cross-compiled versions) every ELF binary in this
297 # chroot.
298 stage3-chroot-original/etc/fedora-release:
299         rm -rf stage3-chroot-original tmp-supermin.d
300         supermin --prepare $(STAGE3_PACKAGES) -o tmp-supermin.d
301         supermin --build -f chroot tmp-supermin.d -o stage3-chroot-original
302         rm -r tmp-supermin.d
303         @echo -n "Total files in chroot: "
304         @find stage3-chroot-original -type f | wc -l
305         @echo -n "ELF files to be rebuilt: "
306         @find stage3-chroot-original -type f | xargs file -N | grep -E '\bELF.*LSB\b' | wc -l
307
308 # Copy the original chroot to the final chroot, remove all the ELF
309 # files.
310 stage3-chroot/etc/fedora-release: stage3-chroot-original/etc/fedora-release
311         rm -rf stage3-chroot
312         cp -a stage3-chroot-original stage3-chroot
313         find stage3-chroot -type d | xargs chmod u+w
314         find stage3-chroot -type f | xargs chmod u+w
315         find stage3-chroot -type f | xargs file -N | grep -E '\bELF.*LSB\b' | awk -F: '{print $$1}' | xargs rm -f
316         rm -f stage3-chroot/lib64/libc.so.6
317
318 # Copy in compiled glibc from the riscv-gnu-toolchain sysroot.  Only
319 # copy files and symlinks, leave the target directory structure
320 # intact.
321 stage3-chroot/lib64/libc.so.6:
322         mkdir -p stage3-chroot/usr/lib/audit
323         mkdir -p stage3-chroot/usr/lib/gconv
324         for f in `cd /usr/sysroot && find -type f -o -type l`; do \
325             cp -d /usr/sysroot/$$f stage3-chroot/$$f; \
326         done
327         cd stage3-chroot/lib64 && for f in ../lib/*; do ln -sf $$f; done
328
329 # Cross-compile ncurses.
330 stage3-chroot/usr/bin/tic: ncurses-$(NCURSES_VERSION).tgz
331         tar zxf $^
332         cd ncurses-$(NCURSES_VERSION) && \
333         PATH=$(ROOT)/fixed-gcc:$$PATH \
334         ./configure --host=riscv64-unknown-linux-gnu \
335             --prefix=/usr --libdir=/usr/lib64 \
336             --with-shared
337         cd ncurses-$(NCURSES_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
338         cd ncurses-$(NCURSES_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make install DESTDIR=$(ROOT)/stage3-chroot
339         cd $(ROOT)/stage3-chroot/usr/lib64 && ln -sf libtinfo.so.6 libtinfo.so
340
341 ncurses-$(NCURSES_VERSION).tgz:
342         rm -f $@ $@-t
343         wget -O $@-t ftp://invisible-island.net/ncurses/current/ncurses-$(NCURSES_VERSION).tgz
344         mv $@-t $@
345
346 # Cross-compile bash.
347 stage3-chroot/bin/bash: bash-$(BASH_VERSION).tar.gz
348         tar zxf $^
349         cd bash-$(BASH_VERSION) && \
350         PATH=$(ROOT)/fixed-gcc:$$PATH \
351         ./configure --host=riscv64-unknown-linux-gnu \
352             --prefix=/usr --libdir=/usr/lib64
353         cd bash-$(BASH_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
354         cd bash-$(BASH_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
355
356 bash-$(BASH_VERSION).tar.gz:
357         rm -f $@ $@-t
358         wget -O $@-t ftp://ftp.gnu.org/gnu/bash/bash-$(BASH_VERSION).tar.gz
359         mv $@-t $@
360
361 # Cross-compile coreutils.  Bleah, coreutils cross-compilation is
362 # known-broken and upstream don't care, hence the 'touch' command.
363
364 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
365
366 stage3-chroot/bin/ls: coreutils-$(COREUTILS_VERSION).tar.xz
367         rm -rf coreutils-$(COREUTILS_VERSION)
368         tar Jxf $^
369         cd coreutils-$(COREUTILS_VERSION) && \
370         PATH=$(ROOT)/fixed-gcc:$$PATH \
371         ./configure --host=riscv64-unknown-linux-gnu \
372             --prefix=/usr --libdir=/usr/lib64
373         -cd coreutils-$(COREUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
374         cd coreutils-$(COREUTILS_VERSION)/man && \
375         for f in $(COREUTILS_PROGRAMS); do touch $$f.1; done
376         cd coreutils-$(COREUTILS_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
377         cd coreutils-$(COREUTILS_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
378
379 coreutils-$(COREUTILS_VERSION).tar.xz:
380         rm -f $@ $@-t
381         wget -O $@-t ftp://ftp.gnu.org/gnu/coreutils/coreutils-$(COREUTILS_VERSION).tar.xz
382         mv $@-t $@
383
384 # Cross-compile binutils.
385 stage3-chroot/usr/bin/as: binutils-$(BINUTILS_X_VERSION).tar.gz
386         rm -rf riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)
387         zcat $^ | tar xf -
388         mkdir riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build
389         cd riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build && \
390         PATH=$(ROOT)/fixed-gcc:$$PATH \
391         ../configure \
392             --host=riscv64-unknown-linux-gnu \
393             --prefix=/usr --libdir=/usr/lib64
394         cd riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build && PATH=$(ROOT)/fixed-gcc:$$PATH make
395         cd riscv-binutils-gdb-riscv-binutils-$(BINUTILS_X_VERSION)/build && make DESTDIR=$(ROOT)/stage3-chroot install
396
397 binutils-$(BINUTILS_X_VERSION).tar.gz:
398         rm -f $@ $@-t
399         wget -O $@-t https://github.com/riscv/riscv-binutils-gdb/archive/riscv-binutils-$(BINUTILS_X_VERSION).tar.gz
400         mv $@-t $@
401
402 # Cross-compile GMP, MPFR and MPC (deps of GCC).
403 stage3-chroot/usr/lib64/libgmp.so.10: gmp-$(GMP_VERSION).tar.lz
404         rm -rf gmp-$(GMP_VERSION)
405         tar --lzip -xf gmp-$(GMP_VERSION).tar.lz
406         cd gmp-$(GMP_VERSION) && \
407         PATH=$(ROOT)/fixed-gcc:$$PATH \
408         ./configure --host=riscv64-unknown-linux-gnu \
409             --prefix=/usr --libdir=/usr/lib64
410         cd gmp-$(GMP_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
411         cd gmp-$(GMP_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
412         cd stage3-chroot/usr/lib && ln -s ../lib64/libgmp.so
413
414 gmp-$(GMP_VERSION).tar.lz:
415         rm -f $@ $@-t
416         wget -O $@-t https://gmplib.org/download/gmp/gmp-$(GMP_VERSION).tar.lz
417         mv $@-t $@
418
419 stage3-chroot/usr/lib64/libmpfr.so.4: mpfr-$(MPFR_VERSION).tar.gz
420         rm -rf mpfr-$(MPFR_VERSION)
421         tar -zxf mpfr-$(MPFR_VERSION).tar.gz
422         cd mpfr-$(MPFR_VERSION) && \
423         PATH=$(ROOT)/fixed-gcc:$$PATH \
424         ./configure --host=riscv64-unknown-linux-gnu \
425             --prefix=/usr --libdir=/usr/lib64 \
426             --with-gmp=$(ROOT)/stage3-chroot/usr
427         cd mpfr-$(MPFR_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
428         cd mpfr-$(MPFR_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
429         cd stage3-chroot/usr/lib && ln -s ../lib64/libmpfr.so
430         rm -f stage3-chroot/usr/lib64/*.la
431
432 mpfr-$(MPFR_VERSION).tar.gz:
433         rm -f $@ $@-t
434         wget -O $@-t http://www.mpfr.org/mpfr-current/mpfr-$(MPFR_VERSION).tar.gz
435         mv $@-t $@
436
437 stage3-chroot/usr/lib64/libmpc.so.3: mpc-$(MPC_VERSION).tar.gz
438         rm -rf mpc-$(MPC_VERSION)
439         tar -zxf mpc-$(MPC_VERSION).tar.gz
440         cd mpc-$(MPC_VERSION) && \
441         PATH=$(ROOT)/fixed-gcc:$$PATH \
442         ./configure --host=riscv64-unknown-linux-gnu \
443             --prefix=/usr --libdir=/usr/lib64 \
444             --with-gmp=$(ROOT)/stage3-chroot/usr \
445             --with-mpfr=$(ROOT)/stage3-chroot/usr
446         cd mpc-$(MPC_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
447         cd mpc-$(MPC_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
448         cd stage3-chroot/usr/lib && ln -s ../lib64/libmpc.so
449         rm -f stage3-chroot/usr/lib64/*.la
450
451 mpc-$(MPC_VERSION).tar.gz:
452         rm -f $@ $@-t
453         wget -O $@-t ftp://ftp.gnu.org/gnu/mpc/mpc-$(MPC_VERSION).tar.gz
454         mv $@-t $@
455
456 # Cross-compile GCC.
457 stage3-chroot/usr/bin/gcc: gcc-$(GCC_X_VERSION).tar.gz
458         rm -rf riscv-gcc-riscv-gcc-$(GCC_X_VERSION)
459         zcat $^ | tar xf -
460         mkdir riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build
461         cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && \
462         PATH=$(ROOT)/fixed-gcc:$$PATH \
463         ../configure \
464             --host=riscv64-unknown-linux-gnu \
465             --prefix=/usr --libdir=/usr/lib64 \
466             --enable-shared \
467             --enable-tls \
468             --enable-languages=c,c++ \
469             --disable-libmudflap \
470             --disable-libssp \
471             --disable-libquadmath \
472             --disable-nls \
473             --disable-multilib
474 # XXX use make all & make install here.  However building libgcc
475 # fails, see 'broken-gcc.log'.
476         cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && PATH=$(ROOT)/fixed-gcc:$$PATH make all-gcc
477         cd riscv-gcc-riscv-gcc-$(GCC_X_VERSION)/build && make install-gcc DESTDIR=$(ROOT)/stage3-chroot
478
479 gcc-$(GCC_X_VERSION).tar.gz:
480         rm -f $@ $@-t
481         wget -O $@-t https://github.com/riscv/riscv-gcc/archive/riscv-gcc-$(GCC_X_VERSION).tar.gz
482         mv $@-t $@
483
484 # Cross-compile util-linux.
485 # XXX Be nice to fix ncurses/tinfo support which in theory should work.
486 stage3-chroot/usr/bin/mount: util-linux-$(UTIL_LINUX_VERSION).tar.xz
487         rm -rf util-linux-$(UTIL_LINUX_VERSION)
488         tar -Jxf $^
489         cd util-linux-$(UTIL_LINUX_VERSION) && \
490         PATH=$(ROOT)/fixed-gcc:$$PATH \
491         ./configure \
492             --host=riscv64-unknown-linux-gnu \
493             --prefix=/usr --libdir=/usr/lib64 \
494             --without-python \
495             --without-tinfo \
496             --without-ncurses \
497             --without-systemd \
498             --disable-makeinstall-chown
499         cd util-linux-$(UTIL_LINUX_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
500 #       libtool fucks something up here, ignore the failure and continue.
501         -cd util-linux-$(UTIL_LINUX_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot -j1 -k V=1
502
503 util-linux-$(UTIL_LINUX_VERSION).tar.xz:
504         rm -f $@ $@-t
505         wget -O $@-t ftp://ftp.kernel.org/pub/linux/utils/util-linux/v$(UTIL_LINUX_VERSION)/util-linux-$(UTIL_LINUX_VERSION).tar.xz
506         mv $@-t $@
507
508 # Cross-compile GNU tar.
509 stage3-chroot/usr/bin/tar: tar-$(TAR_VERSION).tar.xz
510         rm -rf tar-$(TAR_VERSION)
511         tar -Jxf $^
512         cd tar-$(TAR_VERSION) && \
513         PATH=$(ROOT)/fixed-gcc:$$PATH \
514         ./configure \
515             --host=riscv64-unknown-linux-gnu \
516             --prefix=/usr --libdir=/usr/lib64
517         cd tar-$(TAR_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
518         cd tar-$(TAR_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
519
520 tar-$(TAR_VERSION).tar.xz:
521         rm -f $@ $@-t
522         wget -O $@-t https://ftp.gnu.org/gnu/tar/tar-$(TAR_VERSION).tar.xz
523         mv $@-t $@
524
525 # Cross-compile GNU gzip.
526 stage3-chroot/usr/bin/gzip: gzip-$(GZIP_VERSION).tar.gz
527         rm -rf gzip-$(GZIP_VERSION)
528         tar -zxf $^
529         cd gzip-$(GZIP_VERSION) && \
530         PATH=$(ROOT)/fixed-gcc:$$PATH \
531         ./configure \
532             --host=riscv64-unknown-linux-gnu \
533             --prefix=/usr --libdir=/usr/lib64
534         cd gzip-$(GZIP_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make
535         cd gzip-$(GZIP_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
536
537 gzip-$(GZIP_VERSION).tar.gz:
538         rm -f $@ $@-t
539         wget -O $@-t https://ftp.gnu.org/gnu/gzip/gzip-$(GZIP_VERSION).tar.gz
540         mv $@-t $@
541
542 # Cross-compile zlib.
543 stage3-chroot/usr/lib64/libz.so: zlib-$(ZLIB_VERSION).tar.gz
544         rm -rf zlib-$(ZLIB_VERSION)
545         tar -zxf $^
546         cd zlib-$(ZLIB_VERSION) && \
547         PATH=$(ROOT)/fixed-gcc:$$PATH \
548         CC=riscv64-unknown-linux-gnu-gcc \
549         CFLAGS="-I$(ROOT)/stage3-chroot/usr/include -L$(ROOT)/stage3-chroot/usr/lib" \
550         ./configure \
551             --prefix=/usr --libdir=/usr/lib64
552         cd zlib-$(ZLIB_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make shared
553         cd zlib-$(ZLIB_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
554
555 zlib-$(ZLIB_VERSION).tar.gz:
556         rm -f $@ $@-t
557         wget -O $@-t http://zlib.net/zlib-$(ZLIB_VERSION).tar.gz
558         mv $@-t $@
559
560 # Cross-compile file/libmagic.
561 stage3-chroot/usr/bin/file: file-$(FILE_VERSION).tar.gz
562         rm -rf file-$(FILE_VERSION)
563         tar -zxf $^
564         cd file-$(FILE_VERSION) && \
565         PATH=$(ROOT)/fixed-gcc:$$PATH \
566         LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
567         ./configure \
568             --host=riscv64-unknown-linux-gnu \
569             --prefix=/usr --libdir=/usr/lib64 \
570             --disable-static --enable-shared
571         cd file-$(FILE_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
572         cd file-$(FILE_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
573         rm -f stage3-chroot/usr/lib64/*.la
574
575 file-$(FILE_VERSION).tar.gz:
576         rm -f $@ $@-t
577         wget -O $@-t ftp://ftp.astron.com/pub/file/file-$(FILE_VERSION).tar.gz
578         mv $@-t $@
579
580 # Cross-compile popt.
581 stage3-chroot/usr/lib64/libpopt.so: popt-$(POPT_VERSION).tar.gz
582         rm -rf popt-$(POPT_VERSION)
583         tar -zxf $^
584         cd popt-$(POPT_VERSION) && \
585         PATH=$(ROOT)/fixed-gcc:$$PATH \
586         LDFLAGS=-L$(ROOT)/stage3-chroot/usr/lib64 \
587         ./configure \
588             --host=riscv64-unknown-linux-gnu \
589             --prefix=/usr --libdir=/usr/lib64 \
590             --disable-static --enable-shared
591         cd popt-$(POPT_VERSION) && PATH=$(ROOT)/fixed-gcc:$$PATH make V=1
592         cd popt-$(POPT_VERSION) && make install DESTDIR=$(ROOT)/stage3-chroot
593         rm -f stage3-chroot/usr/lib64/*.la
594
595 popt-$(POPT_VERSION).tar.gz:
596         rm -f $@ $@-t
597         wget -O $@-t http://rpm5.org/files/popt/popt-$(POPT_VERSION).tar.gz
598         mv $@-t $@
599
600 # Create an /init script.
601 stage3-chroot/init: init.sh
602         install -m 0755 $^ $@
603
604 # Create the stage3 disk image.
605 # Note `-s +...' adds spare space to the disk image.
606 stage3-disk.img: stage3-chroot
607         cd stage3-chroot && virt-make-fs . ../$@ -t ext2 -F raw -s +4G
608
609 # Upload the compressed disk image.
610 upload-stage3: stage3-disk.img.xz
611         scp $^ tick:public_html/riscv/
612 stage3-disk.img.xz: stage3-disk.img
613         rm -f $@
614         xz --best $^
615
616 # Helper which boots stage3 disk image in spike.
617 boot-stage3-in-spike: stage3-disk.img stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
618         spike +disk=stage3-disk.img \
619             /usr/bin/bbl stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
620
621 # Helper which boots stage3 disk image in qemu.
622 boot-stage3-in-qemu: stage3-disk.img stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
623         qemu-system-riscv -kernel /usr/bin/bbl \
624             -append ./stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux \
625             -drive file=stage3-disk.img,format=raw -nographic
626
627 # Stage 4
628
629 stage4:
630         echo "XXX TO DO"
631         exit 1
632
633 .NOTPARALLEL: