This repository provides scripts to automatically compile and install an SH3/SH4-compatible [GCC cross-compiler](https://gcc.gnu.org/). GCC is a collection of compilers most commonly used for C/C++.
This repo currently builds GCC version 13.1.0 with additional patches from [this fork](https://github.com/antoyo/gcc) by antoyo, who works on the GCC backend for rustc, to allow rustc_codedgen_gcc to work. GCC and any patches are licenced under the GNU General Public License version 3 with a runtime exception; see the [GCC source code](https://ftp.gnu.org/gnu/gcc/gcc-13.1.0/) for more details.
This installs GCC (and binutils if missing) in the fxSDK's SuperH system root. Note that at first it will *not* install the C++ standard library libstdc++, because it requires the C standard library which is not available at this stage. After you install [fxlibc](/Vhex-Kernel-Core/fxlibc/) you should run GiteaPC's install command again, and this time the scripts will build libstdc++. The GiteaPC tutorial has more detailed instructions about this two-stage process.
A `:any` configuration is provided in case you already have another version of GCC installed in the fxSDK sysroot and want to keep using it (ie. skip a version upgrade). This will mark this repository as installed, so other repositories depending on it can build, without actually compiling binutils.
A `:clean` configuration is also provided if you want to clean up the source and build files automatically after the second pass. This frees up some disk space.
First here is the [guide for installing GCC](https://gcc.gnu.org/install/index.html) and here is [the one for libstdc++](https://gcc.gnu.org/onlinedocs/libstdc++/manual/setup.html).
**Warning:** GCC 12.1 to 12.3 for SuperH have a [critical bug](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106609) which causes them to compile add-ins incorrectly. If you install GCC manually, use either GCC 11.1 (or earlier) or GCC 13 (or later).
If using GCC 11.1 (or possibly earlier) for the SuperH compiler, we need to patch the libstdc++ configure script because it tries to run tests that are too advanced for our setup and not actually intended to run on cross-compilers. GCC 12 has this patch upstream.
If you want Rust support you will also need to apply some patches to add some needed functionality to libgccjit, taken from the fork mentioned above. This patch has been tested to work when applied to GCC 13.1.0. Note that arguments to this command are slightly different that the last one and it must be applied within the source directory.
Now choose a prefix for install. If you're installing for the fxSDK, you must use `$(fxsdk path sysroot)`, otherwise anything that is isolated from the native OS is fine.
The next step is to install the libc. The standard fxSDK setup is to install [OpenLibm](https://gitea.planet-casio.com/Lephenixnoir/OpenLibm) and [fxlibc](https://gitea.planet-casio.com/Vhex-Kernel-Core/fxlibc/). Feel free to experiment. Make sure the includes and libraries end up in `$SYSROOT/sh3eb-elf/{bin,include}` since this is where GCC looks in hosted-like situations.
You can then clean up the source archive, source files, and build folder if needed. Link add-ins with `-lm -lstdc++ -lc -lgcc` in this order for the best results.