3 STAMPS = ${TOOLS}/build/.stamps
5 TARGET = riscv64-unknown-linux-musl
9 include ${TOP}/config.mk
15 LINUX_MAJOR != echo ${LINUX_VER} | cut -d. -f1
23 GFORTH_VER = 0.7.9_20240627
30 extra: rvforth oksh mcu # gforth (broken)
32 build: ${STAMPS}/libgcc-install ${STAMPS}/destruct-install
38 rm -rf bin build include lib libexec ${TARGET} share
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
55 $U/download $@ https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VER}.tar.gz
59 $U/download $@ https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VER}/gcc-${GCC_VER}.tar.gz
63 $U/download $@ http://musl.libc.org/releases/musl-${MUSL_VER}.tar.gz
67 $U/download $@ https://mirrors.edge.kernel.org/pub/linux/kernel/v${LINUX_MAJOR}.x/linux-${LINUX_VER}.tar.gz
71 $U/download $@ https://gmplib.org/download/gmp/gmp-${GMP_VER}.tar.gz
75 $U/download $@ https://www.mpfr.org/mpfr-current/mpfr-${MPFR_VER}.tar.gz
79 $U/download $@ https://ftp.gnu.org/gnu/mpc/mpc-${MPC_VER}.tar.gz
83 $U/download $@ https://github.com/ibara/oksh/releases/download/oksh-${OKSH_VER}/oksh-${OKSH_VER}.tar.gz
87 $U/download $@ https://got.stuerz.xyz/download/destruct-${DESTRUCT_VER}.tgz
91 $U/download $@ https://got.stuerz.xyz/download/rvforth-${RVFORTH_VER}.tgz
95 $U/download $@ https://github.com/riscygeek/microcoreutils/archive/refs/tags/v${MCU_VER}.tar.gz
99 $U/download $@ https://www.complang.tuwien.ac.at/forth/gforth/Snapshots/${GFORTH_VER}/gforth-${GFORTH_VER}.tar.xz
103 ${STAMPS}/binutils-extract: src/binutils.tgz
105 rm -rf build/binutils
106 tar -C build -xzf src/binutils.tgz
107 mv build/binutils-* build/binutils
110 ${STAMPS}/gcc-extract: src/gcc.tgz
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
119 ${STAMPS}/musl-extract: src/musl.tgz
122 tar -C build -xzf src/musl.tgz
123 mv build/musl-* build/musl
126 ${STAMPS}/linux-extract: src/linux.tgz
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
134 ${STAMPS}/gmp: src/gmp.tgz
136 tar -C build -xzf src/gmp.tgz
137 mv build/gmp-* build/gmp
140 ${STAMPS}/mpfr: src/mpfr.tgz
142 tar -C build -xzf src/mpfr.tgz
143 mv build/mpfr-* build/mpfr
146 ${STAMPS}/mpc: src/mpc.tgz
148 tar -C build -xzf src/mpc.tgz
149 mv build/mpc-* build/mpc
152 ${STAMPS}/oksh: src/oksh.tgz
154 tar -C build -xzf src/oksh.tgz
155 mv build/oksh-* build/oksh
158 ${STAMPS}/destruct: src/destruct.tgz
160 tar -C build -xzf src/destruct.tgz
161 mv build/destruct-* build/destruct
164 ${STAMPS}/rvforth: src/rvforth.tgz
166 tar -C build -xzf src/rvforth.tgz
167 mv build/rvforth-* build/rvforth
170 ${STAMPS}/mcu: src/mcu.tgz
172 tar -C build -xzf src/mcu.tgz
173 mv build/microcoreutils-* build/mcu
176 ${STAMPS}/gforth: src/gforth.txz
178 xzcat src/gforth.txz | tar -C build -xf -
179 mv build/gforth-* build/gforth
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
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}/
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 \
204 --with-arch=${ARCH} \
211 ${STAMPS}/binutils-build: ${STAMPS}/binutils-configure
212 (cd ${TOOLS}/build/binutils/build && ${GMAKE})
215 ${STAMPS}/binutils-install: ${STAMPS}/binutils-build
216 (cd ${TOOLS}/build/binutils/build && ${SUDO} ${GMAKE} install)
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\"" \
230 --with-arch=${ARCH} \
233 --enable-languages=c \
237 --disable-libsanitizer \
238 --disable-libstdcxx \
240 --disable-libquadmath \
247 ${STAMPS}/gcc-build: ${STAMPS}/gcc-configure
248 (cd ${TOOLS}/build/gcc/build && ${GMAKE} all-gcc)
251 ${STAMPS}/gcc-install: ${STAMPS}/gcc-build
252 (cd ${TOOLS}/build/gcc/build && ${SUDO} ${GMAKE} install-gcc)
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}- \
262 --prefix=${PREFIX}/${TARGET} \
269 ${STAMPS}/musl-build: ${STAMPS}/musl-configure ${STAMPS}/linux-hdrinst
270 (cd ${TOOLS}/build/musl/build && ${GMAKE})
273 ${STAMPS}/musl-install: ${STAMPS}/musl-build
274 (cd ${TOOLS}/build/musl/build && ${SUDO} ${GMAKE} install)
279 ${STAMPS}/libgcc-build: ${STAMPS}/gcc-install ${STAMPS}/musl-install
280 (cd ${TOOLS}/build/gcc/build && ${GMAKE} all-target-libgcc)
283 ${STAMPS}/libgcc-install: ${STAMPS}/libgcc-build
284 (cd ${TOOLS}/build/gcc/build && ${SUDO} ${GMAKE} install-target-libgcc)
289 ${STAMPS}/oksh-configure: ${STAMPS}/oksh ${STAMPS}/gcc-install
290 cd ${TOOLS}/build/oksh && \
291 CFLAGS="-Og -g" ./configure \
293 --cc=${PREFIX}/bin/${TARGET}-gcc \
301 ${STAMPS}/oksh-build: ${STAMPS}/oksh-configure
302 (cd ${TOOLS}/build/oksh && ${MAKE})
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
313 ${STAMPS}/destruct-build: ${STAMPS}/destruct
314 (cd ${TOOLS}/build/destruct && ${MAKE})
317 ${STAMPS}/destruct-install: ${STAMPS}/destruct-build
318 (cd ${TOOLS}/build/destruct && ${MAKE} PREFIX=${TOOLS} install)
322 rm -f bin/destruct ${STAMPS}/destruct*
323 rm -rf build/destruct
325 destruct: ${STAMPS}/destruct-install
329 ${STAMPS}/rvforth-build: ${STAMPS}/rvforth
330 (cd ${TOOLS}/build/rvforth && ${MAKE} CC="${PREFIX}/bin/${TARGET}-gcc")
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)
338 rm -f ${STAMPS}/rvforth*
341 rvforth: ${TOP}/rootfs/bin/rvforth
345 ${STAMPS}/mcu-configure: ${STAMPS}/mcu
346 cd ${TOOLS}/build/mcu && \
347 CC=${PREFIX}/bin/${TARGET}-gcc ./configure \
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)
359 ${STAMPS}/mcu-build: ${STAMPS}/mcu-fix
360 (cd ${TOOLS}/build/mcu && ${MAKE})
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
370 ${STAMPS}/gforth-fix: ${STAMPS}/gforth
371 (cd ${TOOLS}/build/gforth && sed '/^CHECKFLAGS=.*$$/d' configure > configure.new && chmod +x configure.new)
374 ${STAMPS}/gforth-configure: ${STAMPS}/gforth-fix
375 cd ${TOOLS}/build/gforth && \
376 CC=${PREFIX}/bin/${TARGET}-gcc CFLAGS="-O2" ./configure.new \
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 \
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)
410 ${STAMPS}/gforth-build: ${STAMPS}/gforth-configure
411 (cd ${TOOLS}/build/gforth && ${GMAKE})
414 ${TOP}/rootfs/bin/gforth: ${STAMPS}/gforth-build
415 (cd ${TOOLS}/build/gforth && ${GMAKE} DESTDIR=${TOP}/rootfs install)
419 rm -f ${STAMPS}/gforth*
422 gforth: ${TOP}/rootfs/bin/gforth