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.3.0
13 MUSL_VER = 1.2.5
14 LINUX_VER = 6.6.43
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.4
21 RVFORTH_VER = 0.1
22 MCU_VER = 1.2
23 GFORTH_VER = 0.7.9_20240627
24 BUSYBOX_VER = 1.36.1
26 BBFLAGS = HOSTCC="${CC}" HOSTCXX="${CXX}" CROSS_COMPILE="${PREFIX}/bin/${TARGET}-" CONFIG_PREFIX="${TOP}/rootfs/bb"
28 GMAKE = $U/gmake
29 SUDO =
31 all: build
33 extra: rvforth oksh mcu busybox # gforth (broken)
35 build: ${STAMPS}/libgcc-install ${STAMPS}/destruct-install
37 distclean: clean
38 rm -rf src
40 clean:
41 rm -rf bin build include lib libexec ${TARGET} share
43 test:
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
54 # DOWNLOAD
56 src/binutils.tgz:
57 mkdir -p src
58 $U/download $@ https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VER}.tar.gz
60 src/gcc.tgz:
61 mkdir -p src
62 $U/download $@ https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VER}/gcc-${GCC_VER}.tar.gz
64 src/musl.tgz:
65 mkdir -p src
66 $U/download $@ http://musl.libc.org/releases/musl-${MUSL_VER}.tar.gz
68 src/linux.tgz:
69 mkdir -p src
70 $U/download $@ https://mirrors.edge.kernel.org/pub/linux/kernel/v${LINUX_MAJOR}.x/linux-${LINUX_VER}.tar.gz
72 src/gmp.tgz:
73 mkdir -p src
74 $U/download $@ https://gmplib.org/download/gmp/gmp-${GMP_VER}.tar.gz
76 src/mpfr.tgz:
77 mkdir -p src
78 $U/download $@ https://www.mpfr.org/mpfr-current/mpfr-${MPFR_VER}.tar.gz
80 src/mpc.tgz:
81 mkdir -p src
82 $U/download $@ https://ftp.gnu.org/gnu/mpc/mpc-${MPC_VER}.tar.gz
84 src/oksh.tgz:
85 mkdir -p src
86 $U/download $@ https://github.com/ibara/oksh/releases/download/oksh-${OKSH_VER}/oksh-${OKSH_VER}.tar.gz
88 src/destruct.tgz:
89 mkdir -p src
90 $U/download $@ https://got.stuerz.xyz/download/destruct-${DESTRUCT_VER}.tgz
92 src/rvforth.tgz:
93 mkdir -p src
94 $U/download $@ https://got.stuerz.xyz/download/rvforth-${RVFORTH_VER}.tgz
96 src/mcu.tgz:
97 mkdir -p src
98 $U/download $@ https://github.com/riscygeek/microcoreutils/archive/refs/tags/v${MCU_VER}.tar.gz
100 src/gforth.txz:
101 mkdir -p src
102 $U/download $@ https://www.complang.tuwien.ac.at/forth/gforth/Snapshots/${GFORTH_VER}/gforth-${GFORTH_VER}.tar.xz
104 src/busybox.tar.bz2:
105 mkdir -p src
106 $U/download $@ https://busybox.net/downloads/busybox-${BUSYBOX_VER}.tar.bz2
108 # EXTRACT
110 ${STAMPS}/binutils-extract: src/binutils.tgz
111 mkdir -p ${STAMPS}
112 rm -rf build/binutils
113 tar -C build -xzf src/binutils.tgz
114 mv build/binutils-* build/binutils
115 touch $@
117 ${STAMPS}/gcc-extract: src/gcc.tgz
118 mkdir -p ${STAMPS}
119 rm -rf build/gcc
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
124 touch $@
126 ${STAMPS}/musl-extract: src/musl.tgz
127 mkdir -p ${STAMPS}
128 rm -rf build/musl
129 tar -C build -xzf src/musl.tgz
130 mv build/musl-* build/musl
131 touch $@
133 ${STAMPS}/linux-extract: src/linux.tgz
134 mkdir -p ${STAMPS}
135 rm -rf build/linux
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
139 touch $@
141 ${STAMPS}/gmp: src/gmp.tgz
142 mkdir -p ${STAMPS}
143 tar -C build -xzf src/gmp.tgz
144 mv build/gmp-* build/gmp
145 touch $@
147 ${STAMPS}/mpfr: src/mpfr.tgz
148 mkdir -p ${STAMPS}
149 tar -C build -xzf src/mpfr.tgz
150 mv build/mpfr-* build/mpfr
151 touch $@
153 ${STAMPS}/mpc: src/mpc.tgz
154 mkdir -p ${STAMPS}
155 tar -C build -xzf src/mpc.tgz
156 mv build/mpc-* build/mpc
157 touch $@
159 ${STAMPS}/oksh: src/oksh.tgz
160 mkdir -p ${STAMPS}
161 tar -C build -xzf src/oksh.tgz
162 mv build/oksh-* build/oksh
163 touch $@
165 ${STAMPS}/destruct: src/destruct.tgz
166 mkdir -p ${STAMPS}
167 tar -C build -xzf src/destruct.tgz
168 mv build/destruct-* build/destruct
169 touch $@
171 ${STAMPS}/rvforth: src/rvforth.tgz
172 mkdir -p ${STAMPS}
173 tar -C build -xzf src/rvforth.tgz
174 mv build/rvforth-* build/rvforth
175 touch $@
177 ${STAMPS}/mcu: src/mcu.tgz
178 mkdir -p ${STAMPS}
179 tar -C build -xzf src/mcu.tgz
180 mv build/microcoreutils-* build/mcu
181 touch $@
183 ${STAMPS}/gforth: src/gforth.txz
184 mkdir -p ${STAMPS}
185 xzcat src/gforth.txz | tar -C build -xf -
186 mv build/gforth-* build/gforth
187 touch $@
189 ${STAMPS}/busybox: src/busybox.tar.bz2
190 mkdir -p ${STAMPS}
191 tar -C build -xjf src/busybox.tar.bz2
192 mv build/busybox-* build/busybox
193 touch $@
195 # KERNEL HEADERS
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
201 touch $@
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}/
206 touch $@
208 # BINUTILS
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 \
214 --prefix=${PREFIX} \
215 --target=${TARGET} \
216 --with-system-zlib \
217 --with-arch=${ARCH} \
218 --without-zstd \
219 --disable-nls \
220 --disable-werror \
221 --disable-multilib
222 touch $@
224 ${STAMPS}/binutils-build: ${STAMPS}/binutils-configure
225 (cd ${TOOLS}/build/binutils/build && ${GMAKE})
226 touch $@
228 ${STAMPS}/binutils-install: ${STAMPS}/binutils-build
229 (cd ${TOOLS}/build/binutils/build && ${SUDO} ${GMAKE} install)
230 touch $@
232 # GCC
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\"" \
239 ../configure \
240 --prefix=${PREFIX} \
241 --target=${TARGET} \
242 --with-system-zlib \
243 --with-arch=${ARCH} \
244 --with-newlib \
245 --without-headers \
246 --enable-languages=c \
247 --disable-nls \
248 --disable-multilib \
249 --disable-libssp \
250 --disable-libsanitizer \
251 --disable-libstdcxx \
252 --disable-libgomp \
253 --disable-libquadmath \
254 --disable-libvtv \
255 --disable-shared \
256 --enable-static \
257 --disable-threads
258 touch $@
260 ${STAMPS}/gcc-build: ${STAMPS}/gcc-configure
261 (cd ${TOOLS}/build/gcc/build && ${GMAKE} all-gcc)
262 touch $@
264 ${STAMPS}/gcc-install: ${STAMPS}/gcc-build
265 (cd ${TOOLS}/build/gcc/build && ${SUDO} ${GMAKE} install-gcc)
266 touch $@
268 # MUSL
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}- \
274 ../configure \
275 --prefix=${PREFIX}/${TARGET} \
276 --target=${TARGET} \
277 --disable-shared \
278 --disable-wrapper \
279 --enable-static
280 touch $@
282 ${STAMPS}/musl-build: ${STAMPS}/musl-configure ${STAMPS}/linux-hdrinst
283 (cd ${TOOLS}/build/musl/build && ${GMAKE})
284 touch $@
286 ${STAMPS}/musl-install: ${STAMPS}/musl-build
287 (cd ${TOOLS}/build/musl/build && ${SUDO} ${GMAKE} install)
288 touch $@
290 # LIBGCC
292 ${STAMPS}/libgcc-build: ${STAMPS}/gcc-install ${STAMPS}/musl-install
293 (cd ${TOOLS}/build/gcc/build && ${GMAKE} all-target-libgcc)
294 touch $@
296 ${STAMPS}/libgcc-install: ${STAMPS}/libgcc-build
297 (cd ${TOOLS}/build/gcc/build && ${SUDO} ${GMAKE} install-target-libgcc)
298 touch $@
300 # OKSH
302 ${STAMPS}/oksh-configure: ${STAMPS}/oksh ${STAMPS}/libgcc-install
303 cd ${TOOLS}/build/oksh && \
304 CFLAGS="-Og -g" ./configure \
305 --prefix=/ \
306 --cc=${PREFIX}/bin/${TARGET}-gcc \
307 --enable-sh \
308 --enable-ksh \
309 --enable-static \
310 --disable-curses \
311 --no-strip \
312 --no-thanks
313 touch $@
315 ${STAMPS}/oksh-build: ${STAMPS}/oksh-configure
316 (cd ${TOOLS}/build/oksh && ${MAKE})
317 touch $@
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
325 # DESTRUCT
327 ${STAMPS}/destruct-build: ${STAMPS}/destruct
328 (cd ${TOOLS}/build/destruct && ${MAKE})
329 touch $@
331 ${STAMPS}/destruct-install: ${STAMPS}/destruct-build
332 (cd ${TOOLS}/build/destruct && ${MAKE} PREFIX=${TOOLS} install)
333 touch $@
335 clean-destruct:
336 rm -f bin/destruct ${STAMPS}/destruct*
337 rm -rf build/destruct
339 destruct: ${STAMPS}/destruct-install
341 # RVFORTH
343 ${STAMPS}/rvforth-build: ${STAMPS}/rvforth ${STAMPS}/libgcc-install
344 (cd ${TOOLS}/build/rvforth && ${MAKE} CC="${PREFIX}/bin/${TARGET}-gcc")
345 touch $@
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)
351 clean-rvforth:
352 rm -f ${STAMPS}/rvforth*
353 rm -rf build/rvforth
355 rvforth: ${TOP}/rootfs/bin/rvforth
357 # MICROCOREUTILS
359 ${STAMPS}/mcu-configure: ${STAMPS}/mcu ${STAMPS}/libgcc-install
360 cd ${TOOLS}/build/mcu && \
361 CC=${PREFIX}/bin/${TARGET}-gcc ./configure \
362 --prefix=/mcu \
363 --host=${TARGET} \
364 --enable-extra-progs
365 touch $@
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)
371 touch $@
373 ${STAMPS}/mcu-build: ${STAMPS}/mcu-fix
374 (cd ${TOOLS}/build/mcu && ${MAKE})
375 touch $@
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
382 # GFORTH
384 ${STAMPS}/gforth-fix: ${STAMPS}/gforth
385 (cd ${TOOLS}/build/gforth && sed '/^CHECKFLAGS=.*$$/d' configure > configure.new && chmod +x configure.new)
386 touch $@
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 \
391 --prefix=/ \
392 --with-arch=riscv \
393 --without-check \
394 --host=${TARGET} \
395 --enable-static \
396 --disable-shared \
397 --disable-version \
398 --disable-lib \
399 --without-pic \
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 \
404 ac_cv_sizeof_int=4 \
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)
422 touch $@
424 ${STAMPS}/gforth-build: ${STAMPS}/gforth-configure
425 (cd ${TOOLS}/build/gforth && ${GMAKE})
426 touch $@
428 ${TOP}/rootfs/bin/gforth: ${STAMPS}/gforth-build
429 (cd ${TOOLS}/build/gforth && ${GMAKE} DESTDIR=${TOP}/rootfs install)
430 touch $@
432 clean-gforth:
433 rm -f ${STAMPS}/gforth*
434 rm -rf build/gforth
436 gforth: ${TOP}/rootfs/bin/gforth
438 # BUSYBOX
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)
448 touch $@
450 ${STAMPS}/busybox-build: ${STAMPS}/busybox-config
451 (cd ${TOOLS}/build/busybox && ${GMAKE} ${BBFLAGS})
452 touch $@
454 ${TOP}/rootfs/bb/bin/busybox: ${STAMPS}/busybox-build
455 (cd ${TOOLS}/build/busybox && ${GMAKE} ${BBFLAGS} install)
457 busybox: ${TOP}/rootfs/bb/bin/busybox
459 clean-busybox:
460 rm -f ${STAMPS}/busybox*
461 rm -rf build/busybox