How to build AmigaOS4 cross-compiler (binutils 2.23.2 & gcc 8.2.0) on MSYS2.

  • up
    60%
  • down
    40%

...Intro...

IMAGE(http://kas1e.mikendezign.com/aos4/cross_compiling/msys2/images/gcc.png)

The advantage of having up2date crosscompiler for amigaos4 probably have no needs to explain, as everything move forward, and even on amigaos4 we had to move even by small steps. While for having cross-compiler at all there is very good reassons: speed and ability to use all range of helpfull tools such as cmakes,autoconf and scripting languages, but for having updated cross-compiler there is even more reasson: ability to use c++XX till c++17, thread support in c++XX, bugfixes (and new bugs, of course:) ) and all the fancy stuff which come with new gcc. Some opensource projects even can't be compiled anymore on the dated and old compilers (like 4.x series).

While some projects can be fixed for backward compatibility, some of them heavy use new features which impossible to rewrite in accepted timeline. So having up2date version is always better. For those who curious what new in gcc8.2, there is brief list of changes: https://gcc.gnu.org/gcc-8/changes.html

The man who make it possible to have gcc on amigaos4 are Sebastian Bauer (sba1), who maintain adtools project at https://github.com/sba1/adtools/, which aims is to provide a number of tools that can be used to develop applications for AmigaOS and Amigaoid systems. But at the moment only the version for the amigaos4 are mostly maintained and in a relatively good shape, which is kind of expected as maintain alone everything for every possible platform are nightmare, so there is mostly all for aos4. So.. hats of to Sebastian !

IMAGE(http://kas1e.mikendezign.com/aos4/cross_compiling/msys2/images/adtools.png)

Before, i use crosscompilers on Cygwin/Windows and on Linux, but this time i have some HP notebook / icore 3ghz with windows10 onboard (which i take for fast emulation of WinUAE/OS4_FE classic, to be able to do tests not only on x5000 and my old trusty pegasos2 , but also on some classic setup, even if it emulated). And lately i was in needs to have there something fresh for crosscompiling work, and there was 2 ways: or Cygwin again, or something else :) Cygwin was tested very well by me, and while it doing all the stuff well once you setup everything you need, i still didn't like the way how it maintain deps and i just want something more lightweight, different and new. And i choice MSYS2 : https://www.msys2.org/

IMAGE(http://kas1e.mikendezign.com/aos4/cross_compiling/msys2/images/msys2.jpg)

As said on their site:

At its core is an independent rewrite of MSYS, based on modern Cygwin (POSIX compatibility layer) and MinGW-w64 with the aim of better interoperability with native Windows software. It provides a bash shell, Autotools, revision control systems and the like for building native Windows applications using MinGW-w64 toolchains. It features a package management system to provide easy installation of packages, Pacman. It brings many powerful features such as dependency resolution and simple complete system upgrades, as well as straight-forward package building.

So if you like it, you can follow instructions from their site to download and install it.

...Prepare for compiling...

For compiling cross-compiler, you will need native compiler first :) So you install everything you might think of: gcc, make, autotools, cmake, git, subversion, flex, bison, python, perl, etc, etc. Its all can be done via Pacman utility via running it over the msys2 console, so it mostly like apt-get, yum or anything of that sort.

Firstly, when you first time run the msys32.exe or msys64.exe (depend on what you want to use, 32 or x64 verions), you run "pacman" for update all the stuff you already have after initiall installation of MSYS2:

# pacman -Syuu

And you repeat those steps until everything will be updated.

Then, we need to install all that developing stuff about which i told before, and that can be done easyly by that line for example:

# pacman -S --needed base-devel mingw-w64-i686-toolchain mingw-w64-x86_64-toolchain python git subversion mercurial mingw-w64-i686-cmake mingw-w64-x86_64-cmake

All the necessary dependencies (like bisons,flex, etc) will be installed automatically. But if something will be missed later, you can always install it separately via the same pacman tool.

...Get ready for crosscompiler...

Now to the most interesting part: actuall compilation of our amigaos4 crosscompiler. All you need is follow steps on Sebastian's adtools page,i.e:

  1. $ cd /
  2. $ mkdir /amiga
  3. $ cd /amiga
  4. $ git clone https://github.com/sba1/adtools
  5. $ cd adtools
  6.  
  7. $ git submodule init
  8. $ git submodule update
  9.  
  10. $ gild/bin/gild clone
  11. $ gild/bin/gild checkout binutils 2.23.2
  12. $ gild/bin/gild checkout gcc 8

At this step we have downloaded everything we need from adtools repo, and what we need next, is to actually build it.

I for myself build it also with support of objc and obj-c++. Not that its _that_ necessary to have for us, but sometime some stuff want it, so why not. Sebastian of course alone can't mantain everything, and so support of objc and obj-c++ will be "as it", but i see in issues on adtools repo, that Midar was able to build it, and test it by https://github.com/ObjFW/ObjFW where all compiles well and all tests passed, so at least it works in some form already.

For enabling it, i had to change a bit /amiga/adtools/gcc build/features.mk file, by changing that:

--enable-languages=c,c++

on that

--enable-languages=c,c++,objc,obj-c++

And nothing else need it.

Also you can see in the same features.mk file, that there is now --enable-threads=amigaos. This is new feature Sebastian add few months ago, for making c++XX threading works (yeah, this is _THAT_ "threading" about which we ask for 10 or how many years :) ) There is new option "-athread=", where you can choice from 3 options: native (so amigaos4 native implementation,without relying on pthreads at all), single (as it was before for us) and pthread (that one currently didn't work, probably will at some point, but not for now).

...Let's do it...

Now, before we will call "make" and to avoid issues in the process, we firstly will fix some cosmetic issues because of MSYS2.

1. You will have no "lha" installed for sure, which needs to unpack data from SDK archive (which will be auto downloaded from hyperion's site), so do it:

  1. cd /amiga
  2. git clone https://github.com/fragglet/lhasa
  3. cd lhaasa
  4. ./autogen.sh
  5. make
  6. make install

2. MSYS2, do not have needs for "-ldl", and so dind't have it, but building process want it, so we build wrapper which written specially for (for more information about go to the github page):

  1. cd /amiga
  2. git clone https://github.com/dlfcn-win32/dlfcn-win32.git
  3. cd dlfcn-win32/
  4. ./configure
  5. make
  6. make install
  7. ln -s /mingw/lib/libdl.a /mingw32/lib/libdl.a
  8. ln -s /mingw/lib/libdl.a /mingw64/lib/libdl.a

3. MSYS2 (and in whole mingw) , have some issues with absolute patches. I.e. /usr in reality are d:/msys64/usr (or where you installed msys2, point is that it mix of win32 and unix path), so sometime, some includes, or apps, which use some functions which others don't, want it as "real" path (with win32 part at begining). So, to fix issues which may come because of it (and they will, if you didn't fix), we in /amiga/adtools/gcc-build/Makefile, change that:

REAL_SRC_DIR=$(realpath $(SRC_DIR))

on that:

REAL_SRC_DIR=d:/msys64$(realpath $(SRC_DIR))

Taking in mind that its "d:/msys64" where we install MSYS2, so path can be different for you, of course.

Also there will be issues with the @include directive in the *.texi files, so, we just doing that:

cp /amiga/adtools/gcc/repo/gcc/doc/include/* /amiga/adtools/gcc/repo/gcc/doc/
cp /amiga/adtools/native-build/gcc-cross-build-8.2.0/gcc/gcc-vers.texi /amiga/adtools/gcc/repo/gcc/doc/

And that should be enough (at least for me is). If, through, you will see any error from any .texi file, saying that from @include some file can't be found, just replace it with full path, or copy necessary file to that directory.

Then, at last, run the magic line to build and install our os4 crosscompiler.

# make -C native-build gcc-cross CROSS_PREFIX=/usr/local/amiga

It will take a while, so you better add -j2 or -j3 to do parallel building and to speed things up. But once it done, we just issue our magic "export PATH=/usr/local/amiga/bin:$PATH" for make system know where to find amigaos4 compiler binaries (and that line better to add to the /home/user/.bashrc file, so you will have no needs to worry anymore about)

Done !

IMAGE(http://kas1e.mikendezign.com/aos4/cross_compiling/msys2/images/cross_ready.jpg)
(press open image in new tab for full size)

Some test code now:

  1. #include <stdio.h>
  2. void main()
  3. {
  4. pritnf("gcc 8.2.0\n");
  5. }
  6.  
  7. $ ppc-amigaos-gcc test.c -o test

IMAGE(http://kas1e.mikendezign.com/aos4/cross_compiling/msys2/images/test1.jpg)
(press open image in new tab for full size)

Going a bit heavy (c++11 and threading via Sebastian's native implementation):

  1. #include <iostream>
  2. #include <thread>
  3.  
  4. //This function will be called from a thread
  5.  
  6. void call_from_thread() {
  7. std::cout << "only 1200, only hardcore" << std::endl;
  8. }
  9.  
  10. int main() {
  11. //Launch a thread
  12. std::thread t1(call_from_thread);
  13.  
  14. //Join the thread with the main thread
  15. t1.join();
  16.  
  17. return 0;
  18. }
  19.  
  20. $ ppc-amigaos-g++ -athread=native test2.c -o test2

IMAGE(http://kas1e.mikendezign.com/aos4/cross_compiling/msys2/images/test2.jpg)
(press open image in new tab for full size)

...Outro...

That all, hope it will help someone. Even if one of our (or even new?) developers will find if helpfull, that will mean i write that for reasson :)

Tags: 

Blog post type: