Amiga-Development

Please login or register.

Login with username, password and session length
Advanced search  

News:

Created for developers of all Amiga camps

Author Topic: Installing an AmigaOS 4 cross compiler  (Read 2821 times)

0 Members and 1 Guest are viewing this topic.

adminZRt75

  • Administrator
  • Hero Member
  • *****
  • Posts: 590
    • View Profile
Installing an AmigaOS 4 cross compiler
« on: December 24, 2012, 01:54:26 PM »

Installing an AmigaOS 4 cross compiler
by Nicolas Mendoza (utilitybase)

Joachim Birging has made a really nice work on compiling cross compilers of the adtools repository which makes is really useful for people not with an AmigaOS 4 system around. This tutorial will show you step by step how to install a cross compiler on a Linux system with all needed files to make AmigaOS applications.

The Amiga cross compilers have a tradition of residing in /usr/local/amiga. The /usr/local dir is meant for applications and data locally added applications for instance not part of a package management repository or similar, so it makes sense, but it does mean however that you need root access (or at least write access to the /usr/local directory) to add a cross compiler suite to your computer.

Of course it's possible to install such a suite on your on home directory or elsewhere, but then you need to alter the paths used by the compiler and that requires a recompilation (almost, check further down for instructions.)

Also if you are the impatient type all the commands in one script are available at the end of this article.

Download
Let's just download stuff to your home dir. These are quite big packages so you might want to get a snack while they download, depending on their bandwidth. Something like this will fetch them for you:
cd ~
# first we download the cross compiler and binutils packages
wget http://cross.zerohero.se/i686-linux/ppc-amigaos-binutils-2.14.tar.bz2
wget http://cross.zerohero.se/i686-linux/ppc-amigaos-gcc-4.2.0.tar.bz2
# then we download the AmigaOS 4 SDK, we only need the small version with
# includes, similar stuff that the old NDKs provided basically.
wget ftp://ftp.hyperion-entertainment.biz/AmigaOS4_SDK/SDK_51.22-nocontrib.lha




Extracting
Let's extract the cross compiler and the corresponding binutils package to our /usr/local/amiga path. As you might have seen, the packages inside start with an amiga/-path so let's unpack them straight into /usr/local.
cd /usr/local
# need to become root to have right access, type in password
sudo -s || su
tar xjvf ~/ppc-amigaos-binutils-2.14.tar.bz2
tar xjvf ~/ppc-amigaos-gcc-4.2.0.tar.bz2




Next we need to prepare a directory hierarchy where we will put the AmigaOS 4 includes and third party libraries and includes. Also clib2 and newlib files will go there.

To easen the combined use of the SDK from both AmigaOS 4 natively and from other systems like a cross compiler a directory called SDK inside /usr/local/amiga/ppc-amigaos/SDK is made.

Unfortunately the files from the SDK are made for AmigaOS and they have some mixed uppercase and lowercase letters in some directoried. The paths GCC are told to use unfortunately are all lower case, so we have to fix this.
#create the SDK directory
mkdir amiga/ppc-amigaos/SDK
# unpack base.lha and clibs.lha from the SDK archive to a temporary dir.
lha -xw=/tmp ~/SDK_51.22-nocontrib.lha SDK_Install/base.lha SDK_Install/clibs.lha
# enter SDK directory
cd amiga/ppc-amigaos/SDK
# unpack includes from SDK base.lha archive
lha x /tmp/SDK_Install/base.lha Include*
# Make a link from all-lowercase to mixed-case "Include"
ln -s Include include




Now install the clib2 and newlib libraries by doing the following:
# unpack clib2 and newlib libraries from SDK
lha x /tmp/SDK_Install/clibs.lha




Great, now let's check that it works. First we set the path to also include the bin directory inside /usr/local/amiga, then we build an Amiga executable and check if it looks right.
export PATH=$PATH:/usr/local/amiga/bin
which ppc-amigaos-gcc
echo "int main(void) {return 0;}" | ppc-amigaos-gcc -xc - -o /tmp/ppc-amigaos-test-exec
file /tmp/ppc-amigaos-test-exec




You should basically be ready now, but the next section goes slighly more in-depth to the dir hierarchy in the SDK dir, and how you can make sure all dirs are there in case you need them later.

Being specific about it
To find out exactly how the hierarchy shall look like, we can take a peek at what paths gcc expects to exist by dumping its specification.
ppc-amigaos-gcc -dumpspecs




which prints out a lot of text, we will concentrate on some parts of it. Take at look at
*base_gcc:
/usr/local/amiga/

*base_sdk:
/usr/local/amiga/ppc-amigaos/SDK/




This is our clue, we need to find all the dirs that are expected to be found inside the SDK dir. The base_sdk line in the ouput basically stores that path to a variable, so we look out for it in the rest of the output. By doing a bit of black magic with perl (basically replacing all variables defined in the spec file making them slightly more human readable, then extracting all paths related to /usr/local/amiga/ppc-amigaos/SDK/ and sorting and printing them)
ppc-amigaos-gcc -dumpspecs | perl -le 'local $/ = undef; my %a; $_=<>; while (/^\*(.*?):\n(.*?)\n\n/msig) { $a{$1} = $2} while (s/%\((.*?)\)/($a{"$1"} ne ""?$a{"$1"}:"-$1-")/emsig) {}; s/([:;]) /$1/msig; s/-L//msig; while(m!\b/SDK/(\S*)!msg) { s/%.*//; print $1; }' | sort | uniq




we get:
clib2/
clib2/include
ixemul/include
ixemul/lib
libnix/include
libnix/lib
local/clib2/include
local/ixemul/include
local/libnix/include
local/newlib/include
newlib/include
newlib/lib




(You might notice that there is no clib2/lib dir, but that's probably the perl magic not being 100% correct.)

By peeking in the dumpspecs output we also notice that the lib dirs have subdirs depending on some variable sets. I'll let you take a look yourself if you are really interested, but they are basically: soft-float, small-data and baserel.

So, we make the dirs we need:
for dir in /usr/local/amiga/SDK /usr/local/amiga/SDK/local;
do
mkdir $dir
cd $dir
# common dir to put libs and includes that don't need any special c library
mkdir -p common/include
mkdir -p common/lib
mkdir -p common/lib/soft-float
mkdir -p common/lib/small-data
mkdir -p common/lib/baserel

# Olaf Barthel clib2 C library related
mkdir -p clib2/include
mkdir -p clib2/lib
mkdir -p clib2/lib/soft-float
mkdir -p clib2/lib/small-data
mkdir -p clib2/lib/baserel

# Old BSD kernel emulation C library related
mkdir -p ixemul/include
mkdir -p ixemul/lib
mkdir -p ixemul/lib/soft-float
mkdir -p ixemul/lib/small-data
mkdir -p ixemul/lib/baserel

# Old libnix.a related
mkdir -p libnix/include
mkdir -p libnix/lib
mkdir -p libnix/lib/soft-float
mkdir -p libnix/lib/small-data
mkdir -p libnix/lib/baserel

# Red Hat's newlib C library related
mkdir -p newlib/include
mkdir -p newlib/lib
mkdir -p newlib/lib/soft-float
mkdir -p newlib/lib/small-data
mkdir -p newlib/lib/baserel
done




The dirs should be pretty self-explanatory, but use the local ones for your own and third-party libraries and includes, and let the others be used for official newlib and clib2 (and ixemul and libnix) distributions.

For more information about the specs file, check out "info gcc" and type "g Spec Files"

Installing cross compiler suite elsewhere
As I mentioned in the beginning it's not trivial to place the SDK in a different path than /usr/local/amiga, however it's not rocket science, and you don't need to recompile gcc if you are prepared to add a parameter to any ppc-amigaos-gcc call you do. As you noticed the -dumpsecs parameter contains base_gcc being /usr/local/amiga and base_sdk being /usr/local/amiga/ppc-amigaos/SDK. If you save the dump to a file, and alter those paths to your liking, you can tell gcc to use your custom specsfile by using
ppc-amigaos-gcc -specs=/path/to/specsfile




Stop blabbering, give me the stash
If you are the lazy type, you are surely not interested in my carefully written explanationas and just want to get on with it. Here is the whole process in one script, make it executable and just run it.
#!/bin/sh
cd ~
# first we download the cross compiler and binutils packages
wget http://cross.zerohero.se/i686-linux/ppc-amigaos-binutils-2.14.tar.bz2
wget http://cross.zerohero.se/i686-linux/ppc-amigaos-gcc-4.2.0.tar.bz2
# then we download the AmigaOS 4 SDK, we only need the small version with
# includes, similar stuff that the old NDKs provided basically.
wget ftp://ftp.hyperion-entertainment.biz/AmigaOS4_SDK/SDK_51.22-nocontrib.lha
cd /usr/local
# need to become root to have right access, type in password
sudo -s || su
tar xjvf ~/ppc-amigaos-binutils-2.14.tar.bz2
tar xjvf ~/ppc-amigaos-gcc-4.2.0.tar.bz2
#create the SDK directory
mkdir amiga/ppc-amigaos/SDK
# unpack base.lha and clibs.lha from the SDK archive to a temporary dir.
lha -xw=/tmp ~/SDK_51.22-nocontrib.lha SDK_Install/base.lha SDK_Install/clibs.lha
# enter SDK directory
cd amiga/ppc-amigaos/SDK
# unpack includes from SDK base.lha archive
lha x /tmp/SDK_Install/base.lha Include*
# Make a link from all-lowercase to mixed-case "Include"
ln -s Include include
# unpack clib2 and newlib libraries from SDK
lha x /tmp/SDK_Install/clibs.lha
for dir in /usr/local/amiga/SDK /usr/local/amiga/SDK/local;
do
mkdir $dir
cd $dir
# common dir to put libs and includes that don't need any special c library
mkdir -p common/include
mkdir -p common/lib
mkdir -p common/lib/soft-float
mkdir -p common/lib/small-data
mkdir -p common/lib/baserel

# Olaf Barthel clib2 C library related
mkdir -p clib2/include
mkdir -p clib2/lib
mkdir -p clib2/lib/soft-float
mkdir -p clib2/lib/small-data
mkdir -p clib2/lib/baserel

# Old BSD kernel emulation C library related
mkdir -p ixemul/include
mkdir -p ixemul/lib
mkdir -p ixemul/lib/soft-float
mkdir -p ixemul/lib/small-data
mkdir -p ixemul/lib/baserel

# Old libnix.a related
mkdir -p libnix/include
mkdir -p libnix/lib
mkdir -p libnix/lib/soft-float
mkdir -p libnix/lib/small-data
mkdir -p libnix/lib/baserel

# Red Hat's newlib C library related
mkdir -p newlib/include
mkdir -p newlib/lib
mkdir -p newlib/lib/soft-float
mkdir -p newlib/lib/small-data
mkdir -p newlib/lib/baserel
done

export PATH=$PATH:/usr/local/amiga/bin
which ppc-amigaos-gcc
echo "int main(void) {return 0;}" | ppc-amigaos-gcc -xc - -o /tmp/ppc-amigaos-test-exec
file /tmp/ppc-amigaos-test-exec



Rate this item
Logged