Build stage3 kernel from the linux-4.1.y-riscv branch of https://github.com/riscv...
[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_FESVR_COMMIT              = 0f34d7ad311f78455a674224225f5b3056efba1d
11 RISCV_FESVR_SHORTCOMMIT         = 0f34d7ad
12 RISCV_ISA_SIM_COMMIT            = 3bfc00ef2a1b1f0b0472a39a866261b00f67027e
13 RISCV_ISA_SIM_SHORTCOMMIT       = 3bfc00ef
14 RISCV_GNU_TOOLCHAIN_COMMIT      = 728afcddcb0526a0f6560c4032da82805f054d58
15 RISCV_GNU_TOOLCHAIN_SHORTCOMMIT = 728afcdd
16 RISCV_PK_COMMIT                 = 85ae17aa149b9ea114bdd70cc30ea7e73813fb48
17 RISCV_PK_SHORTCOMMIT            = 85ae17aa
18
19 # For the correct versions, see
20 # riscv-gnu-toolchain/Makefile.in *_version variables
21 BINUTILS_VERSION = 2.25.1
22 GLIBC_VERSION    = 2.22
23 GCC_VERSION      = 5.3.0
24 NEWLIB_VERSION   = 2.2.0
25
26 # See linux-4.1.y-riscv branch of
27 # https://github.com/riscv/riscv-linux
28 KERNEL_VERSION   = 4.1.26
29
30 # A local copy of Linux git repo so you don't have to keep downloading
31 # git commits (optional).
32 LOCAL_LINUX_GIT_COPY = $(HOME)/d/linux
33
34 all: stage1 stage2 stage3 stage4
35
36 # Stage 1
37
38 stage1: stage1-riscv-qemu/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz \
39         stage1-riscv-qemu/riscv-qemu.spec \
40         stamp-riscv-qemu-installed \
41         stage1-riscv-fesvr/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz \
42         stage1-riscv-fesvr/riscv-fesvr.spec \
43         stamp-riscv-fesvr-installed \
44         stage1-riscv-isa-sim/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz \
45         stage1-riscv-isa-sim/riscv-isa-sim.spec \
46         stamp-riscv-isa-sim-installed
47
48 stage1-riscv-qemu/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz:
49         rm -f $@ $@-t
50         wget -O $@-t 'https://github.com/riscv/riscv-qemu/archive/$(RISCV_QEMU_COMMIT)/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz'
51         mv $@-t $@
52
53 stage1-riscv-qemu/riscv-qemu.spec: stage1-riscv-qemu/riscv-qemu.spec.in
54         sed -e 's/@COMMIT@/$(RISCV_QEMU_COMMIT)/g' \
55             -e 's/@SHORTCOMMIT@/$(RISCV_QEMU_SHORTCOMMIT)/g' \
56             < $^ > $@-t
57         mv $@-t $@
58
59 stamp-riscv-qemu-installed:
60         rm -f $@
61         @rpm -q riscv-qemu >/dev/null || { \
62           echo "ERROR: You must install riscv-qemu:"; \
63           echo; \
64           echo "       dnf copr enable rjones/riscv"; \
65           echo "       dnf install riscv-qemu"; \
66           echo; \
67           echo "OR: you can build it yourself from the stage1-riscv-qemu directory."; \
68           echo; \
69           exit 1; \
70         }
71         @qemu-system-riscv --version || { \
72           echo "ERROR: qemu-system-riscv is not working."; \
73           echo "Make sure you installed the riscv-qemu package."; \
74           exit 1; \
75         }
76         touch $@
77
78 stage1-riscv-fesvr/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz:
79         rm -f $@ $@-t
80         wget -O $@-t 'https://github.com/riscv/riscv-fesvr/archive/$(RISCV_FESVR_COMMIT)/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz'
81         mv $@-t $@
82
83 stage1-riscv-fesvr/riscv-fesvr.spec: stage1-riscv-fesvr/riscv-fesvr.spec.in
84         sed -e 's/@COMMIT@/$(RISCV_FESVR_COMMIT)/g' \
85             -e 's/@SHORTCOMMIT@/$(RISCV_FESVR_SHORTCOMMIT)/g' \
86             < $^ > $@-t
87         mv $@-t $@
88
89 stamp-riscv-fesvr-installed:
90         rm -f $@
91         @rpm -q riscv-fesvr >/dev/null || { \
92           echo "ERROR: You must install riscv-fesvr:"; \
93           echo; \
94           echo "       dnf copr enable rjones/riscv"; \
95           echo "       dnf install riscv-fesvr"; \
96           echo; \
97           echo "OR: you can build it yourself from the stage1-riscv-fesvr directory."; \
98           echo; \
99           exit 1; \
100         }
101         touch $@
102
103 stage1-riscv-isa-sim/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz:
104         rm -f $@ $@-t
105         wget -O $@-t 'https://github.com/riscv/riscv-isa-sim/archive/$(RISCV_ISA_SIM_COMMIT)/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz'
106         mv $@-t $@
107
108 stage1-riscv-isa-sim/riscv-isa-sim.spec: stage1-riscv-isa-sim/riscv-isa-sim.spec.in
109         sed -e 's/@COMMIT@/$(RISCV_ISA_SIM_COMMIT)/g' \
110             -e 's/@SHORTCOMMIT@/$(RISCV_ISA_SIM_SHORTCOMMIT)/g' \
111             < $^ > $@-t
112         mv $@-t $@
113
114 stamp-riscv-isa-sim-installed:
115         rm -f $@
116         @rpm -q riscv-isa-sim >/dev/null || { \
117           echo "ERROR: You must install riscv-isa-sim:"; \
118           echo; \
119           echo "       dnf copr enable rjones/riscv"; \
120           echo "       dnf install riscv-isa-sim"; \
121           echo; \
122           echo "OR: you can build it yourself from the stage1-riscv-isa-sim directory."; \
123           echo; \
124           exit 1; \
125         }
126         touch $@
127
128 # Stage 2
129
130 stage2: stage2-riscv-gnu-toolchain/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz \
131         stage2-riscv-gnu-toolchain/binutils-$(BINUTILS_VERSION).tar.gz \
132         stage2-riscv-gnu-toolchain/gcc-$(GCC_VERSION).tar.gz \
133         stage2-riscv-gnu-toolchain/glibc-$(GLIBC_VERSION).tar.gz \
134         stage2-riscv-gnu-toolchain/newlib-$(NEWLIB_VERSION).tar.gz \
135         stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec \
136         stamp-riscv-gnu-toolchain-installed \
137         stage2-riscv-pk/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz \
138         stage2-riscv-pk/riscv-pk.spec \
139         stamp-riscv-pk-installed
140
141 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz:
142         rm -f $@ $@-t
143         wget -O $@-t https://github.com/lowRISC/riscv-gnu-toolchain/archive/$(RISCV_GNU_TOOLCHAIN_COMMIT)/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz
144         mv $@-t $@
145
146 stage2-riscv-gnu-toolchain/binutils-$(BINUTILS_VERSION).tar.gz:
147         rm -f $@ $@-t
148         wget -O $@-t http://mirrors.kernel.org/gnu/binutils/binutils-$(BINUTILS_VERSION).tar.gz
149         mv $@-t $@
150
151 # GCC 5 no longer compiles with GCC 6 unless we patch it.
152 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69959
153 stage2-riscv-gnu-toolchain/gcc-$(GCC_VERSION).tar.gz:
154         rm -f $@ $@-t
155         wget -O $@-t http://mirrors.kernel.org/gnu/gcc/gcc-$(GCC_VERSION)/gcc-$(GCC_VERSION).tar.gz
156         zcat $@-t | tar xf -
157         cd gcc-$(GCC_VERSION) && patch -p0 < ../stage2-riscv-gnu-toolchain/gcc-5-fix-compilation-with-gcc-6.patch
158         tar zcf $@-t gcc-$(GCC_VERSION)
159         rm -r gcc-$(GCC_VERSION)
160         mv $@-t $@
161
162 stage2-riscv-gnu-toolchain/glibc-$(GLIBC_VERSION).tar.gz:
163         rm -f $@ $@-t
164         wget -O $@-t http://mirrors.kernel.org/gnu/glibc/glibc-$(GLIBC_VERSION).tar.gz
165         mv $@-t $@
166
167 stage2-riscv-gnu-toolchain/newlib-$(NEWLIB_VERSION).tar.gz:
168         rm -f $@ $@-t
169         wget -O $@-t ftp://sourceware.org/pub/newlib/newlib-$(NEWLIB_VERSION).tar.gz
170         mv $@-t $@
171
172 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec: stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec.in
173         sed -e 's/@COMMIT@/$(RISCV_GNU_TOOLCHAIN_COMMIT)/g' \
174             -e 's/@SHORTCOMMIT@/$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT)/g' \
175             -e 's/@BINUTILS_VERSION@/$(BINUTILS_VERSION)/g' \
176             -e 's/@GCC_VERSION@/$(GCC_VERSION)/g' \
177             -e 's/@GLIBC_VERSION@/$(GLIBC_VERSION)/g' \
178             -e 's/@NEWLIB_VERSION@/$(NEWLIB_VERSION)/g' \
179             < $^ > $@-t
180         mv $@-t $@
181
182 stamp-riscv-gnu-toolchain-installed:
183         rm -f $@
184         @rpm -q riscv-gnu-toolchain >/dev/null || { \
185           echo "ERROR: You must install riscv-gnu-toolchain:"; \
186           echo; \
187           echo "       dnf copr enable rjones/riscv"; \
188           echo "       dnf install riscv-gnu-toolchain"; \
189           echo; \
190           echo "OR: you can build it yourself from the stage2-riscv-gnu-toolchain directory."; \
191           echo; \
192           exit 1; \
193         }
194         @riscv64-unknown-elf-gcc --version || { \
195           echo "ERROR: riscv64-unknown-elf-gcc (cross compiler) is not working."; \
196           echo "Make sure you installed the riscv-gnu-toolchain package."; \
197           exit 1; \
198         }
199         touch $@
200
201 stage2-riscv-pk/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz:
202         rm -f $@ $@-t
203         wget -O $@-t https://github.com/lowRISC/riscv-pk/archive/$(RISCV_PK_COMMIT)/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz
204         mv $@-t $@
205
206 stage2-riscv-pk/riscv-pk.spec: stage2-riscv-pk/riscv-pk.spec.in
207         sed -e 's/@COMMIT@/$(RISCV_PK_COMMIT)/g' \
208             -e 's/@SHORTCOMMIT@/$(RISCV_PK_SHORTCOMMIT)/g' \
209             < $^ > $@-t
210         mv $@-t $@
211
212 stamp-riscv-pk-installed:
213         rm -f $@
214         @rpm -q riscv-pk >/dev/null || { \
215           echo "ERROR: You must install riscv-pk:"; \
216           echo; \
217           echo "       dnf copr enable rjones/riscv"; \
218           echo "       dnf install riscv-pk"; \
219           echo; \
220           echo "OR: you can build it yourself from the stage2-riscv-pk directory."; \
221           echo; \
222           exit 1; \
223         }
224         touch $@
225
226 # Stage 3
227
228 stage3: stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
229
230 stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux:
231         rm -rf stage3-kernel/linux-$(KERNEL_VERSION)
232         cp -a $(LOCAL_LINUX_GIT_COPY) stage3-kernel/linux-$(KERNEL_VERSION) || { \
233           mkdir stage3-kernel/linux-$(KERNEL_VERSION) && \
234           cd stage3-kernel/linux-$(KERNEL_VERSION) && \
235           git init; \
236         }
237         cd stage3-kernel/linux-$(KERNEL_VERSION) && \
238         git remote add riscv https://github.com/riscv/riscv-linux && \
239         git fetch riscv && \
240         git checkout -f linux-4.1.y-riscv && \
241         make mrproper && \
242         make ARCH=riscv defconfig && \
243         make ARCH=riscv CONFIG_CROSS_COMPILE=riscv64-unknown-elf- vmlinux
244         ls -l $@
245
246 # Stage 4
247
248 stage4:
249         echo "XXX TO DO"
250         exit 1
251
252 .NOTPARALLEL: