During my adventures with porting Torque I have been using a variety of different build environments. First I was working natively on my Amiga, but compile times were horrible on my AmigaOne. So I decided to try cross compiling instead.

Windows and cygwin

My first choice was to try it on Windows with Cygwin installed. Building the cross compiler and building software for Amiga was easy simply follow the instructions from adtools.

Besides the speed up in compile time, another nice feature of cross compiling is, that you are able to run configure scripts. But if you try this, you will run into a performance issue with Cygwin. Cygwin is slow at creating new files and opening files and starting executables, unfortunately this is what a configure script does a lot of inorder to determine compiler features, hence configuring can be terribly slow. Actually you will see this already when building the cross compiler as it takes a long time.

Which made me decide to try something else.

OSX Lion

I could of course have chosen to try cross compiling under Linux, but my main computer, that is not an Amiga, is my Mac Book Pro, where I run both Windows and OSX. Before deciding to try cross compiling I had just updated OSX to Lion and XCode to 4.1, so that is what I had to work with.

What I did was to download the tar file for trunk in the svn repository and the tar file for gcc 4.5 in the branches in the svn repository.

I then setup my directory structure in the same way as the adtools svn repository:

  • adtools
  • –branches
  • —-gcc
  • ——4.5.x
  • –trunk

Simply follow the instruction to build the binutils, there was no problem building those.

Then go into adtools/trunk/gcc-build and change the following lines in the Makefile

SRC_DIR=../../branches/gcc/4.5.x
VERSION=4.5.x
DEST_DIR=cross-$(VERSION)
PREFIX=/usr/local/amiga
#BUILD=i686-pc-linux-gnu ## for some reasons configure script of gcc 4.2.4 doesn't identify the correct build type

Now simply type make and your cross compiler should build, but on OSX Lion with XCode 4.1 that is unfortunately not the case.

To clang or not to clang?

By default with XCode 4.1 the installed gcc uses clang which turned out to be a problem. While configuring the cross compiler I would always get this error:

configure: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details.

I inspected config.log and found this:

conftest.c:16:1: internal compiler error: in execute_ipa_pass_list, at passes.c:1800
Please submit a full bug report

That is really strange and the code in conftest.c looks absolutely fine, but after spending some time on Google I found more people with the same problem and one actually had a solution and an answer to the questions above, which is it not to clang.

So instead of simply typing make inside the gcc-build folder type:

CC=/usr/bin/gcc-4.2 CPP=/usr/bin/cpp-4.2 CXX=/usr/bin/g++-4.2 LD=/usr/bin/gcc-4.2 make

Will it build?

No, it will not. Now I got compile errors like this:

../../../../../branches/gcc/4.5.x/libiberty/physmem.c:52:25: fatal error: sys/sysctl.h: No such file or directory
compilation terminated.

I found this very strange. Usually configure detects missing headers and sets some defines to change code paths. It is correct that sys/sysctl.h is not part of clib2 but looking at the configure log shows that it is able to find sys/sysctl.h.  I still do not know why this happens or if it is caused to explicitly setting of CC and the others, but I do know that sys/sysctl.h is found among the standard headers of OSX.

My fix for this was to remove any references to sys/sysctl.h in /adtools/branches/gcc/4.5.x/libiberty/configure which made the build go further but more headers where mistakenly being found. I ended up removing references to:

  • sys/sysctl.h
  • sys/file.h
  • sys/params.h
  • alloca.h

Now it would build and I have successfully used it to build programs for my Amiga.

Notes

I am not sure I have found the right solution but it works for me. If some one knows of a better solution for not getting the wrong headers please let me know.

It should also be noted that there is a bug in the spec file for gcc which prevents C++ code to link correctly for Amiga OS, this can be fixed by explicitly linking with the C++ libraries like this:  -lstdc++ -lgcc_eh

Have fun writing programs for Amiga on OSX.