@@ -22,6 +22,14 @@ N64_BUILD=${N64_BUILD:-""}
2222N64_HOST=${N64_HOST:- " " }
2323N64_TARGET=${N64_TARGET:- mips64-elf}
2424
25+ # Toolchain configuration options.
26+ N64_USE_PICOLIBC=${N64_USE_PICOLIBC:- " false" }
27+ N64_USE_PICOLIBC_TINYSTDIO=${N64_USE_PICOLIBC_TINYSTDIO:- " false" }
28+ N64_USE_PICOLIBC_LEGACY_STDIO=true
29+ if [ " $N64_USE_PICOLIBC_TINYSTDIO " == " true" ]; then
30+ N64_USE_PICOLIBC_LEGACY_STDIO=false
31+ fi
32+
2533# Set N64_INST before calling the script to change the default installation directory path
2634INSTALL_PATH=" ${N64_INST} "
2735# Set PATH for newlib to compile using GCC for MIPS N64 (pass 1)
@@ -38,8 +46,9 @@ GCC_CONFIGURE_ARGS=()
3846BINUTILS_V=2.43.1
3947GCC_V=14.2.0
4048NEWLIB_V=4.4.0.20231231
41- GMP_V=6.3.0
42- MPC_V=1.3.1
49+ PICOLIBC_V=e0a04fec075f5cb1ddb80ea8c359748ef72b9122
50+ GMP_V=6.3.0
51+ MPC_V=1.3.1
4352MPFR_V=4.2.1
4453MAKE_V=${MAKE_V:- " " }
4554
@@ -104,8 +113,13 @@ test -d "binutils-$BINUTILS_V" || tar -xzf "binutils-$BINUTILS_V.tar.gz"
104113test -f " gcc-$GCC_V .tar.gz" || download " https://ftp.gnu.org/gnu/gcc/gcc-$GCC_V /gcc-$GCC_V .tar.gz"
105114test -d " gcc-$GCC_V " || tar -xzf " gcc-$GCC_V .tar.gz"
106115
107- test -f " newlib-$NEWLIB_V .tar.gz" || download " https://sourceware.org/pub/newlib/newlib-$NEWLIB_V .tar.gz"
108- test -d " newlib-$NEWLIB_V " || tar -xzf " newlib-$NEWLIB_V .tar.gz"
116+ if [ " $N64_USE_PICOLIBC " == " true" ]; then
117+ test -f " picolibc-$PICOLIBC_V .zip" || ( download " https://github.com/picolibc/picolibc/archive/$PICOLIBC_V .zip" && mv " $PICOLIBC_V .zip" " picolibc-$PICOLIBC_V .zip" )
118+ test -d " picolibc-$PICOLIBC_V " || unzip " picolibc-$PICOLIBC_V .zip"
119+ else
120+ test -f " newlib-$NEWLIB_V .tar.gz" || download " https://sourceware.org/pub/newlib/newlib-$NEWLIB_V .tar.gz"
121+ test -d " newlib-$NEWLIB_V " || tar -xzf " newlib-$NEWLIB_V .tar.gz"
122+ fi
109123
110124if [ " $GMP_V " != " " ]; then
111125 test -f " gmp-$GMP_V .tar.bz2" || download " https://ftp.gnu.org/gnu/gmp/gmp-$GMP_V .tar.bz2"
@@ -220,20 +234,57 @@ make all-target-libgcc -j "$JOBS"
220234make install-target-libgcc || sudo make install-target-libgcc || su -c " make install-target-libgcc"
221235popd
222236
223- # Compile newlib for target.
224- mkdir -p newlib_compile_target
225- pushd newlib_compile_target
226- CFLAGS_FOR_TARGET=" -DHAVE_ASSERT_FUNC -O2 -fpermissive" ../" newlib-$NEWLIB_V " /configure \
227- --prefix=" $CROSS_PREFIX " \
228- --target=" $N64_TARGET " \
229- --with-cpu=mips64vr4300 \
230- --disable-libssp \
231- --disable-werror \
232- --enable-newlib-multithread \
233- --enable-newlib-retargetable-locking
234- make -j " $JOBS "
235- make install || sudo env PATH=" $PATH " make install || su -c " env PATH=\" $PATH \" make install"
236- popd
237+ if [ " $N64_USE_PICOLIBC " == " true" ]; then
238+ # Compile picolibc for target.
239+ mkdir -p picolibc_compile_target
240+ pushd picolibc_compile_target
241+ meson setup \
242+ --cross-file=../../meson-cross.txt \
243+ -Dmultilib=false \
244+ -Dpicocrt=false \
245+ -Dpicolib=false \
246+ -Dsemihost=false \
247+ -Dspecsdir=none \
248+ -Dtests=false \
249+ -Dtinystdio=" $N64_USE_PICOLIBC_TINYSTDIO " \
250+ -Dfast-bufio=true \
251+ -Dio-long-long=true \
252+ -Dio-pos-args=" $N64_USE_PICOLIBC_TINYSTDIO " \
253+ -Dio-percent-b=true \
254+ -Dposix-console=true \
255+ -Dformat-default=double \
256+ -Dnewlib-fseek-optimization=" $N64_USE_PICOLIBC_LEGACY_STDIO " \
257+ -Dnewlib-fvwrite-in-streamio=" $N64_USE_PICOLIBC_LEGACY_STDIO " \
258+ -Dnewlib-io-float=" $N64_USE_PICOLIBC_LEGACY_STDIO " \
259+ -Dnewlib-stdio64=false \
260+ -Dnewlib-unbuf-stream-opt=" $N64_USE_PICOLIBC_LEGACY_STDIO " \
261+ -Dnewlib-nano-malloc=false \
262+ -Dnewlib-multithread=true \
263+ -Dnewlib-retargetable-locking=true \
264+ -Dthread-local-storage=true \
265+ -Dprefix=" $CROSS_PREFIX " \
266+ -Dlibdir=mips64-elf/lib \
267+ -Dincludedir=mips64-elf/include \
268+ ../" picolibc-$PICOLIBC_V "
269+ ninja -j " $JOBS "
270+ ninja install || sudo env PATH=" $PATH " ninja install || su -c " env PATH=\" $PATH \" ninja install"
271+ popd
272+ else
273+ # Compile newlib for target.
274+ mkdir -p newlib_compile_target
275+ pushd newlib_compile_target
276+ CFLAGS_FOR_TARGET=" -DHAVE_ASSERT_FUNC -O2 -fpermissive" ../" newlib-$NEWLIB_V " /configure \
277+ --prefix=" $CROSS_PREFIX " \
278+ --target=" $N64_TARGET " \
279+ --with-cpu=mips64vr4300 \
280+ --disable-libssp \
281+ --disable-werror \
282+ --enable-newlib-multithread \
283+ --enable-newlib-retargetable-locking
284+ make -j " $JOBS "
285+ make install || sudo env PATH=" $PATH " make install || su -c " env PATH=\" $PATH \" make install"
286+ popd
287+ fi
237288
238289# For a standard cross-compiler, the only thing left is to finish compiling the target libraries
239290# like libstd++. We can continue on the previous GCC build target.
@@ -286,20 +337,57 @@ else
286337 make install-target-libgcc || sudo make install-target-libgcc || su -c " make install-target-libgcc"
287338 popd
288339
289- # Compile newlib for target.
290- mkdir -p newlib_compile
291- pushd newlib_compile
292- CFLAGS_FOR_TARGET=" -DHAVE_ASSERT_FUNC -O2 -fpermissive" ../" newlib-$NEWLIB_V " /configure \
293- --prefix=" $INSTALL_PATH " \
294- --target=" $N64_TARGET " \
295- --with-cpu=mips64vr4300 \
296- --disable-libssp \
297- --disable-werror \
298- --enable-newlib-multithread \
299- --enable-newlib-retargetable-locking
300- make -j " $JOBS "
301- make install || sudo env PATH=" $PATH " make install || su -c " env PATH=\" $PATH \" make install"
302- popd
340+ if [ " $N64_USE_PICOLIBC " == " true" ]; then
341+ # Compile picolibc for target.
342+ mkdir -p picolibc_compile_target
343+ pushd picolibc_compile_target
344+ meson setup \
345+ --cross-file=../../meson-cross.txt \
346+ -Dmultilib=false \
347+ -Dpicocrt=false \
348+ -Dpicolib=false \
349+ -Dsemihost=false \
350+ -Dspecsdir=none \
351+ -Dtests=false \
352+ -Dtinystdio=" $N64_USE_PICOLIBC_TINYSTDIO " \
353+ -Dfast-bufio=true \
354+ -Dio-long-long=true \
355+ -Dio-pos-args=" $N64_USE_PICOLIBC_TINYSTDIO " \
356+ -Dio-percent-b=true \
357+ -Dposix-console=true \
358+ -Dformat-default=double \
359+ -Dnewlib-fseek-optimization=" $N64_USE_PICOLIBC_LEGACY_STDIO " \
360+ -Dnewlib-fvwrite-in-streamio=" $N64_USE_PICOLIBC_LEGACY_STDIO " \
361+ -Dnewlib-io-float=" $N64_USE_PICOLIBC_LEGACY_STDIO " \
362+ -Dnewlib-stdio64=false \
363+ -Dnewlib-unbuf-stream-opt=" $N64_USE_PICOLIBC_LEGACY_STDIO " \
364+ -Dnewlib-nano-malloc=false \
365+ -Dnewlib-multithread=true \
366+ -Dnewlib-retargetable-locking=true \
367+ -Dthread-local-storage=false \
368+ -Dprefix=" $INSTALL_PATH " \
369+ -Dlibdir=mips64-elf/lib \
370+ -Dincludedir=mips64-elf/include \
371+ ../" picolibc-$PICOLIBC_V "
372+ ninja -j " $JOBS "
373+ ninja install || sudo env PATH=" $PATH " ninja install || su -c " env PATH=\" $PATH \" ninja install"
374+ popd
375+ else
376+ # Compile newlib for target.
377+ mkdir -p newlib_compile_target
378+ pushd newlib_compile_target
379+ CFLAGS_FOR_TARGET=" -DHAVE_ASSERT_FUNC -O2 -fpermissive" ../" newlib-$NEWLIB_V " /configure \
380+ --prefix=" $INSTALL_PATH " \
381+ --target=" $N64_TARGET " \
382+ --with-cpu=mips64vr4300 \
383+ --disable-libssp \
384+ --disable-werror \
385+ --enable-newlib-multithread \
386+ --enable-newlib-retargetable-locking
387+ make -j " $JOBS "
388+ make install || sudo env PATH=" $PATH " make install || su -c " env PATH=\" $PATH \" make install"
389+ popd
390+ fi
303391
304392 # Finish compiling GCC
305393 mkdir -p gcc_compile
0 commit comments