HOWTO/FAQ: Ada on OS X

Some years ago, Truman started its own Macintosh Users Group (MUG) and I found myself as one of it's faculty co-sponsors. Our goal is to promote the value and virtue of OS X as an environment for research, study, and play. We also see ourselves as an important resource for students in this Windoze-centric environment.

To help give the Mac a toe-hold in the mathematics and computer science world here, I've taken it upon myself to learn how to compile Ada code using the tools that ship with OS X. Each year, a few students ask me how to do this, and I'm happy to say that I've finally found an answer. Read on for more.

Questions

  1. Does OS X have a tool for compiling Ada code at the command line? (Answer [here])
  2. How does one configure Apple's Xcode to compile Ada code? (Answer [here])
  3. Are there alternative environments for Ada development on OS X? (Answer [here])
  4. I have other questions about Ada on OS X. Where can I get them answered? (Answer [here])
  5. I have questions on Xcode. Where can I get them answered? (Answer [here])

Please email any other Frequently Asked Questions (and their answers, if possible) to the author at [this email address]. He will do his best to grow this FAQ to better serve the OS X student community.


Answers

1. Does OS X have a tool for compiling Ada code at the command line?
You must have the OS X Developer Tools installed on your system so that you will have gcc available. As the gcc man page says, the out-of-the-box gcc does not compile Ada, but there is an update available at [this page]; click on the "Download gcc 4.01" link and follow the instructions immediately below the link. After updating, you will use the command gnatmake at the command line to compile and build your code.

Once the update is installed (download, uncompress, mount the DMG file, following the instructions for preparing your system, and unpack the PKG file), you will be able to use gnatmake at the command line to compile your code.

2. How does one configure Apple's Xcode to compile Ada code?
Xcode is a sophisticated IDE for developing software for OS X. This is certainly more than a CS 180 student needs for their course, but it's good to know what you're getting. Getting Xcode to compile and build Ada code is a multi-step process.

First, you need to have Xcode on your system. Xcode is installed as part of the OS X Developer Tools. This can be installed from your original OS X 10.x install disks or it can be downloaded from Apple at this [Apple Developer Page]. (A free membership to Apple's Developer Community may be required.)

After you install the Developer Tools you will have an app called Xcode. You should be able to find it in /Developer/Applications/. This is the IDE that you will eventually use to compile and build your code.

A screenshot showing in the Finder the location of Xcode.

If you were to launch Xcode before you install the Ada bindings, and if you were to try to start a new Ada project, you might see something like the following:

A screenshot showing how to select a new project from the File menu in Xcode.
Opening a new project in Xcode.

A screenshot showing the list of project types in the Xcode Assistant window.  There is not Ada project in the default installation of Xcode.
Options for the types of projects/code you see. Notice that there is no Ada option on the list.

At this point, Ada does not appear as an project option in Xcode, and it won't until you carry out the third step of the process described here.

The second step of this process requires that you apply the Ada update to gcc to allow the compiling and building of Ada code at the command line. Download the latest update with the Ada bindings for Xcode at [macada.org], on it's bindings page. If that link doesn't work, you can get a (possibly old) copy [here].

Installing this update does not give you any Ada project options in Xcode, nor does it configure Xcode to compile Ada. The next step will do that.

The third step of this process requires you to install the Ada carbon binding. (Carbon is a bit of OS X jargon.) These can be found at [macada.org]. Download the bindings that are appropriate for your version of OS X. The disk imgae should automatically mount after you download and unpack the bindings. Double-click Carbon_Bindings_xcode.pkg to install the bindings.

A screenshot showing the contents of the disk image mounted by double-clicking on the Carbon_Bindinds_xcode.pkg.

The last step is documented in the Jambase Patch.rtf file that's included in the Xcode bindings disk image that you downloaded in the third step of this process. You must have administrator privileges to do this. Here is part of the instructions from the Jambase Patch.rtf file, but beware that the directions distributed with the Xcode bindings will be the more up-to-date than the text on this web page:

to install this patch copy the file jambase_patch to the 
directory "/Developer/Makefiles/pbx_jamfiles".  Then in 
the terminal do the following commands:

cd /Developer/Makefiles/pbx_jamfiles
sudo patch -p0 ProjectBuilderJambase < jambase_patch Of course be sure and backup your original ProjectBuilderJambase file in case of problems.

Steve Holland says, "for step 3 of the install I'd modify the install with an automatic backup option"

sudo patch -b -p0 ProjectBuilderJambase < jambase_patch

At this point, you are all set to develop software in Ada using gcc and Xcode. You can find Ada project examples in /Developer/Examples/Ada. At this point, when you launch Xcode and start a new project, the project Assistant should show you some new items:

A screenshot showing the Ada Corbon Application and Ada Carbon Application (Nib Based) that are present in the Xcode Assistant after installing the Carbon bindings.
This is the first Ada-type project you'll see in this list. You would select this type of project if you wanted to develop software using Carbon and the GUI tools. This would be overkill for a CS 180 or CS 185 project. You should probably choose Ada Standard Tool as your project type.

A screenshot showing the Ada Standard Tool is present in the Xcode Assistant after installing the Carbon bindings.
Scrolling down the list of project types will reveal the Ada Standard Tool. This is the project type that a CS 180 or CS 185 student should choose.

Note that the triangles in this list of project types are flippy triangles. You can hide the project types that you'll probably never use.

A screenshot showing that you can close the flippy triangles in the Xcode Assistant to hide the project types that you'll not be using.

To test that Xcode now compiles and builds Ada code, you can do the following. Launch Xcode, create a new Ada Standard Tool project, and call it something innocuous like test. Click on Finish to create the project.

A screenshot showing how the Xcode Assistant allows you to name a new project and choose its location on your harddrive.

Once you've created the project, the Xcode IDE will open with a few files in the workspace.

A screenshot showing the Xcode IDE with the Ada default 'Hello World' program called test.adb.
If you double-click on the project's source code .adb file, the code will open in a separate editor window. you can see that this is a standard "Hello World" program.
A screenshot showing the Xcode IDE's text editory with the Ada default 'Hello World' program displayed.
Click on the "Build" menubar icon to compile and link the code. You'll see some activite near the bottom of the IDE's menubar, and then you should see this:
A screenshot showing the Xcode IDE after a successful build of the Ada default 'Hello World' program.

If you click the "Build and Run" icon, you'll also see that a window opens to discplay the output of your code as if you had run it at the command line.

A screenshot showing output after a successful 'Build and Run' of the Ada default 'Hello World' program.
If this is what you experience, then you've succeesed in setting up Xcode as an Ada coding environment!

Note that when you compile Ada code in Xcode, the executeable gets put into a build subdirectory of your project directory. To execute the binary at the command line, open a Terminal window (available in /Applications/Utilities/), cd to ~/test, and "ls -la". You should see

A screenshot of the Terminal showing the location of the build subdirectory of your project directory.  This subdirectory contains the binary executable created by Xcode.

Your binary executable is in the build subdirectory. You can run it from the test directory by entering "./build/test" at the command line. Or you can change your working directory to be the build subdirectory, and execute it from there, as illustrated below.

A screenshot of the Terminal showing the execution of the binary executable created by Xcode.

The above screenshot shows a successful execution of the test Ada program!

Note that the name of your project's main program file (e.g., test.adb in the above example) should be same name as your project. You can get around this. To find out how, submit the question to the gnat-osx mailing list.

If you experience problems getting your system patched and configured to compile Ada code, I strongly recommend the gnat-osx mailing list as a resource for getting your questions answered. The members of that community are knowledgeable and quick to respond to questions. (You'll also note that that community is deeply involved in the macada.org project.)

3. Are there alternative environments for Ada development on OS X?
As mentioned above, Xcode with the Ada carbon bindings provide more tools than a CS 180 or CS 185 student really needs. Though Xcode is a remarkable IDE that alloww you to develope software in many languages, it's more than a beginning student needs. All those bells and whistles can be distracting and confusing.

An Ada alternative to Xcode is jGRASP, a development environment written in Java that compiles Ada out-of-the-box. It can be downloaded from the jGRASP web site along with tutorials in its use. Like Xcode, it does have some functionality that will not be of interest to CS 180 or CS 185 students. Unlike Xcode, a project's main

The jGRAP project seems to be a vigorous and well supported activity, so it is reasonable to expect its development to continue and support for jGRASP to be available well into the foreseeable future.

4. I have other questions about Ada on OS X. Where can I get them answered?
The author of this HOWTO/FAQ knows very little about Ada, so it's not likely that he'll have the answers you seek. Don't let this keep you from asking him for help, however.

If he can't answer your question outright, he'll forward it on to the gnat-osx email list. You might as well skip the middleman and subscribe to that list yourself. You can do so [here]. The members of that community are knowledgeable and quick to respond to questions. They are also very happy to answer questions from students. (You'll also not that that community is deeply involved in the macada.org project.)

5. I have questions on Xcode. Where can I get them answered?
Here are a couple helpful documents on Xcode. (Contributed by Jim Hopper.)

Created by Jason Miller on 26 September 2004 using Snapz Pro X for the screenshots. Updated on 30 August 2006.
James Hopper, Stephen Holland, and the [gnat-osx list] made this HOWTO/FAQ possible.
Last modified on <September 26, 2004

Valid HTML 4.01!