\chapter{Building an Ada program}
\section{Building with GNAT}
With GNAT, you can run this command:
\begin{verbatim}
gnat make <your_unit_file>
\end{verbatim}
If the file contains a procedure, gnatmake will generate an executable
file with the procedure as main program. Otherwise, e.g. a package,
gnatmake will compile the unit and all its dependencies.
\subsection{GNAT command line}
gnatmake can be written as one word gnatmake or two words gnat make.
For a full list of gnat commands just type gnat without any command
options. The output will look something like this:
\begin{verbatim}
GNAT 3.4.3 Copyright 1996-2004 Free Software Foundation, Inc.
List of available commands
GNAT BIND gnatbind
GNAT CHOP gnatchop
GNAT CLEAN gnatclean
GNAT COMPILE gnatmake -f -u -c
GNAT ELIM gnatelim
GNAT FIND gnatfind
GNAT KRUNCH gnatkr
GNAT LINK gnatlink
GNAT LIST gnatls
GNAT MAKE gnatmake
GNAT NAME gnatname
GNAT PREPROCESS gnatprep
GNAT PRETTY gnatpp
GNAT STUB gnatstub
GNAT XREF gnatxref
Commands FIND, LIST, PRETTY, STUB and XREF accept project file
switches -vPx, -Pprj and -Xnam=val
\end{verbatim}
For further help on the option just type the command (one word or two
words - as you like) without any command options.
\subsection{GNAT IDE}
The GNAT toolchain comes with an IDE (Integrated Development
Environment) called GPS (GNAT Programming System). You need to
download and install it separately. The GPS features a graphical user
interface.
There are also GNAT plugins for Emacs (Ada
Mode\footnote{https://libre2.adacore.com/adamode/}), KDevelop and Vim
(Mode) available.
Both Emacs and Vim Ada-Mode are maintained by The GNU Ada
project\footnote{http://gnuada.sourceforge.net/}.
\subsection{GNAT with XCode}
Apple's free (gratis) IDE, XCode, is included with every Macintosh but
requires an explicit installation step from DVD-ROM or CD-ROM. It is
also downloadable from http://developer.apple.com. XCode uses the GNU
Compiler Collection and thus supports Ada, GDB, etc., and also
includes myriad tools for optimizing code which are unique to the
Macintosh platform. However, GNAT must be installed separately as it
is (as of 2005) not distributed as part of XCode. Get the binary
and/or sources at http://www.macada.org/, along with numerous tools
and bindings including bindings to Apple's Carbon frameworks which
allow the development of complete, "real" Mac programs, all in Ada.
\section {Compiling our Demo Source}
Once you have
downloaded\footnote{http://sourceforge.net/projects/wikibook-ada/} our
example programs you might wonder how to compile them.
First you need to extract the sources. Use your favorite zip tool to
achieve that. On extraction a directory with the same name as the
filename is created. Beware: WinZip might also create a directory
equaling the filename so Windows users need to be careful using the
right option otherwise they end up with
wikibook-ada-1\_2\_0.src/wikibook-ada-1\_2\_0.
Once extraced, you will find all sources in
wikibook-ada-1\_2\_0/Source. You could compile them right there. For
your convinience we also provide ready made project files for the
following IDEs (If you find a directory for an IDEs not named it might
be in the making and not actualy work).
\subsection{GNAT}
You will find multi-target GNAT Project files and a multi-make
Makefile file in wikibook-ada-2\_0\_0/GNAT. For i686 Linux and Windows
you can compile any demo using:
\begin{verbatim}
gnat make -P project_file
\end{verbatim}
You can also open them inside the GPS with
\begin{verbatim}
gps -P project_file
\end{verbatim}
For other target platform it is a bit more difficult since you need to
tell the project files which target you want to create. The following
options can be used:
\begin{description}
\item[style (``Debug'', ``Release'')] you can define if you like a
debug or release version so you can compare how the options affect
size and speed.
\item[os (``Linux'', ``OS2'', ``Windows\_NT'', ``VMS'')] an option to
choose your operating system. Since there is no Ada 2005 available
for OS/2 don't expect all examples to compile.
\item[target (``i686'', ``x86\_64'', ``AXP'')] choose your CPU ---
``i686'' is any form of 32bit Intel or AMD CPU, ``x86\_64'' is an 64
bit Intel or AMD CPU and if you have an ``AXP'' then you know it.
\end{description}
Remember to type all options as they are shown. To compile a debug
version on x86\_64 Linux you type:
\begin{verbatim}
gnat make -P project_file -Xstyle=Debug -Xos=Linux \
-Xtarget=x86_64
\end{verbatim}
As said in the beginning there is also a makefile available that will
automatically determine the target used. So if you have a GNU make you
can save yourself a lot of typing by using \verb|make project|. Or you
can even use \verb|make all| to make all examples in debug and release
in one go.
Each compile is stored inside it's own directory which is created in
the form of wikibook-ada-2\_0\_0/GNAT/OS-Target-Style. Empty
directorys are provided inside the archive.
\section{See Also}
GNAT User's Guide: \small{http://gcc.gnu.org/onlinedocs/gcc-4.0.1/gnat\_ugn\_unw/}