Building the gcc cross-compilers depends on wget, gcc, libmpc, mpfr, gmp, gcc-multilib, and g++-multilib, so make sure you have them installed or the cross-compiler build will fail. (You will likely run into issues trying to build the cross-compiler using clang.)
On macOS High Sierra: you will need to install gcc (as opposed to using the gcc alias on modern macOS that is just an alias for clang). Because of various design choices made in the implementation of gcc (mixing of C and C++ conventions for source file name extensions), you will need to have a separate g++ binary that treats its input as either a C++ source or a C++ object file. (You won't be able to get away with calling gcc with -x c++ -lstdc++ -shared-libgcc.) One version of gcc that fulfills this requirement is gcc version 4.9. MacPorts no longer installs separate binaries for gcc versus g++, so you will need to use Homebrew (or some other alternative) to install gcc-4.9 and to set the TOOLCC and TOOLCXX appropriately to this gcc-4.9 (more details below).
On macOS Mojave: you need to explicitly install the development headers using
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg.
Edit conf/setup.conf and set SUNFLOWERROOT, TOOLCC, and TOOLCXX appropriately. You will need to set your $OSTYPE environment variable in your shell if it is not already set. Examples include darwin for MacOSX, and the eponymous OpenBSD, linux, and solaris. You will also need to set MACHTYPE. A common correct value (depends on your host platform) is i386.
-
Add
$SUNFLOWERROOT/tools/binto your path (substitute$SUNFLOWERROOTas appropriate). -
To build the cross-compiler, first populate
tools/sourcewith the appropriate source distributions for gcc, binutils, and newlib. There is a script intools/sourcewhich will automate this for you by downloading the files using wget, and then uncompressing. You can also manually download the above intotools/source. -
Due to some bugs in the
binutilsdocumentationtexinfofiles, which are caught by newer versions ofmakeinfo, you must make sure that your version ofmakeinfois older than 5.0 (or you can temporarily makemakeinfounexecutable so that the build skips generating the man pages). -
Next, type
make cross-superHormake cross-riscvto build the SuperH or RISC-V cross-compilers (ormake cross-allto build all the supported cross-compilers) from the root of the installation (the directory containing thisREADME.mdfile). That will start the process of configuring the aforementioned distributions to build the binary utilities, cross-compilers, and embedded C libraries, for all the supported architectures. See theMakefilefor the build targets to build just one of the cross-compilers. -
On Mac OS 10.5 and older versions of macOS, you may need to do
make cross-all CFLAGS=-Osinstead of justmake cross-allto prevent the build of the cross-compiler from generating.dylibdebugging symbol files, which currently causes many problems withautoconfrelated tools. -
If the cross compiler build fails due, e.g., to a difference in behavior between the
perlormakeinfoexpected by the GCC build versus what is on your system, you might be able to recover by going intotools/source/gcc-<version number>/objdir, runningmake install, then going totools/and completing the cross compilation by runningmake gcc-post; make newlib.