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 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.
These are experimental notes on attempts at building the C++ standard library implementation bundled with GCC, `libstdc++-v3`. For the official manual, see [libstdc++ info manual, Chapter 2: Setup](https://gcc.gnu.org/onlinedocs/libstdc++/manual/setup.html) (gcc.gnu.org).
So far, I was only able to build the **free-standing subset** which has basically nothing in it, see [Freestanding and hosted implementations](https://en.cppreference.com/w/cpp/freestanding) (cppreference.com). As a rule of thumb only features that look like extensions of the language are supported in there (RTTI, exceptions, coroutines, etc.) and everything that looks like a library (STL containers, I/O tools, filesystem) you can forget about. This subset does not include familiar features but it is needed nonetheless for C++ programs to work at all.
First configure GCC as usual (follow `configure.sh`), but use a separate build folder. Since this is experimental the files are likely to stay here longer while debugging and you don't want them gone during a GCC upgrade. There are a couple of additional flags to care about, mainly described [here](https://gcc.gnu.org/onlinedocs/libstdc++/manual/configure.html).
*`--enable-cxx-flags="-ffreestanding -fno-exceptions"`: Everything should be free-standing since we don't use a standard runtime.
Currently I don't know of a way to completely disable exceptions in a way that linking with libstdc++ does not include all the stack unwinding and RTTI code for exceptions, but it sure starts with `-fno-exceptions` so it can't hurt to have that.
Next step is to install [OpenLibm](https://gitea.planet-casio.com/Lephenixnoir/OpenLibm) and [fxlibc](https://gitea.planet-casio.com/Vhex-Kernel-Core/fxlibc/) since we're certainly not going to build the C++ standard library without the C standard library.
For some reason OpenLibm installs its headers in the `include/openlibm` subfolder, but then includes them as if they were in `include`, so we have to add a path. Normally either the projet provides that path, or gint does it through its CMake find module. Here we can symlink to the `sh3eb-elf/sys-include` folder in this repo's root folder (or `include` but it's already symlinked to the compiler's install folder and we don't really want to override that).
Also `<stdint.h>` has issues because GCC only redirects to its default `"stdint-gcc.h"` when free-standing, which conftest programs are not, so we have to provide some version of `<stdint.h>`.
After this, come back to the build folder, run the build command for libstdc++-v3, and hope it works out. I recommend not using `-j` as it makes error messages and logs more linear, and the library builds very fast anyway.
If it fails, check out `sh3eb-elf/libstdc++-v3/config.log` for configure errors, or other log files if you make it past the configuration step. `config.log` has many details on programs that failed to compile; not all failures to build are fatal for the configuration step, but some are.