When prepending something to PATH, we should use PATH=/foo/bar:$PATH
and not PATH=/foo/bar:PATH. Because your shell won't certainly find
something under the literal name PATH.
If one is not using devkitarm, TOOLCHAIN will resolve to an empty
string. If TOOLCHAIN is an empty string the only search path for the
modern gcc will be /bin which may work on some installations but is
probably not what was originally intended with this line. So let's just
search the standard search path if nothing can be found under $(TOOLCHAIN).
Either way, PATH is already set up previously, so we can make sure
MODERNCC is invoked properly by calling MODERNCC with PATH=$(PATH).
In order to correctly link a program which uses libc functions
a few sections are required to satisfy the linker.
This currently adds 0x3C bytes to IWRAM.
When actually utilizing functions from libc, linking will fail
because the functions used from libc have to be defined after libc.
This is the case with libgcc, so we swap their order.
Before, when compiling MultiBootWaitCycles with O3 and MODERN=1, you
might have run into problems during optimizations when the compiler tried
to optimize the function, even if declared NOINLINE.
When rewriting this function as NAKED function, this no longer happens
as the optimizer will treat it as black box and compilation will resume.
Previously, aggressive loop optimizations with a new compiler were not
possible due to undefined behaviour at end of arrays.
A macro "UBFIX" is added to allow ifdefs for fixes which resolve
undefined behavior. For example newer GCC versions will detect various
bugs in the original game code and will otherwise not compile with -Werror.
gcc has this nice option "-print-file-name=" to locate a file
in its search path. This is a more portable way to locate
libgcc.a and libc.a so there is no longer the need to mess around with
devkitARM's path's.
This problem is only going to occur in versions where the palette
buffer isn't aligned to 4 bytes (which it is in a matching pokeemerald).
Since agbcc returns sizeof(PlttData) = 4, it will read words
instead of half words. This causes unnecessary emulator warnings
in the function "BlendPalette".
Aligning the buffers to 4 bytes fixes this.