041dfbca8423dfd717470b66e6985174eefa6092
[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 stage2-riscv-gnu-toolchain/gcc-$(GCC_VERSION).tar.gz:
84         rm -f $@ $@-t
85         wget -O $@-t http://mirrors.kernel.org/gnu/gcc/gcc-$(GCC_VERSION)/gcc-$(GCC_VERSION).tar.gz
86         mv $@-t $@
87
88 stage2-riscv-gnu-toolchain/glibc-$(GLIBC_VERSION).tar.gz:
89         rm -f $@ $@-t
90         wget -O $@-t http://mirrors.kernel.org/gnu/glibc/glibc-$(GLIBC_VERSION).tar.gz
91         mv $@-t $@
92
93 stage2-riscv-gnu-toolchain/newlib-$(NEWLIB_VERSION).tar.gz:
94         rm -f $@ $@-t
95         wget -O $@-t ftp://sourceware.org/pub/newlib/newlib-$(NEWLIB_VERSION).tar.gz
96         mv $@-t $@
97
98 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec: stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec.in
99         sed -e 's/@COMMIT@/$(RISCV_GNU_TOOLCHAIN_COMMIT)/g' \
100             -e 's/@SHORTCOMMIT@/$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT)/g' \
101             -e 's/@BINUTILS_VERSION@/$(BINUTILS_VERSION)/g' \
102             -e 's/@GCC_VERSION@/$(GCC_VERSION)/g' \
103             -e 's/@GLIBC_VERSION@/$(GLIBC_VERSION)/g' \
104             -e 's/@NEWLIB_VERSION@/$(NEWLIB_VERSION)/g' \
105             < $^ > $@-t
106         mv $@-t $@
107
108 stamp-riscv-gnu-toolchain-installed:
109         rm -f $@
110         @rpm -q riscv-gnu-toolchain >/dev/null || { \
111           echo "ERROR: You must install riscv-gnu-toolchain:"; \
112           echo; \
113           echo "       dnf copr enable rjones/riscv"; \
114           echo "       dnf install riscv-gnu-toolchain"; \
115           echo; \
116           echo "OR: you can build it yourself from the stage2-riscv-gnu-toolchain directory."; \
117           echo; \
118           exit 1; \
119         }
120         @riscv64-unknown-elf-gcc --version || { \
121           echo "ERROR: riscv64-unknown-elf-gcc (cross compiler) is not working."; \
122           echo "Make sure you installed the riscv-gnu-toolchain package."; \
123           exit 1; \
124         }
125         touch $@
126
127 stage2-riscv-pk/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz:
128         rm -f $@ $@-t
129         wget -O $@-t https://github.com/lowRISC/riscv-pk/archive/$(RISCV_PK_COMMIT)/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz
130         mv $@-t $@
131
132 stage2-riscv-pk/riscv-pk.spec: stage2-riscv-pk/riscv-pk.spec.in
133         sed -e 's/@COMMIT@/$(RISCV_PK_COMMIT)/g' \
134             -e 's/@SHORTCOMMIT@/$(RISCV_PK_SHORTCOMMIT)/g' \
135             < $^ > $@-t
136         mv $@-t $@
137
138 stamp-riscv-pk-installed:
139         rm -f $@
140         @rpm -q riscv-pk >/dev/null || { \
141           echo "ERROR: You must install riscv-pk:"; \
142           echo; \
143           echo "       dnf copr enable rjones/riscv"; \
144           echo "       dnf install riscv-pk"; \
145           echo; \
146           echo "OR: you can build it yourself from the stage2-riscv-pk directory."; \
147           echo; \
148           exit 1; \
149         }
150         touch $@
151
152 # Stage 3
153
154 stage3: stage3-kernel/linux-4.6.2.tar.xz \
155         stage3-kernel/linux-4.6.2/vmlinux
156
157 stage3-kernel/linux-4.6.2.tar.xz:
158         rm -f $@ $@-t
159         wget -O $@-t https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.6.2.tar.xz
160         mv $@-t $@
161
162 stage3-kernel/linux-4.6.2/vmlinux:
163         rm -rf stage3-kernel/linux-4.6.2
164         cat stage3-kernel/linux-4.6.2.tar.xz | tar -x --xz -C stage3-kernel
165         cd stage3-kernel/linux-4.6.2 && \
166         git init
167         cd stage3-kernel/linux-4.6.2 && \
168         git remote add origin https://github.com/lowrisc/riscv-linux.git
169         cd stage3-kernel/linux-4.6.2 && \
170         git fetch
171         cd stage3-kernel/linux-4.6.2 && \
172         git checkout -f -t origin/debug-v0.3
173         cd stage3-kernel/linux-4.6.2 && \
174         patch -p1 < spi_sd_power_hack.patch
175         cd stage3-kernel/linux-4.6.2 && \
176         make ARCH=riscv defconfig
177         cd stage3-kernel/linux-4.6.2 && \
178         make ARCH=riscv CONFIG_CROSS_COMPILE=riscv64-unknown-elf- vmlinux
179         ls -l $@
180
181 # Stage 4
182
183 stage4:
184         echo "XXX TO DO"
185         exit 1
186
187 .NOTPARALLEL: