Blob


1 TOOLS != pwd
2 TOP = ${TOOLS}/..
3 STAMPS = ${TOOLS}/build/.stamps
4 PREFIX = ${TOOLS}
5 TARGET = riscv64-unknown-linux-musl
6 ARCH = rv64ima
7 U = ${TOOLS}/util
9 include ${TOP}/config.mk
11 BINUTILS_VER = 2.42
12 GCC_VER = 13.2.0
13 MUSL_VER = 1.2.4
14 LINUX_VER = 6.6.17
15 LINUX_MAJOR != echo ${LINUX_VER} | cut -d. -f1
16 GMP_VER = 6.3.0
17 MPFR_VER = 4.2.1
18 MPC_VER = 1.3.1
19 OKSH_VER = 7.5
20 DESTRUCT_VER = 0.2
21 RVFORTH_VER = 0.1
22 MCU_VER = 1.2
23 GFORTH_VER = 0.7.9_20240627
25 GMAKE = $U/gmake
26 SUDO =
28 all: build
30 extra: rvforth oksh mcu # gforth (broken)
32 build: ${STAMPS}/libgcc-install ${STAMPS}/destruct-install
34 distclean: clean
35 rm -rf src
37 clean:
38 rm -rf bin build include lib libexec ${TARGET} share
40 test:
41 ${PREFIX}/bin/${TARGET}-gcc -o /dev/null $U/test.c
43 download: src/binutils.tgz src/gcc.tgz src/musl.tgz src/linux.tgz src/gmp.tgz src/mpfr.tgz src/mpc.tgz src/oksh.tgz src/destruct.tgz src/rvforth.tgz src/mcu.tgz src/gforth.txz
44 extract: ${STAMPS}/binutils-extract ${STAMPS}/gcc-extract ${STAMPS}/musl-extract ${STAMPS}/linux-extract ${STAMPS}/gmp ${STAMPS}/mpfr ${STAMPS}/mpc ${STAMPS}/oksh ${STAMPS}/destruct ${STAMPS}/rvforth ${STAMPS}/mcu ${STAMPS}/gforth
46 headers: ${STAMPS}/linux-headers
47 install-headers: ${STAMPS}/linux-hdrinst
48 binutils: ${STAMPS}/binutils-build
49 install-binutils: ${STAMPS}/binutils-install
51 # DOWNLOAD
53 src/binutils.tgz:
54 mkdir -p src
55 $U/download $@ https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VER}.tar.gz
57 src/gcc.tgz:
58 mkdir -p src
59 $U/download $@ https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VER}/gcc-${GCC_VER}.tar.gz
61 src/musl.tgz:
62 mkdir -p src
63 $U/download $@ http://musl.libc.org/releases/musl-${MUSL_VER}.tar.gz
65 src/linux.tgz:
66 mkdir -p src
67 $U/download $@ https://mirrors.edge.kernel.org/pub/linux/kernel/v${LINUX_MAJOR}.x/linux-${LINUX_VER}.tar.gz
69 src/gmp.tgz:
70 mkdir -p src
71 $U/download $@ https://gmplib.org/download/gmp/gmp-${GMP_VER}.tar.gz
73 src/mpfr.tgz:
74 mkdir -p src
75 $U/download $@ https://www.mpfr.org/mpfr-current/mpfr-${MPFR_VER}.tar.gz
77 src/mpc.tgz:
78 mkdir -p src
79 $U/download $@ https://ftp.gnu.org/gnu/mpc/mpc-${MPC_VER}.tar.gz
81 src/oksh.tgz:
82 mkdir -p src
83 $U/download $@ https://github.com/ibara/oksh/releases/download/oksh-${OKSH_VER}/oksh-${OKSH_VER}.tar.gz
85 src/destruct.tgz:
86 mkdir -p src
87 $U/download $@ https://got.stuerz.xyz/download/destruct-${DESTRUCT_VER}.tgz
89 src/rvforth.tgz:
90 mkdir -p src
91 $U/download $@ https://got.stuerz.xyz/download/rvforth-${RVFORTH_VER}.tgz
93 src/mcu.tgz:
94 mkdir -p src
95 $U/download $@ https://github.com/riscygeek/microcoreutils/archive/refs/tags/v${MCU_VER}.tar.gz
97 src/gforth.txz:
98 mkdir -p src
99 $U/download $@ https://www.complang.tuwien.ac.at/forth/gforth/Snapshots/${GFORTH_VER}/gforth-${GFORTH_VER}.tar.xz
101 # EXTRACT
103 ${STAMPS}/binutils-extract: src/binutils.tgz
104 mkdir -p ${STAMPS}
105 rm -rf build/binutils
106 tar -C build -xzf src/binutils.tgz
107 mv build/binutils-* build/binutils
108 touch $@
110 ${STAMPS}/gcc-extract: src/gcc.tgz
111 mkdir -p ${STAMPS}
112 rm -rf build/gcc
113 tar -C build -xzf src/gcc.tgz
114 mv build/gcc-* build/gcc
115 cd build/gcc && ln -sf ../gmp ../mpfr ../mpc .
116 $U/fix-gcc ${TOOLS}/build/gcc
117 touch $@
119 ${STAMPS}/musl-extract: src/musl.tgz
120 mkdir -p ${STAMPS}
121 rm -rf build/musl
122 tar -C build -xzf src/musl.tgz
123 mv build/musl-* build/musl
124 touch $@
126 ${STAMPS}/linux-extract: src/linux.tgz
127 mkdir -p ${STAMPS}
128 rm -rf build/linux
129 tar -C build -xzf src/linux.tgz
130 mv build/linux-* build/linux
131 $U/fix-headers ${TOOLS}/build/linux/scripts/headers_install.sh
132 touch $@
134 ${STAMPS}/gmp: src/gmp.tgz
135 mkdir -p ${STAMPS}
136 tar -C build -xzf src/gmp.tgz
137 mv build/gmp-* build/gmp
138 touch $@
140 ${STAMPS}/mpfr: src/mpfr.tgz
141 mkdir -p ${STAMPS}
142 tar -C build -xzf src/mpfr.tgz
143 mv build/mpfr-* build/mpfr
144 touch $@
146 ${STAMPS}/mpc: src/mpc.tgz
147 mkdir -p ${STAMPS}
148 tar -C build -xzf src/mpc.tgz
149 mv build/mpc-* build/mpc
150 touch $@
152 ${STAMPS}/oksh: src/oksh.tgz
153 mkdir -p ${STAMPS}
154 tar -C build -xzf src/oksh.tgz
155 mv build/oksh-* build/oksh
156 touch $@
158 ${STAMPS}/destruct: src/destruct.tgz
159 mkdir -p ${STAMPS}
160 tar -C build -xzf src/destruct.tgz
161 mv build/destruct-* build/destruct
162 touch $@
164 ${STAMPS}/rvforth: src/rvforth.tgz
165 mkdir -p ${STAMPS}
166 tar -C build -xzf src/rvforth.tgz
167 mv build/rvforth-* build/rvforth
168 touch $@
170 ${STAMPS}/mcu: src/mcu.tgz
171 mkdir -p ${STAMPS}
172 tar -C build -xzf src/mcu.tgz
173 mv build/microcoreutils-* build/mcu
174 touch $@
176 ${STAMPS}/gforth: src/gforth.txz
177 mkdir -p ${STAMPS}
178 xzcat src/gforth.txz | tar -C build -xf -
179 mv build/gforth-* build/gforth
180 touch $@
182 # KERNEL HEADERS
184 ${STAMPS}/linux-headers: ${STAMPS}/linux-extract
185 (cd ${TOOLS}/build/linux && ${GMAKE} ARCH=riscv HOSTCC="${CC}" headers)
186 rm -f ${TOOLS}/build/linux/usr/include/Makefile
187 rm -f ${TOOLS}/build/linux/usr/include/headers_check.pl
188 touch $@
190 ${STAMPS}/linux-hdrinst: ${STAMPS}/linux-headers
191 mkdir -p ${PREFIX}/${TARGET}
192 cd ${TOOLS}/build/linux && ${SUDO} cp -rf ${TOOLS}/build/linux/usr/include ${PREFIX}/${TARGET}/
193 touch $@
195 # BINUTILS
197 ${STAMPS}/binutils-configure: ${STAMPS}/binutils-extract
198 mkdir -p ${TOOLS}/build/binutils/build
199 cd ${TOOLS}/build/binutils/build \
200 && CC="${CC}" CXX="${CXX}" ../configure \
201 --prefix=${PREFIX} \
202 --target=${TARGET} \
203 --with-system-zlib \
204 --with-arch=${ARCH} \
205 --without-zstd \
206 --disable-nls \
207 --disable-werror \
208 --disable-multilib
209 touch $@
211 ${STAMPS}/binutils-build: ${STAMPS}/binutils-configure
212 (cd ${TOOLS}/build/binutils/build && ${GMAKE})
213 touch $@
215 ${STAMPS}/binutils-install: ${STAMPS}/binutils-build
216 (cd ${TOOLS}/build/binutils/build && ${SUDO} ${GMAKE} install)
217 touch $@
219 # GCC
221 ${STAMPS}/gcc-configure: ${STAMPS}/gcc-extract ${STAMPS}/binutils-install ${STAMPS}/gmp ${STAMPS}/mpfr ${STAMPS}/mpc
222 mkdir -p ${TOOLS}/build/gcc/build
223 cd ${TOOLS}/build/gcc/build \
224 && CC="${CC}" CXX="${CXX}" \
225 CXXFLAGS="${CXXFLAGS} -Dvec_step=\"xvec_step\"" \
226 ../configure \
227 --prefix=${PREFIX} \
228 --target=${TARGET} \
229 --with-system-zlib \
230 --with-arch=${ARCH} \
231 --with-newlib \
232 --without-headers \
233 --enable-languages=c \
234 --disable-nls \
235 --disable-multilib \
236 --disable-libssp \
237 --disable-libsanitizer \
238 --disable-libstdcxx \
239 --disable-libgomp \
240 --disable-libquadmath \
241 --disable-libvtv \
242 --disable-shared \
243 --enable-static \
244 --disable-threads
245 touch $@
247 ${STAMPS}/gcc-build: ${STAMPS}/gcc-configure
248 (cd ${TOOLS}/build/gcc/build && ${GMAKE} all-gcc)
249 touch $@
251 ${STAMPS}/gcc-install: ${STAMPS}/gcc-build
252 (cd ${TOOLS}/build/gcc/build && ${SUDO} ${GMAKE} install-gcc)
253 touch $@
255 # MUSL
257 ${STAMPS}/musl-configure: ${STAMPS}/musl-extract ${STAMPS}/gcc-install
258 mkdir -p ${TOOLS}/build/musl/build
259 cd ${TOOLS}/build/musl/build && \
260 CROSS_COMPILE=${PREFIX}/bin/${TARGET}- \
261 ../configure \
262 --prefix=${PREFIX}/${TARGET} \
263 --target=${TARGET} \
264 --disable-shared \
265 --disable-wrapper \
266 --enable-static
267 touch $@
269 ${STAMPS}/musl-build: ${STAMPS}/musl-configure ${STAMPS}/linux-hdrinst
270 (cd ${TOOLS}/build/musl/build && ${GMAKE})
271 touch $@
273 ${STAMPS}/musl-install: ${STAMPS}/musl-build
274 (cd ${TOOLS}/build/musl/build && ${SUDO} ${GMAKE} install)
275 touch $@
277 # LIBGCC
279 ${STAMPS}/libgcc-build: ${STAMPS}/gcc-install ${STAMPS}/musl-install
280 (cd ${TOOLS}/build/gcc/build && ${GMAKE} all-target-libgcc)
281 touch $@
283 ${STAMPS}/libgcc-install: ${STAMPS}/libgcc-build
284 (cd ${TOOLS}/build/gcc/build && ${SUDO} ${GMAKE} install-target-libgcc)
285 touch $@
287 # OKSH
289 ${STAMPS}/oksh-configure: ${STAMPS}/oksh ${STAMPS}/gcc-install
290 cd ${TOOLS}/build/oksh && \
291 CFLAGS="-Og -g" ./configure \
292 --prefix=/ \
293 --cc=${PREFIX}/bin/${TARGET}-gcc \
294 --enable-sh \
295 --enable-ksh \
296 --enable-static \
297 --disable-curses \
298 --no-thanks
299 touch $@
301 ${STAMPS}/oksh-build: ${STAMPS}/oksh-configure
302 (cd ${TOOLS}/build/oksh && ${MAKE})
303 touch $@
305 ${TOP}/rootfs/bin/ksh: ${STAMPS}/oksh-build
306 mkdir -p ${TOP}/rootfs
307 (cd ${TOOLS}/build/oksh && ${MAKE} DESTDIR=${TOP}/rootfs install)
309 oksh: ${TOP}/rootfs/bin/ksh
311 # DESTRUCT
313 ${STAMPS}/destruct-build: ${STAMPS}/destruct
314 (cd ${TOOLS}/build/destruct && ${MAKE})
315 touch $@
317 ${STAMPS}/destruct-install: ${STAMPS}/destruct-build
318 (cd ${TOOLS}/build/destruct && ${MAKE} PREFIX=${TOOLS} install)
319 touch $@
321 clean-destruct:
322 rm -f bin/destruct ${STAMPS}/destruct*
323 rm -rf build/destruct
325 destruct: ${STAMPS}/destruct-install
327 # RVFORTH
329 ${STAMPS}/rvforth-build: ${STAMPS}/rvforth
330 (cd ${TOOLS}/build/rvforth && ${MAKE} CC="${PREFIX}/bin/${TARGET}-gcc")
331 touch $@
333 ${TOP}/rootfs/bin/rvforth: ${STAMPS}/rvforth-build
334 mkdir -p ${TOP}/rootfs/bin
335 (cd ${TOOLS}/build/rvforth && ${MAKE} PREFIX=/ DESTDIR=${TOP}/rootfs install)
337 clean-rvforth:
338 rm -f ${STAMPS}/rvforth*
339 rm -rf build/rvforth
341 rvforth: ${TOP}/rootfs/bin/rvforth
343 # MICROCOREUTILS
345 ${STAMPS}/mcu-configure: ${STAMPS}/mcu
346 cd ${TOOLS}/build/mcu && \
347 CC=${PREFIX}/bin/${TARGET}-gcc ./configure \
348 --prefix=/mcu \
349 --host=${TARGET} \
350 --enable-extra-progs
351 touch $@
353 ${STAMPS}/mcu-fix: ${STAMPS}/mcu-configure
354 (cd ${TOOLS}/build/mcu && \
355 sed '/^#define malloc/d; /^#define realloc/d' config.h > config.h.new && \
356 mv config.h.new config.h)
357 touch $@
359 ${STAMPS}/mcu-build: ${STAMPS}/mcu-fix
360 (cd ${TOOLS}/build/mcu && ${MAKE})
361 touch $@
363 ${TOP}/rootfs/mcu/bin/ls: ${STAMPS}/mcu-build
364 (cd ${TOOLS}/build/mcu && ${MAKE} DESTDIR=${TOP}/rootfs install)
366 mcu: ${TOP}/rootfs/mcu/bin/ls
368 # GFORTH
370 ${STAMPS}/gforth-fix: ${STAMPS}/gforth
371 (cd ${TOOLS}/build/gforth && sed '/^CHECKFLAGS=.*$$/d' configure > configure.new && chmod +x configure.new)
372 touch $@
374 ${STAMPS}/gforth-configure: ${STAMPS}/gforth-fix
375 cd ${TOOLS}/build/gforth && \
376 CC=${PREFIX}/bin/${TARGET}-gcc CFLAGS="-O2" ./configure.new \
377 --prefix=/ \
378 --with-arch=riscv \
379 --without-check \
380 --host=${TARGET} \
381 --enable-static \
382 --disable-shared \
383 --disable-version \
384 --disable-lib \
385 --without-pic \
386 ac_cv_sizeof_void_p=8 \
387 ac_cv_sizeof_char_p=8 \
388 ac_cv_sizeof_char=1 \
389 ac_cv_sizeof_short=2 \
390 ac_cv_sizeof_int=4 \
391 ac_cv_sizeof_long=8 \
392 ac_cv_sizeof_long_long=8 \
393 ac_cv_sizeof_intptr_t=8 \
394 ac_cv_sizeof___int128_t=16 \
395 ac_cv_sizeof___uint128_t=16 \
396 ac_cv_sizeof_off_t=8 \
397 ac_cv_c_bigendian=no \
398 ac_cv_func_memcmp_working=yes \
399 ac_cv_func_memmove=yes \
400 ac_cv_func_getpagesize=yes \
401 ac_cv_func_wcwidth=yes \
402 ac_cv_func_mcheck=no \
403 ac_cv_func_dlopen=no \
404 ac_cv_export_dynamic=no
405 (cd ${TOOLS}/build/gforth && \
406 sed 's@\(DITCENGINE\) = \(.*$$\)@\1 = ${TOP}/linurv \2@' Makefile > Makefile.new && \
407 mv Makefile.new Makefile)
408 touch $@
410 ${STAMPS}/gforth-build: ${STAMPS}/gforth-configure
411 (cd ${TOOLS}/build/gforth && ${GMAKE})
412 touch $@
414 ${TOP}/rootfs/bin/gforth: ${STAMPS}/gforth-build
415 (cd ${TOOLS}/build/gforth && ${GMAKE} DESTDIR=${TOP}/rootfs install)
416 touch $@
418 clean-gforth:
419 rm -f ${STAMPS}/gforth*
420 rm -rf build/gforth
422 gforth: ${TOP}/rootfs/bin/gforth