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
26 BBFLAGS = HOSTCC="${CC}" HOSTCXX="${CXX}" CROSS_COMPILE="${PREFIX}/bin/${TARGET}-" CONFIG_PREFIX="${TOP}/rootfs/bb"
33 extra: rvforth oksh mcu busybox # gforth (broken)
35 build: ${STAMPS}/libgcc-install ${STAMPS}/destruct-install
41 rm -rf bin build include lib libexec ${TARGET} share
44 ${PREFIX}/bin/${TARGET}-gcc -o /dev/null $U/test.c
46 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 src/busybox.tar.bz2
47 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 ${STAMPS}/busybox
49 headers: ${STAMPS}/linux-headers
50 install-headers: ${STAMPS}/linux-hdrinst
51 binutils: ${STAMPS}/binutils-build
52 install-binutils: ${STAMPS}/binutils-install
58 $U/download $@ https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VER}.tar.gz
62 $U/download $@ https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VER}/gcc-${GCC_VER}.tar.gz
66 $U/download $@ http://musl.libc.org/releases/musl-${MUSL_VER}.tar.gz
70 $U/download $@ https://mirrors.edge.kernel.org/pub/linux/kernel/v${LINUX_MAJOR}.x/linux-${LINUX_VER}.tar.gz
74 $U/download $@ https://gmplib.org/download/gmp/gmp-${GMP_VER}.tar.gz
78 $U/download $@ https://www.mpfr.org/mpfr-current/mpfr-${MPFR_VER}.tar.gz
82 $U/download $@ https://ftp.gnu.org/gnu/mpc/mpc-${MPC_VER}.tar.gz
86 $U/download $@ https://github.com/ibara/oksh/releases/download/oksh-${OKSH_VER}/oksh-${OKSH_VER}.tar.gz
90 $U/download $@ https://got.stuerz.xyz/download/destruct-${DESTRUCT_VER}.tgz
94 $U/download $@ https://got.stuerz.xyz/download/rvforth-${RVFORTH_VER}.tgz
98 $U/download $@ https://github.com/riscygeek/microcoreutils/archive/refs/tags/v${MCU_VER}.tar.gz
102 $U/download $@ https://www.complang.tuwien.ac.at/forth/gforth/Snapshots/${GFORTH_VER}/gforth-${GFORTH_VER}.tar.xz
106 $U/download $@ https://busybox.net/downloads/busybox-${BUSYBOX_VER}.tar.bz2
110 ${STAMPS}/binutils-extract: src/binutils.tgz
112 rm -rf build/binutils
113 tar -C build -xzf src/binutils.tgz
114 mv build/binutils-* build/binutils
117 ${STAMPS}/gcc-extract: src/gcc.tgz
120 tar -C build -xzf src/gcc.tgz
121 mv build/gcc-* build/gcc
122 cd build/gcc && ln -sf ../gmp ../mpfr ../mpc .
123 $U/fix-gcc ${TOOLS}/build/gcc
126 ${STAMPS}/musl-extract: src/musl.tgz
129 tar -C build -xzf src/musl.tgz
130 mv build/musl-* build/musl
133 ${STAMPS}/linux-extract: src/linux.tgz
136 tar -C build -xzf src/linux.tgz
137 mv build/linux-* build/linux
138 $U/fix-headers ${TOOLS}/build/linux/scripts/headers_install.sh
141 ${STAMPS}/gmp: src/gmp.tgz
143 tar -C build -xzf src/gmp.tgz
144 mv build/gmp-* build/gmp
147 ${STAMPS}/mpfr: src/mpfr.tgz
149 tar -C build -xzf src/mpfr.tgz
150 mv build/mpfr-* build/mpfr
153 ${STAMPS}/mpc: src/mpc.tgz
155 tar -C build -xzf src/mpc.tgz
156 mv build/mpc-* build/mpc
159 ${STAMPS}/oksh: src/oksh.tgz
161 tar -C build -xzf src/oksh.tgz
162 mv build/oksh-* build/oksh
165 ${STAMPS}/destruct: src/destruct.tgz
167 tar -C build -xzf src/destruct.tgz
168 mv build/destruct-* build/destruct
171 ${STAMPS}/rvforth: src/rvforth.tgz
173 tar -C build -xzf src/rvforth.tgz
174 mv build/rvforth-* build/rvforth
177 ${STAMPS}/mcu: src/mcu.tgz
179 tar -C build -xzf src/mcu.tgz
180 mv build/microcoreutils-* build/mcu
183 ${STAMPS}/gforth: src/gforth.txz
185 xzcat src/gforth.txz | tar -C build -xf -
186 mv build/gforth-* build/gforth
189 ${STAMPS}/busybox: src/busybox.tar.bz2
191 tar -C build -xjf src/busybox.tar.bz2
192 mv build/busybox-* build/busybox
197 ${STAMPS}/linux-headers: ${STAMPS}/linux-extract
198 (cd ${TOOLS}/build/linux && ${GMAKE} ARCH=riscv HOSTCC="${CC}" headers)
199 rm -f ${TOOLS}/build/linux/usr/include/Makefile
200 rm -f ${TOOLS}/build/linux/usr/include/headers_check.pl
203 ${STAMPS}/linux-hdrinst: ${STAMPS}/linux-headers
204 mkdir -p ${PREFIX}/${TARGET}
205 cd ${TOOLS}/build/linux && ${SUDO} cp -rf ${TOOLS}/build/linux/usr/include ${PREFIX}/${TARGET}/
210 ${STAMPS}/binutils-configure: ${STAMPS}/binutils-extract
211 mkdir -p ${TOOLS}/build/binutils/build
212 cd ${TOOLS}/build/binutils/build \
213 && CC="${CC}" CXX="${CXX}" ../configure \
217 --with-arch=${ARCH} \
224 ${STAMPS}/binutils-build: ${STAMPS}/binutils-configure
225 (cd ${TOOLS}/build/binutils/build && ${GMAKE})
228 ${STAMPS}/binutils-install: ${STAMPS}/binutils-build
229 (cd ${TOOLS}/build/binutils/build && ${SUDO} ${GMAKE} install)
234 ${STAMPS}/gcc-configure: ${STAMPS}/gcc-extract ${STAMPS}/binutils-install ${STAMPS}/gmp ${STAMPS}/mpfr ${STAMPS}/mpc
235 mkdir -p ${TOOLS}/build/gcc/build
236 cd ${TOOLS}/build/gcc/build \
237 && CC="${CC}" CXX="${CXX}" \
238 CXXFLAGS="${CXXFLAGS} -Dvec_step=\"xvec_step\"" \
243 --with-arch=${ARCH} \
246 --enable-languages=c \
250 --disable-libsanitizer \
251 --disable-libstdcxx \
253 --disable-libquadmath \
260 ${STAMPS}/gcc-build: ${STAMPS}/gcc-configure
261 (cd ${TOOLS}/build/gcc/build && ${GMAKE} all-gcc)
264 ${STAMPS}/gcc-install: ${STAMPS}/gcc-build
265 (cd ${TOOLS}/build/gcc/build && ${SUDO} ${GMAKE} install-gcc)
270 ${STAMPS}/musl-configure: ${STAMPS}/musl-extract ${STAMPS}/gcc-install
271 mkdir -p ${TOOLS}/build/musl/build
272 cd ${TOOLS}/build/musl/build && \
273 CROSS_COMPILE=${PREFIX}/bin/${TARGET}- \
275 --prefix=${PREFIX}/${TARGET} \
282 ${STAMPS}/musl-build: ${STAMPS}/musl-configure ${STAMPS}/linux-hdrinst
283 (cd ${TOOLS}/build/musl/build && ${GMAKE})
286 ${STAMPS}/musl-install: ${STAMPS}/musl-build
287 (cd ${TOOLS}/build/musl/build && ${SUDO} ${GMAKE} install)
292 ${STAMPS}/libgcc-build: ${STAMPS}/gcc-install ${STAMPS}/musl-install
293 (cd ${TOOLS}/build/gcc/build && ${GMAKE} all-target-libgcc)
296 ${STAMPS}/libgcc-install: ${STAMPS}/libgcc-build
297 (cd ${TOOLS}/build/gcc/build && ${SUDO} ${GMAKE} install-target-libgcc)
302 ${STAMPS}/oksh-configure: ${STAMPS}/oksh ${STAMPS}/libgcc-install
303 cd ${TOOLS}/build/oksh && \
304 CFLAGS="-Og -g" ./configure \
306 --cc=${PREFIX}/bin/${TARGET}-gcc \
315 ${STAMPS}/oksh-build: ${STAMPS}/oksh-configure
316 (cd ${TOOLS}/build/oksh && ${MAKE})
319 ${TOP}/rootfs/bin/ksh: ${STAMPS}/oksh-build
320 mkdir -p ${TOP}/rootfs
321 (cd ${TOOLS}/build/oksh && ${MAKE} DESTDIR=${TOP}/rootfs install)
323 oksh: ${TOP}/rootfs/bin/ksh
327 ${STAMPS}/destruct-build: ${STAMPS}/destruct
328 (cd ${TOOLS}/build/destruct && ${MAKE})
331 ${STAMPS}/destruct-install: ${STAMPS}/destruct-build
332 (cd ${TOOLS}/build/destruct && ${MAKE} PREFIX=${TOOLS} install)
336 rm -f bin/destruct ${STAMPS}/destruct*
337 rm -rf build/destruct
339 destruct: ${STAMPS}/destruct-install
343 ${STAMPS}/rvforth-build: ${STAMPS}/rvforth ${STAMPS}/libgcc-install
344 (cd ${TOOLS}/build/rvforth && ${MAKE} CC="${PREFIX}/bin/${TARGET}-gcc")
347 ${TOP}/rootfs/bin/rvforth: ${STAMPS}/rvforth-build
348 mkdir -p ${TOP}/rootfs/bin
349 (cd ${TOOLS}/build/rvforth && ${MAKE} PREFIX=/ DESTDIR=${TOP}/rootfs install)
352 rm -f ${STAMPS}/rvforth*
355 rvforth: ${TOP}/rootfs/bin/rvforth
359 ${STAMPS}/mcu-configure: ${STAMPS}/mcu ${STAMPS}/libgcc-install
360 cd ${TOOLS}/build/mcu && \
361 CC=${PREFIX}/bin/${TARGET}-gcc ./configure \
367 ${STAMPS}/mcu-fix: ${STAMPS}/mcu-configure
368 (cd ${TOOLS}/build/mcu && \
369 sed '/^#define malloc/d; /^#define realloc/d' config.h > config.h.new && \
370 mv config.h.new config.h)
373 ${STAMPS}/mcu-build: ${STAMPS}/mcu-fix
374 (cd ${TOOLS}/build/mcu && ${MAKE})
377 ${TOP}/rootfs/mcu/bin/ls: ${STAMPS}/mcu-build
378 (cd ${TOOLS}/build/mcu && ${MAKE} DESTDIR=${TOP}/rootfs install)
380 mcu: ${TOP}/rootfs/mcu/bin/ls
384 ${STAMPS}/gforth-fix: ${STAMPS}/gforth
385 (cd ${TOOLS}/build/gforth && sed '/^CHECKFLAGS=.*$$/d' configure > configure.new && chmod +x configure.new)
388 ${STAMPS}/gforth-configure: ${STAMPS}/gforth-fix ${STAMPS}/libgcc-install
389 cd ${TOOLS}/build/gforth && \
390 CC=${PREFIX}/bin/${TARGET}-gcc CFLAGS="-O2" ./configure.new \
400 ac_cv_sizeof_void_p=8 \
401 ac_cv_sizeof_char_p=8 \
402 ac_cv_sizeof_char=1 \
403 ac_cv_sizeof_short=2 \
405 ac_cv_sizeof_long=8 \
406 ac_cv_sizeof_long_long=8 \
407 ac_cv_sizeof_intptr_t=8 \
408 ac_cv_sizeof___int128_t=16 \
409 ac_cv_sizeof___uint128_t=16 \
410 ac_cv_sizeof_off_t=8 \
411 ac_cv_c_bigendian=no \
412 ac_cv_func_memcmp_working=yes \
413 ac_cv_func_memmove=yes \
414 ac_cv_func_getpagesize=yes \
415 ac_cv_func_wcwidth=yes \
416 ac_cv_func_mcheck=no \
417 ac_cv_func_dlopen=no \
418 ac_cv_export_dynamic=no
419 (cd ${TOOLS}/build/gforth && \
420 sed 's@\(DITCENGINE\) = \(.*$$\)@\1 = ${TOP}/linurv \2@' Makefile > Makefile.new && \
421 mv Makefile.new Makefile)
424 ${STAMPS}/gforth-build: ${STAMPS}/gforth-configure
425 (cd ${TOOLS}/build/gforth && ${GMAKE})
428 ${TOP}/rootfs/bin/gforth: ${STAMPS}/gforth-build
429 (cd ${TOOLS}/build/gforth && ${GMAKE} DESTDIR=${TOP}/rootfs install)
433 rm -f ${STAMPS}/gforth*
436 gforth: ${TOP}/rootfs/bin/gforth
440 ${STAMPS}/busybox-config: ${STAMPS}/busybox ${STAMPS}/libgcc-install
441 (cd ${TOOLS}/build/busybox \
442 && ${GMAKE} ${BBFLAGS} defconfig \
443 && mv .config .config.old \
444 && sed -e 's/^# CONFIG_DEBUG is not set/CONFIG_DEBUG=y/' \
445 -e 's/^# CONFIG_DEBUG_PESSIMIZE is not set/CONFIG_DEBUG_PESSIMIZE=y/' \
446 -e 's/^CONFIG_NO_DEBUG_LIB=y/# CONFIG_NO_DEBUG_LIB is not set/' \
447 < .config.old > .config)
450 ${STAMPS}/busybox-build: ${STAMPS}/busybox-config
451 (cd ${TOOLS}/build/busybox && ${GMAKE} ${BBFLAGS})
454 ${TOP}/rootfs/bb/bin/busybox: ${STAMPS}/busybox-build
455 (cd ${TOOLS}/build/busybox && ${GMAKE} ${BBFLAGS} install)
457 busybox: ${TOP}/rootfs/bb/bin/busybox
460 rm -f ${STAMPS}/busybox*