comp.lang.ada
 help / color / mirror / Atom feed
* Newbie question: How to use gnat make
@ 2009-09-19 14:05 Markus
  2009-09-19 15:20 ` Ludovic Brenta
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Markus @ 2009-09-19 14:05 UTC (permalink / raw)


Hi,

I am new to Ada, learning with the book "Programming in Ada 2005" from
John Barnes. I want to build a program using the GNAT GPL compiler on
the command line. If my program resides in a single file I just call

gnat make myfun.adb,

but how do I call the compiler if I want to use ("with") packages
defined in another file? I know the include, compile and link
procedure from C programs, is it similar in Ada? What about the file
extensions .ada/.adb/.ads?

Yours
Markus



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Newbie question: How to use gnat make
  2009-09-19 14:05 Newbie question: How to use gnat make Markus
@ 2009-09-19 15:20 ` Ludovic Brenta
  2009-09-19 15:54 ` John B. Matthews
  2009-09-20 18:17 ` Stephen Leake
  2 siblings, 0 replies; 5+ messages in thread
From: Ludovic Brenta @ 2009-09-19 15:20 UTC (permalink / raw)


Markus Bühren wrote on comp.lang.ada:
> I am new to Ada, learning with the book "Programming in Ada 2005" from
> John Barnes. I want to build a program using the GNAT GPL compiler on
> the command line. If my program resides in a single file I just call
>
> gnat make myfun.adb,
>
> but how do I call the compiler if I want to use ("with") packages
> defined in another file? I know the include, compile and link
> procedure from C programs, is it similar in Ada? What about the file
> extensions .ada/.adb/.ads?

*.ads: Ada Specification
*.adb: Ada Body

Each file contains exactly one compilation unit (i.e. a package, a
function, or a procedure; possibly generic).  For child units, name
the file after the fully-qualified name of the unit with a dash as the
separator, e.g.

package Foo.Bar is...      -> foo-bar.ads
package body Foo.Bar is... -> foo-bar.adb

You cannot place multiple compilation units in the same file.

If you follow this convention, then gnatmake does everything else for
you because contrary to C, Ada has built-in support for multiple
compilation.  You do not need any Makefiles or explicit calls to the
linker.  In the simple case where all your source files are in the
same directory, "gnat make myfun" will recompile all units that are
out of date, then bind them, then link them together without your
intervention. The only compilation unit that you name on the command
line is the main procedure; gnat finds all other files by following
the "with" clauses in the main procedure.

In the more complex case where you spread your source files in
multiple directories, you can either use command-line options (i.e.
gnat make -Idir) or project files to tell gnat make where your sources
are.  GNAT project files also allow you to use a non-default naming
convention for your source files but this is only recommended when
migrating from another compiler.  See the GNAT User's Guide for
details on both methods.

HTH and welcome to Ada!

--
Ludovic Brenta.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Newbie question: How to use gnat make
  2009-09-19 14:05 Newbie question: How to use gnat make Markus
  2009-09-19 15:20 ` Ludovic Brenta
@ 2009-09-19 15:54 ` John B. Matthews
  2009-09-20  9:34   ` Markus
  2009-09-20 18:17 ` Stephen Leake
  2 siblings, 1 reply; 5+ messages in thread
From: John B. Matthews @ 2009-09-19 15:54 UTC (permalink / raw)


In article 
<b1f1461a-4899-437e-a20b-0a9dbf583c0d@n2g2000vba.googlegroups.com>,
 Markus <markus.buehren@gmail.com> wrote:

> What about the file extensions .ada/.adb/.ads?

In addition to Ludovic Brenta's discussion of .ads and .adb, a file 
ending in .ada is a convenient way to store multiple compilation units 
in a single file. Such a file is typically created with the 'cat' 
command. Typically, it is not directly compilable, but it can be 
restored to individual units with the 'gnatchop' utility. For example,

<http://gcc.gnu.org/onlinedocs/gcc-4.3.4/gnat_ugn_unw/
Renaming-Files-Using-gnatchop.html#Renaming-Files-Using-gnatchop>

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Newbie question: How to use gnat make
  2009-09-19 15:54 ` John B. Matthews
@ 2009-09-20  9:34   ` Markus
  0 siblings, 0 replies; 5+ messages in thread
From: Markus @ 2009-09-20  9:34 UTC (permalink / raw)


Great, thanks for your kind and quick help!

Markus



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Newbie question: How to use gnat make
  2009-09-19 14:05 Newbie question: How to use gnat make Markus
  2009-09-19 15:20 ` Ludovic Brenta
  2009-09-19 15:54 ` John B. Matthews
@ 2009-09-20 18:17 ` Stephen Leake
  2 siblings, 0 replies; 5+ messages in thread
From: Stephen Leake @ 2009-09-20 18:17 UTC (permalink / raw)


Markus <markus.buehren@gmail.com> writes:

> I am new to Ada, learning with the book "Programming in Ada 2005" from
> John Barnes. I want to build a program using the GNAT GPL compiler on
> the command line. If my program resides in a single file I just call
>
> gnat make myfun.adb,
>
> but how do I call the compiler if I want to use ("with") packages
> defined in another file? I know the include, compile and link
> procedure from C programs, is it similar in Ada? What about the file
> extensions .ada/.adb/.ads?

There is a short tutorial on compiling Ada code in multiple files as
part of the Emacs Ada mode tutorial; see
http://www.stephe-leake.org/emacs/ada-mode/emacs-ada-mode.html 

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-09-20 18:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-19 14:05 Newbie question: How to use gnat make Markus
2009-09-19 15:20 ` Ludovic Brenta
2009-09-19 15:54 ` John B. Matthews
2009-09-20  9:34   ` Markus
2009-09-20 18:17 ` Stephen Leake

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox