Partner sites: Aminet - Amiga downloadsIntuitionBase - Amiga guidesAmigaNN - Amiga newsAmiFund - Sponsor projects

[Y]UtilityBase
Your guide to Amiga development
Not logged in
  HomeProjectsForumArticlesResourcesLinksChatAbout 
Search
Login
Username:
Password:
Register now!
Forgot your password?
Aminet - Development
DECH.lha (dev/e)
ecxsrc.lha (dev/e)
powersdl_sdk.lha (dev/misc)
ADBs_Games_Vol2.lha (dev/amos)
ADBs_Games_Vol1.lha (dev/amos)
sdlgfx.i386-aros.zip (dev/c)
libmikmod-bin-m68k.lha (dev/lib)
custom-ti.lha (dev/gg)
audiofile-bin-m68k.lha (dev/lib)
murks.zip (dev/misc)
More...
Newest users
NJ2CIL (Chace K. Daggers)
smithy
Langolier
Will
tiffers (Collin)

Pending:
ZebraZeem, Mad_Dog, hhjoker
More...
Who's Online
Online members:


5 guests are online.

You are an Anonymous user. You can register for free by clicking here.
News sites
Amiga-News.de
Amiga.org
AmigaDev.net
AmigaNN
Amigans.net
Amigaweb.net
AmigaWorld.net
AROS-Exec
MorphOS-News.de
MorphZone
polarBoing
Tutorials
Installing an AmigaOS 4 cross compiler
Size does matter: Optimizing with size in mind with GCC
Spot's Porting Guide for Dummies 1.6.1 [UPDATED]
Building Amiga OS 4 GCC Cross Compiler for UNIX/MAC
Pointers and Arrays in C
More...
Sources
How to make clean picture datatypes
Most of the old ClassACT examples converted to OS4
AmigaAnywhere Tutorial - Part 2 Source window1.c
AmigaAnywhere Tutorial - Part 2 Source window2.c
AmigaAnywhere Tutorial - Part 2 Source window3.c
More...
Documentations
How to write portable code for Amiga (english)
Comment écrire du code portable pour Amiga (français)
Development How to with OS3.9 SDK
The PartyPack Hack
The Amiga PDA Programming Guidelines
More...
DreamHost

Support
UtilityBase

[Valid RSS]

UtilityBase needs your help!

Build Amiga GCC 3.3.3 Cross Compiler for Linux or Windows
by Troy Silvey

This tutorial will help build an Amiga GCC 3.3.3 cross compiler on Linux or Windows XP. I've sucessfully tested this doc on RedHat Linux and Windows XP. Other tutorials used GCC 2.95 and usually ended in failed builds for me, so I decided to do a new tutorial. Please send comments if you attempt a build or find an error. I also added a small bit on building a library and allocating chip memory with GCC.

All in One Classic Amiga C/C++ Dev System
Copyright Troy Silvey 2005
HTML and Doc versions ...
http://adsl-065-006-130-241.sip.asm.bellsouth.net/files

Please read this doc through a couple of times before attempting to use it. I may save some time and irritation later.
Consider this guide a beta document. It’s only been used successfully a few of times on specific hardware.
You should backup any important data on your system before continuing. I recommend starting with a new clean system
that you can afford to erase and start over if things don’t go well. But that would never happen, right? : )

This guide will help you build a development box based on Linux or WindowsXP. It uses the Cygwin Linux environment on WindowsXP to make and use a GCC cross compiler that cranks out Amiga 68k code for OS3.x or OS4.x. (Maybe even 2.x). It should be possible to follow this document and do a PPC compiler also using a TARGET=powerpc-amigaos, but I don’t have PPC yet to test. Add UAE (http://www.winuae.net) or (www.amigaforever.com) and you have a computer that can create, test and use Windows, Linux and Amiga apps. This guide will help you build the Amiga cross compiler on a Linux based system also if you prefer. Just ignore the Cygwin install section if you’re working on Linux.

Requirements
I’ve written this to help the newbie, but it expects you to know or learn many basics for the different OS’s, programming and compilers we’re using. All ofthat would be impossible to cover in these few pages.If you are a newbie, make sure to follow the instructions closely. You need to execute commands from the proper folders and have correct files in those folders to succeed. Miss a file or a directory change(cd) command and the build will probably fail. As the build progresses, many warning messages appear. These errors do not affect the build and are probably results of the “patched” amiga code that appears in some of the files. If you encounter a true error message however, that indicates the build has probably failed. There are a couple of error exceptions that I’ll mention as we go that don’t seem to harm the build.

So… you’re already an expert on Amiga  ,you grew up using Windows and you already know the basics of Linux and it’s text based editors.If that’s not the case, this project may be a bit over your head. But you can still learn a lot by trying it out. And there’s always plenty of help on the Amiga forums, web sitesand other books. If you build on Windows, you can use cut and paste editors like notepad making changes to the Cygwin Linux files easier if you’ve never used Linux text editors like Vi or Ed.

You’ll need a fast internet connection to install all the components. A slow connection will work, but may take hours to download Cygwin. You will need a fast PC with WindowsXP installed, 2gig free harddrivespace and 256meg memory. (Win9x or Millieum might work but aren’t tested). I started this project with a PII-350/128meg memory. It worked but was very very slow. A slower PC will be ok for GCC, but if you plan to install UAE, I recommend the fastest PC you can get. I’ve moved to a P4 1.6gig and that runs very nicely. This also takes a huge amount of HD space. Once the build was complete it used 1.7 gig. Your install make need more space. Some of that can probably be cleaned up later, but I haven’t bothered yet. Much of that spaced is used up by the Linux environment.If you build on a Linux system instead, you won’t need as much free harddrive space.

Last you will need several Amiga specific files that we can get from Aminet, geekgadgets and other links. It’s important as you follow the steps to make sure that the folders and files go into the proper locations. When it’s time to do the “makes” and compiles, the system will count on files being in certain locations. If your build fails, you might try backing up and making sure that all files and folders have been created moved and copied into the necessary locations.

Important – If for any reason you want to start over from scratch, you can delete the work folders while saving all of your downloaded files. Delete this list of folders, then start the instructions over again bypassing the download instructions. (I’ve done this 30-40 times while writing this doc  )

# rm -R ~/amigaos/build-binutils
# rm -R ~/amigaos/binutils-2.14
# rm -R ~/amigaos/build-gcc
# rm -R ~/amigaos/gcc-3.3.3
# rm -R ~/usr/local/amigatools


Getting Started:

1a.(Start here if you’re building on a WindowsXP system)
Ok you have Windows installed, you’re connected to the internet and ready to go. Cygwin installation is first on the list. You may want to read a bit about Cygwin and see what you’re installing. Check the home page at http://www.cygwin.com/ . Once you’re ready, this site …( Installing Cygwin ) has a great guide for installing Cygwin that chooses all of the same features that we need, so we’ll follow their lead. Follow the instructions on their page and especially pay attention to the instructions for installing the “Devel”, “Doc” and “Editor” options. You may want to print out the instructions so you can have them handy for quick reference as you work. It’s also important that we include BZIP2 from the Utils options and WGET from the Web options. Make sure to include them. We use these two utilities to download and install some of our software. Once the Cygwin installation is finished, you will have a new icon on your Windows desktop ready to run the Linux environment on your PC.If you did not install Cygwin on your C: drive, you will need to edit the file INSTALLDRIVE:\cygwin\cygwin.bat and change the line that reads‘C:’ to your actual drive letter, or the batch file short cut won’t launch Cygwin. Click on your new Cygwin icon and we’re at a text prompt ready for step 2.

1b. (Start here if you’re building on a Linux system)
This guide expects you to be working as a user other than root. Root normally does not have a home folder that we will be using to do much of our work. If you wish to work as root, then create a base folder to work from and adjust the commands in this tutorial as needed. While working as a normal user, there will be times we have to execute commands as Root or SU to root because a normal user does not have permissions to certain files and folders. The instructions will guide you when it’s time to SU to root or run a command as root. Each time we use root you will be prompted for the root password so be prepared to enter it.

If you have not already installed the development tools and libraries on your Linux system, you will need to do so. We will need the dev tools to build our Amiga cross compiler. For my system I used GCC 3.3.3. the GCC tools that come with your Linux are probably a different release. Try to stick with 3.x if you can. I have no way to tell if using a different version will cause a problem for you. I have seen posts where others have successfully built compilers using GCC 2.7, 2.95, 3.1, 3.2, 3.4 and EGCS 1.1.2, so you should be ok. You’ll need these basics installed…. binutils - gcc - gdb - make – mktemp - bison and the utilities bzip2 and wget.
** If you’re building on a Macintosh, WGET can be found at http://www.statusq.org/images/wget.zip
(Thanks to Mark Larsson for this and other tips)

2. (Steps from here forward are identical for either Windows or Linux)
Next we’ll create work folders in our home directory and download the needed source files. ~/ is equal to your home folder. In the following lines ‘#’ is your command line prompt so don’t type it. Your character may differ.

# mkdir -p ~/amigaos/build-binutils/m68k-amigaos
# mkdir -p ~/amigaos/build-gcc/gcc/include
# mkdir~/amigaos/gg-archives
# cd ~/amigaos


You should still be in the ~/amigaos folder, now download these files with Wget

# wget http://adsl-065-006-130-241.sip.asm.bellsouth.net/files/binutils-2.14-src.tar.bz2
# wget http://adsl-065-006-130-241.sip.asm.bellsouth.net/files/gcc-3.3.3-m68k-src.tar.bz2


Now unarchive them.

# bzip2 -dc binutils-2.14-src.tar.bz2 | tar -xf -
# bzip2 -dc gcc-3.3.3-m68k-src.tar.bz2 | tar -xf -


Download the following files from geekgadgets to the gg-archives folder:

# cd ~/amigaos/gg-archives
# wget http://gg.portail-e.com/geekgadgets/amiga/m68k/snapshots/current/bin/fd2inline-1.11-bin.tgz
# wget http://gg.portail-e.com/geekgadgets/amiga/m68k/snapshots/current/bin/ixemul-48.0-bin.tgz
# wget http://gg.portail-e.com/geekgadgets/amiga/m68k/snapshots/current/bin/ixemul-48.0-env-bin.tgz
# wget http://gg.portail-e.com/geekgadgets/amiga/m68k/snapshots/current/bin/ixemul-48.0-inc-bin.tgz
# wget http://gg.portail-e.com/geekgadgets/amiga/m68k/snapshots/current/bin/libamiga-bin.tgz
# wget http://gg.portail-e.com/geekgadgets/amiga/m68k/snapshots/current/bin/libnix-1.2-bin.tgz


Now they will be extracted them to the dir ~/amigaos/build-binutils/m68k-amigaos

# cd ~/amigaos/build-binutils/m68k-amigaos
# tar -xzf ../../gg-archives/fd2inline-1.11-bin.tgz
# tar -xzf ../../gg-archives/libamiga-bin.tgz
# tar -xzf ../../gg-archives/libnix-1.2-bin.tgz
# tar -xzf ../../gg-archives/ixemul-48.0-env-bin.tgz
# tar -xzf ../../gg-archives/ixemul-48.0-inc-bin.tgz
# tar -xzf ../../gg-archives/ixemul-48.0-bin.tgz


Make a folder where the finished executables will be created.
You need root permission to create folders in the /usr/local folder. SU to root ( su – root ) if necessary for these steps.

# su – root(Skip this step if building on Windows/Cygwin)
# mkdir -p /usr/local/amigatools/lib
# mkdir -p /usr/local/amigatools/m68k-amigaos/sys-include
# mkdir -p /usr/local/amigatools/m68k-amigaos/include/dos
# chmod -R 755 /usr/local/amigatools

If you had to SU to root for the last 4 steps, exit back to your normal account.

# exit (Skip this step if building on Windows/Cygwin)

Now we’ll set our PREFIX and TARGET variables used to build the utilities and compiler.

# export PREFIX=/usr/local/amigatools
# export TARGET=m68k-amigaos
# cd ~/amigaos/build-binutils


Now we can begin to create the 680XX Binary Utilities by running the configuration script. This command is shown on 2 lines, but is actually one single command. The ‘\’ (the continuation mark) says to continue my command typing on the next line. It makes code easier to read some times. You can cut and paste these lines into your command line directly from here, one line at a time. Leave out the # and be careful to stop at the ‘\’ and hit return after each line paste. If you paste the blank space after the ‘\’, it will enter an unwanted carriage return at the end and cause the script to execute wrong. If you make a mistake, just run it again.

# ../binutils-2.14/configure --target=$TARGET --prefix=$PREFIX --disable-nls \
--with-gnu-as --with-gnu-ld --with-headers=$PREFIX/m68k-amigaos/include


Configuration is done, now it’s time to build the source code for binutils. If you are building on a Linux system, make sure you have rights to install to your chosen directory (PREFIX). If you are installing on Linux, you may need to su to root to run the next commands if your current account doesn’t have sufficient rights. This will take 10-30 mins or more if you have a slower system.

# make(took about 3 minutes on my 1.8ghz AMD)
# make install (su –c ‘make install’ If working in Linux)


We’re ready to build the GCC cross compiler. We add the new binutils to the search path, and change to the build folder.

# export PATH=$PREFIX/bin:$PATH
# cd ~/amigaos/build-gcc


Run the configuration script for the GCC compiler. Once again you can cut and paste. Just follow the same guide lines as above with binutils.

# ../gcc-3.3.3/configure --target=$TARGET --prefix=$PREFIX --enable-languages=c,c++ \
--with-headers=$PREFIX/m68k-amigaos/include --with-gnu-as --with-gnu-ld


Now we need to edit the file ~/amigaos/gcc-3.3.3/gcc/config/m68k/amigaos.h
This commandassumes you know how to use the editor vi. If you’re using windows, you can use notepad/wordpad to edit the file.
In windows the path of the file will be …..
c:\cygwin\home\YOURHOMEFOLDER\amigaos\gcc-3.3.3\gcc\config\m68k\amigaos.h

#vi ~/amigaos/gcc-3.3.3/gcc/config/m68k/amigaos.h


In amigaos.h locate STARTFILE_SPEC section. This is where we find the line we need to edit.
( Use the search function in vi …. Esc /STARTFILE_SPECenter )
( If you make a mistake, you can exit with out saving with Esc q! enter)

#define STARTFILE_SPEC
"%{!noixemul:"
"%{fbaserel:%{!resident:bcrt0.o%s}}"
"%{resident:rcrt0.o%s}"
"%{fbaserel32:%{!resident32:lcrt0.o%s}}"
"%{resident32:scrt0.o%s}"
"%{!resident:%{!fbaserel:%{!resident32:%{!fbaserel32:"
"%{pg:gcrt0.o%s}%{!pg:%{p:mcrt0.o%s}%{!p:/crt0.o%s}}}}}}}"
"%{noixemul:"
"%{resident:libnix/nrcrt0.o%s} "
"%{!resident:%{fbaserel:libnix/nbcrt0.o%s}%{!fbaserel:libnix/ncrt0.o%s}}}"


We need to add our PREFIX/lib path to the /crt0.o entry. Locate and change this line…

"%{pg:gcrt0.o%s}%{!pg:%{p:mcrt0.o%s}%{!p:/crt0.o%s}}}}}}}"
( Arrow key to the position and use Esc I to enter vi’s insert mode )

When you are finished, the edited line should read …

"%{pg:gcrt0.o%s}%{!pg:%{p:mcrt0.o%s}%{!p:/usr/local/amigatools/lib/crt0.o%s}}}}}}}"

When you have the PREFIX path inserted, save the file and exit vi. ( vi save and exit - Esc wq! )

Now we need to move the crt0.o file into place.

# cp ~/amigaos/build-binutils/m68k-amigaos/lib/crt0.o /usr/local/amigatools/lib


Time to build the Amiga GCC executable with ‘make’ and install it with ‘make install’.
This part is tricky. Make is going to FAIL! the first time through. It is going to be looking for files that are not yet present. Once make fails, we will copy the needed files into place and rerun make. If we move the files in to place before the first pass, It’s possible they will get over written and cause make to exit with an error anyway. So we have to wait for the process to fail then put them in place.
# make

If you see this message about several minutes later (5mins on my 1.8Ghz), then make has failed as expected.
/home/tsilvey/amigaos/build-gcc/gcc/include/stddef.h:57:26: machine/ansi.h: No such file or directory
make[2]: *** [libgcc/./_muldi3.o] Error 1
make[2]: Leaving directory `/home/user1/amigaos/build-gcc/gcc'
make[1]: *** [libgcc.a] Error 2
make[1]: Leaving directory `/home/user1/amigaos/build-gcc/gcc'
make: *** [all-gcc] Error 2


Now it’s time to move the needed files in to the proper path and run make again. Make will pick up where it left off so it won’t take as long the second time. If a file already exist when we copy over the new files, you will be asked if you want to over write the current file. Always answer NO!! to the over-write prompt. There sould be 8 files we need to skip over.

# cp -ir ~/amigaos/build-binutils/m68k-amigaos/include ~/amigaos/build-gcc/gcc/
# cp ~/amigaos/build-binutils/m68k-amigaos/lib/libamiga.a~/amigaos/build-gcc/m68k-amigaos/lib
# make


The second time through make, it ends with the error message below. It doesn’t seem to harm any thing. Our new utilities and cross compiler have been created. (Seems odd to me, but I’m not a guru)

configure: error: installation or configuration problem: C
compiler cannot create executables.
make: *** [configure-target-libiberty] Error 1

Now it’s time to finish the build.

# make install (su –c ‘make install’ If working in Linux)
You can look to see if the new compiler is in place now.
# ls -l/usr/local/amigatools/m68k-amigaos/bin
Run gcc to show it’s working and that we have the correct version
# /usr/local/amigatools/m68k-amigaos/bin/gcc –v


You should find ….Configured with: ../gcc-3.3.3/configure --target=m68k-amigaos …among the information.

Now we need to move these amiga libraries into place so the new cross compiler can find them. Ifwe are building on Linux as a non-root user, we need to fix permissions so average users can get to the new folders.

# su - root (Skip if building on Windows/Cygwin)
# chmod -R 755/usr/local/amigatools (Skip if building on Windows/Cygwin)
# exit (Skip if building on Windows/Cygwin)
# cp ~/amigaos/build-binutils/m68k-amigaos/lib/libc.a /usr/local/amigatools/lib/gcc-lib/m68k-amigaos/3.3.3
# cp ~/amigaos/build-binutils/m68k-amigaos/lib/libamiga.a /usr/local/amigatools/lib/gcc-lib/m68k-amigaos/3.3.3


If we made it this far with out major errors, then we’re ready to work. The new compiler is located at
/usr/local/amigatools/bin/m68k-amigaos-gcc.exe I make a shorter symbolic link name for myself.

# cd /usr/local/amigatools/m68k-amigaos/bin
# ln -s ./gcc ./gcc68


This separates the new GCC 68K cross compiler from the local Linux GCC you just used to build GCC68.
(And helps end confusion for me)
Now add it to your path

# export PATH=$PATH:/usr/local/amigatools/m68k-amigaos/bin


You may also want to add this to your users login path by adding it to file .bashrcin your user home folder.
That way you don’t have to manually enter the path each time you log in.

Once the compiler is built, the paths to it’s libs and headers are hard-coded. So don’t move things out of the /usr/local/amigatools folder unless you’re really surethat you know what doing. To see the default setting and folder paths use the command

# gcc68 –v

We’re done building the executables, but we still have a few things to do to complete our development environment. First let’s test our new compiler on the famous helloworld.cI’ve used vi to create it in my home folder ~/helloworld.cIf you’re working on a windows platform, you can use anything like notepad to do the same. For our first test we need to put a copy of stdio.h into place.

# cp ~/amigaos/build-binutils/m68k-amigaos/include/stdio.h /usr/local/amigatools/m68k-amigaos/include/dos


Now let’s go back to our home folder, create a test file and compile it.

# cd ~/
# vi helloworld.c

Once you’re in vi editor, type in this sample code and save with the keystrokes Esc wq!

#include <dos/stdio.h>
int main(void)
{
printf("Hello World n");
return 0;
}

Let’s see if it works. This will compile the executable and try to optimize it. Trying to optimize this tiny program is not practical, but simply tests the compiler functionality.

# gcc68 -O -o helloworld -m68020 ./helloworld.c


If the compile fails for any reason, you can use this command to compile with verbose and error output. You can examine the output for clues to what is missing or broken. I used this to find a path that was incorrect.

# gcc68 -v ./helloworld.c –m68020 -Wl,--verbose 2> ldlog.txt
# vi ./ldlog.txt


If there were no errors, then we are almost ready to run the helloworld file on an Amiga for the final test. One last library file needs to be loaded on your Amiga. You need to download the ixemul library version 48.0 from aminet and put it in your Amiga’s Libs folder. You need this file whether you’re on a real Amiga or using UAE. The ixemul library makes the Amiga more POSIX compliant by adding additional library functions. This is needed to run the code generated by the POSIX compliant GCC compiler we’ve just built. The archive from aminet comes with different versions for different CPU’s.For our setup we need the 68020 version. Download, uncompress and copy the files into the Amiga LIBS folder. Rename the file from ixemul-020-fpu.library to ixemul.library. Here are a couple of locations to get the file, but you can choose another aminet mirror that works best for you.
http://main.aminet.net/util/libs/ixemul-48.0.lhaor
http://ftp.plig.org/pub/aminet/util/libs/ixemul-48.0.lha

Now copy the helloworld we compiled earlier to your Amiga by putting it in one of your UAE folders, (I chose a test folder on Work) or by using a network connection or floppy to move the file to your real Amiga. Now run it either from command line or by clicking it from your Amiga GUI. You should see a small window displaying the simple line “Hello World”. If you got this far, excellent! Now we will move the remaining Amiga Include and Header files to the cross compiler work area so you can start working on real projects.

Last we need to copy all the Amiga specific headers over to our new dev system. You can get these from the Amiga dev CD 2.1. Amiga.org used to host these files at http://www.amiga.com/3.9/download/NDK3.9. lha but removed it with out notice when their site was last updated. It is still available at the Aweb OpenSource project at address http://aweb.sunsite.dk/files/dev/NDK3.9.lzx. You can probably ask some friendly user at your local Amiga Dev or chat site for a copy. Once you get a copy and have it uncompressed to a folder on your Dev system,you need to copy the header files from the /include_h folder from NDK 3.9 over to our work folders. I also moved the old includes out of the build path that were created during the build of gcc68. We still need our old stdio.h file it should remain in the /include/dos folder where we copied it earlier.

# cp -R /YOUR_NDK_3.9_FOLDER/Include/include_h/* /usr/local/amigatools/m68k-amigaos/include
# mv /usr/local/amigatools/lib/gcc-lib/m68k-amigaos/3.3.3/include /usr/local/amigatools/lib/gcc-lib/m68k-amigaos/3.3.3/include.not



Now test the new library by compiling some real Amiga Code.Read closely the sample code included below. For this cross-compiler, it’s necessary to include the matching PROTO header for any Amiga libraries you are using. You must also cast the Amiga libraries properly. Sample code from books, magazines and internet sources written specifically for Amiga probably won’t compile properly with out some editing. Notice the lines from the Sample that include the Protos …..


#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/graphics.h>


And also notice the casting needed when opening and closing libraries….


IntuitionBase =(struct IntuitionBase *)OpenLibrary("intuition.library",37L);
GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",33L);
CloseLibrary((struct Library *)GfxBase);
CloseLibrary((struct Library *)IntuitionBase);


You may need to edit sample code that you get from other sources to match these examples,
or it will fail to compile with “missing file”, “undefined function” or “type mismatch” errors.

This sample code includes many of the library calls that all Amiga programs will typically use and will be a good test of the functionality of the new cross compiler. If you can compile and run this sample, you should be on your way to developing more serious projects on your new system. I have been able to down load open source Amiga code from aminet, re-write a few lines to make it GCC friendly, compile and run successfully on UAE. So I believe if you have made it this far, your dev system should be reliable.

You can cut, paste and save the following code for your next test as we did with the helloworld example.
Save the file as windowtest.c to your preferred work folder, cd to your folder and run the following commands.
Remember your search path must be set correctly to run gcc68 without using the complete folder path name.
If you haven’t already added this path to your login script in .bashrc or .profile, then you will have to execute this export each time you log in

# export PATH=$PATH:/usr/local/amigatools/bin (if needed)
# cd (to your project work folder)
# gcc68 -o ./windowtest -m68020 ./windowtest.c –lamiga (Remember to use –lamiga from now on)



//Amiga Cross-Compiler sample code windowtest.c
#include <dos/stdio.h>
#include <exec/types.h>
#include <exec/exec.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <intuition/screens.h>
#include <graphics/gfxmacros.h>
#include <graphics/gfxbase.h>
#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/graphics.h>

struct IntuitionBase*IntuitionBase;
struct GfxBase *GfxBase;
struct TagItem win_tags[] ={
{WA_Left,20},
{WA_Top,20},
{WA_Width,200},
{WA_Height,160},
{WA_CloseGadget,TRUE},
{WA_IDCMP,IDCMP_CLOSEWINDOW},
};

int main(void)
{
struct Window *win;
struct RastPort *rastport;
int x;
IntuitionBase =(struct IntuitionBase *)OpenLibrary("intuition.library",37L);
if (IntuitionBase!=NULL)
{
GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",33L);
if (GfxBase!=NULL)
{
win=OpenWindowTagList(NULL,win_tags);
if (win!=NULL)
{
rastport=win->RPort;
for (x=20;x<200;x+=2)
{
Move(rastport,x,150);
Draw(rastport,20,20);
}
WaitPort(win->UserPort);
CloseWindow(win);
}
CloseLibrary((struct Library *)GfxBase);
}
CloseLibrary((struct Library *)IntuitionBase);
}
return 0;
}


You can check for errors using ….

# gcc68 -v ./windowtest.c –m68020 -lamiga -Wl,--verbose 2> ldlog.txt
# vi ./ldlog.txt


If the compile completed without errors, it’s time to copy the finished executable over to your Amiga or to one of your UAE folders and run it. If it works, then a simple window withdiagonal lines will appear on your workbench. You can then close it with the close gadget. If you’ve made it this far and the test program has worked, then congratulations! It’s time to get busy coding your next Amiga project.

Below I’ve created a couple of extra topics that I though were important. They will help when it comes time to make your own libraries and deal with old code that uses the __chip pre-processor directive.
You might also like to check out a nice editor for windows and linux at
http://www.scintilla.org/SciTE.html. It does a very nice job, and it’s free !

Extra Stuff …. Building Your Own libamiga.a file
First we need the utility hunk2gcc.
This is an Amiga utility that has to be run on a real Amiga or UAE. It is not a Linux or Cygwin executable.
Get the utility at http://main.aminet.net/dev/gg/hunk2aout-bin.lha.
Make a new folder Ram:amigalib on your Amiga
Uncompress the hunk2aout executable file to your Amiga Ram: folder.
Now also copy the file amiga.lib from your NDK 3.9 folder or CD to your Amiga Ram: folder
Optionally I copied over the reaction.lib file too, but the doc says it will only work with SAS/C.
I plan to try it out and see what other libs reaction.lib might add. You can leave this extra file out.
From your Ram: folder run hunk2aout amiga.lib reaction.lib(reaction.lib is optional)
This will create an a.out object file for every lib function in the amiga.lib hunk file. (and any other lib files you include in your ram: folder and command line) There will be many with names of obj*.

If you’re working in UAE on your Cygwin system, move all the new obj files from the UAE Ram: folder to a Cygwin folder by using window explorer to move all the obj files to /usr/local/crosstools/newlibamiga (MAJOR CHEAT  ) If not, you will have to copy the files over to the Cygwin system by net or floppy.

# mkdir /usr/local/crosstools/newlibamiga
# cd /usr/local/crosstools/newlibamiga


Now convert all the new objfiles into an a.out style library called libamiga.a .

# ../m68k-amigaos/bin/m68k-amigaos-ar.exe qc ./libamiga.a obj.*
# ../m68k-amigaos/bin/m68k-amigos-ranlib.exe ./libamiga.a


Find and remove all the old libamiga.a files. (Or rename them if you prefer)

find /usr/local/crosstools -name libamiga.a –exec rm ‘{}’ \; (this
command will find and remove them)
(Here’s the output from my folders )
/usr/local/crosstools/lib/libamiga.a
/usr/local/crosstools/lib/libb/libamiga.a
/usr/local/crosstools/m68k-amigaos/sys-include/lib/libamiga.a
/usr/local/crosstools/m68k-amigaos/sys-include/lib/libb/libamiga.a
/usr/local/crosstools/m68k-amigaos/lib/libamiga.a


Copy the new libamiga.a file in to the GCC environment.

# cp /usr/local/crosstools/newlibamiga/libamiga.a/usr/local/crosstools/m68k-amigaos/lib/
# ../../bin/m68k-amigaos-ranlib.exe ./libamiga.a
# cd /usr/local/crosstools/bin


More Extra Stuff on Chip Memory Allocation in GCG

If your are going to be working with existing code or you are used to working with native Amiga compilers that handle chip memory with pre-processor labels like __chip, then you will need to make a few changes to your new code. Here is an example that that I worked with while working on this document.
The original code was written as….

__chipUWORD Data[] = {
0x0,0x0,0x0,0x0,0x3,0x8000, 0x7,0xc000, 0xf,
0xe000, 0x1f, 0xf000, 0x7f, 0xfc00, 0x1ff,0xff00, 0x7ff,0xffc0,
0x3fff, 0xfff8, 0x7ff,0xffc0, 0x1ff,0xff00, 0x7f, 0xfc00, 0x1f,
0xf000, 0xf,0xe000, 0x7,0xc000, 0x3,0x8000, 0x0,0x0,
0x0, 0x0, };


The native compiler knows how an where in Amiga memory to allocate the data when it reads __chip. GCC does note understand __chip. This version of GCC can allocate chip memory though if we write the code properly. Here is my example of how to allocate chip memory. My function doesn’t include error checking as it should, but you can add that later.

First we change the data struct a bit and add a new pointer.

UWORD *Data;
UWORD chipmem_Data[] = {
0x0,0x0,0x0,0x0,0x3,0x8000, 0x7,0xc000, 0xf,
0xe000, 0x1f, 0xf000, 0x7f, 0xfc00, 0x1ff,0xff00, 0x7ff,0xffc0,
0x3fff, 0xfff8, 0x7ff,0xffc0, 0x1ff,0xff00, 0x7f, 0xfc00, 0x1f,
0xf000, 0xf,0xe000, 0x7,0xc000, 0x3,0x8000, 0x0,0x0,
0x0, 0x0, };


Then we create a new proto and function .

int LoadData(void);
int LoadData(void){
int j;
Data = (UWORD *)AllocMem(sizeof(chipmem_Data), MEMF_CHIP);
for (j=0; j<37;j++)
Data[j]=chipmem_Data[j];
return 0;
}


Later we call our new function to load our data into chip memory.

int main(int argc, char *argv[]) {
****
(Some where after all your libs have been opened)
LoadData();
****
}


Props and Acknowledgements:
Written by Troy Silvey with thanks to:
Maciek Plewa (http://www.mil-sim.net), Par Taz (http://www.guru-meditation.net),
Nicolas Mendoza for helping me solve the casting and lib problems,
Nick Gammon (http://www.gammon.com.au), Kurt Wall and William von Hagen the authors of
“The Definitive Guide to GCC” (http://www.apress.com/DefinitiveGCC).
Thanks for the knowledge gained in reading their books and guide on the net.

Rate this item
12345678910


Last poster Message


Posted: 2005-Jul-8 21:29:32
great


Posted: 2005-Jul-8 22:39:43
This tutorial is a nice idea but it has a lot of flaws :-(


Posted: 2005-Jul-8 23:21:01
chmod 777? Are you nuts?

That alone would keep me from giving this tutorial a try... can someone help this bloke work this over?

For those who don't know about protection bits - like this author - use chmod 755 at best, but certainly not 777. 777 means that *anyone* can change your libs into *whatever*. You don't set 777. Ever.


Posted: 2005-Jul-9 00:19:10
Gunther: you could be constructive and point them out :)


Posted: 2005-Jul-9 02:52:07
Solar: good point, if you are doing it on a server and not on your own desktop computer.


Posted: 2005-Jul-11 17:24:00
nicomen: Looking at how the internet has become a premium source of virii, worms and other exploits, you shouldn't compromise your desktop either.

As for Gunther's comment, I will take the liberty of cross-posting / translating what he said on amiga-news.de. Mind, I don't think he has time or motivation for an in-depth analysis, so some of this might not be correct, don't flame either him or myself. Just trying to be helpful.

* during configuring you don't need --with-gnu-<as,ld> - neither with binutils nor gcc.
* --with-headers (without the path!) is needed for gcc only.
* Amiga headers and libraries should be installed *prior* to building the compiler.
* IN NO WAY do you have to edit m68k/amigaos.h :-(
* there are other hair-raising mistakes in handling the includes...
* "chmod 777" is complete nonsense :-(
* "include <dos/stdio.h>" and printf() don't go together.

HTH.


Posted: 2005-Jul-10 17:16:12
I would suggest Gunther is just alerting the masses (since such
coming from someone as established as himself it actually means
something constructive and not potentially unsubstantiated)

As for the listing of such, he is probably stretched for resources
as is...

and my part? errr... at times even I am guilty of conveying the
obvious

;)

@Gunther, greetings I wonder if you recognise me :D


Posted: 2005-Jul-12 00:23:33 · Edited by: Plaz
@Solar

>chmod 777? Are you nuts?

If I left that in there, yes I am. I'll claim sleep depravation or something.

777 was definitly a mistake if I left that in. It may have been part of my notes as I worked this out and should have been changed to 755 before I posted the final edit. I don't see it in the doc now. Maybe someone already fixed it. Running 'make install' as root eliminated the need for 777. In case I didn't explain clearly, I am a newbie. This was done as both a way to help other newbies and to help me learn. I'm open to any suggestions to make it better. I can only say that it builds a working cross compiler where other tutorials left me with failed builds and lots of waisted time, and I didn't claim it was perfect :).

I'll try to address some of your points the best I can.

>* during configuring you don't need --with-gnu-<as,ld> - neither >with binutils nor gcc.

Fair enough, but it didn't seem to hurt. These options were pulled from other tutorials on the net. No one posted problems with those examples, so I thought it was ok to leave it.

>* --with-headers (without the path!) is needed for gcc only.

Hmmm.... didn't even really think about that. Makes sence.

>* Amiga headers and libraries should be installed *prior* to >building the compiler.

That may be true, but it didn't cause the build to fail. I build it, then placed the includes after. If it's more logical to place them before, that's ok with me.

>* IN NO WAY do you have to edit m68k/amigaos.h :-(

I did. I can't explain fully (as a newbie), but the build claimed it could not find the crt0.o even after copying crt0.o to paths 'seemingly' in the include path. I didn't want to mess with the original file in the native linux environment, so I finally went to the source of amiga.h and put my path in manually. That finally made it happy, but I didn't really like the method either.

>* there are other hair-raising mistakes in handling the includes...

Hair-raising, I like that analogy :). That's what I would call my whole effort. If you're willing to share, please tell how it might be improved.

>*"chmod 777" is complete nonsense :-(

Mistake that should already be gone.

>* "include <dos/stdio.h>" and printf() don't go together.

I claim newbie status on this one. Can you expand this for me a bit?

Plaz


Posted: 2005-Jul-12 00:28:45
I can't as those are Gunther's comments. You should not have any troubles getting into contact with him since he's rather prominent (just google for his name...). Perhaps he'll give you a hand in polishing this.


Posted: 2005-Jul-12 00:38:38
for me , poor newbe this tutorial helped a lot :o)


Posted: 2005-Jul-12 03:15:54
I can't as those are Gunther's comments. You should not have

Ah, after re-reading the list I understand the cross posting now, thanks.

Plaz


Posted: 2005-Jul-12 03:16:42
for me , poor newbe this tutorial helped a lot :o)

I'm glad to hear it. Did you actually get it to work though :)

Plaz


Posted: 2005-Jul-12 03:28:05
Just finished reading amiganews.de (the best I could in german) and the tone was actually mostly favorable. I was going to try an reply in my broken German, but that will probably go badly. Wish me luck :)

Plaz


Posted: 2005-Jul-12 04:43:20 · Edited by: avanham
Great tutorial! It worked flawlessly on Mac OS 10.4.1. Well, except for one thing: you have this line:

# cp -R /YOUR_NDK_3.9_FOLDER/Include/include.h/* /usr/local/amigatools/m68k-amigaos/include

but the "include.h" should really be "include_h"

Thanks for taking the time to make this tutorial.

Do anyone know how I would change it to allow me to compile Objective-C code as well? I added "objc" to the following line like this:
# ../gcc-3.3.3/configure --target=$TARGET --prefix=$PREFIX --enable-languages=c,c++,objc \

and it added the ability to compile with objective-c but didn't create the libobjc.a file. If anyone knows how to do this, let me know.


Posted: 2005-Jul-12 05:19:14
Ok. I answered my own question. I just found a libobjc.a from an older version of gcc that I already had for the amiga (gcc 2.95) and stuck it in with the 3.3.3 libs. It seems to work.


Posted: 2005-Jul-12 05:55:49
Excellent stuff... I've been looking for a guide like this for ages!

Well done Plaz :)


Posted: 2005-Jul-12 10:09:45
@avanham
but the "include.h" should really be "include_h"

That's great you got it working on Mac 10.4.1
When I started working on this I didn't realize Mac could be an option. Thanks for the proof read. I've already updated the doc.

@Anonymous
Excellent stuff... I've been looking for a guide like this for ages!

So was I, that's why I finally deceided to try and write one. :) Of course I had no idea what I was getting my self into.

@Thread
I replied the best I could at amiga-news.de in german.
I hope I didn't insult everyone with my horrible langauge :)

Plaz


Posted: 2005-Jul-12 12:00:58
I hope you replied with useful stuff here and changed whatever was necessary, I changed from the 777 to 755 though, except it's not critical, but good practice. (755 means read, execute and write for the owner and only read and execute for others)


Posted: 2005-Jul-12 20:20:04
* --with-headers (without the path!) is needed for gcc only.
* Amiga headers and libraries should be installed *prior* to building the compiler.

If you supply --with-headers with the path then the headers will be copied automatically. --with-libs (or was it --with-libraries? Don't remember) does the same for the libraries.


Posted: 2005-Jul-12 20:22:52
If you supply --with-headers with the path then the headers will be copied automatically. --with-libs (or was it --with-libraries? Don't remember) does the same for the libraries.

Hadn't looked at the tutorial yet: the usage of --with-headers there is wrong, the path should point to a location where headers can be found, not where they need to be placed.


Posted: 2005-Jul-13 00:52:29
the usage of --with-headers there is wrong, the path should point to a location where headers can be found

You can install headers and libraries manually. Since that is easy and --prefix= never changes, I would suggest doing it that way. Then you can simply say "--with-headers=yes" (with GCC2 omit =yes).


Posted: 2005-Jul-13 01:39:25
You can install headers and libraries manually.

But you don't need to, so why bother?


Posted: 2005-Jul-13 18:29:47
But you don't need to, so why bother?

Because I have separate OS and non-OS includes? Because --with-headers has changed behaviour between GCC versions? Because --prefix never changes and thus your --with-headers is only required the first time? IMHO installing headers and libraries manually is the better approach.


Posted: 2005-Jul-15 01:52:14
IMHO installing headers and libraries manually is the better approach.

IMHO it's not: let the build system take care of that stuff :)

Differing opinions, nothing bad with that.


Posted: 2005-Jul-23 18:54:03
While trying to build gcc on linux with gcc 3.4.3 on gentoo linux, I got this message on the second call to make :

*** glibc detected *** double free or corruption (!prev): 0x00000000005b4ee0 ***
xgcc: Internal error: Aborted (program as)
Please submit a full bug report.

Do you think it is related to gcc version 3.4.3 ?


Posted: 2005-Aug-28 07:19:37
could you use the gcc68 to crosscompile itself so you could actually use gcc68 ON the Amiga, not just to compile FOR it?


Posted: 2005-Oct-15 06:44:22
What does this mean, and where do you place the file. The text aren't very helpful?

This separates the new GCC 68K cross compiler from the local Linux GCC you just used to build GCC68.
(And helps end confusion for me)

Now add it to your path

# export PATH=$PATH:/usr/local/amigatools/m68k-amigaos/bin

You may also want to add this to your users login path by adding it to file .bashrc in your user home folder.
That way you don’t have to manually enter the path each time you log in.

Once the compiler is built, the paths to it’s libs and headers are hard-coded. So don’t move things out of the /usr/local/amigatools folder unless you’re really surethat you know what doing. To see the default setting and folder paths use the command

:: Your comment
Bold Style  Italic Style  Underlined Style  Image Link  Insert URL  Email Link  Quote  C/C++ Source  Disable *What`s that?


Before posting non-english message, check your browser`s encoding!
» Name » Password

UtilityBase is a site focused on development for Amiga systems,
spanning over all different Amiga clones, that be AmigaOS 3.x, 4.x, MorphOS, AROS or AmigaDE/Anywhere.
News syndication: RSS
Contact address: mail@utilitybase com