Building a cross-compiler for MIPS target on Mac OS X host fails
I was able to build a cross-compiling GHC on a Ubuntu 16.04 host with just a few changes to the source code (see this article I wrote about it, the necessary source code changes are in the GHC/Haskell section: https://medium.com/\@wereHamster/cross-compiling-for-the-onion-omega-1cf8ee80df02)
Replicating the necessary steps on my Mac OS X laptop didn't work. The build system doesn't clearly distinguish between CPP/C/LD flags required by the host and target compilers (which in my case are quite different, clang for the host and gcc for the target).
The C/LD flags determined by
--with-curses-includes/libraries are passed to both the host and target compiler. The host has ncurses installed in a standard search path (/usr), I used this option to let the build system know where a version of ncurses for the target is installed (required for the stage2 compiler I believe). The problem here is that the host compiler fails to build stage1 libraries/terminfo because it first finds the cross-compiled ncurses library in its search path and stops because it is incompatible. Maybe it's a peculiarity of clang that it doesn't keep on searching when it comes across the first library it can find, even though later in the search path there is one which is compatible. I was able to get past that by changing some makefile rules and pass the necessary options only when building the stage2 terminfo.
Similar issue is when wrong CPP options are passed to the pre-processor during building of stage2. The configure script adds
-m64 to CPP options (because the build host is x86_64 darwin). However, these options are then passed to the target compiler which doesn't understand
-m64. I tried to track down where exactly that happens but I was not able to find where (
addCFileDeps is who calls
$(CPP) with the wrong flags).