a66af860a7e87460780f4be71944b66ed9f8a8f0
[fedora-riscv.git] / Makefile
1 # Refer to the README file to understand how Fedora on RISC-V is
2 # bootstrapped.
3
4 # Note these are chosen very specifically to ensure the different
5 # versions work together.  Don't blindly update to the latest
6 # versions.  See also:
7 # https://github.com/riscv/riscv-pk/issues/18#issuecomment-206115996
8 RISCV_QEMU_COMMIT               = 94f5eb73091fb4fe272db3e943f173ecc0f78ffd
9 RISCV_QEMU_SHORTCOMMIT          = 94f5eb73
10 RISCV_GNU_TOOLCHAIN_COMMIT      = 728afcddcb0526a0f6560c4032da82805f054d58
11 RISCV_GNU_TOOLCHAIN_SHORTCOMMIT = 728afcdd
12 RISCV_PK_COMMIT                 = 85ae17aa149b9ea114bdd70cc30ea7e73813fb48
13 RISCV_PK_SHORTCOMMIT            = 85ae17aa
14
15 # For the correct versions, see
16 # riscv-gnu-toolchain/Makefile.in *_version variables
17 BINUTILS_VERSION = 2.25.1
18 GLIBC_VERSION    = 2.22
19 GCC_VERSION      = 5.3.0
20 NEWLIB_VERSION   = 2.2.0
21
22 all: stage1 stage2 stage3 stage4
23
24 # Stage 1
25
26 stage1: stage1-riscv-qemu/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz \
27         stage1-riscv-qemu/riscv-qemu.spec \
28         stamp-riscv-qemu-installed
29
30 stage1-riscv-qemu/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz:
31         rm -f $@ $@-t
32         wget -O $@-t 'https://github.com/riscv/riscv-qemu/archive/$(RISCV_QEMU_COMMIT)/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz'
33         mv $@-t $@
34
35 stage1-riscv-qemu/riscv-qemu.spec: stage1-riscv-qemu/riscv-qemu.spec.in
36         sed -e 's/@COMMIT@/$(RISCV_QEMU_COMMIT)/g' \
37             -e 's/@SHORTCOMMIT@/$(RISCV_QEMU_SHORTCOMMIT)/g' \
38             < $^ > $@-t
39         mv $@-t $@
40
41 stamp-riscv-qemu-installed:
42         rm -f $@
43         @rpm -q riscv-qemu >/dev/null || { \
44           echo "ERROR: You must install riscv-qemu:"; \
45           echo; \
46           echo "       dnf copr enable rjones/riscv"; \
47           echo "       dnf install riscv-qemu"; \
48           echo; \
49           echo "OR: you can build it yourself from the stage1-riscv-qemu directory."; \
50           echo; \
51           exit 1; \
52         }
53         @qemu-system-riscv --version || { \
54           echo "ERROR: qemu-system-riscv is not working."; \
55           echo "Make sure you installed the riscv-qemu package."; \
56           exit 1; \
57         }
58         touch $@
59
60 # Stage 2
61
62 stage2: stage2-riscv-gnu-toolchain/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz \
63         stage2-riscv-gnu-toolchain/binutils-$(BINUTILS_VERSION).tar.gz \
64         stage2-riscv-gnu-toolchain/gcc-$(GCC_VERSION).tar.gz \
65         stage2-riscv-gnu-toolchain/glibc-$(GLIBC_VERSION).tar.gz \
66         stage2-riscv-gnu-toolchain/newlib-$(NEWLIB_VERSION).tar.gz \
67         stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec \
68         stamp-riscv-gnu-toolchain-installed \
69         stage2-riscv-pk/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz \
70         stage2-riscv-pk/riscv-pk.spec \
71         stamp-riscv-pk-installed
72
73 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz:
74         rm -f $@ $@-t
75         wget -O $@-t https://github.com/lowRISC/riscv-gnu-toolchain/archive/$(RISCV_GNU_TOOLCHAIN_COMMIT)/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz
76         mv $@-t $@
77
78 stage2-riscv-gnu-toolchain/binutils-$(BINUTILS_VERSION).tar.gz:
79         rm -f $@ $@-t
80         wget -O $@-t http://mirrors.kernel.org/gnu/binutils/binutils-$(BINUTILS_VERSION).tar.gz
81         mv $@-t $@
82
83 # GCC 5 no longer compiles with GCC 6 unless we patch it.
84 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69959
85 stage2-riscv-gnu-toolchain/gcc-$(GCC_VERSION).tar.gz:
86         rm -f $@ $@-t
87         wget -O $@-t http://mirrors.kernel.org/gnu/gcc/gcc-$(GCC_VERSION)/gcc-$(GCC_VERSION).tar.gz
88         zcat $@-t | tar xf -
89         cd gcc-$(GCC_VERSION) && patch -p0 < ../stage2-riscv-gnu-toolchain/gcc-5-fix-compilation-with-gcc-6.patch
90         tar zcf $@-t gcc-$(GCC_VERSION)
91         rm -r gcc-$(GCC_VERSION)
92         mv $@-t $@
93
94 stage2-riscv-gnu-toolchain/glibc-$(GLIBC_VERSION).tar.gz:
95         rm -f $@ $@-t
96         wget -O $@-t http://mirrors.kernel.org/gnu/glibc/glibc-$(GLIBC_VERSION).tar.gz
97         mv $@-t $@
98
99 stage2-riscv-gnu-toolchain/newlib-$(NEWLIB_VERSION).tar.gz:
100         rm -f $@ $@-t
101         wget -O $@-t ftp://sourceware.org/pub/newlib/newlib-$(NEWLIB_VERSION).tar.gz
102         mv $@-t $@
103
104 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec: stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec.in
105         sed -e 's/@COMMIT@/$(RISCV_GNU_TOOLCHAIN_COMMIT)/g' \
106             -e 's/@SHORTCOMMIT@/$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT)/g' \
107             -e 's/@BINUTILS_VERSION@/$(BINUTILS_VERSION)/g' \
108             -e 's/@GCC_VERSION@/$(GCC_VERSION)/g' \
109             -e 's/@GLIBC_VERSION@/$(GLIBC_VERSION)/g' \
110             -e 's/@NEWLIB_VERSION@/$(NEWLIB_VERSION)/g' \
111             < $^ > $@-t
112         mv $@-t $@
113
114 stamp-riscv-gnu-toolchain-installed:
115         rm -f $@
116         @rpm -q riscv-gnu-toolchain >/dev/null || { \
117           echo "ERROR: You must install riscv-gnu-toolchain:"; \
118           echo; \
119           echo "       dnf copr enable rjones/riscv"; \
120           echo "       dnf install riscv-gnu-toolchain"; \
121           echo; \
122           echo "OR: you can build it yourself from the stage2-riscv-gnu-toolchain directory."; \
123           echo; \
124           exit 1; \
125         }
126         @riscv64-unknown-elf-gcc --version || { \
127           echo "ERROR: riscv64-unknown-elf-gcc (cross compiler) is not working."; \
128           echo "Make sure you installed the riscv-gnu-toolchain package."; \
129           exit 1; \
130         }
131         touch $@
132
133 stage2-riscv-pk/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz:
134         rm -f $@ $@-t
135         wget -O $@-t https://github.com/lowRISC/riscv-pk/archive/$(RISCV_PK_COMMIT)/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz
136         mv $@-t $@
137
138 stage2-riscv-pk/riscv-pk.spec: stage2-riscv-pk/riscv-pk.spec.in
139         sed -e 's/@COMMIT@/$(RISCV_PK_COMMIT)/g' \
140             -e 's/@SHORTCOMMIT@/$(RISCV_PK_SHORTCOMMIT)/g' \
141             < $^ > $@-t
142         mv $@-t $@
143
144 stamp-riscv-pk-installed:
145         rm -f $@
146         @rpm -q riscv-pk >/dev/null || { \
147           echo "ERROR: You must install riscv-pk:"; \
148           echo; \
149           echo "       dnf copr enable rjones/riscv"; \
150           echo "       dnf install riscv-pk"; \
151           echo; \
152           echo "OR: you can build it yourself from the stage2-riscv-pk directory."; \
153           echo; \
154           exit 1; \
155         }
156         touch $@
157
158 # Stage 3
159
160 stage3: stage3-kernel/linux-4.6.2.tar.xz \
161         stage3-kernel/linux-4.6.2/vmlinux
162
163 stage3-kernel/linux-4.6.2.tar.xz:
164         rm -f $@ $@-t
165         wget -O $@-t https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.6.2.tar.xz
166         mv $@-t $@
167
168 stage3-kernel/linux-4.6.2/vmlinux:
169         rm -rf stage3-kernel/linux-4.6.2
170         cat stage3-kernel/linux-4.6.2.tar.xz | tar -x --xz -C stage3-kernel
171         cd stage3-kernel/linux-4.6.2 && \
172         git init
173         cd stage3-kernel/linux-4.6.2 && \
174         git remote add origin https://github.com/lowrisc/riscv-linux.git
175         cd stage3-kernel/linux-4.6.2 && \
176         git fetch
177         cd stage3-kernel/linux-4.6.2 && \
178         git checkout -f -t origin/debug-v0.3
179         cd stage3-kernel/linux-4.6.2 && \
180         patch -p1 < spi_sd_power_hack.patch
181         cd stage3-kernel/linux-4.6.2 && \
182         make ARCH=riscv defconfig
183         cd stage3-kernel/linux-4.6.2 && \
184         make ARCH=riscv CONFIG_CROSS_COMPILE=riscv64-unknown-elf- vmlinux
185         ls -l $@
186
187 # Stage 4
188
189 stage4:
190         echo "XXX TO DO"
191         exit 1
192
193 .NOTPARALLEL: