From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,39f177ee703875f6 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!h30g2000vbr.googlegroups.com!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: Newbie question: How to use gnat make Date: Sat, 19 Sep 2009 08:20:29 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: NNTP-Posting-Host: 94.108.136.15 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1253373629 6857 127.0.0.1 (19 Sep 2009 15:20:29 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 19 Sep 2009 15:20:29 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: h30g2000vbr.googlegroups.com; posting-host=94.108.136.15; posting-account=pcLQNgkAAAD9TrXkhkIgiY6-MDtJjIlC User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.11) Gecko/2009061208 Iceweasel/3.0.12 (Debian-3.0.12-1),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:8395 Date: 2009-09-19T08:20:29-07:00 List-Id: Markus B=FChren 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.