AROS self-compilation

Introduction

In April 2008 I got interested in AROS. It's an open source operating system aiming for compatibility with AmigaOS, working on variety of hardware platforms: i386, AMD64 and PowerPC, also as a hosted operating system on *nix systems. I was using AmigaOS before and remember reading some news about AROS in Polish "Amiga Magazyn" magazine long time ago, so I was very curious how far the project went.

First look at AROS

What I saw actually amazed me. AROS is currently almost completed and contains far more than AmigaOS. However it suffers from several problems, most important are in my opinion:

Currently AROS development sometimes reminds me of brownian motions - a little in this direction, a little in that, quite randomly overall. Official goal of AROS is to became compatible with AmigaOS 3.1, however I don't see much work in this area. There's a bounty system containing various task to be done that helps a little, but most of them are not related to AROS 1.0 roadmap. Lack of official releases is a source of frustration for the common users. Fortunately Paolo Besser is working on VmwAROS - preconfigured AROS distribution with the best available software included.

Initial work

I wanted to work on AROS self-compilation, however AROS Linux hosted version was not working on AMD64 hardware, so I decided to work on it first. After some time spent mostly with gdb I got it running and managed to remove a whole load of bugs related mostly to AMD64 increased pointer size not only in kernel, but also software packages like TCP/IP stack, Zune/MUI classes or AHI sound system.

Road to self-compilation

It's kind of funny fact that AROS being an AmigaOS-related system needs almost the whole GNU world to compile: not only gcc, make and binutils, but also coreutils, findutils, sed, bison/yacc, awk and more. AROS build system is quite complicated and to make things worse some packages have their own custom tools. For example there's a Perl-based sfdc tool required to compile AHI. There are also a few Python scripts used in the build system.

AROS has its C library and POSIX compatibility layer making it much easier to port *nix software, so I managed to complete or update ports of most of needed software pretty quickly. I've also decided to port new versions of some partially or completely broken packages. In the process many bugs in AROS POSIX layer were fixed and a dozen of missing functions was implemented. There was no gcc port working on x86-64 hardware, so I had to make one as well.

One of remaining dependencies was bash-compatible shell. Unix shells are complicated programs using many system functions not present in AROS POSIX layer, some of them currently almost impossible to implement (like fork). Luckily abc shell saved the day, I completed the AROS port of this project started by Markus Weiss and was ready to run configure scripts on AROS.

Configure starting
Configure starting
In the middle
In the middle
Finished without errors
Finished without errors

With configure scripts running correctly I could move to the actual build process. AROS build system is using MetaMake and GNU Make, so ports of these programs are necessary to self-compile AROS. MetaMake being rather simple program is not a problem to port. There's also GNU Make port to AROS, however it's based on AmigaOS Make port which uses Shell to run programs and doesn't fully support environment variables. It can't be used by the AROS build system in the current state, but after some changes (like launching all programs with abc-shell) I managed to use it to build some packages on AROS and run initial part of AROS build process. Here you can see some screens showing it running:

Generating mmakefiles
Generating mmakefiles
Copying includes
Copying includes
Building Exec
Building Exec

There was still some serious work needed to make AROS self-compilation possible. First of all, port of Python was needed, because AROS build system contains genmf tool written in Python (there's also C version, but only Python version is being maintained now), also several Python scripts are used to generate headers for AboutAROS. Python port for AROS already exists, however it's very old, not maintained, and it doesn't work on x86-64 architecture.

Another requirement was a Perl port. A tool called sfdc written in Perl is used to generate AHI headers, Perl is also used by Autotools. I tried to adapt AmigaOS4 Perl port created by Andy Broad to AROS, but it's using AmigaOS4 pthread library which makes it non-trivial to port.

Instead of creating native port of Perl I decided to implement vfork() function in AROS POSIX compatibility layer that would allow to compile Perl without major changes in its sources. I also had to implement wait() and complete waitpid() function to allow access to child exit statuses in parent process. Thankfully there was already some functionality present in AROS exec.library implemented seven years ago by Iain Templeton in a form ChildStatus() and ChildWait() functions that considerably reduced the amount of needed work (thanks Iain!). With process management functions implemented I spent a few days hunting bugs connected with various quirks of AROS C library. For example I had to create new pipe handler that sole purpose was to emulate Unix pipes. AROS pipes couldn't be used for this, as they are not buffered and writing to pipe is blocking if there is no process reading the other end of the pipe. Then I finally managed to build Perl on AROS and successfully use it in AROS build process. Porting Autotools after all that work was simply a pleasure.

Encouraged by the successful port of Perl I quickly replaced my dirty GNU Make port with the current Make version using new process management functions and then I was ready to continue my self-compilation journey. The next stop was Python. Amazingly it took only one day to port the current stable version (2.5.2) of Python to AROS. I made it static, without any support for loadable dynamic extensions, but it's more than enough for scripts used in the AROS build process.

With major obstacles removed and some minor flaws in bison and m4 ports fixed it was finally possible to compile AROS on AROS. The resulting build was somewhat buggy, but the build process itself completed successfully. In the meantime some problems appeared with my vfork() implementation caused by GCC optimizer interacting with stack switches, but one morning after a flash of genius I rewrote vfork() and managed to make it much simpler and more reliable.

I've spent the following weeks hunting for bugs and making all ported software working on native i386 AROS. I also found and fixed some problems with file descriptor handling in AROS C library. There was some code duplicating file handles opened in write mode there, while it's actually possible only in ram.handler and emul.handler. It resulted in problems with redirecting standard output and error, so I had to reorganize relevant parts. This code is already commited to AROS SVN and should fix problems with redirecting standard streams to files.

Last bigger work needed for self-compiling AROS was implementing soft link support in dos.library and AROS filesystems. My modifications done to AmberRAM were sent to its author, Neil Cafferkey, who is currently working on completing soft link support. In SFS this feature was in pretty good shape and only minor fixes were needed.

All code related to AROS Self-Compiling bounty is already commited to the AROS repository, it's now possible to build AROS by using the AROS nightly builds and few additional packages from The AROS Archives: Perl, Python, Automake, Autoconf and LZO.

Below you can see some screenshots showing finished build process and some utilities executed to verify the correctness of the resulting binaries.

Calculator is working.
Calculator is working
What time is it?
What time is it?
It lacks some "built on AROS" info.
It lacks some "built on AROS" info.

Complete list of created or modified ports is shown below.

Package name and versionWork doneCommited
gawk 3.1.3Fixed problems in existing portyes
grep 2.5.1Fixed problems in existing portyes
netpbm 10.26.53Ported pngtopnm and ppmtoilbmyes
sed 4.1.5Created new portyes
coreutils 6.9Created new portyes
findutils 4.2.31Created new portyes
gcc 4.1.2Created new port based on existing portsyes
abc shellCompleted existing portyes
Make 3.81Created new portyes
LZO 2.03Created new portyes
perl 5.7.2Created new portyes
Python 2.5.2Created new portyes
Bison 1.875Fixed problems in existing portyes
automake 1.9.6Created new portyes
autoconf 2.62Created new portyes
gzip 1.3.12Created new portyes
tar 1.18Created new portyes

Some changes had to be made also to host-side software distributed with AROS source code. Here's the table showing modified packages:

Package name and versionWork doneCommited
fd2inline 1.37Fixed problems with building on AROSyes
fd2pragma 2.164Fixed problems with building on AROSyes
cxref 1.5gFixed problems with building on AROSyes

Last but not least, here's the list of functions implemented in arosc.library along the way (in order of appearance):

[1] only the function stub was created.

AROS self-compilation demo CD

Here you can download ISO images of AROS Live CDs containing software ported during my work on AROS Self-Compiling bounty along with other programs needed to compile open source software (including AROS itself) on AROS. They were created to demonstrate opportunities opened by these ports, but currently it's already possible to build AROS by using AROS nightly builds. I'm leaving these demo CDs available to download just in case anyone found them useful.

Self-compiling in RAM Disk

This live CD is intended for building software in RAM Disk (modified AmberRAM). Check the next section if you are interested in building AROS on SFS partition.

Click here to download AROS RAM Disk self-compilation demo CD (zip archive, 115 MB)

Currently you can use this Live CD to build AROS, Perl and Python in RAM Disk. Sources and patches are already included on CD. You will need at least 256 MB of RAM to build Perl or Python and at least 512 MB to build AROS. Run AROS Shell and then:

Building Perl or Python takes about half an hour in VMware Player running on Opteron 270 (2 x 2GHz). Complete AROS build in RAM takes about 6 hours in VMware Player running on the same hardware. For the sake of comparison, building AROS on i386 Linux running in the same VMware Player takes about 20 minutes. Building AROS in RAM on real hardware takes about 4 hours on Athlon 64 X2 4400+ 2.3GHz (reported by Nikolaos Tomatsidis).

Self-compiling on SFS partition

For people that would like to try building AROS on SFS partition I created another version of the live CD.

Click here to download AROS SFS self-compilation demo CD (zip archive, 115 MB)

This version won't allow you to build AROS in RAM Disk. It's intended for installing on SFS partition and building AROS there. Follow these steps to compile AROS on SFS partition:

  1. Download this CD and use it to install AROS on single SFS partition. Make sure to include development software in the installation.
  2. Boot AROS from the SFS partition.
  3. For maximum performance you can increase SFS cache and number of DOS buffers. I used the following commands:
    SetCache dh0: 1024
    AddBuffers dh0: 99900
    
    Of course you have to replace dh0: with your partition device.
  4. Run AROS Shell and execute the following commands:
    bin:sh
    cd /SYS/Development/Sources
    ./build_AROS.sh
    
    AROS sources will be unpacked to AROS-20081027-source directory on your partition and built there.

Building AROS on SFS partition takes nearly 5 hours in VMware Player running on Opteron 270 (2 x 2GHz). On real hardware it's much faster, Nikolaos Tomatsidis reported compilation time 1 hour and 20 minutes. Olivier Tigréat self-compiled AROS running in QEMU Emulator executed on PowerPC Linux. In this case building took almost 50 hours, well done Olivier!

Known problems with these Live CDs

Please let me know if you have any problems self-compiling AROS.