OSDN Git Service

2011-09-02 Pascal Obry <obry@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / projects.texi
1 @set gprconfig GPRconfig
2
3 @c ------ projects.texi
4 @c This file is shared between the GNAT user's guide and gprbuild. It is not
5 @c compilable on its own, you should instead compile the other two manuals.
6 @c For that reason, there is no toplevel @menu
7
8 @c ---------------------------------------------
9 @node GNAT Project Manager
10 @chapter GNAT Project Manager
11 @c ---------------------------------------------
12
13 @noindent
14 @menu
15 * Introduction::
16 * Building With Projects::
17 * Organizing Projects into Subsystems::
18 * Scenarios in Projects::
19 * Library Projects::
20 * Project Extension::
21 * Aggregate Projects::
22 * Project File Reference::
23 @end menu
24
25 @c ---------------------------------------------
26 @node Introduction
27 @section Introduction
28 @c ---------------------------------------------
29
30 @noindent
31 This chapter describes GNAT's @emph{Project Manager}, a facility that allows
32 you to manage complex builds involving a number of source files, directories,
33 and options for different system configurations. In particular,
34 project files allow you to specify:
35
36 @itemize @bullet
37 @item The directory or set of directories containing the source files, and/or the
38   names of the specific source files themselves
39 @item The directory in which the compiler's output
40   (@file{ALI} files, object files, tree files, etc.) is to be placed
41 @item The directory in which the executable programs are to be placed
42 @item Switch settings for any of the project-enabled tools;
43   you can apply these settings either globally or to individual compilation units.
44 @item The source files containing the main subprogram(s) to be built
45 @item The source programming language(s)
46 @item Source file naming conventions; you can specify these either globally or for
47   individual compilation units (@pxref{Naming Schemes}).
48 @item Change any of the above settings depending on external values, thus enabling
49   the reuse of the projects in various @b{scenarios} (@pxref{Scenarios
50   in Projects}).
51 @item Automatically build libraries as part of the build process
52   (@pxref{Library Projects}).
53
54 @end itemize
55
56 @noindent
57 Project files are written in a syntax close to that of Ada, using familiar
58 notions such as packages, context clauses, declarations, default values,
59 assignments, and inheritance (@pxref{Project File Reference}).
60
61 Project files can be built hierarchically from other project files, simplifying
62 complex system integration and project reuse (@pxref{Organizing Projects into
63 Subsystems}).
64
65 @itemize @bullet
66 @item One project can import other projects containing needed source files.
67   More generally, the Project Manager lets you structure large development
68   efforts into hierarchical subsystems, where build decisions are delegated
69   to the subsystem level, and thus different compilation environments
70   (switch settings) used for different subsystems.
71 @item You can organize GNAT projects in a hierarchy: a child project
72   can extend a parent project, inheriting the parent's source files and
73   optionally overriding any of them with alternative versions
74   (@pxref{Project Extension}).
75
76 @end itemize
77
78 @noindent
79 Several tools support project files, generally in addition to specifying
80 the information on the command line itself). They share common switches
81 to control the loading of the project (in particular
82 @option{^-P^/PROJECT_FILE=^@emph{projectfile}} and
83 @option{^-X^/EXTERNAL_REFERENCE=^@emph{vbl}=@emph{value}}).
84 @xref{Switches Related to Project Files}.
85
86 The Project Manager supports a wide range of development strategies,
87 for systems of all sizes.  Here are some typical practices that are
88 easily handled:
89
90 @itemize @bullet
91 @item Using a common set of source files and generating object files in different
92   directories via different switch settings. It can be used for instance, for
93   generating separate sets of object files for debugging and for production.
94 @item Using a mostly-shared set of source files with different versions of
95   some units or subunits. It can be used for instance, for grouping and hiding
96 @end itemize
97
98 @noindent
99 all OS dependencies in a small number of implementation units.
100
101 Project files can be used to achieve some of the effects of a source
102 versioning system (for example, defining separate projects for
103 the different sets of sources that comprise different releases) but the
104 Project Manager is independent of any source configuration management tool
105 that might be used by the developers.
106
107 The various sections below introduce the different concepts related to
108 projects. Each section starts with examples and use cases, and then goes into
109 the details of related project file capabilities.
110
111 @c ---------------------------------------------
112 @node Building With Projects
113 @section Building With Projects
114 @c ---------------------------------------------
115
116 @noindent
117 In its simplest form, a unique project is used to build a single executable.
118 This section concentrates on such a simple setup. Later sections will extend
119 this basic model to more complex setups.
120
121 The following concepts are the foundation of project files, and will be further
122 detailed later in this documentation. They are summarized here as a reference.
123
124 @table @asis
125 @item @b{Project file}:
126   A text file using an Ada-like syntax, generally using the @file{.gpr}
127   extension. It defines build-related characteristics of an application.
128   The characteristics include the list of sources, the location of those
129   sources, the location for the generated object files, the name of
130   the main program, and the options for the various tools involved in the
131   build process.
132
133 @item @b{Project attribute}:
134   A specific project characteristic is defined by an attribute clause. Its
135   value is a string or a sequence of strings. All settings in a project
136   are defined through a list of predefined attributes with precise
137   semantics. @xref{Attributes}.
138
139 @item @b{Package in a project}:
140   Global attributes are defined at the top level of a project.
141   Attributes affecting specific tools are grouped in a
142   package whose name is related to tool's function. The most common
143   packages are @code{Builder}, @code{Compiler}, @code{Binder},
144   and @code{Linker}. @xref{Packages}.
145
146 @item @b{Project variables}:
147   In addition to attributes, a project can use variables to store intermediate
148   values and avoid duplication in complex expressions. It can be initialized
149   with a value coming from the environment.
150   A frequent use of variables is to define scenarios.
151   @xref{External Values}, @xref{Scenarios in Projects}, and @xref{Variables}.
152
153 @item @b{Source files} and @b{source directories}:
154   A source file is associated with a language through a naming convention. For
155   instance, @code{foo.c} is typically the name of a C source file;
156   @code{bar.ads} or @code{bar.1.ada} are two common naming conventions for a
157   file containing an Ada spec. A compilation unit is often composed of a main
158   source file and potentially several auxiliary ones, such as header files in C.
159   The naming conventions can be user defined @xref{Naming Schemes}, and will
160   drive the builder to call the appropriate compiler for the given source file.
161   Source files are searched for in the source directories associated with the
162   project through the @b{Source_Dirs} attribute. By default, all the files (in
163   these source directories) following the naming conventions associated with the
164   declared languages are considered to be part of the project. It is also
165   possible to limit the list of source files using the @b{Source_Files} or
166   @b{Source_List_File} attributes. Note that those last two attributes only
167   accept basenames with no directory information.
168
169 @item @b{Object files} and @b{object directory}:
170   An object file is an intermediate file produced by the compiler from a
171   compilation unit. It is used by post-compilation tools to produce
172   final executables or libraries. Object files produced in the context of
173   a given project are stored in a single directory that can be specified by the
174   @b{Object_Dir} attribute. In order to store objects in
175   two or more object directories, the system must be split into
176   distinct subsystems with their own project file.
177
178 @end table
179
180 The following subsections introduce gradually all the attributes of interest
181 for simple build needs. Here is the simple setup that will be used in the
182 following examples.
183
184 The Ada source files @file{pack.ads}, @file{pack.adb}, and @file{proc.adb} are in
185 the @file{common/} directory. The file @file{proc.adb} contains an Ada main
186 subprogram @code{Proc} that @code{with}s package @code{Pack}. We want to compile
187 these source files with the switch @option{-O2}, and put the resulting files in
188 the directory @file{obj/}.
189
190 @smallexample
191 @group
192 ^common/^[COMMON]^
193   pack.ads
194   pack.adb
195   proc.adb
196 @end group
197 @group
198 ^common/release/^[COMMON.RELEASE]^
199   proc.ali, proc.o pack.ali, pack.o
200 @end group
201 @end smallexample
202
203 @noindent
204 Our project is to be called @emph{Build}. The name of the
205 file is the name of the project (case-insensitive) with the
206 @file{.gpr} extension, therefore the project file name is @file{build.gpr}. This
207 is not mandatory, but a warning is issued when this convention is not followed.
208
209 This is a very simple example, and as stated above, a single project
210 file is enough for it. We will thus create a new file, that for now
211 should contain the following code:
212
213 @smallexample
214 @b{project} Build @b{is}
215 @b{end} Build;
216 @end smallexample
217
218 @menu
219 * Source Files and Directories::
220 * Object and Exec Directory::
221 * Main Subprograms::
222 * Tools Options in Project Files::
223 * Compiling with Project Files::
224 * Executable File Names::
225 * Avoid Duplication With Variables::
226 * Naming Schemes::
227 @end menu
228
229 @c ---------------------------------------------
230 @node Source Files and Directories
231 @subsection Source Files and Directories
232 @c ---------------------------------------------
233
234 @noindent
235 When you create a new project, the first thing to describe is how to find the
236 corresponding source files. This is the only settings that are needed by all
237 the tools that will use this project (builder, compiler, binder and linker for
238 the compilation, IDEs to edit the source files,@dots{}).
239
240 @cindex Source directories
241 First step is to declare the source directories, which are the directories
242 to be searched to find source files. In the case of the example,
243 the @file{common} directory is the only source directory.
244
245 @cindex @code{Source_Dirs}
246 There are several ways of defining source directories:
247
248 @itemize @bullet
249 @item When the attribute @b{Source_Dirs} is not used, a project contains a
250   single source directory which is the one where the project file itself
251   resides. In our example, if @file{build.gpr} is placed in the @file{common}
252   directory, the project has the needed implicit source directory.
253
254 @item The attribute @b{Source_Dirs} can be set to a list of path names, one
255   for each of the source directories. Such paths can either be absolute
256   names (for instance @file{"/usr/local/common/"} on UNIX), or relative to the
257   directory in which the project file resides (for instance "." if
258   @file{build.gpr} is inside @file{common/}, or "common" if it is one level up).
259   Each of the source directories must exist and be readable.
260
261 @cindex portability
262   The syntax for directories is platform specific. For portability, however,
263   the project manager will always properly translate UNIX-like path names to
264   the native format of specific platform. For instance, when the same project
265   file is to be used both on Unix and Windows, "/" should be used as the
266   directory separator rather than "\".
267
268 @item The attribute @b{Source_Dirs} can automatically include subdirectories
269   using a special syntax inspired by some UNIX shells. If any of the path in
270   the list ends with @emph{"**"}, then that path and all its subdirectories
271   (recursively) are included in the list of source directories. For instance,
272   @file{**} and @file{./**} represent the complete directory tree rooted at ".".
273 @cindex Source directories, recursive
274
275 @cindex @code{Excluded_Source_Dirs}
276   When using that construct, it can sometimes be convenient to also use the
277   attribute @b{Excluded_Source_Dirs}, which is also a list of paths. Each entry
278   specifies a directory whose immediate content, not including subdirs, is to
279   be excluded. It is also possible to exclude a complete directory subtree
280   using the "**" notation.
281
282 @cindex @code{Ignore_Source_Sub_Dirs}
283   It is often desirable to remove, from the source directories, directory
284   subtrees rooted at some subdirectories. An example is the subdirectories
285   created by a Version Control System such as Subversion that creates directory
286   subtrees .svn/**. To do that, attribute  @b{Ignore_Source_Sub_Dirs} can be
287   used. It specifies the list of simple file names for the root of these
288   undesirable directory subtrees.
289
290 @end itemize
291
292 @noindent
293 When applied to the simple example, and because we generally prefer to have
294 the project file at the toplevel directory rather than mixed with the sources,
295 we will create the following file
296
297 @smallexample
298    build.gpr
299    @b{project} Build @b{is}
300       @b{for} Source_Dirs @b{use} ("common");  --  <<<<
301    @b{end} Build;
302 @end smallexample
303
304 @noindent
305 Once source directories have been specified, one may need to indicate
306 source files of interest. By default, all source files present in the source
307 directories are considered by the project manager. When this is not desired,
308 it is possible to specify the list of sources to consider explicitly.
309 In such a case, only source file base names are indicated and not
310 their absolute or relative path names. The project manager is in charge of
311 locating the specified source files in the specified source directories.
312
313 @itemize @bullet
314 @item By default, the project manager  search for all source files of all
315   specified languages in all the source directories.
316
317   Since the project manager was initially developed for Ada environments, the
318   default language is usually Ada and the above project file is complete: it
319   defines without ambiguity the sources composing the project: that is to say,
320   all the sources in subdirectory "common" for the default language (Ada) using
321   the default naming convention.
322
323 @cindex @code{Languages}
324   However, when compiling a multi-language application, or a pure C
325   application, the project manager must be told which languages are of
326   interest, which is done by setting the @b{Languages} attribute to a list of
327   strings, each of which is the name of a language. Tools like
328   @command{gnatmake} only know about Ada, while other tools like
329   @command{gprbuild} know about many more languages such as C, C++, Fortran,
330   assembly and others can be added dynamically.
331
332 @cindex Naming scheme
333   Even when using only Ada, the default naming might not be suitable. Indeed,
334   how does the project manager recognizes an "Ada file" from any other
335   file? Project files can describe the naming scheme used for source files,
336   and override the default (@pxref{Naming Schemes}). The default is the
337   standard GNAT extension (@file{.adb} for bodies and @file{.ads} for
338   specs), which is what is used in our example, explaining why no naming scheme
339   is explicitly specified.
340   @xref{Naming Schemes}.
341
342 @item @code{Source Files}
343   @cindex @code{Source_Files}
344   In some cases, source directories might contain files that should not be
345   included in a project. One can specify the explicit list of file names to
346   be considered through the @b{Source_Files} attribute.
347   When this attribute is defined, instead of looking at every file in the
348   source directories, the project manager takes only those names into
349   consideration  reports  errors if they cannot be found in the source
350   directories or does not correspond to the naming scheme.
351
352 @item For various reasons, it is sometimes useful to have a project with no
353   sources (most of the time because the attributes defined in the project
354   file will be reused in other projects, as explained in @pxref{Organizing
355   Projects into Subsystems}. To do this, the attribute
356   @emph{Source_Files} is set to the empty list, i.e. @code{()}. Alternatively,
357   @emph{Source_Dirs} can be set to the empty list, with the same
358   result.
359
360 @item @code{Source_List_File}
361 @cindex @code{Source_List_File}
362   If there is a great number of files, it might be more convenient to use
363   the attribute @b{Source_List_File}, which specifies the full path of a file.
364   This file must contain a list of source file names (one per line, no
365   directory information) that are searched as if they had been defined
366   through @emph{Source_Files}. Such a file can easily be created through
367   external tools.
368
369   A warning is issued if both attributes @code{Source_Files} and
370   @code{Source_List_File} are given explicit values. In this case, the
371   attribute @code{Source_Files} prevails.
372
373 @item @code{Excluded_Source_Files}
374 @cindex @code{Excluded_Source_Files}
375 @cindex @code{Locally_Removed_Files}
376 @cindex @code{Excluded_Source_List_File}
377   Specifying an explicit list of files is not always convenient.It might be
378   more convenient to use the default search rules with specific exceptions.
379   This can be done thanks to the attribute @b{Excluded_Source_Files}
380   (or its synonym @b{Locally_Removed_Files}).
381   Its value is the list of file names that should not be taken into account.
382   This attribute is often used when extending a project, @xref{Project
383   Extension}. A similar attribute @b{Excluded_Source_List_File} plays the same
384   role but takes the name of file containing file names similarly to
385   @code{Source_List_File}.
386
387 @end itemize
388
389 @noindent
390 In most simple cases, such as the above example, the default source file search
391 behavior provides the expected result, and we do not need to add anything after
392 setting @code{Source_Dirs}. The project manager automatically finds
393 @file{pack.ads}, @file{pack.adb} and @file{proc.adb} as source files of the
394 project.
395
396 Note that it is considered an error for a project file to have no sources
397 attached to it unless explicitly declared as mentioned above.
398
399 If the order of the source directories is known statically, that is if
400 @code{"**"} is not used in the string list @code{Source_Dirs}, then there may
401 be several files with the same source file name sitting in different
402 directories of the project. In this case, only the file in the first directory
403 is considered as a source of the project and the others are hidden. If
404 @code{"**"} is not used in the string list @code{Source_Dirs}, it is an error
405 to have several files with the same source file name in the same directory
406 @code{"**"} subtree, since there would be an ambiguity as to which one should
407 be used. However, two files with the same source file name may in two single
408 directories or directory subtrees. In this case, the one in the first directory
409 or directory subtree is a source of the project.
410
411 @c ---------------------------------------------
412 @node Object and Exec Directory
413 @subsection Object and Exec Directory
414 @c ---------------------------------------------
415
416 @noindent
417 The next step when writing a project is to indicate where the compiler should
418 put the object files. In fact, the compiler and other tools might create
419 several different kind of files (for GNAT, there is the object file and the ALI
420 file for instance). One of the important concepts in projects is that most
421 tools may consider source directories as read-only and do not attempt to create
422 new or temporary files there. Instead, all files are created in the object
423 directory. It is of course not true for project-aware IDEs, whose purpose it is
424 to create the source files.
425
426 @cindex @code{Object_Dir}
427 The object directory is specified through the @b{Object_Dir} attribute.
428 Its value is the path to the object directory, either absolute or
429 relative to the directory containing the project file. This
430 directory must already exist and be readable and writable, although
431 some tools have a switch to create the directory if needed (See
432 the switch @code{-p} for @command{gnatmake} and @command{gprbuild}).
433
434 If the attribute @code{Object_Dir} is not specified, it defaults to
435 the project directory, that is the directory containing the project file.
436
437 For our example, we can specify the object dir in this way:
438
439 @smallexample
440    @b{project} Build @b{is}
441       @b{for} Source_Dirs @b{use} ("common");
442       @b{for} Object_Dir @b{use} "obj";   --  <<<<
443    @b{end} Build;
444 @end smallexample
445
446 @noindent
447 As mentioned earlier, there is a single object directory per project. As a
448 result, if you have an existing system where the object files are spread in
449 several directories, you can either move all of them into the same directory if
450 you want to build it with a single project file, or study the section on
451 subsystems (@pxref{Organizing Projects into Subsystems}) to see how each
452 separate object directory can be associated with one of the subsystem
453 constituting the application.
454
455 When the @command{linker} is called, it usually creates an executable. By
456 default, this executable is placed in the object directory of the project. It
457 might be convenient to store it in its own directory.
458
459 @cindex @code{Exec_Dir}
460 This can be done through the @code{Exec_Dir} attribute, which, like
461 @emph{Object_Dir} contains a single absolute or relative path and must point to
462 an existing and writable directory, unless you ask the tool to create it on
463 your behalf. When not specified, It defaults to the object directory and
464 therefore to the project file's directory if neither @emph{Object_Dir} nor
465 @emph{Exec_Dir} was specified.
466
467 In the case of the example, let's place the executable in the root
468 of the hierarchy, ie the same directory as @file{build.gpr}. Hence
469 the project file is now
470
471 @smallexample
472    @b{project} Build @b{is}
473       @b{for} Source_Dirs @b{use} ("common");
474       @b{for} Object_Dir @b{use} "obj";
475       @b{for} Exec_Dir @b{use} ".";  --   <<<<
476    @b{end} Build;
477 @end smallexample
478
479 @c ---------------------------------------------
480 @node Main Subprograms
481 @subsection Main Subprograms
482 @c ---------------------------------------------
483
484 @noindent
485 In the previous section, executables were mentioned. The project manager needs
486 to be taught what they are. In a project file, an executable is indicated by
487 pointing to source file of the main subprogram. In C this is the file that
488 contains the @code{main} function, and in Ada the file that contains the main
489 unit.
490
491 There can be any number of such main files within a given project, and thus
492 several executables can be built in the context of a single project file. Of
493 course, one given executable might not (and in fact will not) need all the
494 source files referenced by the project. As opposed to other build environments
495 such as @command{makefile}, one does not need to specify the list of
496 dependencies of each executable, the project-aware builders knows enough of the
497 semantics of the languages to build ands link only the necessary elements.
498
499 @cindex @code{Main}
500 The list of main files is specified via the @b{Main} attribute. It contains
501 a list of file names (no directories). If a project defines this
502 attribute, it is not necessary to identify  main files on the
503 command line when invoking a builder, and editors like
504 @command{GPS} will be able to create extra menus to spawn or debug the
505 corresponding executables.
506
507 @smallexample
508    @b{project} Build @b{is}
509       @b{for} Source_Dirs @b{use} ("common");
510       @b{for} Object_Dir @b{use} "obj";
511       @b{for} Exec_Dir @b{use} ".";
512       @b{for} Main @b{use} ("proc.adb");  --   <<<<
513    @b{end} Build;
514 @end smallexample
515
516 @noindent
517 If this attribute is defined in the project, then spawning the builder
518 with a command such as
519
520 @smallexample
521    gnatmake ^-Pbuild^/PROJECT_FILE=build^
522 @end smallexample
523
524 @noindent
525 automatically builds all the executables corresponding to the files
526 listed in the @emph{Main} attribute. It is possible to specify one
527 or more executables on the command line to build a subset of them.
528
529 @c ---------------------------------------------
530 @node Tools Options in Project Files
531 @subsection Tools Options in Project Files
532 @c ---------------------------------------------
533
534 @noindent
535 We now have a project file that fully describes our environment, and can be
536 used to build the application with a simple @command{gnatmake} command as seen
537 in the previous section. In fact, the empty project we showed immediately at
538 the beginning (with no attribute at all) could already fulfill that need if it
539 was put in the @file{common} directory.
540
541 Of course, we always want more control. This section will show you how to
542 specify the compilation switches that the various tools involved in the
543 building of the executable should use.
544
545 @cindex command line length
546 Since source names and locations are described into the project file, it is not
547 necessary to use switches on the command line for this purpose (switches such
548 as -I for gcc). This removes a major source of command line length overflow.
549 Clearly, the builders will have to communicate this information one way or
550 another to the underlying compilers and tools they call but they usually use
551 response files for this and thus should not be subject to command line
552 overflows.
553
554 Several tools are participating to the creation of an executable: the compiler
555 produces object files from the source files; the binder (in the Ada case)
556 creates an source file that takes care, among other things, of elaboration
557 issues and global variables initialization; and the linker gathers everything
558 into a single executable that users can execute. All these tools are known by
559 the project manager and will be called with user defined switches from the
560 project files. However, we need to introduce a new project file concept to
561 express which switches to be used for any of the tools involved in the build.
562
563 @cindex project file packages
564 A project file is subdivided into zero or more @b{packages}, each of which
565 contains the attributes specific to one tool (or one set of tools). Project
566 files use an Ada-like syntax for packages. Package names permitted in project
567 files are restricted to a predefined set (@pxref{Packages}), and the contents
568 of packages are limited to a small set of constructs and attributes
569 (@pxref{Attributes}).
570
571 Our example project file can be extended with the following empty packages. At
572 this stage, they could all be omitted since they are empty, but they show which
573 packages would be involved in the build process.
574
575 @smallexample
576    @b{project} Build @b{is}
577       @b{for} Source_Dirs @b{use} ("common");
578       @b{for} Object_Dir @b{use} "obj";
579       @b{for} Exec_Dir @b{use} ".";
580       @b{for} Main @b{use} ("proc.adb");
581    @b{end} Build;
582
583    @b{package} Builder @b{is}  --<<<  for gnatmake and gprbuild
584    @b{end} Builder;
585
586    @b{package} Compiler @b{is} --<<<  for the compiler
587    @b{end} Compiler;
588
589    @b{package} Binder @b{is}   --<<<  for the binder
590    @b{end} Binder;
591
592    @b{package} Linker @b{is}   --<<<  for the linker
593    @b{end} Linker;
594 @end smallexample
595
596 @noindent
597 Let's first examine the compiler switches. As stated in the initial description
598 of the example, we want to compile all files with @option{-O2}. This is a
599 compiler switch, although it is usual, on the command line, to pass it to the
600 builder which then passes it to the compiler. It is recommended to use directly
601 the right package, which will make the setup easier to understand for other
602 people.
603
604 Several attributes can be used to specify the switches:
605
606 @table @asis
607 @item @b{Default_Switches}:
608 @cindex @code{Default_Switches}
609   This is the first mention in this manual of an @b{indexed attribute}. When
610   this attribute is defined, one must supply an @emph{index} in the form of a
611   literal string.
612   In the case of @emph{Default_Switches}, the index is the name of the
613   language to which the switches apply (since a different compiler will
614   likely be used for each language, and each compiler has its own set of
615   switches). The value of the attribute is a list of switches.
616
617   In this example, we want to compile all Ada source files with the
618   @option{-O2} switch, and the resulting project file is as follows
619   (only the @code{Compiler} package is shown):
620
621   @smallexample
622   @b{package} Compiler @b{is}
623     @b{for} Default_Switches ("Ada") @b{use} ("-O2");
624   @b{end} Compiler;
625   @end smallexample
626
627 @item @b{Switches}:
628 @cindex @code{Switches}
629   in some cases, we might want to use specific switches
630   for one or more files. For instance, compiling @file{proc.adb} might not be
631   possible at high level of optimization because of a compiler issue.
632   In such a case, the @emph{Switches}
633   attribute (indexed on the file name) can be used and will override the
634   switches defined by @emph{Default_Switches}. Our project file would
635   become:
636
637   @smallexample
638   @b{package} Compiler @b{is}
639     @b{for} Default_Switches ("Ada") @b{use} ("-O2");
640     @b{for} Switches ("proc.adb") @b{use} ("-O0");
641   @b{end} Compiler;
642   @end smallexample
643
644   @noindent
645   @code{Switches} may take a pattern as an index, such as in:
646
647   @smallexample
648   @b{package} Compiler @b{is}
649     @b{for} Default_Switches ("Ada") @b{use} ("-O2");
650     @b{for} Switches ("pkg*") @b{use} ("-O0");
651   @b{end} Compiler;
652   @end smallexample
653
654   @noindent
655   Sources @file{pkg.adb} and @file{pkg-child.adb} would be compiled with -O0,
656   not -O2.
657
658   @noindent
659   @code{Switches} can also be given a language name as index instead of a file
660   name in which case it has the same semantics as @emph{Default_Switches}.
661   However, indexes with wild cards are never valid for language name.
662
663 @item @b{Local_Configuration_Pragmas}:
664 @cindex @code{Local_Configuration_Pragmas}
665   this attribute may specify the path
666   of a file containing configuration pragmas for use by the Ada compiler,
667   such as @code{pragma Restrictions (No_Tasking)}. These pragmas will be
668   used for all the sources of the project.
669
670 @end table
671
672 The switches for the other tools are defined in a similar manner through the
673 @b{Default_Switches} and @b{Switches} attributes, respectively in the
674 @emph{Builder} package (for @command{gnatmake} and @command{gprbuild}),
675 the @emph{Binder} package (binding Ada executables) and the @emph{Linker}
676 package (for linking executables).
677
678 @c ---------------------------------------------
679 @node Compiling with Project Files
680 @subsection Compiling with Project Files
681 @c ---------------------------------------------
682
683 @noindent
684 Now that our project files are written, let's build our executable.
685 Here is the command we would use from the command line:
686
687 @smallexample
688    gnatmake ^-Pbuild^/PROJECT_FILE=build^
689 @end smallexample
690
691 @noindent
692 This will automatically build the executables specified through the
693 @emph{Main} attribute: for each, it will compile or recompile the
694 sources for which the object file does not exist or is not up-to-date; it
695 will then run the binder; and finally run the linker to create the
696 executable itself.
697
698 @command{gnatmake} only knows how to handle Ada files. By using
699 @command{gprbuild} as a builder, you could automatically manage C files the
700 same way: create the file @file{utils.c} in the @file{common} directory,
701 set the attribute @emph{Languages} to @code{"(Ada, C)"}, and run
702
703 @smallexample
704    gprbuild ^-Pbuild^/PROJECT_FILE=build^
705 @end smallexample
706
707 @noindent
708 Gprbuild knows how to recompile the C files and will
709 recompile them only if one of their dependencies has changed. No direct
710 indication on how to build the various elements is given in the
711 project file, which describes the project properties rather than a
712 set of actions to be executed. Here is the invocation of
713 @command{gprbuild} when building a multi-language program:
714
715 @smallexample
716 $ gprbuild -Pbuild
717 gcc -c proc.adb
718 gcc -c pack.adb
719 gcc -c utils.c
720 gprbind proc
721 ...
722 gcc proc.o -o proc
723 @end smallexample
724
725 @noindent
726 Notice the three steps described earlier:
727
728 @itemize @bullet
729 @item The first three gcc commands correspond to the compilation phase.
730 @item The gprbind command corresponds to the post-compilation phase.
731 @item The last gcc command corresponds to the final link.
732
733 @end itemize
734
735 @noindent
736 @cindex @option{-v} option (for GPRbuild)
737 The default output of GPRbuild's execution is kept reasonably simple and easy
738 to understand. In particular, some of the less frequently used commands are not
739 shown, and some parameters are abbreviated. So it is not possible to rerun the
740 effect of the @command{gprbuild} command by cut-and-pasting its output.
741 GPRbuild's option @code{-v} provides a much more verbose output which includes,
742 among other information, more complete compilation, post-compilation and link
743 commands.
744
745 @c ---------------------------------------------
746 @node Executable File Names
747 @subsection Executable File Names
748 @c ---------------------------------------------
749
750 @noindent
751 @cindex @code{Executable}
752 By default, the executable name corresponding to a main file is
753 computed from the main source file name. Through the attribute
754 @b{Builder.Executable}, it is possible to change this default.
755
756 For instance, instead of building @command{proc} (or @command{proc.exe}
757 on Windows), we could configure our project file to build "proc1"
758 (resp proc1.exe) with the following addition:
759
760 @smallexample @c projectfile
761    project Build is
762       ...  --  same as before
763       package Builder is
764          for Executable ("proc.adb") use "proc1";
765       end Builder
766    end Build;
767 @end smallexample
768
769 @noindent
770 @cindex @code{Executable_Suffix}
771 Attribute @b{Executable_Suffix}, when specified, may change the suffix
772 of the executable files, when no attribute @code{Executable} applies:
773 its value replace the platform-specific executable suffix.
774 The default executable suffix is empty on UNIX and ".exe" on Windows.
775
776 It is also possible to change the name of the produced executable by using the
777 command line switch @option{-o}. When several mains are defined in the project,
778 it is not possible to use the @option{-o} switch and the only way to change the
779 names of the executable is provided by Attributes @code{Executable} and
780 @code{Executable_Suffix}.
781
782 @c ---------------------------------------------
783 @node Avoid Duplication With Variables
784 @subsection Avoid Duplication With Variables
785 @c ---------------------------------------------
786
787 @noindent
788 To illustrate some other project capabilities, here is a slightly more complex
789 project using similar sources and a main program in C:
790
791 @smallexample @c projectfile
792 project C_Main is
793    for Languages    use ("Ada", "C");
794    for Source_Dirs  use ("common");
795    for Object_Dir   use  "obj";
796    for Main         use ("main.c");
797    package Compiler is
798       C_Switches := ("-pedantic");
799       for Default_Switches ("C")   use C_Switches;
800       for Default_Switches ("Ada") use ("-gnaty");
801       for Switches ("main.c") use C_Switches & ("-g");
802    end Compiler;
803 end C_Main;
804 @end smallexample
805
806 @noindent
807 This project has many similarities with the previous one.
808 As expected, its @code{Main} attribute now refers to a C source.
809 The attribute @emph{Exec_Dir} is now omitted, thus the resulting
810 executable will be put in the directory @file{obj}.
811
812 The most noticeable difference is the use of a variable in the
813 @emph{Compiler} package to store settings used in several attributes.
814 This avoids text duplication, and eases maintenance (a single place to
815 modify if we want to add new switches for C files). We will revisit
816 the use of variables in the context of scenarios (@pxref{Scenarios in
817 Projects}).
818
819 In this example, we see how the file @file{main.c} can be compiled with
820 the switches used for all the other C files, plus @option{-g}.
821 In this specific situation the use of a variable could have been
822 replaced by a reference to the @code{Default_Switches} attribute:
823
824 @smallexample @c projectfile
825    for Switches ("c_main.c") use Compiler'Default_Switches ("C") & ("-g");
826 @end smallexample
827
828 @noindent
829 Note the tick (@emph{'}) used to refer to attributes defined in a package.
830
831 Here is the output of the GPRbuild command using this project:
832
833 @smallexample
834 $gprbuild -Pc_main
835 gcc -c -pedantic -g main.c
836 gcc -c -gnaty proc.adb
837 gcc -c -gnaty pack.adb
838 gcc -c -pedantic utils.c
839 gprbind main.bexch
840 ...
841 gcc main.o -o main
842 @end smallexample
843
844 @noindent
845 The default switches for Ada sources,
846 the default switches for C sources (in the compilation of @file{lib.c}),
847 and the specific switches for @file{main.c} have all been taken into
848 account.
849
850 @c ---------------------------------------------
851 @node Naming Schemes
852 @subsection Naming Schemes
853 @c ---------------------------------------------
854
855 @noindent
856 Sometimes an Ada software system is ported from one compilation environment to
857 another (say GNAT), and the file are not named using the default GNAT
858 conventions. Instead of changing all the file names, which for a variety of
859 reasons might not be possible, you can define the relevant file naming scheme
860 in the @b{Naming} package of your project file.
861
862 The naming scheme has two distinct goals for the project manager: it
863 allows finding of source files when searching in the source
864 directories, and given a source file name it makes it possible to guess
865 the associated language, and thus the compiler to use.
866
867 Note that the use by the Ada compiler of pragmas Source_File_Name is not
868 supported when using project files. You must use the features described in this
869 paragraph. You can however specify other configuration pragmas
870 (@pxref{Specifying Configuration Pragmas}).
871
872 The following attributes can be defined in package @code{Naming}:
873
874 @table @asis
875 @item @b{Casing}:
876 @cindex @code{Casing}
877   Its value must be one of @code{"lowercase"} (the default if
878   unspecified), @code{"uppercase"} or @code{"mixedcase"}. It describes the
879   casing of file names with regards to the Ada unit name. Given an Ada unit
880   My_Unit, the file name will respectively be @file{my_unit.adb} (lowercase),
881   @file{MY_UNIT.ADB} (uppercase) or @file{My_Unit.adb} (mixedcase).
882   On Windows, file names are case insensitive, so this attribute is
883   irrelevant.
884
885 @item @b{Dot_Replacement}:
886 @cindex @code{Dot_Replacement}
887   This attribute specifies the string that should replace the "." in unit
888   names. Its default value is @code{"-"} so that a unit
889   @code{Parent.Child} is expected to be found in the file
890   @file{parent-child.adb}. The replacement string must satisfy the following
891   requirements to avoid ambiguities in the naming scheme:
892
893   @itemize -
894   @item It must not be empty
895   @item It cannot start or end with an alphanumeric character
896   @item It cannot be a single underscore
897   @item It cannot start with an underscore followed by an alphanumeric
898   @item It cannot contain a dot @code{'.'} except if the entire string
899      is @code{"."}
900
901   @end itemize
902
903 @item @b{Spec_Suffix} and @b{Specification_Suffix}:
904 @cindex @code{Spec_Suffix}
905 @cindex @code{Specification_Suffix}
906   For Ada, these attributes give the suffix used in file names that contain
907   specifications. For other languages, they give the extension for files
908   that contain declaration (header files in C for instance). The attribute
909   is indexed on the language.
910   The two attributes are equivalent, but the latter is obsolescent.
911   If @code{Spec_Suffix ("Ada")} is not specified, then the default is
912   @code{"^.ads^.ADS^"}.
913   The value must satisfy the following requirements:
914
915   @itemize -
916   @item It must not be empty
917   @item It cannot start with an alphanumeric character
918   @item It cannot start with an underscore followed by an alphanumeric character
919   @item It must include at least one dot
920
921   @end itemize
922
923 @item @b{Body_Suffix} and @b{Implementation_Suffix}:
924 @cindex @code{Body_Suffix}
925 @cindex @code{Implementation_Suffix}
926   These attributes give the extension used for file names that contain
927   code (bodies in Ada). They are indexed on the language. The second
928   version is obsolescent and fully replaced by the first attribute.
929
930   These attributes must satisfy the same requirements as @code{Spec_Suffix}.
931   In addition, they must be different from any of the values in
932   @code{Spec_Suffix}.
933   If @code{Body_Suffix ("Ada")} is not specified, then the default is
934   @code{"^.adb^.ADB^"}.
935
936   If @code{Body_Suffix ("Ada")} and @code{Spec_Suffix ("Ada")} end with the
937   same string, then a file name that ends with the longest of these two
938   suffixes will be a body if the longest suffix is @code{Body_Suffix ("Ada")}
939   or a spec if the longest suffix is @code{Spec_Suffix ("Ada")}.
940
941   If the suffix does not start with a '.', a file with a name exactly equal
942   to the suffix will also be part of the project (for instance if you define
943   the suffix as @code{Makefile}, a file called @file{Makefile} will be part
944   of the project. This capability is usually not interesting  when building.
945   However, it might become useful when a project is also used to
946   find the list of source files in an editor, like the GNAT Programming System
947   (GPS).
948
949 @item @b{Separate_Suffix}:
950 @cindex @code{Separate_Suffix}
951   This attribute is specific to Ada. It denotes the suffix used in file names
952   that contain separate bodies. If it is not specified, then it defaults to
953   same value as @code{Body_Suffix ("Ada")}. The same rules apply as for the
954   @code{Body_Suffix} attribute. The only accepted index is "Ada".
955
956 @item @b{Spec} or @b{Specification}:
957 @cindex @code{Spec}
958 @cindex @code{Specification}
959   This attribute @code{Spec} can be used to define the source file name for a
960   given Ada compilation unit's spec. The index is the literal name of the Ada
961   unit (case insensitive). The value is the literal base name of the file that
962   contains this unit's spec (case sensitive or insensitive depending on the
963   operating system). This attribute allows the definition of exceptions to the
964   general naming scheme, in case some files do not follow the usual
965   convention.
966
967   When a source file contains several units, the relative position of the unit
968   can be indicated. The first unit in the file is at position 1
969
970   @smallexample @c projectfile
971    for Spec ("MyPack.MyChild") use "mypack.mychild.spec";
972    for Spec ("top") use "foo.a" at 1;
973    for Spec ("foo") use "foo.a" at 2;
974   @end smallexample
975
976 @item @b{Body} or @b{Implementation}:
977 @cindex @code{Body}
978 @cindex @code{Implementation}
979   These attribute play the same role as @emph{Spec} for Ada bodies.
980
981 @item @b{Specification_Exceptions} and @b{Implementation_Exceptions}:
982 @cindex @code{Specification_Exceptions}
983 @cindex @code{Implementation_Exceptions}
984   These attributes define exceptions to the naming scheme for languages
985   other than Ada. They are indexed on the language name, and contain
986   a list of file names respectively for headers and source code.
987
988 @end table
989
990 @ifclear vms
991 For example, the following package models the Apex file naming rules:
992
993 @smallexample @c projectfile
994 @group
995   package Naming is
996     for Casing               use "lowercase";
997     for Dot_Replacement      use ".";
998     for Spec_Suffix ("Ada")  use ".1.ada";
999     for Body_Suffix ("Ada")  use ".2.ada";
1000   end Naming;
1001 @end group
1002 @end smallexample
1003 @end ifclear
1004
1005 @ifset vms
1006 For example, the following package models the DEC Ada file naming rules:
1007
1008 @smallexample @c projectfile
1009 @group
1010   package Naming is
1011     for Casing               use "lowercase";
1012     for Dot_Replacement      use "__";
1013     for Spec_Suffix ("Ada")  use "_.ada";
1014     for Body_Suffix ("Ada")  use ".ada";
1015   end Naming;
1016 @end group
1017 @end smallexample
1018
1019 @noindent
1020 (Note that @code{Casing} is @code{"lowercase"} because GNAT gets the file
1021 names in lower case)
1022 @end ifset
1023
1024 @c ---------------------------------------------
1025 @node Organizing Projects into Subsystems
1026 @section Organizing Projects into Subsystems
1027 @c ---------------------------------------------
1028
1029 @noindent
1030 A @b{subsystem} is a coherent part of the complete system to be built. It is
1031 represented by a set of sources and one single object directory. A system can
1032 be composed of a single subsystem when it is simple as we have seen in the
1033 first section. Complex systems are usually composed of several interdependent
1034 subsystems. A subsystem is dependent on another subsystem if knowledge of the
1035 other one is required to build it, and in particular if visibility on some of
1036 the sources of this other subsystem is required. Each subsystem is usually
1037 represented by its own project file.
1038
1039 In this section, the previous example is being extended. Let's assume some
1040 sources of our @code{Build} project depend on other sources.
1041 For instance, when building a graphical interface, it is usual to depend upon
1042 a graphical library toolkit such as GtkAda. Furthermore, we also need
1043 sources from a logging module we had previously written.
1044
1045 @menu
1046 * Project Dependencies::
1047 * Cyclic Project Dependencies::
1048 * Sharing Between Projects::
1049 * Global Attributes::
1050 @end menu
1051
1052 @c ---------------------------------------------
1053 @node Project Dependencies
1054 @subsection Project Dependencies
1055 @c ---------------------------------------------
1056
1057 @noindent
1058 GtkAda comes with its own project file (appropriately called
1059 @file{gtkada.gpr}), and we will assume we have already built a project
1060 called @file{logging.gpr} for the logging module. With the information provided
1061 so far in @file{build.gpr}, building the application would fail with an error
1062 indicating that the gtkada and logging units that are relied upon by the sources
1063 of this project cannot be found.
1064
1065 This is easily solved by adding the following @b{with} clauses at the beginning
1066 of our project:
1067
1068 @smallexample @c projectfile
1069   with "gtkada.gpr";
1070   with "a/b/logging.gpr";
1071   project Build is
1072      ...  --  as before
1073   end Build;
1074 @end smallexample
1075
1076 @noindent
1077 @cindex @code{Externally_Built}
1078 When such a project is compiled, @command{gnatmake} will automatically
1079 check the other projects and recompile their sources when needed. It will also
1080 recompile the sources from @code{Build} when needed, and finally create the
1081 executable. In some cases, the implementation units needed to recompile a
1082 project are not available, or come from some third-party and you do not want to
1083 recompile it yourself. In this case, the attribute @b{Externally_Built} to
1084 "true" can be set, indicating to the builder that this project can be assumed
1085 to be up-to-date, and should not be considered for recompilation. In Ada, if
1086 the sources of this externally built project were compiled with another version
1087 of the compiler or with incompatible options, the binder will issue an error.
1088
1089 The project's @code{with} clause has several effects. It provides source
1090 visibility between projects during the compilation process. It also guarantees
1091 that the necessary object files from @code{Logging} and @code{GtkAda} are
1092 available when linking @code{Build}.
1093
1094 As can be seen in this example, the syntax for importing projects is similar
1095 to the syntax for importing compilation units in Ada. However, project files
1096 use literal strings instead of names, and the @code{with} clause identifies
1097 project files rather than packages.
1098
1099 Each literal string after @code{with} is the path
1100 (absolute or relative) to a project file. The @code{.gpr} extension is
1101 optional, although we recommend adding it. If no extension is specified,
1102 and no project file with the @file{^.gpr^.GPR^} extension is found, then
1103 the file is searched for exactly as written in the @code{with} clause,
1104 that is with no extension.
1105
1106 As mentioned above, the path after a @code{with} has to be a literal
1107 string, and you cannot use concatenation, or lookup the value of external
1108 variables to change the directories from which a project is loaded.
1109 A solution if you need something like this is to use aggregate projects
1110 (@pxref{Aggregate Projects}).
1111
1112 @cindex project path
1113 When a relative path or a base name is used, the
1114 project files are searched relative to each of the directories in the
1115 @b{project path}. This path includes all the directories found with the
1116 following algorithm, in that order, as soon as a matching file is found,
1117 the search stops:
1118
1119 @itemize @bullet
1120 @item First, the file is searched relative to the directory that contains the
1121   current project file.
1122
1123 @item
1124 @cindex @code{ADA_PROJECT_PATH}
1125 @cindex @code{GPR_PROJECT_PATH}
1126   Then it is searched relative to all the directories specified in the
1127   ^environment variables^logical names^ @b{GPR_PROJECT_PATH} and
1128   @b{ADA_PROJECT_PATH} (in that order) if they exist. The former is
1129   recommended, the latter is kept for backward compatibility.
1130
1131 @item Finally, it is searched relative to the default project directories.
1132   Such directories depends on the tool used. The different locations searched
1133   in the specified order are:
1134
1135   @itemize @bullet
1136   @item @file{<prefix>/<target>/lib/gnat}
1137   (for @command{gnatmake} in all cases, and for @command{gprbuild} if option
1138   @option{--target} is specified)
1139   @item @file{<prefix>/share/gpr/}
1140   (for @command{gnatmake} and @command{gprbuild})
1141   @item @file{<prefix>/lib/gnat/}
1142   (for @command{gnatmake} and @command{gprbuild})
1143   @end itemize
1144
1145   In our example, @file{gtkada.gpr} is found in the predefined directory if
1146   it was installed at the same root as GNAT.
1147 @end itemize
1148
1149 @noindent
1150 Some tools also support extending the project path from the command line,
1151 generally through the @option{-aP}. You can see the value of the project
1152 path by using the @command{gnatls -v} command.
1153
1154 Any symbolic link will be fully resolved in the directory of the
1155 importing project file before the imported project file is examined.
1156
1157 Any source file in the imported project can be used by the sources of the
1158 importing project, transitively.
1159 Thus if @code{A} imports @code{B}, which imports @code{C}, the sources of
1160 @code{A} may depend on the sources of @code{C}, even if @code{A} does not
1161 import @code{C} explicitly. However, this is not recommended, because if
1162 and when @code{B} ceases to import @code{C}, some sources in @code{A} will
1163 no longer compile. @command{gprbuild} has a switch @option{--no-indirect-imports}
1164 that will report such indirect dependencies.
1165
1166 One very important aspect of a project hierarchy is that
1167 @b{a given source can only belong to one project} (otherwise the project manager
1168 would not know which settings apply to it and when to recompile it). It means
1169 that different project files do not usually share source directories or
1170 when they do, they need to specify precisely which project owns which sources
1171 using attribute @code{Source_Files} or equivalent. By contrast, 2 projects
1172 can each own a source with the same base file name as long as they live in
1173 different directories. The latter is not true for Ada Sources because of the
1174 correlation between source files and Ada units.
1175
1176 @c ---------------------------------------------
1177 @node Cyclic Project Dependencies
1178 @subsection Cyclic Project Dependencies
1179 @c ---------------------------------------------
1180
1181 @noindent
1182 Cyclic dependencies are mostly forbidden:
1183 if @code{A} imports @code{B} (directly or indirectly) then @code{B}
1184 is not allowed to import @code{A}. However, there are cases when cyclic
1185 dependencies would be beneficial. For these cases, another form of import
1186 between projects exists: the @b{limited with}.  A project @code{A} that
1187 imports a project @code{B} with a straight @code{with} may also be imported,
1188 directly or indirectly, by @code{B} through a @code{limited with}.
1189
1190 The difference between straight @code{with} and @code{limited with} is that
1191 the name of a project imported with a @code{limited with} cannot be used in the
1192 project importing it. In particular, its packages cannot be renamed and
1193 its variables cannot be referred to.
1194
1195 @smallexample @c 0projectfile
1196 with "b.gpr";
1197 with "c.gpr";
1198 project A is
1199     For Exec_Dir use B'Exec_Dir; -- ok
1200 end A;
1201
1202 limited with "a.gpr";   --  Cyclic dependency: A -> B -> A
1203 project B is
1204    For Exec_Dir use A'Exec_Dir; -- not ok
1205 end B;
1206
1207 with "d.gpr";
1208 project C is
1209 end C;
1210
1211 limited with "a.gpr";  --  Cyclic dependency: A -> C -> D -> A
1212 project D is
1213    For Exec_Dir use A'Exec_Dir; -- not ok
1214 end D;
1215 @end smallexample
1216
1217 @c ---------------------------------------------
1218 @node Sharing Between Projects
1219 @subsection Sharing Between Projects
1220 @c ---------------------------------------------
1221
1222 @noindent
1223 When building an application, it is common to have similar needs in several of
1224 the projects corresponding to the subsystems under construction. For instance,
1225 they will all have the same compilation switches.
1226
1227 As seen before (@pxref{Tools Options in Project Files}), setting compilation
1228 switches for all sources of a subsystem is simple: it is just a matter of
1229 adding a @code{Compiler.Default_Switches} attribute to each project files with
1230 the same value. Of course, that means duplication of data, and both places need
1231 to be changed in order to recompile the whole application with different
1232 switches. It can become a real problem if there are many subsystems and thus
1233 many project files to edit.
1234
1235 There are two main approaches to avoiding this duplication:
1236
1237 @itemize @bullet
1238 @item Since @file{build.gpr} imports @file{logging.gpr}, we could change it
1239   to reference the attribute in Logging, either through a package renaming,
1240   or by referencing the attribute. The following example shows both cases:
1241
1242   @smallexample @c projectfile
1243   project Logging is
1244      package Compiler is
1245         for Switches ("Ada") use ("-O2");
1246      end Compiler;
1247      package Binder is
1248         for Switches ("Ada") use ("-E");
1249      end Binder;
1250   end Logging;
1251
1252   with "logging.gpr";
1253   project Build is
1254      package Compiler renames Logging.Compiler;
1255      package Binder is
1256         for Switches ("Ada") use Logging.Binder'Switches ("Ada");
1257      end Binder;
1258   end Build;
1259   @end smallexample
1260
1261   @noindent
1262   The solution used for @code{Compiler} gets the same value for all
1263   attributes of the package, but you cannot modify anything from the
1264   package (adding extra switches or some exceptions). The second
1265   version is more flexible, but more verbose.
1266
1267   If you need to refer to the value of a variable in an imported
1268   project, rather than an attribute, the syntax is similar but uses
1269   a "." rather than an apostrophe. For instance:
1270
1271   @smallexample @c projectfile
1272   with "imported";
1273   project Main is
1274      Var1 := Imported.Var;
1275   end Main;
1276   @end smallexample
1277
1278 @item The second approach is to define the switches in a third project.
1279   That project is setup without any sources (so that, as opposed to
1280   the first example, none of the project plays a special role), and
1281   will only be used to define the attributes. Such a project is
1282   typically called @file{shared.gpr}.
1283
1284   @smallexample @c projectfile
1285   abstract project Shared is
1286      for Source_Files use ();   --  no project
1287      package Compiler is
1288         for Switches ("Ada") use ("-O2");
1289      end Compiler;
1290   end Shared;
1291
1292   with "shared.gpr";
1293   project Logging is
1294      package Compiler renames Shared.Compiler;
1295   end Logging;
1296
1297   with "shared.gpr";
1298   project Build is
1299      package Compiler renames Shared.Compiler;
1300   end Build;
1301   @end smallexample
1302
1303   @noindent
1304   As for the first example, we could have chosen to set the attributes
1305   one by one rather than to rename a package. The reason we explicitly
1306   indicate that @code{Shared} has no sources is so that it can be created
1307   in any directory and we are sure it shares no sources with @code{Build}
1308   or @code{Logging}, which of course would be invalid.
1309
1310 @cindex project qualifier
1311   Note the additional use of the @b{abstract} qualifier in @file{shared.gpr}.
1312   This qualifier is optional, but helps convey the message that we do not
1313   intend this project to have sources (@pxref{Qualified Projects} for
1314   more qualifiers).
1315 @end itemize
1316
1317 @c ---------------------------------------------
1318 @node Global Attributes
1319 @subsection Global Attributes
1320 @c ---------------------------------------------
1321
1322 @noindent
1323 We have already seen many examples of attributes used to specify a special
1324 option of one of the tools involved in the build process. Most of those
1325 attributes are project specific. That it to say, they only affect the invocation
1326 of tools on the sources of the project where they are defined.
1327
1328 There are a few additional attributes that apply to all projects in a
1329 hierarchy as long as they are defined on the "main" project.
1330 The main project is the project explicitly mentioned on the command-line.
1331 The project hierarchy is the "with"-closure of the main project.
1332
1333 Here is a list of commonly used global attributes:
1334
1335 @table @asis
1336 @item @b{Builder.Global_Configuration_Pragmas}:
1337 @cindex @code{Global_Configuration_Pragmas}
1338   This attribute points to a file that contains configuration pragmas
1339   to use when building executables. These pragmas apply for all
1340   executables build from this project hierarchy. As we have seen before,
1341   additional pragmas can be specified on a per-project basis by setting the
1342   @code{Compiler.Local_Configuration_Pragmas} attribute.
1343
1344 @item @b{Builder.Global_Compilation_Switches}:
1345 @cindex @code{Global_Compilation_Switches}
1346   This attribute is a list of compiler switches to use when compiling any
1347   source file in the project hierarchy. These switches are used in addition
1348   to the ones defined in the @code{Compiler} package, which only apply to
1349   the sources of the corresponding project. This attribute is indexed on
1350   the name of the language.
1351
1352 @end table
1353
1354 Using such global capabilities is convenient. It can also lead to unexpected
1355 behavior. Especially when several subsystems are shared among different main
1356 projects and the different global attributes are not
1357 compatible. Note that using aggregate projects can be a safer and more powerful
1358 replacement to global attributes.
1359
1360 @c ---------------------------------------------
1361 @node Scenarios in Projects
1362 @section Scenarios in Projects
1363 @c ---------------------------------------------
1364
1365 @noindent
1366 Various aspects of the projects can be modified based on @b{scenarios}. These
1367 are user-defined modes that change the behavior of a project. Typical
1368 examples are the setup of platform-specific compiler options, or the use of
1369 a debug and a release mode (the former would activate the generation of debug
1370 information, when the second will focus on improving code optimization).
1371
1372 Let's enhance our example to support a debug and a release modes.The issue is to
1373 let the user choose what kind of system he is building:
1374 use @option{-g} as compiler switches in debug mode and @option{-O2}
1375 in release mode. We will also setup the projects so that we do not share the
1376 same object directory in both modes, otherwise switching from one to the other
1377 might trigger more recompilations than needed or mix objects from the 2 modes.
1378
1379 One naive approach is to create two different project files, say
1380 @file{build_debug.gpr} and @file{build_release.gpr}, that set the appropriate
1381 attributes as explained in previous sections. This solution does not scale well,
1382 because in presence of multiple projects depending on each other,
1383 you will also have to duplicate the complete hierarchy and adapt the project
1384 files to point to the right copies.
1385
1386 @cindex scenarios
1387 Instead, project files support the notion of scenarios controlled
1388 by external values. Such values can come from several sources (in decreasing
1389 order of priority):
1390
1391 @table @asis
1392 @item @b{Command line}:
1393 @cindex @option{-X}
1394   When launching @command{gnatmake} or @command{gprbuild}, the user can pass
1395   extra @option{-X} switches to define the external value. In
1396   our case, the command line might look like
1397
1398   @smallexample
1399        gnatmake -Pbuild.gpr -Xmode=debug
1400    or  gnatmake -Pbuild.gpr -Xmode=release
1401   @end smallexample
1402
1403 @item @b{^Environment variables^Logical names^}:
1404   When the external value does not come from the command line, it can come from
1405   the value of ^environment variables^logical names^ of the appropriate name.
1406   In our case, if ^an environment variable^a logical name^ called "mode"
1407   exist, its value will be taken into account.
1408
1409 @item @b{External function second parameter}
1410
1411 @end table
1412
1413 @cindex @code{external}
1414 We now need to get that value in the project. The general form is to use
1415 the predefined function @b{external} which returns the current value of
1416 the external. For instance, we could setup the object directory to point to
1417 either @file{obj/debug} or @file{obj/release} by changing our project to
1418
1419 @smallexample @c projectfile
1420    project Build is
1421        for Object_Dir use "obj/" & external ("mode", "debug");
1422        ... --  as before
1423    end Build;
1424 @end smallexample
1425
1426 @noindent
1427 The second parameter to @code{external} is optional, and is the default
1428 value to use if "mode" is not set from the command line or the environment.
1429
1430 In order to set the switches according to the different scenarios, other
1431 constructs have to be introduced such as typed variables and case statements.
1432
1433 @cindex typed variable
1434 @cindex case statement
1435 A @b{typed variable} is a variable that
1436 can take only a limited number of values, similar to an enumeration in Ada.
1437 Such a variable can then be used in a @b{case statement} and create conditional
1438 sections in the project. The following example shows how this can be done:
1439
1440 @smallexample @c projectfile
1441    project Build is
1442       type Mode_Type is ("debug", "release");  --  all possible values
1443       Mode : Mode_Type := external ("mode", "debug"); -- a typed variable
1444
1445       package Compiler is
1446          case Mode is
1447             when "debug" =>
1448                for Switches ("Ada") use ("-g");
1449             when "release" =>
1450                for Switches ("Ada") use ("-O2");
1451          end case;
1452       end Compiler;
1453    end Build;
1454 @end smallexample
1455
1456 @noindent
1457 The project has suddenly grown in size, but has become much more flexible.
1458 @code{Mode_Type} defines the only valid values for the @code{mode} variable. If
1459 any other value is read from the environment, an error is reported and the
1460 project is considered as invalid.
1461
1462 The @code{Mode} variable is initialized with an external value
1463 defaulting to @code{"debug"}. This default could be omitted and that would
1464 force the user to define the value. Finally, we can use a case statement to set the
1465 switches depending on the scenario the user has chosen.
1466
1467 Most aspects of the projects can depend on scenarios. The notable exception
1468 are project dependencies (@code{with} clauses), which may not depend on a scenario.
1469
1470 Scenarios work the same way with @b{project hierarchies}: you can either
1471 duplicate a variable similar to @code{Mode} in each of the project (as long
1472 as the first argument to @code{external} is always the same and the type is
1473 the same), or simply set the variable in the @file{shared.gpr} project
1474 (@pxref{Sharing Between Projects}).
1475
1476 @c ---------------------------------------------
1477 @node Library Projects
1478 @section Library Projects
1479 @c ---------------------------------------------
1480
1481 @noindent
1482 So far, we have seen examples of projects that create executables. However,
1483 it is also possible to create libraries instead. A @b{library} is a specific
1484 type of subsystem where, for convenience, objects are grouped together
1485 using system-specific means such as archives or windows DLLs.
1486
1487 Library projects provide a system- and language-independent way of building both @b{static}
1488 and @b{dynamic} libraries. They also support the concept of @b{standalone
1489 libraries} (SAL) which offers two significant properties: the elaboration
1490 (e.g. initialization) of the library is either automatic or very simple;
1491 a change in the
1492 implementation part of the library implies minimal post-compilation actions on
1493 the complete system and potentially no action at all for the rest of the
1494 system in the case of dynamic SALs.
1495
1496 The GNAT Project Manager takes complete care of the library build, rebuild and
1497 installation tasks, including recompilation of the source files for which
1498 objects do not exist or are not up to date, assembly of the library archive, and
1499 installation of the library (i.e., copying associated source, object and
1500 @file{ALI} files to the specified location).
1501
1502 @menu
1503 * Building Libraries::
1504 * Using Library Projects::
1505 * Stand-alone Library Projects::
1506 * Installing a library with project files::
1507 @end menu
1508
1509 @c ---------------------------------------------
1510 @node Building Libraries
1511 @subsection Building Libraries
1512 @c ---------------------------------------------
1513
1514 @noindent
1515 Let's enhance our example and transform the @code{logging} subsystem into a
1516 library.  In order to do so, a few changes need to be made to @file{logging.gpr}.
1517 A number of specific attributes needs to be defined: at least @code{Library_Name}
1518 and @code{Library_Dir}; in addition, a number of other attributes can be used
1519 to specify specific aspects of the library. For readability, it is also
1520 recommended (although not mandatory), to use the qualifier @code{library} in
1521 front of the @code{project} keyword.
1522
1523 @table @asis
1524 @item @b{Library_Name}:
1525 @cindex @code{Library_Name}
1526   This attribute is the name of the library to be built. There is no
1527   restriction on the name of a library imposed by the project manager;
1528   however, there may be system specific restrictions on the name.
1529   In general, it is recommended to stick to alphanumeric characters
1530   (and possibly underscores) to help portability.
1531
1532 @item @b{Library_Dir}:
1533 @cindex @code{Library_Dir}
1534   This attribute  is the path (absolute or relative) of the directory where
1535   the library is to be installed. In the process of building a library,
1536   the sources are compiled, the object files end up  in the explicit or
1537   implicit @code{Object_Dir} directory. When all sources of a library
1538   are compiled, some of the compilation artifacts, including the library itself,
1539   are copied to the library_dir directory. This directory must exists and be
1540   writable. It must also be different from the object directory so that cleanup
1541   activities in the Library_Dir do not affect recompilation needs.
1542
1543 @end table
1544
1545 Here is the new version of @file{logging.gpr} that makes it a library:
1546
1547 @smallexample @c projectfile
1548 library project Logging is          --  "library" is optional
1549    for Library_Name use "logging";  --  will create "liblogging.a" on Unix
1550    for Object_Dir   use "obj";
1551    for Library_Dir  use "lib";      --  different from object_dir
1552 end Logging;
1553 @end smallexample
1554
1555 @noindent
1556 Once the above two attributes are defined, the library project is valid and
1557 is enough for building a library with default characteristics.
1558 Other library-related attributes can be used to change the defaults:
1559
1560 @table @asis
1561 @item @b{Library_Kind}:
1562 @cindex @code{Library_Kind}
1563   The value of this attribute must be either @code{"static"}, @code{"dynamic"} or
1564   @code{"relocatable"} (the latter is a synonym for dynamic). It indicates
1565   which kind of library should be build (the default is to build a
1566   static library, that is an archive of object files that can potentially
1567   be linked into a static executable). When the library is set to be dynamic,
1568   a separate image is created that will be loaded independently, usually
1569   at the start of the main program execution. Support for dynamic libraries is
1570   very platform specific, for instance on Windows it takes the form of a DLL
1571   while on GNU/Linux, it is a dynamic elf image whose suffix is usually
1572   @file{.so}. Library project files, on the other hand, can be written in
1573   a platform independent way so that the same project file can be used to build
1574   a library on different operating systems.
1575
1576   If you need to build both a static and a dynamic library, it is recommended
1577   use two different object directories, since in some cases some extra code
1578   needs to be generated for the latter. For such cases, one can
1579   either define two different project files, or a single one which uses scenarios
1580   to indicate at the various kinds of library to be build and their
1581   corresponding object_dir.
1582
1583 @cindex @code{Library_ALI_Dir}
1584 @item @b{Library_ALI_Dir}:
1585   This attribute may be specified to indicate the directory where the ALI
1586   files of the library are installed. By default, they are copied into the
1587   @code{Library_Dir} directory, but as for the executables where we have a
1588   separate @code{Exec_Dir} attribute, you might want to put them in a separate
1589   directory since there can be hundreds of them. The same restrictions as for
1590   the @code{Library_Dir} attribute apply.
1591
1592 @cindex @code{Library_Version}
1593 @item @b{Library_Version}:
1594   This attribute is platform dependent, and has no effect on VMS and Windows.
1595   On Unix, it is used only for dynamic libraries as the internal
1596   name of the library (the @code{"soname"}). If the library file name (built
1597   from the @code{Library_Name}) is different from the @code{Library_Version},
1598   then the library file will be a symbolic link to the actual file whose name
1599   will be @code{Library_Version}. This follows the usual installation schemes
1600   for dynamic libraries on many Unix systems.
1601
1602 @smallexample @c projectfile
1603 @group
1604   project Logging is
1605      Version := "1";
1606      for Library_Dir use "lib";
1607      for Library_Name use "logging";
1608      for Library_Kind use "dynamic";
1609      for Library_Version use "liblogging.so." & Version;
1610   end Logging;
1611 @end group
1612 @end smallexample
1613
1614   @noindent
1615   After the compilation, the directory @file{lib} will contain both a
1616   @file{libdummy.so.1} library and a symbolic link to it called
1617   @file{libdummy.so}.
1618
1619 @cindex @code{Library_GCC}
1620 @item @b{Library_GCC}:
1621   This attribute is the name of the tool to use instead of "gcc" to link shared
1622   libraries. A common use of this attribute is to define a wrapper script that
1623   accomplishes specific actions before calling gcc (which itself is calling the
1624   linker to build the library image).
1625
1626 @item @b{Library_Options}:
1627 @cindex @code{Library_Options}
1628   This attribute may be used to specify additional switches (last switches)
1629   when linking a shared library.
1630
1631 @item @b{Leading_Library_Options}:
1632 @cindex @code{Leading_Library_Options}
1633   This attribute, that is taken into account only by @command{gprbuild}, may be
1634   used to specified leading options (first switches) when linking a shared
1635   library.
1636
1637 @cindex @code{Linker_Options}
1638 @item @b{Linker.Linker_Options}:
1639   This attribute specifies additional switches to be given to the linker when
1640   linking an executable. It is ignored when defined in the main project and
1641   taken into account in all other projects that are imported directly or
1642   indirectly. These switches complement the @code{Linker.Switches}
1643   defined in the main project. This is useful when a particular subsystem
1644   depends on an external library: adding this dependency as a
1645   @code{Linker_Options} in the project of the subsystem is more convenient than
1646   adding it to all the @code{Linker.Switches} of the main projects that depend
1647   upon this subsystem.
1648 @end table
1649
1650 @c ---------------------------------------------
1651 @node Using Library Projects
1652 @subsection Using Library Projects
1653 @c ---------------------------------------------
1654
1655 @noindent
1656 When the builder detects that a project file is a library project file, it
1657 recompiles all sources of the project that need recompilation and rebuild the
1658 library if any of the sources have been recompiled. It then groups all object
1659 files into a single file, which is a shared or a static library. This library
1660 can later on be linked with multiple executables. Note that the use
1661 of shard libraries reduces the size of the final executable and can also reduce
1662 the memory footprint at execution time when the library is shared among several
1663 executables.
1664
1665 It is also possible to build @b{multi-language libraries}. When using
1666 @command{gprbuild} as a builder, multi-language library projects allow naturally
1667 the creation of multi-language libraries . @command{gnatmake}, does not try to
1668 compile non Ada sources. However, when the project is multi-language, it will
1669 automatically link all object files found in the object directory, whether or
1670 not they were compiled from an Ada source file. This specific behavior does not
1671 apply to Ada-only projects which only take into account the objects
1672 corresponding to the sources of the project.
1673
1674 A non-library project can import a library project. When the builder is invoked
1675 on the former, the library of the latter is only rebuilt when absolutely
1676 necessary. For instance, if a unit of the
1677 library is not up-to-date but non of the executables need this unit, then the
1678 unit is not recompiled and the library is not reassembled.
1679 For instance, let's assume in our example that logging has the following
1680 sources: @file{log1.ads}, @file{log1.adb}, @file{log2.ads} and
1681 @file{log2.adb}. If @file{log1.adb} has been modified, then the library
1682 @file{liblogging} will be rebuilt when compiling all the sources of
1683 @code{Build} only if @file{proc.ads}, @file{pack.ads} or @file{pack.adb}
1684 include a @code{"with Log1"}.
1685
1686 To ensure that all the sources in the @code{Logging} library are
1687 up to date, and that all the sources of @code{Build} are also up to date,
1688 the following two commands needs to be used:
1689
1690 @smallexample
1691 gnatmake -Plogging.gpr
1692 gnatmake -Pbuild.gpr
1693 @end smallexample
1694
1695 @noindent
1696 All @file{ALI} files will also be copied from the object directory to the
1697 library directory. To build executables, @command{gnatmake} will use the
1698 library rather than the individual object files.
1699
1700 @ifclear vms
1701 Library projects can also be useful to describe a library that need to be used
1702 but, for some reason, cannot be rebuilt. For instance, it is the case when some
1703 of the library sources are not available. Such library projects need simply to
1704 use the @code{Externally_Built} attribute as in the example below:
1705
1706 @smallexample @c projectfile
1707 library project Extern_Lib is
1708    for Languages    use ("Ada", "C");
1709    for Source_Dirs  use ("lib_src");
1710    for Library_Dir  use "lib2";
1711    for Library_Kind use "dynamic";
1712    for Library_Name use "l2";
1713    for Externally_Built use "true";  --  <<<<
1714 end Extern_Lib;
1715 @end smallexample
1716
1717 @noindent
1718 In the case of externally built libraries, the @code{Object_Dir}
1719 attribute does not need to be specified because it will never be
1720 used.
1721
1722 The main effect of using such an externally built library project is mostly to
1723 affect the linker command in order to reference the desired library. It can
1724 also be achieved by using @code{Linker.Linker_Options} or @code{Linker.Switches}
1725 in the project corresponding to the subsystem needing this external library.
1726 This latter method is more straightforward in simple cases but when several
1727 subsystems depend upon the same external library, finding the proper place
1728 for the @code{Linker.Linker_Options} might not be easy and if it is
1729 not placed properly, the final link command is likely to present ordering issues.
1730 In such a situation, it is better to use the externally built library project
1731 so that all other subsystems depending on it can declare this dependency thanks
1732 to a project @code{with} clause, which in turn will trigger the builder to find
1733 the proper order of libraries in the final link command.
1734 @end ifclear
1735
1736 @c ---------------------------------------------
1737 @node Stand-alone Library Projects
1738 @subsection Stand-alone Library Projects
1739 @c ---------------------------------------------
1740
1741 @noindent
1742 @cindex standalone libraries
1743 A @b{stand-alone library} is a library that contains the necessary code to
1744 elaborate the Ada units that are included in the library. A stand-alone
1745 library is a convenient way to add an Ada subsystem to a more global system
1746 whose main is not in Ada since it makes the elaboration of the Ada part mostly
1747 transparent. However, stand-alone libraries are also useful when the main is in
1748 Ada: they provide a means for minimizing relinking & redeployment of complex
1749 systems when localized changes are made.
1750
1751 The most prominent characteristic of a stand-alone library is that it offers a
1752 distinction between interface units and implementation units. Only the former
1753 are visible to units outside the library. A stand-alone library project is thus
1754 characterised by a third attribute, @b{Library_Interface}, in addition to the
1755 two attributes that make a project a Library Project (@code{Library_Name} and
1756 @code{Library_Dir}).
1757
1758 @table @asis
1759 @item @b{Library_Interface}:
1760 @cindex @code{Library_Interface}
1761   This attribute defines an explicit subset of the units of the project.
1762   Projects importing this library project may only "with" units whose sources
1763   are listed in the @code{Library_Interface}. Other sources are considered
1764   implementation units.
1765
1766 @smallexample @c projectfile
1767 @group
1768      for Library_Dir use "lib";
1769      for Library_Name use "loggin";
1770      for Library_Interface use ("lib1", "lib2");  --  unit names
1771 @end group
1772 @end smallexample
1773
1774 @end table
1775
1776 In order to include the elaboration code in the stand-alone library, the binder
1777 is invoked on the closure of the library units creating a package whose name
1778 depends on the library name (^b~logging.ads/b^B$LOGGING.ADS/B^ in the example).
1779 This binder-generated package includes @b{initialization} and @b{finalization}
1780 procedures whose names depend on the library name (@code{logginginit} and
1781 @code{loggingfinal} in the example). The object corresponding to this package is
1782 included in the library.
1783
1784 @table @asis
1785 @item @b{Library_Auto_Init}:
1786 @cindex @code{Library_Auto_Init}
1787   A dynamic stand-alone Library is automatically initialized
1788   if automatic initialization of Stand-alone Libraries is supported on the
1789   platform and if attribute @b{Library_Auto_Init} is not specified or
1790   is specified with the value "true". A static Stand-alone Library is never
1791   automatically initialized. Specifying "false" for this attribute
1792   prevent automatic initialization.
1793
1794   When a non-automatically initialized stand-alone library is used in an
1795   executable, its initialization procedure must be called before any service of
1796   the library is used. When the main subprogram is in Ada, it may mean that the
1797   initialization procedure has to be called during elaboration of another
1798   package.
1799
1800 @item @b{Library_Dir}:
1801 @cindex @code{Library_Dir}
1802   For a stand-alone library, only the @file{ALI} files of the interface units
1803   (those that are listed in attribute @code{Library_Interface}) are copied to
1804   the library directory. As a consequence, only the interface units may be
1805   imported from Ada units outside of the library. If other units are imported,
1806   the binding phase will fail.
1807
1808 @item @b{Binder.Default_Switches}:
1809   When a stand-alone library is bound, the switches that are specified in
1810   the attribute @b{Binder.Default_Switches ("Ada")} are
1811   used in the call to @command{gnatbind}.
1812
1813 @item @b{Library_Src_Dir}:
1814 @cindex @code{Library_Src_Dir}
1815   This attribute defines the location (absolute or relative to the project
1816   directory) where the sources of the interface units are copied at
1817   installation time.
1818   These sources includes the specs of the interface units along with the closure
1819   of sources necessary to compile them successfully. That may include bodies and
1820   subunits, when pragmas @code{Inline} are used, or when there is a generic
1821   units in the spec. This directory cannot point to the object directory or
1822   one of the source directories, but it can point to the library directory,
1823   which is the default value for this attribute.
1824
1825 @item @b{Library_Symbol_Policy}:
1826 @cindex @code{Library_Symbol_Policy}
1827   This attribute controls the export of symbols and, on some platforms (like
1828   VMS) that have the notions of major and minor IDs built in the library
1829   files, it controls the setting of these IDs. It is not supported on all
1830   platforms (where it will just have no effect). It may have one of the
1831   following values:
1832
1833   @itemize -
1834   @item @code{"autonomous"} or @code{"default"}: exported symbols are not controlled
1835   @item @code{"compliant"}: if attribute @b{Library_Reference_Symbol_File}
1836      is not defined, then it is equivalent to policy "autonomous". If there
1837      are exported symbols in the reference symbol file that are not in the
1838      object files of the interfaces, the major ID of the library is increased.
1839      If there are symbols in the object files of the interfaces that are not
1840      in the reference symbol file, these symbols are put at the end of the list
1841      in the newly created symbol file and the minor ID is increased.
1842   @item @code{"controlled"}: the attribute @b{Library_Reference_Symbol_File} must be
1843      defined. The library will fail to build if the exported symbols in the
1844      object files of the interfaces do not match exactly the symbol in the
1845      symbol file.
1846   @item @code{"restricted"}: The attribute @b{Library_Symbol_File} must be defined.
1847      The library will fail to build if there are symbols in the symbol file that
1848      are not in the exported symbols of the object files of the interfaces.
1849      Additional symbols in the object files are not added to the symbol file.
1850   @item @code{"direct"}: The attribute @b{Library_Symbol_File} must be defined and
1851      must designate an existing file in the object directory. This symbol file
1852      is passed directly to the underlying linker without any symbol processing.
1853
1854   @end itemize
1855
1856 @item @b{Library_Reference_Symbol_File}
1857 @cindex @code{Library_Reference_Symbol_File}
1858   This attribute may define the path name of a reference symbol file that is
1859   read when the symbol policy is either "compliant" or "controlled", on
1860   platforms that support symbol control, such as VMS, when building a
1861   stand-alone library. The path may be an absolute path or a path relative
1862   to the project directory.
1863
1864 @item @b{Library_Symbol_File}
1865 @cindex @code{Library_Symbol_File}
1866   This attribute may define the name of the symbol file to be created when
1867   building a stand-alone library when the symbol policy is either "compliant",
1868   "controlled" or "restricted", on platforms that support symbol control,
1869   such as VMS. When symbol policy is "direct", then a file with this name
1870   must exist in the object directory.
1871 @end table
1872
1873 @c ---------------------------------------------
1874 @node Installing a library with project files
1875 @subsection Installing a library with project files
1876 @c ---------------------------------------------
1877
1878 @noindent
1879 When using project files, library installation is part of the library build
1880 process. Thus no further action is needed in order to make use of the
1881 libraries that are built as part of the general application build. A usable
1882 version of the library is installed in the directory specified by the
1883 @code{Library_Dir} attribute of the library project file.
1884
1885 You may want to install a library in a context different from where the library
1886 is built. This situation arises with third party suppliers, who may want
1887 to distribute a library in binary form where the user is not expected to be
1888 able to recompile the library. The simplest option in this case is to provide
1889 a project file slightly different from the one used to build the library, by
1890 using the @code{externally_built} attribute. @ref{Using Library Projects}
1891
1892 @c ---------------------------------------------
1893 @node Project Extension
1894 @section Project Extension
1895 @c ---------------------------------------------
1896
1897 @noindent
1898 During development of a large system, it is sometimes necessary to use
1899 modified versions of some of the source files, without changing the original
1900 sources. This can be achieved through the @b{project extension} facility.
1901
1902 Suppose for instance that our example @code{Build} project is build every night
1903 for the whole team, in some shared directory. A developer usually need to work
1904 on a small part of the system, and might not want to have a copy of all the
1905 sources and all the object files (mostly because that would require too much
1906 disk space, time to recompile everything). He prefers to be able to override
1907 some of the source files in his directory, while taking advantage of all the
1908 object files generated at night.
1909
1910 Another example can be taken from large software systems, where it is common to have
1911 multiple implementations of a common interface; in Ada terms, multiple
1912 versions of a package body for the same spec.  For example, one implementation
1913 might be safe for use in tasking programs, while another might only be used
1914 in sequential applications.  This can be modeled in GNAT using the concept
1915 of @emph{project extension}.  If one project (the ``child'') @emph{extends}
1916 another project (the ``parent'') then by default all source files of the
1917 parent project are inherited by the child, but the child project can
1918 override any of the parent's source files with new versions, and can also
1919 add new files or remove unnecessary ones.
1920 This facility is the project analog of a type extension in
1921 object-oriented programming.  Project hierarchies are permitted (an extending
1922 project may itself be extended), and a project that
1923 extends a project can also import other projects.
1924
1925 A third example is that of using project extensions to provide different
1926 versions of the same system. For instance, assume that a @code{Common}
1927 project is used by two development branches. One of the branches has now
1928 been frozen, and no further change can be done to it or to @code{Common}.
1929 However, the other development branch still needs evolution of @code{Common}.
1930 Project extensions provide a flexible solution to create a new version
1931 of a subsystem while sharing and reusing as much as possible from the original
1932 one.
1933
1934 A project extension inherits implicitly all the sources and objects from the
1935 project it extends. It is possible to create a new version of some of the
1936 sources in one of the additional source dirs of the extending project. Those new
1937 versions hide the original versions. Adding new sources or removing existing
1938 ones is also possible. Here is an example on how to extend the project
1939 @code{Build} from previous examples:
1940
1941 @smallexample @c projectfile
1942    project Work extends "../bld/build.gpr" is
1943    end Work;
1944 @end smallexample
1945
1946 @noindent
1947 The project after @b{extends} is the one being extended. As usual, it can be
1948 specified using an absolute path, or a path relative to any of the directories
1949 in the project path (@pxref{Project Dependencies}). This project does not
1950 specify source or object directories, so the default value for these attribute
1951 will be used that is to say the current directory (where project @code{Work} is
1952 placed). We can already compile that project with
1953
1954 @smallexample
1955    gnatmake -Pwork
1956 @end smallexample
1957
1958 @noindent
1959 If no sources have been placed in the current directory, this command
1960 won't do anything, since this project does not change the
1961 sources it inherited from @code{Build}, therefore all the object files
1962 in @code{Build} and its dependencies are still valid and are reused
1963 automatically.
1964
1965 Suppose we now want to supply an alternate version of @file{pack.adb}
1966 but use the existing versions of @file{pack.ads} and @file{proc.adb}.
1967 We can create the new file Work's current directory  (likely
1968 by copying the one from the @code{Build} project and making changes to
1969 it. If new packages are needed at the same time, we simply create
1970 new files in the source directory of the extending project.
1971
1972 When we recompile, @command{gnatmake} will now automatically recompile
1973 this file (thus creating @file{pack.o} in the current directory) and
1974 any file that depends on it (thus creating @file{proc.o}). Finally, the
1975 executable is also linked locally.
1976
1977 Note that we could have obtained the desired behavior using project import
1978 rather than project inheritance. A @code{base} project would contain the
1979 sources for @file{pack.ads} and @file{proc.adb}, and @code{Work} would
1980 import @code{base} and add @file{pack.adb}. In this scenario,  @code{base}
1981 cannot contain the original version of @file{pack.adb} otherwise there would be
1982 2 versions of the same unit in the closure of the project and this is not
1983 allowed. Generally speaking, it is not recommended to put the spec and the
1984 body of a unit in different projects since this affects their autonomy and
1985 reusability.
1986
1987 In a project file that extends another project, it is possible to
1988 indicate that an inherited source is @b{not part} of the sources of the
1989 extending project. This is necessary sometimes when a package spec has
1990 been overridden and no longer requires a body: in this case, it is
1991 necessary to indicate that the inherited body is not part of the sources
1992 of the project, otherwise there will be a compilation error
1993 when compiling the spec.
1994
1995 @cindex @code{Excluded_Source_Files}
1996 @cindex @code{Excluded_Source_List_File}
1997 For that purpose, the attribute @b{Excluded_Source_Files} is used.
1998 Its value is a list of file names.
1999 It is also possible to use attribute @code{Excluded_Source_List_File}.
2000 Its value is the path of a text file containing one file name per
2001 line.
2002
2003 @smallexample @c @projectfile
2004 project Work extends "../bld/build.gpr" is
2005    for Source_Files use ("pack.ads");
2006    --  New spec of Pkg does not need a completion
2007    for Excluded_Source_Files use ("pack.adb");
2008 end Work;
2009 @end smallexample
2010
2011 @noindent
2012 An extending project retains all the switches specified in the
2013 extended project.
2014
2015 @menu
2016 * Project Hierarchy Extension::
2017 @end menu
2018
2019 @c ---------------------------------------------
2020 @node Project Hierarchy Extension
2021 @subsection Project Hierarchy Extension
2022 @c ---------------------------------------------
2023
2024 @noindent
2025 One of the fundamental restrictions in project extension is the following:
2026 @b{A project is not allowed to import directly or indirectly at the same time an
2027 extending project and one of its ancestors}.
2028
2029 By means of example, consider the following hierarchy of projects.
2030
2031 @smallexample
2032    a.gpr  contains package A1
2033    b.gpr, imports a.gpr and contains B1, which depends on A1
2034    c.gpr, imports b.gpr and contains C1, which depends on B1
2035 @end smallexample
2036
2037 @noindent
2038 If we want to locally extend the packages @code{A1} and @code{C1}, we need to
2039 create several extending projects:
2040
2041 @smallexample
2042    a_ext.gpr which extends a.gpr, and overrides A1
2043    b_ext.gpr which extends b.gpr and imports a_ext.gpr
2044    c_ext.gpr which extends c.gpr, imports b_ext.gpr and overrides C1
2045 @end smallexample
2046
2047 @noindent
2048 @smallexample @c projectfile
2049    project A_Ext extends "a.gpr" is
2050       for Source_Files use ("a1.adb", "a1.ads");
2051    end A_Ext;
2052
2053    with "a_ext.gpr";
2054    project B_Ext extends "b.gpr" is
2055    end B_Ext;
2056
2057    with "b_ext.gpr";
2058    project C_Ext extends "c.gpr" is
2059       for Source_Files use ("c1.adb");
2060    end C_Ext;
2061 @end smallexample
2062
2063 @noindent
2064 The extension @file{b_ext.gpr} is required, even though we are not overriding
2065 any of the sources of @file{b.gpr} because otherwise @file{c_expr.gpr} would
2066 import @file{b.gpr} which itself knows nothing about @file{a_ext.gpr}.
2067
2068 @cindex extends all
2069 When extending a large system spanning multiple projects, it is often
2070 inconvenient to extend every project in the hierarchy that is impacted by a
2071 small change introduced in a low layer. In such cases, it is possible to create
2072 an @b{implicit extension} of entire hierarchy using @b{extends all}
2073 relationship.
2074
2075 When the project is extended using @code{extends all} inheritance, all projects
2076 that are imported by it, both directly and indirectly, are considered virtually
2077 extended. That is, the project manager creates implicit projects
2078 that extend every project in the hierarchy; all these implicit projects do not
2079 control sources on their own and use the object directory of
2080 the "extending all" project.
2081
2082 It is possible to explicitly extend one or more projects in the hierarchy
2083 in order to modify the sources. These extending projects must be imported by
2084 the "extending all" project, which will replace the corresponding virtual
2085 projects with the explicit ones.
2086
2087 When building such a project hierarchy extension, the project manager will
2088 ensure that both modified sources and sources in implicit extending projects
2089 that depend on them, are recompiled.
2090
2091 Thus, in our example we could create the following projects instead:
2092
2093 @smallexample
2094    a_ext.gpr, extends a.gpr and overrides A1
2095    c_ext.gpr, "extends all" c.gpr, imports a_ext.gpr and overrides C1
2096
2097 @end smallexample
2098
2099 @noindent
2100 @smallexample @c projectfile
2101    project A_Ext extends "a.gpr" is
2102       for Source_Files use ("a1.adb", "a1.ads");
2103    end A_Ext;
2104
2105    with "a_ext.gpr";
2106    project C_Ext extends all "c.gpr" is
2107      for Source_Files use ("c1.adb");
2108    end C_Ext;
2109 @end smallexample
2110
2111 @noindent
2112 When building project @file{c_ext.gpr}, the entire modified project space is
2113 considered for recompilation, including the sources of @file{b.gpr} that are
2114 impacted by the changes in @code{A1} and @code{C1}.
2115
2116 @c ---------------------------------------------
2117 @node Aggregate Projects
2118 @section Aggregate Projects
2119 @c ---------------------------------------------
2120
2121 @noindent
2122
2123 Aggregate projects are an extension of the project paradigm, and are
2124 meant to solve a few specific use cases that cannot be solved directly
2125 using standard projects. This section will go over a few of these use
2126 cases to try and explain what you can use aggregate projects for.
2127
2128 @subsection Building all main units from a single project tree
2129
2130 Most often, an application is organized into modules and submodules,
2131 which are very conveniently represented as a project tree or graph
2132 (the root project A @code{with}s the projects for each modules (say B and C),
2133 which in turn @code{with} projects for submodules.
2134
2135 Very often, modules will build their own executables (for testing
2136 purposes for instance), or libraries (for easier reuse in various
2137 contexts).
2138
2139 However, if you build your project through gnatmake or gprbuild, using
2140 a syntax similar to
2141
2142 @smallexample
2143    gprbuild -PA.gpr
2144 @end smallexample
2145
2146 this will only rebuild the main units of project A, not those of the
2147 imported projects B and C. Therefore you have to spawn several
2148 gnatmake commands, one per project, to build all executables.
2149 This is a little inconvenient, but more importantly is inefficient
2150 (since gnatmake needs to do duplicate work to ensure that sources are
2151 up-to-date, and cannot easily compile things in parallel when using
2152 the -j switch).
2153
2154 Also libraries are always rebuild when building a project.
2155
2156 You could therefore define an aggregate project Agg that groups A, B
2157 and C. Then, when you build with
2158
2159 @smallexample
2160     gprbuild -PAgg.gpr
2161 @end smallexample
2162
2163 this will build all main units from A, B and C.
2164
2165 @smallexample @c projectfile
2166    aggregate project Agg is
2167       for Project_Files use ("a.gpr", "b.gpr", "c.gpr");
2168    end Agg;
2169 @end smallexample
2170
2171 If B or C do not define any main unit (through their Main
2172 attribute), all their sources are build. When you do not group them
2173 in the aggregate project, only those sources that are needed by A
2174 will be build.
2175
2176 If you add a main unit to a project P not already explicitly referenced in the
2177 aggregate project, you will need to add "p.gpr" in the list of project
2178 files for the aggregate project, or the main unit will not be built when
2179 building the aggregate project.
2180
2181 @subsection Building a set of projects with a single command
2182
2183 One other case is when you have multiple applications and libraries
2184 that are build independently from each other (but they can be build in
2185 parallel). For instance, you have a project tree rooted at A, and
2186 another one (which might share some subprojects) rooted at B.
2187
2188 Using only gprbuild, you could do
2189
2190 @smallexample
2191   gprbuild -PA.gpr
2192   gprbuild -PB.gpr
2193 @end smallexample
2194
2195 to build both. But again, gprbuild has to do some duplicate work for
2196 those files that are shared between the two, and cannot truly build
2197 things in parallel efficiently.
2198
2199 If the two projects are really independent, share no sources other
2200 than through a common subproject, and have no source files with a
2201 common basename, you could create a project C that imports A and
2202 B. But these restrictions are often too strong, and one has to build
2203 them independently. An aggregate project does not have these
2204 limitations, and can aggregate two project trees that have common
2205 sources.
2206
2207 @smallexample
2208 Aggregate projects can group projects with duplicate file names
2209 @end smallexample
2210
2211 This scenario is particularly useful in environment like VxWork 653
2212 where the applications running in the multiple partitions can be build
2213 in parallel through a single gprbuild command. This also works nicely
2214 with Annex E.
2215
2216 @smallexample
2217    Aggregate projects can be used to build multiple partitions
2218 @end smallexample
2219
2220 @subsection Define a build environment
2221
2222 The environment variables at the time you launch gprbuild or gprbuild
2223 will influence the view these tools have of the project (PATH to find
2224 the compiler, ADA_PROJECT_PATH or GPR_PROJECT_PATH to find the
2225 projects, environment variables that are referenced in project files
2226 through the "external" statement,...). Several command line switches
2227 can be used to override those (-X or -aP), but on some systems and
2228 with some projects, this might make the command line too long, and on
2229 all systems often make it hard to read.
2230
2231 An aggregate project can be used to set the environment for all
2232 projects build through that aggregate. One of the nice aspects is that
2233 you can put the aggregate project under configuration management, and
2234 make sure all your user have a consistent environment when
2235 building. The syntax looks like
2236
2237 @smallexample @c projectfile
2238    aggregate project Agg is
2239       for Project_Files use ("A.gpr", "B.gpr");
2240       for Project_Path use ("../dir1", "../dir1/dir2");
2241       for External ("BUILD") use "PRODUCTION";
2242
2243       package Builder is
2244          for Switches ("Ada") use ("-q");
2245       end Builder;
2246    end Agg;
2247 @end smallexample
2248
2249 One of the often requested features in projects is to be able to
2250 reference external variables in @code{with} statements, as in
2251
2252 @smallexample @c projectfile
2253   with external("SETUP") & "path/prj.gpr";   --  ILLEGAL
2254   project MyProject is
2255      ...
2256   end MyProject;
2257 @end smallexample
2258
2259 For various reasons, this isn't authorized. But using aggregate
2260 projects provide an elegant solution. For instance, you could
2261 use a project file like:
2262
2263 @smallexample @c projectfile
2264 aggregate project Agg is
2265     for Project_Path use (external("SETUP") % "path");
2266     for Project_Files use ("myproject.gpr");
2267 end Agg;
2268
2269 with "prj.gpr";  --  searched on Agg'Project_Path
2270 project MyProject is
2271    ...
2272 end MyProject;
2273 @end smallexample
2274
2275 @subsection Performance improvements in builder
2276
2277 The loading of aggregate projects is optimized in gprbuild and
2278 gnatmake, so that all files are searched for only once on the disk
2279 (thus reducing the number of system calls and contributing to faster
2280 compilation times especially on systems with sources on remote
2281 servers). As part of the loading, gprbuild and gnatmake compute how
2282 and where a source file should be compiled, and even if it is found
2283 several times in the aggregated projects it will be compiled only
2284 once.
2285
2286 Since there is no ambiguity as to which switches should be used, files
2287 can be compiled in parallel (through the usual -j switch) and this can
2288 be done while maximizing the use of CPUs (compared to launching
2289 multiple gprbuild and gnatmake commands in parallel).
2290
2291 @subsection Syntax of aggregate projects
2292
2293 An aggregate project follows the general syntax of project files. The
2294 recommended extension is still @file{.gpr}. However, a special
2295 @code{aggregate} qualifier must be put before the keyword
2296 @code{project}.
2297
2298 An aggregate project cannot @code{with} any other project (standard or
2299 aggregate), except an abstract project which can be used to share
2300 attribute values. Building other aggregate projects from an aggregate
2301 project is done through the Project_Files attribute (see below).
2302
2303 An aggregate project does not have any source files directly (only
2304 through other standard projects). Therefore a number of the standard
2305 attributes and packages are forbidden in an aggregate project. Here is the
2306 (non exhaustive) list:
2307
2308 @itemize @bullet
2309 @item Languages
2310 @item Source_Files, Source_List_File and other attributes dealing with
2311   list of sources.
2312 @item Source_Dirs, Exec_Dir and Object_Dir
2313 @item Library_Dir, Library_Name and other library-related attributes
2314 @item Main
2315 @item Roots
2316 @item Externally_Built
2317 @item Inherit_Source_Path
2318 @item Excluded_Source_Dirs
2319 @item Locally_Removed_Files
2320 @item Excluded_Source_Files
2321 @item Excluded_Source_List_File
2322 @item Interfaces
2323 @end itemize
2324
2325 The only package that is authorized (albeit optional) is
2326 Builder. Other packages (in particular Compiler, Binder and Linker)
2327 are forbidden. It is an error to have any of these
2328 (and such an error prevents the proper loading of the aggregate
2329 project).
2330
2331 Three new attributes have been created, which can only be used in the
2332 context of aggregate projects:
2333
2334 @table @asis
2335 @item @b{Project_Files}:
2336 @cindex @code{Project_Files}
2337
2338 This attribute is compulsory (or else we are not aggregating any project,
2339 and thus not doing anything). It specifies a list of @file{.gpr} files
2340 that are grouped in the aggregate. The list may be empty. The project
2341 files can be either other aggregate projects, or standard projects. When
2342 grouping standard projects, you can have both the root of a project tree
2343 (and you do not need to specify all its imported projects), and any project
2344 within the tree.
2345
2346 Basically, the idea is to specify all those projects that have
2347 main units you want to build and link, or libraries you want to
2348 build. You can even specify projects that do not use the Main
2349 attribute nor the @code{Library_*} attributes, and the result will be to
2350 build all their source files (not just the ones needed by other
2351 projects).
2352
2353 The file can include paths (absolute or relative). Paths are
2354 relative to the location of the aggregate project file itself (if
2355 you use a base name, we expect to find the .gpr file in the same
2356 directory as the aggregate project file). The extension @file{.gpr} is
2357 mandatory, since this attribute contains file names, not project names.
2358
2359 Paths can also include the @code{"*"} and @code{"**"} globbing patterns. The
2360 latter indicates that any subdirectory (recursively) will be
2361 searched for matching files. The latter (@code{"**"}) can only occur at the
2362 last position in the directory part (ie @code{"a/**/*.gpr"} is supported, but
2363 not @code{"**/a/*.gpr"}). Starting the pattern with @code{"**"} is equivalent
2364 to starting with @code{"./**"}.
2365
2366 For now, the pattern @code{"*"} is only allowed in the filename part, not
2367 in the directory part. This is mostly for efficiency reasons to limit the
2368 number of system calls that are needed.
2369
2370 Here are a few valid examples:
2371
2372 @smallexample @c projectfile
2373     for Project_Files use ("a.gpr", "subdir/b.gpr");
2374     --  two specific projects relative to the directory of agg.gpr
2375
2376     for Project_Files use ("**/*.gpr");
2377     --  all projects recursively
2378 @end smallexample
2379
2380 @item @b{Project_Path}:
2381 @cindex @code{Project_Path}
2382
2383 This attribute can be used to specify a list of directories in
2384 which to look for project files in @code{with} statements.
2385
2386 When you specify a project in Project_Files
2387 say @code{"x/y/a.gpr"}), and this projects imports a project "b.gpr", only
2388 b.gpr is searched in the project path. a.gpr must be exactly at
2389 <dir of the aggregate>/x/y/a.gpr.
2390
2391 This attribute, however, does not affect the search for the aggregated
2392 project files specified with @code{Project_Files}.
2393
2394 Each aggregate project has its own (that is if agg1.gpr includes
2395 agg2.gpr, they can potentially both have a different project path).
2396 This project path is defined as the concatenation, in that order, of
2397 the current directory, followed by the command line -aP switches,
2398 then the directories from the Project_Path attribute, then the
2399 directories from the GPR_PROJECT_PATH and ADA_PROJECT_PATH env.
2400 variables, and finally the predefined directories.
2401
2402 In the example above, agg2.gpr's project path is not influenced by
2403 the attribute agg1'Project_Path, nor is agg1 influenced by
2404 agg2'Project_Path.
2405
2406 This can potentially lead to errors. In the following example:
2407
2408 @smallexample
2409      +---------------+                  +----------------+
2410      | Agg1.gpr      |-=--includes--=-->| Agg2.gpr       |
2411      |  'project_path|                  |  'project_path |
2412      |               |                  |                |
2413      +---------------+                  +----------------+
2414            :                                   :
2415            includes                        includes
2416            :                                   :
2417            v                                   v
2418        +-------+                          +---------+
2419        | P.gpr |<---------- withs --------|  Q.gpr  |
2420        +-------+---------\                +---------+
2421            |             |
2422            withs         |
2423            |             |
2424            v             v
2425        +-------+      +---------+
2426        | R.gpr |      | R'.gpr  |
2427        +-------+      +---------+
2428 @end smallexample
2429
2430 When looking for p.gpr, both aggregates find the same physical file on
2431 the disk. However, it might happen that with their different project
2432 paths, both aggregate projects would in fact find a different r.gpr.
2433 Since we have a common project (p.gpr) "with"ing two different r.gpr,
2434 this will be reported as an error by the builder.
2435
2436 Directories are relative to the location of the aggregate project file.
2437
2438 Here are a few valid examples:
2439
2440 @smallexample @c projectfile
2441    for Project_Path use ("/usr/local/gpr", "gpr/");
2442 @end smallexample
2443
2444 @item @b{External}:
2445 @cindex @code{External}
2446
2447 This attribute can be used to set the value of environment
2448 variables as retrieved through the @code{external} statement
2449 in projects. It does not affect the environment variables
2450 themselves (so for instance you cannot use it to change the value
2451 of your PATH as seen from the spawned compiler).
2452
2453 This attribute affects the external values as seen in the rest of
2454 the aggreate projects, and in the aggregated projects.
2455
2456 The exact value of external a variable comes from one of three
2457 sources (each level overrides the previous levels):
2458
2459 @itemize @bullet
2460 @item An External attribute in aggregate project, for instance
2461     @code{for External ("BUILD_MODE") use "DEBUG"};
2462
2463 @item Environment variables
2464
2465 These override the value given by the attribute, so that
2466 users can override the value set in the (presumably shared
2467 with others in his team) aggregate project.
2468
2469 @item The -X command line switch to gprbuild and gnatmake
2470
2471 This always takes precedence.
2472
2473 @end itemize
2474
2475 This attribute is only taken into account in the main aggregate
2476 project (i.e. the one specified on the command line to gprbuild or
2477 natmake), and ignored in other aggregate projects. It is invalid
2478 in standard projects.
2479 The goal is to have a consistent value in all
2480 projects that are build through the aggregate, which would not
2481 be the case in the diamond case: A groups the aggregate
2482 projects B and C, which both (either directly or indirectly)
2483 build the project P. If B and C could set different values for
2484 the environment variables, we would have two different views of
2485 P, which in particular might impact the list of source files in P.
2486
2487 @end table
2488
2489 @subsection package Builder in aggregate projects
2490
2491 As we mentioned before, only the package Builder can be specified in
2492 an aggregate project. In this package, only the following attributes
2493 are valid:
2494
2495 @table @asis
2496 @item @b{Switches}:
2497 @cindex @code{Switches}
2498 This attribute gives the list of switches to use for the builder
2499 (gprbuild or gnatmake), depending on the language of the main file.
2500 For instance,
2501
2502 @smallexample @c projectfile
2503 for Switches ("Ada") use ("-d", "-p");
2504 for Switches ("C")   use ("-p");
2505 @end smallexample
2506
2507 These switches are only read from the main aggregate project (the
2508 one passed on the command line), and ignored in all other aggregate
2509 projects or projects.
2510
2511 It can only contain builder switches, not compiler switches.
2512
2513 @item @b{Global_Compilation_Switches}
2514 @cindex @code{Global_Compilation_Switches}
2515
2516 This attribute gives the list of compiler switches for the various
2517 languages. For instance,
2518
2519 @smallexample @c projectfile
2520 for Global_Compilation_Switches ("Ada") use ("-O1", "-g");
2521 for Global_Compilation_Switches ("C")   use ("-O2");
2522 @end smallexample
2523
2524 This attribute is only taken into account in the aggregate project
2525 specified on the command line, not in other aggregate projects.
2526
2527 In the projects grouped by that aggregate, the attribute
2528 Builder.Global_Compilation_Switches is also ignored. However, the
2529 attribute Compiler.Default_Switches will be taken into account (but
2530 that of the aggregate have higher priority). The attribute
2531 Compiler.Switches is also taken into account and can be used to
2532 override the switches for a specific file. As a result, it always
2533 has priority.
2534
2535 The rules are meant to avoid ambiguities when compiling. For
2536 instance, aggregate project Agg groups the projects A and B, that
2537 both depend on C. Here is an extra for all of these projects:
2538
2539 @smallexample @c projectfile
2540       aggregate project Agg is
2541           for Project_Files use ("a.gpr", "b.gpr");
2542           package Builder is
2543              for Global_Compilation_Switches ("Ada") use ("-O2");
2544           end Builder;
2545       end Agg;
2546
2547       with "c.gpr";
2548       project A is
2549           package Builder is
2550              for Global_Compilation_Switches ("Ada") use ("-O1");
2551              --  ignored
2552           end Builder;
2553
2554           package Compiler is
2555              for Default_Switches ("Ada") use ("-O1", "-g");
2556              for Switches ("a_file1.adb") use ("-O0");
2557           end Compiler;
2558       end A;
2559
2560       with "c.gpr";
2561       project B is
2562           package Compiler is
2563              for Default_Switches ("Ada") use ("-O0");
2564           end Compiler;
2565       end B;
2566
2567       project C is
2568           package Compiler is
2569              for Default_Switches ("Ada") use ("-O3, "-gnatn");
2570              for Switches ("c_file1.adb") use ("-O0", "-g");
2571           end Compiler;
2572       end C;
2573 @end smallexample
2574
2575 then the following switches are used:
2576
2577 @itemize @bullet
2578 @item all files from project A except a_file1.adb are compiled
2579       with "-O2 -g", since the aggregate project has priority.
2580 @item the file a_file1.adb is compiled with
2581       "-O0", since the Compiler.Switches has priority
2582 @item all files from project B are compiled with
2583       "-O2", since the aggregate project has priority
2584 @item all files from C are compiled with "-O2 -gnatn", except for
2585       c_file1.adb which is compiled with "-O0 -g"
2586 @end itemize
2587
2588 Even though C is seen through two paths (through A and through
2589 B), the switches used by the compiler are unambiguous.
2590
2591 @item @b{Global_Configuration_Pragmas}
2592 @cindex @code{Global_Configuration_Pragmas}
2593
2594 This attribute can be used to specify a file containing
2595 configuration pragmas, to be passed to the compiler.  Since we
2596 ignore the package Builder in other aggregate projects and projects,
2597 only those pragmas defined in the main aggregate project will be
2598 taken into account.
2599
2600 Projects can locally add to those by using the
2601 @code{Compiler.Local_Configuration_Pragmas} attribute if they need.
2602
2603 @end table
2604
2605 For projects that are build through the aggregate, the package Builder
2606 is ignored, except for the Executable attribute which specifies the
2607 name of the executables resulting from the link of the main units, and
2608 for the Executable_Suffix.
2609
2610 @c ---------------------------------------------
2611 @node Project File Reference
2612 @section Project File Reference
2613 @c ---------------------------------------------
2614
2615 @noindent
2616 This section describes the syntactic structure of project files, the various
2617 constructs that can be used. Finally, it ends with a summary of all available
2618 attributes.
2619
2620 @menu
2621 * Project Declaration::
2622 * Qualified Projects::
2623 * Declarations::
2624 * Packages::
2625 * Expressions::
2626 * External Values::
2627 * Typed String Declaration::
2628 * Variables::
2629 * Attributes::
2630 * Case Statements::
2631 @end menu
2632
2633 @c ---------------------------------------------
2634 @node Project Declaration
2635 @subsection Project Declaration
2636 @c ---------------------------------------------
2637
2638 @noindent
2639 Project files have an Ada-like syntax. The minimal project file is:
2640
2641 @smallexample @c projectfile
2642 @group
2643 project Empty is
2644 end Empty;
2645 @end group
2646 @end smallexample
2647
2648 @noindent
2649 The identifier @code{Empty} is the name of the project.
2650 This project name must be present after the reserved
2651 word @code{end} at the end of the project file, followed by a semi-colon.
2652
2653 @b{Identifiers} (i.e.@: the user-defined names such as project or variable names)
2654 have the same syntax as Ada identifiers: they must start with a letter,
2655 and be followed by zero or more letters, digits or underscore characters;
2656 it is also illegal to have two underscores next to each other. Identifiers
2657 are always case-insensitive ("Name" is the same as "name").
2658
2659 @smallexample
2660 simple_name ::= identifier
2661 name        ::= simple_name @{ . simple_name @}
2662 @end smallexample
2663
2664 @noindent
2665 @b{Strings} are used for values of attributes or as indexes for these
2666 attributes. They are in general case sensitive, except when noted
2667 otherwise (in particular, strings representing file names will be case
2668 insensitive on some systems, so that "file.adb" and "File.adb" both
2669 represent the same file).
2670
2671 @b{Reserved words} are the same as for standard Ada 95, and cannot
2672 be used for identifiers. In particular, the following words are currently
2673 used in project files, but others could be added later on. In bold are the
2674 extra reserved words in project files: @code{all, at, case, end, for, is,
2675 limited, null, others, package, renames, type, use, when, with, @b{extends},
2676 @b{external}, @b{project}}.
2677
2678 @b{Comments} in project files have the same syntax as in Ada, two consecutive
2679 hyphens through the end of the line.
2680
2681 A project may be an @b{independent project}, entirely defined by a single
2682 project file. Any source file in an independent project depends only
2683 on the predefined library and other source files in the same project.
2684 But a project may also depend on other projects, either by importing them
2685 through @b{with clauses}, or by @b{extending} at most one other project. Both
2686 types of dependency can be used in the same project.
2687
2688 A path name denotes a project file. It can be absolute or relative.
2689 An absolute path name includes a sequence of directories, in the syntax of
2690 the host operating system, that identifies uniquely the project file in the
2691 file system. A relative path name identifies the project file, relative
2692 to the directory that contains the current project, or relative to a
2693 directory listed in the environment variables ADA_PROJECT_PATH and
2694 GPR_PROJECT_PATH. Path names are case sensitive if file names in the host
2695 operating system are case sensitive. As a special case, the directory
2696 separator can always be "/" even on Windows systems, so that project files
2697 can be made portable across architectures.
2698 The syntax of the environment variable ADA_PROJECT_PATH and
2699 GPR_PROJECT_PATH is a list of directory names separated by colons on UNIX and
2700 semicolons on Windows.
2701
2702 A given project name can appear only once in a context clause.
2703
2704 It is illegal for a project imported by a context clause to refer, directly
2705 or indirectly, to the project in which this context clause appears (the
2706 dependency graph cannot contain cycles), except when one of the with clause
2707 in the cycle is a @b{limited with}.
2708 @c ??? Need more details here
2709
2710 @smallexample @c projectfile
2711 with "other_project.gpr";
2712 project My_Project extends "extended.gpr" is
2713 end My_Project;
2714 @end smallexample
2715
2716 @noindent
2717 These dependencies form a @b{directed graph}, potentially cyclic when using
2718 @b{limited with}. The subprogram reflecting the @b{extends} relations is a
2719 tree.
2720
2721 A project's @b{immediate sources} are the source files directly defined by
2722 that project, either implicitly by residing in the project source directories,
2723 or explicitly through any of the source-related attributes.
2724 More generally, a project sources are the immediate sources of the project
2725 together with the immediate sources (unless overridden) of any
2726 project on which it depends directly or indirectly.
2727
2728 A @b{project hierarchy} can be created, where projects are children of
2729 other projects. The name of such a child project must be @code{Parent.Child},
2730 where @code{Parent} is the name of the parent project. In particular, this
2731 makes all @code{with} clauses of the parent project automatically visible
2732 in the child project.
2733
2734 @smallexample
2735 project        ::= context_clause project_declaration
2736
2737 context_clause ::= @{with_clause@}
2738 with_clause    ::= @i{with} path_name @{ , path_name @} ;
2739 path_name      ::= string_literal
2740
2741 project_declaration ::= simple_project_declaration | project_extension
2742 simple_project_declaration ::=
2743   @i{project} @i{<project_>}name @i{is}
2744     @{declarative_item@}
2745   @i{end} <project_>simple_name;
2746 @end smallexample
2747
2748 @c ---------------------------------------------
2749 @node Qualified Projects
2750 @subsection Qualified Projects
2751 @c ---------------------------------------------
2752
2753 @noindent
2754 Before the reserved @code{project}, there may be one or two @b{qualifiers}, that
2755 is identifiers or reserved words, to qualify the project.
2756 The current list of qualifiers is:
2757
2758 @table @asis
2759 @item @b{abstract}: qualifies a project with no sources. Such a
2760   project must either have no declaration of attributes @code{Source_Dirs},
2761   @code{Source_Files}, @code{Languages} or @code{Source_List_File}, or one of
2762   @code{Source_Dirs}, @code{Source_Files}, or @code{Languages} must be declared
2763   as empty. If it extends another project, the project it extends must also be a
2764   qualified abstract project.
2765 @item @b{standard}: a standard project is a non library project with sources.
2766   This is the default (implicit) qualifier.
2767 @item @b{aggregate}: for future extension
2768 @item @b{aggregate library}: for future extension
2769 @item @b{library}: a library project must declare both attributes
2770   @code{Library_Name} and @code{Library_Dir}.
2771 @item @b{configuration}: a configuration project cannot be in a project tree.
2772   It describes compilers and other tools to @code{gprbuild}.
2773 @end table
2774
2775 @c ---------------------------------------------
2776 @node Declarations
2777 @subsection Declarations
2778 @c ---------------------------------------------
2779
2780 @noindent
2781 Declarations introduce new entities that denote types, variables, attributes,
2782 and packages. Some declarations can only appear immediately within a project
2783 declaration. Others can appear within a project or within a package.
2784
2785 @smallexample
2786 declarative_item ::= simple_declarative_item
2787   | typed_string_declaration
2788   | package_declaration
2789
2790 simple_declarative_item ::= variable_declaration
2791   | typed_variable_declaration
2792   | attribute_declaration
2793   | case_construction
2794   | empty_declaration
2795
2796 empty_declaration ::= @i{null} ;
2797 @end smallexample
2798
2799 @noindent
2800 An empty declaration is allowed anywhere a declaration is allowed. It has
2801 no effect.
2802
2803 @c ---------------------------------------------
2804 @node Packages
2805 @subsection Packages
2806 @c ---------------------------------------------
2807
2808 @noindent
2809 A project file may contain @b{packages}, that group attributes (typically
2810 all the attributes that are used by one of the GNAT tools).
2811
2812 A package with a given name may only appear once in a project file.
2813 The following packages are currently supported in project files
2814 (See @pxref{Attributes} for the list of attributes that each can contain).
2815
2816 @table @code
2817 @item Binder
2818   This package specifies characteristics useful when invoking the binder either
2819   directly via the @command{gnat} driver or when using a builder such as
2820   @command{gnatmake} or @command{gprbuild}. @xref{Main Subprograms}.
2821 @item Builder
2822   This package specifies the compilation options used when building an
2823   executable or a library for a project. Most of the options should be
2824   set in one of @code{Compiler}, @code{Binder} or @code{Linker} packages,
2825   but there are some general options that should be defined in this
2826   package. @xref{Main Subprograms}, and @pxref{Executable File Names} in
2827   particular.
2828 @item Check
2829   This package specifies the options used when calling the checking tool
2830   @command{gnatcheck} via the @command{gnat} driver. Its attribute
2831   @b{Default_Switches} has the same semantics as for the package
2832   @code{Builder}. The first string should always be @code{-rules} to specify
2833   that all the other options belong to the @code{-rules} section of the
2834   parameters to @command{gnatcheck}.
2835 @item Compiler
2836   This package specifies the compilation options used by the compiler for
2837   each languages. @xref{Tools Options in Project Files}.
2838 @item Cross_Reference
2839   This package specifies the options used when calling the library tool
2840   @command{gnatxref} via the @command{gnat} driver. Its attributes
2841   @b{Default_Switches} and @b{Switches} have the same semantics as for the
2842   package @code{Builder}.
2843 @item Eliminate
2844   This package specifies the options used when calling the tool
2845   @command{gnatelim} via the @command{gnat} driver. Its attributes
2846   @b{Default_Switches} and @b{Switches} have the same semantics as for the
2847   package @code{Builder}.
2848 @item Finder
2849   This package specifies the options used when calling the search tool
2850   @command{gnatfind} via the @command{gnat} driver. Its attributes
2851   @b{Default_Switches} and @b{Switches} have the same semantics as for the
2852   package @code{Builder}.
2853 @item Gnatls
2854   This package the options to use when invoking @command{gnatls} via the
2855   @command{gnat} driver.
2856 @item Gnatstub
2857   This package specifies the options used when calling the tool
2858   @command{gnatstub} via the @command{gnat} driver. Its attributes
2859   @b{Default_Switches} and @b{Switches} have the same semantics as for the
2860   package @code{Builder}.
2861 @item IDE
2862   This package specifies the options used when starting an integrated
2863   development environment, for instance @command{GPS} or @command{Gnatbench}.
2864   @xref{The Development Environments}.
2865 @item Linker
2866   This package specifies the options used by the linker.
2867   @xref{Main Subprograms}.
2868 @item Makefile
2869 @cindex Makefile package in projects
2870   This package is used by the GPS plugin Makefile.py. See the documentation
2871   in that plugin (from GPS: /Tools/Plug-ins).
2872 @item Metrics
2873   This package specifies the options used when calling the tool
2874   @command{gnatmetric} via the @command{gnat} driver. Its attributes
2875   @b{Default_Switches} and @b{Switches} have the same semantics as for the
2876   package @code{Builder}.
2877 @item Naming
2878   This package specifies the naming conventions that apply
2879   to the source files in a project. In particular, these conventions are
2880   used to automatically find all source files in the source directories,
2881   or given a file name to find out its language for proper processing.
2882   @xref{Naming Schemes}.
2883 @item Pretty_Printer
2884   This package specifies the options used when calling the formatting tool
2885   @command{gnatpp} via the @command{gnat} driver. Its attributes
2886   @b{Default_Switches} and @b{Switches} have the same semantics as for the
2887   package @code{Builder}.
2888 @item Stack
2889   This package specifies the options used when calling the tool
2890   @command{gnatstack} via the @command{gnat} driver. Its attributes
2891   @b{Default_Switches} and @b{Switches} have the same semantics as for the
2892   package @code{Builder}.
2893 @item Synchronize
2894   This package specifies the options used when calling the tool
2895   @command{gnatsync} via the @command{gnat} driver.
2896
2897 @end table
2898
2899 In its simplest form, a package may be empty:
2900
2901 @smallexample @c projectfile
2902 @group
2903 project Simple is
2904   package Builder is
2905   end Builder;
2906 end Simple;
2907 @end group
2908 @end smallexample
2909
2910 @noindent
2911 A package may contain @b{attribute declarations},
2912 @b{variable declarations} and @b{case constructions}, as will be
2913 described below.
2914
2915 When there is ambiguity between a project name and a package name,
2916 the name always designates the project. To avoid possible confusion, it is
2917 always a good idea to avoid naming a project with one of the
2918 names allowed for packages or any name that starts with @code{gnat}.
2919
2920 A package can also be defined by a @b{renaming declaration}. The new package
2921 renames a package declared in a different project file, and has the same
2922 attributes as the package it renames. The name of the renamed package
2923 must be the same as the name of the renaming package. The project must
2924 contain a package declaration with this name, and the project
2925 must appear in the context clause of the current project, or be its parent
2926 project. It is not possible to add or override attributes to the renaming
2927 project. If you need to do so, you should use an @b{extending declaration}
2928 (see below).
2929
2930 Packages that are renamed in other project files often come from project files
2931 that have no sources: they are just used as templates. Any modification in the
2932 template will be reflected automatically in all the project files that rename
2933 a package from the template. This is a very common way to share settings
2934 between projects.
2935
2936 Finally, a package can also be defined by an @b{extending declaration}. This is
2937 similar to a @b{renaming declaration}, except that it is possible to add or
2938 override attributes.
2939
2940 @smallexample
2941 package_declaration ::= package_spec | package_renaming | package_extension
2942 package_spec ::=
2943   @i{package} @i{<package_>}simple_name @i{is}
2944     @{simple_declarative_item@}
2945   @i{end} package_identifier ;
2946 package_renaming ::==
2947   @i{package} @i{<package_>}simple_name @i{renames} @i{<project_>}simple_name.package_identifier ;
2948 package_extension ::==
2949   @i{package} @i{<package_>}simple_name @i{extends} @i{<project_>}simple_name.package_identifier @i{is}
2950     @{simple_declarative_item@}
2951   @i{end} package_identifier ;
2952 @end smallexample
2953
2954 @c ---------------------------------------------
2955 @node Expressions
2956 @subsection Expressions
2957 @c ---------------------------------------------
2958
2959 @noindent
2960 An expression is any value that can be assigned to an attribute or a
2961 variable. It is either a literal value, or a construct requiring runtime
2962 computation by the project manager. In a project file, the computed value of
2963 an expression is either a string or a list of strings.
2964
2965 A string value is one of:
2966 @itemize @bullet
2967 @item A literal string, for instance @code{"comm/my_proj.gpr"}
2968 @item The name of a variable that evaluates to a string (@pxref{Variables})
2969 @item The name of an attribute that evaluates to a string (@pxref{Attributes})
2970 @item An external reference (@pxref{External Values})
2971 @item A concatenation of the above, as in @code{"prefix_" & Var}.
2972
2973 @end itemize
2974
2975 @noindent
2976 A list of strings is one of the following:
2977
2978 @itemize @bullet
2979 @item A parenthesized comma-separated list of zero or more string expressions, for
2980   instance @code{(File_Name, "gnat.adc", File_Name & ".orig")} or @code{()}.
2981 @item The name of a variable that evaluates to a list of strings
2982 @item The name of an attribute that evaluates to a list of strings
2983 @item A concatenation of a list of strings and a string (as defined above), for
2984   instance @code{("A", "B") & "C"}
2985 @item A concatenation of two lists of strings
2986
2987 @end itemize
2988
2989 @noindent
2990 The following is the grammar for expressions
2991
2992 @smallexample
2993 string_literal ::= "@{string_element@}"  --  Same as Ada
2994 string_expression ::= string_literal
2995     | @i{variable_}name
2996     | external_value
2997     | attribute_reference
2998     | ( string_expression @{ & string_expression @} )
2999 string_list  ::= ( string_expression @{ , string_expression @} )
3000    | @i{string_variable}_name
3001    | @i{string_}attribute_reference
3002 term ::= string_expression | string_list
3003 expression ::= term @{ & term @}     --  Concatenation
3004 @end smallexample
3005
3006 @noindent
3007 Concatenation involves strings and list of strings. As soon as a list of
3008 strings is involved, the result of the concatenation is a list of strings. The
3009 following Ada declarations show the existing operators:
3010
3011 @smallexample @c ada
3012   function "&" (X : String;      Y : String)      return String;
3013   function "&" (X : String_List; Y : String)      return String_List;
3014   function "&" (X : String_List; Y : String_List) return String_List;
3015 @end smallexample
3016
3017 @noindent
3018 Here are some specific examples:
3019
3020 @smallexample @c projectfile
3021 @group
3022    List := () & File_Name; --  One string in this list
3023    List2 := List & (File_Name & ".orig"); -- Two strings
3024    Big_List := List & Lists2;  --  Three strings
3025    Illegal := "gnat.adc" & List2;  --  Illegal, must start with list
3026 @end group
3027 @end smallexample
3028
3029 @c ---------------------------------------------
3030 @node External Values
3031 @subsection External Values
3032 @c ---------------------------------------------
3033
3034 @noindent
3035 An external value is an expression whose value is obtained from the command
3036 that invoked the processing of the current project file (typically a
3037 gnatmake or gprbuild command).
3038
3039 There are two kinds of external values, one that returns a single string, and
3040 one that returns a string list.
3041
3042 The syntax of a single string external value is:
3043
3044 @smallexample
3045 external_value ::= @i{external} ( string_literal [, string_literal] )
3046 @end smallexample
3047
3048 @noindent
3049 The first string_literal is the string to be used on the command line or
3050 in the environment to specify the external value. The second string_literal,
3051 if present, is the default to use if there is no specification for this
3052 external value either on the command line or in the environment.
3053
3054 Typically, the external value will either exist in the
3055 ^environment variables^logical name^
3056 or be specified on the command line through the
3057 @option{^-X^/EXTERNAL_REFERENCE=^@emph{vbl}=@emph{value}} switch. If both
3058 are specified, then the command line value is used, so that a user can more
3059 easily override the value.
3060
3061 The function @code{external} always returns a string. It is an error if the
3062 value was not found in the environment and no default was specified in the
3063 call to @code{external}.
3064
3065 An external reference may be part of a string expression or of a string
3066 list expression, and can therefore appear in a variable declaration or
3067 an attribute declaration.
3068
3069 Most of the time, this construct is used to initialize typed variables, which
3070 are then used in @b{case} statements to control the value assigned to
3071 attributes in various scenarios. Thus such variables are often called
3072 @b{scenario variables}.
3073
3074 The syntax for a string list external value is:
3075
3076 @smallexample
3077 external_value ::= @i{external_as_list} ( string_literal , string_literal )
3078 @end smallexample
3079
3080 @noindent
3081 The first string_literal is the string to be used on the command line or
3082 in the environment to specify the external value. The second string_literal is
3083 the separator between each component of the string list.
3084
3085 If the external value does not exist in the environment or on the command line,
3086 the result is an empty list. This is also the case, if the separator is an
3087 empty string or if the external value is only one separator.
3088
3089 Any separator at the beginning or at the end of the external value is
3090 discarded. Then, if there is no separator in the external value, the result is
3091 a string list with only one string. Otherwise, any string between the beginning
3092 and the first separator, between two consecutive separators and between the
3093 last separator and the end are components of the string list.
3094
3095 @smallexample
3096    @i{external_as_list} ("SWITCHES", ",")
3097 @end smallexample
3098
3099 @noindent
3100 If the external value is "-O2,-g", the result is ("-O2", "-g").
3101
3102 If the external value is ",-O2,-g,", the result is also ("-O2", "-g").
3103
3104 if the external value is "-gnav", the result is ("-gnatv").
3105
3106 If the external value is ",,", the result is ("").
3107
3108 If the external value is ",", the result is (), the empty string list.
3109
3110 @c ---------------------------------------------
3111 @node Typed String Declaration
3112 @subsection Typed String Declaration
3113 @c ---------------------------------------------
3114
3115 @noindent
3116 A @b{type declaration} introduces a discrete set of string literals.
3117 If a string variable is declared to have this type, its value
3118 is restricted to the given set of literals. These are the only named
3119 types in project files. A string type may only be declared at the project
3120 level, not inside a package.
3121
3122 @smallexample
3123 typed_string_declaration ::=
3124   @i{type} @i{<typed_string_>}_simple_name @i{is} ( string_literal @{, string_literal@} );
3125 @end smallexample
3126
3127 @noindent
3128 The string literals in the list are case sensitive and must all be different.
3129 They may include any graphic characters allowed in Ada, including spaces.
3130 Here is an example of a string type declaration:
3131
3132 @smallexample @c projectfile
3133    type OS is ("NT", "nt", "Unix", "GNU/Linux", "other OS");
3134 @end smallexample
3135
3136 @noindent
3137 Variables of a string type are called @b{typed variables}; all other
3138 variables are called @b{untyped variables}. Typed variables are
3139 particularly useful in @code{case} constructions, to support conditional
3140 attribute declarations. (@pxref{Case Statements}).
3141
3142 A string type may be referenced by its name if it has been declared in the same
3143 project file, or by an expanded name whose prefix is the name of the project
3144 in which it is declared.
3145
3146 @c ---------------------------------------------
3147 @node Variables
3148 @subsection Variables
3149 @c ---------------------------------------------
3150
3151 @noindent
3152 @b{Variables} store values (strings or list of strings) and can appear
3153 as part of an expression. The declaration of a variable creates the
3154 variable and assigns the value of the expression to it. The name of the
3155 variable is available immediately after the assignment symbol, if you
3156 need to reuse its old value to compute the new value. Before the completion
3157 of its first declaration, the value of a variable defaults to the empty
3158 string ("").
3159
3160 A @b{typed} variable can be used as part of a @b{case} expression to
3161 compute the value, but it can only be declared once in the project file,
3162 so that all case statements see the same value for the variable. This
3163 provides more consistency and makes the project easier to understand.
3164 The syntax for its declaration is identical to the Ada syntax for an
3165 object declaration. In effect, a typed variable acts as a constant.
3166
3167 An @b{untyped} variable can be declared and overridden multiple times
3168 within the same project. It is declared implicitly through an Ada
3169 assignment. The first declaration establishes the kind of the variable
3170 (string or list of strings) and successive declarations must respect
3171 the initial kind. Assignments are executed in the order in which they
3172 appear, so the new value replaces the old one and any subsequent reference
3173 to the variable uses the new value.
3174
3175 A variable may be declared at the project file level, or within a package.
3176
3177 @smallexample
3178 typed_variable_declaration ::=
3179   @i{<typed_variable_>}simple_name : @i{<typed_string_>}name := string_expression;
3180 variable_declaration ::= @i{<variable_>}simple_name := expression;
3181 @end smallexample
3182
3183 @noindent
3184 Here are some examples of variable declarations:
3185
3186 @smallexample @c projectfile
3187 @group
3188    This_OS : OS := external ("OS"); --  a typed variable declaration
3189    That_OS := "GNU/Linux";          --  an untyped variable declaration
3190
3191    Name      := "readme.txt";
3192    Save_Name := Name & ".saved";
3193
3194    Empty_List := ();
3195    List_With_One_Element := ("-gnaty");
3196    List_With_Two_Elements := List_With_One_Element & "-gnatg";
3197    Long_List := ("main.ada", "pack1_.ada", "pack1.ada", "pack2_.ada");
3198 @end group
3199 @end smallexample
3200
3201 @noindent
3202 A @b{variable reference} may take several forms:
3203
3204 @itemize @bullet
3205 @item The simple variable name, for a variable in the current package (if any)
3206   or in the current project
3207 @item An expanded name, whose prefix is a context name.
3208
3209 @end itemize
3210
3211 @noindent
3212 A @b{context} may be one of the following:
3213
3214 @itemize @bullet
3215 @item The name of an existing package in the current project
3216 @item The name of an imported project of the current project
3217 @item The name of an ancestor project (i.e., a project extended by the current
3218   project, either directly or indirectly)
3219 @item An expanded name whose prefix is an imported/parent project name, and
3220   whose selector is a package name in that project.
3221 @end itemize
3222
3223 @c ---------------------------------------------
3224 @node Attributes
3225 @subsection Attributes
3226 @c ---------------------------------------------
3227
3228 @noindent
3229 A project (and its packages) may have @b{attributes} that define
3230 the project's properties.  Some attributes have values that are strings;
3231 others have values that are string lists.
3232
3233 @smallexample
3234 attribute_declaration ::=
3235    simple_attribute_declaration | indexed_attribute_declaration
3236 simple_attribute_declaration ::= @i{for} attribute_designator @i{use} expression ;
3237 indexed_attribute_declaration ::=
3238   @i{for} @i{<indexed_attribute_>}simple_name ( string_literal) @i{use} expression ;
3239 attribute_designator ::=
3240   @i{<simple_attribute_>}simple_name
3241   | @i{<indexed_attribute_>}simple_name ( string_literal )
3242 @end smallexample
3243
3244 @noindent
3245 There are two categories of attributes: @b{simple attributes}
3246 and @b{indexed attributes}.
3247 Each simple attribute has a default value: the empty string (for string
3248 attributes) and the empty list (for string list attributes).
3249 An attribute declaration defines a new value for an attribute, and overrides
3250 the previous value. The syntax of a simple attribute declaration is similar to
3251 that of an attribute definition clause in Ada.
3252
3253 Some attributes are indexed. These attributes are mappings whose
3254 domain is a set of strings. They are declared one association
3255 at a time, by specifying a point in the domain and the corresponding image
3256 of the attribute.
3257 Like untyped variables and simple attributes, indexed attributes
3258 may be declared several times. Each declaration supplies a new value for the
3259 attribute, and replaces the previous setting.
3260
3261 Here are some examples of attribute declarations:
3262
3263 @smallexample @c projectfile
3264    --  simple attributes
3265    for Object_Dir use "objects";
3266    for Source_Dirs use ("units", "test/drivers");
3267
3268    --  indexed attributes
3269    for Body ("main") use "Main.ada";
3270    for Switches ("main.ada") use ("-v", "-gnatv");
3271    for Switches ("main.ada") use Builder'Switches ("main.ada") & "-g";
3272
3273    --  indexed attributes copy (from package Builder in project Default)
3274    --  The package name must always be specified, even if it is the current
3275    --  package.
3276    for Default_Switches use Default.Builder'Default_Switches;
3277 @end smallexample
3278
3279 @noindent
3280 Attributes references may be appear anywhere in expressions, and are used
3281 to retrieve the value previously assigned to the attribute. If an attribute
3282 has not been set in a given package or project, its value defaults to the
3283 empty string or the empty list.
3284
3285 @smallexample
3286 attribute_reference ::= attribute_prefix ' @i{<simple_attribute>_}simple_name [ (string_literal) ]
3287 attribute_prefix ::= @i{project}
3288   | @i{<project_>}simple_name
3289   | package_identifier
3290   | @i{<project_>}simple_name . package_identifier
3291 @end smallexample
3292
3293 @noindent
3294 Examples are:
3295
3296 @smallexample @c projectfile
3297   project'Object_Dir
3298   Naming'Dot_Replacement
3299   Imported_Project'Source_Dirs
3300   Imported_Project.Naming'Casing
3301   Builder'Default_Switches ("Ada")
3302 @end smallexample
3303
3304 @noindent
3305 The prefix of an attribute may be:
3306
3307 @itemize @bullet
3308 @item @code{project} for an attribute of the current project
3309 @item The name of an existing package of the current project
3310 @item The name of an imported project
3311 @item The name of a parent project that is extended by the current project
3312 @item An expanded name whose prefix is imported/parent project name,
3313   and whose selector is a package name
3314
3315 @end itemize
3316
3317 @noindent
3318 Legal attribute names are listed below, including the package in
3319 which they must be declared. These names are case-insensitive. The
3320 semantics for the attributes is explained in great details in other sections.
3321
3322 The column @emph{index} indicates whether the attribute is an indexed attribute,
3323 and when it is whether its index is case sensitive (sensitive) or not (insensitive), or if case sensitivity depends is the same as file names sensitivity on the
3324 system (file). The text is between brackets ([]) if the index is optional.
3325
3326 @multitable @columnfractions .3 .1 .2 .4
3327 @headitem Attribute Name @tab Value @tab Package @tab Index
3328 @headitem General attributes @tab @tab @tab @pxref{Building With Projects}
3329 @item Name @tab string @tab - @tab (Read-only, name of project)
3330 @item Project_Dir @tab string @tab - @tab (Read-only, directory of project)
3331 @item Source_Files @tab list @tab - @tab -
3332 @item Source_Dirs  @tab list @tab - @tab -
3333 @item Source_List_File @tab string @tab - @tab -
3334 @item Locally_Removed_Files @tab list @tab - @tab -
3335 @item Excluded_Source_Files @tab list @tab - @tab -
3336 @item Object_Dir   @tab string @tab - @tab -
3337 @item Exec_Dir     @tab string @tab - @tab -
3338 @item Excluded_Source_Dirs @tab list @tab - @tab -
3339 @item Excluded_Source_Files @tab list @tab - @tab -
3340 @item Excluded_Source_List_File @tab list @tab - @tab -
3341 @item Inherit_Source_Path  @tab list @tab - @tab insensitive
3342 @item Languages @tab list @tab - @tab -
3343 @item Main      @tab list @tab - @tab -
3344 @item Main_Language @tab string @tab - @tab -
3345 @item Externally_Built      @tab string @tab - @tab -
3346 @item Roots      @tab list @tab - @tab file
3347 @headitem
3348    Library-related attributes @tab @tab @tab @pxref{Library Projects}
3349 @item Library_Dir @tab string @tab - @tab -
3350 @item Library_Name @tab string @tab - @tab -
3351 @item Library_Kind @tab string @tab - @tab -
3352 @item Library_Version @tab string @tab - @tab -
3353 @item Library_Interface @tab string @tab - @tab -
3354 @item Library_Auto_Init @tab string @tab - @tab -
3355 @item Library_Options @tab list @tab - @tab -
3356 @item Leading_Library_Options @tab list @tab - @tab -
3357 @item Library_Src_Dir @tab string @tab - @tab -
3358 @item Library_ALI_Dir @tab string @tab - @tab -
3359 @item Library_GCC @tab string @tab - @tab -
3360 @item Library_Symbol_File @tab string @tab - @tab -
3361 @item Library_Symbol_Policy @tab string @tab - @tab -
3362 @item Library_Reference_Symbol_File @tab string @tab - @tab -
3363 @item Interfaces @tab list @tab - @tab -
3364 @headitem
3365    Naming @tab @tab @tab @pxref{Naming Schemes}
3366 @item Spec_Suffix @tab string @tab Naming @tab insensitive (language)
3367 @item Body_Suffix @tab string @tab Naming @tab insensitive (language)
3368 @item Separate_Suffix @tab string @tab Naming @tab -
3369 @item Casing @tab string @tab Naming @tab -
3370 @item Dot_Replacement @tab string @tab Naming @tab -
3371 @item Spec @tab string @tab Naming @tab insensitive (Ada unit)
3372 @item Body @tab string @tab Naming @tab insensitive (Ada unit)
3373 @item Specification_Exceptions @tab list @tab Naming @tab insensitive (language)
3374 @item Implementation_Exceptions @tab list @tab Naming @tab insensitive (language)
3375 @headitem
3376    Building @tab @tab @tab @pxref{Switches and Project Files}
3377 @item Default_Switches @tab list @tab Builder, Compiler, Binder, Linker, Cross_Reference, Finder, Pretty_Printer, gnatstub, Check, Synchronize, Eliminate, Metrics, IDE @tab insensitive (language name)
3378 @item Switches @tab list @tab Builder, Compiler, Binder, Linker, Cross_Reference, Finder, gnatls, Pretty_Printer, gnatstub, Check, Synchronize, Eliminate, Metrics, Stack @tab [file] (file name)
3379 @item Local_Configuration_Pragmas @tab string @tab Compiler @tab -
3380 @item Local_Config_File @tab string @tab insensitive @tab -
3381 @item Global_Configuration_Pragmas @tab list @tab Builder @tab -
3382 @item Global_Compilation_Switches @tab list @tab Builder @tab language
3383 @item Executable @tab string @tab Builder @tab [file]
3384 @item Executable_Suffix @tab string @tab Builder @tab -
3385 @item Global_Config_File @tab string @tab Builder @tab insensitive (language)
3386 @headitem
3387    IDE (used and created by GPS) @tab @tab @tab
3388 @item Remote_Host @tab string @tab IDE @tab -
3389 @item Program_Host @tab string @tab IDE @tab -
3390 @item Communication_Protocol @tab string @tab IDE @tab -
3391 @item Compiler_Command @tab string @tab IDE @tab insensitive (language)
3392 @item Debugger_Command @tab string @tab IDE @tab -
3393 @item Gnatlist @tab string @tab IDE @tab -
3394 @item Gnat @tab string @tab IDE @tab -
3395 @item VCS_Kind @tab string @tab IDE @tab -
3396 @item VCS_File_Check @tab string @tab IDE @tab -
3397 @item VCS_Log_Check @tab string @tab IDE @tab -
3398 @item Documentation_Dir @tab string @tab IDE @tab -
3399 @headitem
3400    Configuration files @tab @tab @tab See gprbuild manual
3401 @item Default_Language @tab string @tab - @tab -
3402 @item Run_Path_Option @tab list @tab - @tab -
3403 @item Run_Path_Origin @tab string @tab - @tab -
3404 @item Separate_Run_Path_Options @tab string @tab - @tab -
3405 @item Toolchain_Version @tab string @tab - @tab insensitive
3406 @item Toolchain_Description @tab string @tab - @tab insensitive
3407 @item Object_Generated @tab string @tab - @tab insensitive
3408 @item Objects_Linked @tab string @tab - @tab insensitive
3409 @item Target @tab string @tab - @tab -
3410 @item Library_Builder @tab string @tab - @tab -
3411 @item Library_Support @tab string @tab - @tab -
3412 @item Archive_Builder @tab list @tab - @tab -
3413 @item Archive_Builder_Append_Option @tab list @tab - @tab -
3414 @item Archive_Indexer @tab list @tab - @tab -
3415 @item Archive_Suffix @tab string @tab - @tab -
3416 @item Library_Partial_Linker @tab list @tab - @tab -
3417 @item Shared_Library_Prefix @tab string @tab - @tab -
3418 @item Shared_Library_Suffix @tab string @tab - @tab -
3419 @item Symbolic_Link_Supported @tab string @tab - @tab -
3420 @item Library_Major_Minor_Id_Supported @tab string @tab - @tab -
3421 @item Library_Auto_Init_Supported @tab string @tab - @tab -
3422 @item Shared_Library_Minimum_Switches @tab list @tab - @tab -
3423 @item Library_Version_Switches @tab list @tab - @tab -
3424 @item Library_Install_Name_Option @tab string @tab - @tab -
3425 @item Runtime_Library_Dir @tab string @tab - @tab insensitive
3426 @item Runtime_Source_Dir @tab string @tab - @tab insensitive
3427 @item Driver @tab string @tab Compiler,Binder,Linker @tab insensitive (language)
3428 @item Required_Switches @tab list @tab Compiler,Binder,Linker @tab insensitive (language)
3429 @item Leading_Required_Switches @tab list @tab Compiler @tab insensitive (language)
3430 @item Trailing_Required_Switches @tab list @tab Compiler @tab insensitive (language)
3431 @item Pic_Options @tab list @tab Compiler @tab insensitive (language)
3432 @item Path_Syntax @tab string @tab Compiler @tab insensitive (language)
3433 @item Object_File_Suffix @tab string @tab Compiler @tab insensitive (language)
3434 @item Object_File_Switches @tab list @tab Compiler @tab insensitive (language)
3435 @item Multi_Unit_Switches @tab list @tab Compiler @tab insensitive (language)
3436 @item Multi_Unit_Object_Separator @tab string @tab Compiler @tab insensitive (language)
3437 @item Mapping_File_Switches @tab list @tab Compiler @tab insensitive (language)
3438 @item Mapping_Spec_Suffix @tab string @tab Compiler @tab insensitive (language)
3439 @item Mapping_body_Suffix @tab string @tab Compiler @tab insensitive (language)
3440 @item Config_File_Switches @tab list @tab Compiler @tab insensitive (language)
3441 @item Config_Body_File_Name @tab string @tab Compiler @tab insensitive (language)
3442 @item Config_Body_File_Name_Index @tab string @tab Compiler @tab insensitive (language)
3443 @item Config_Body_File_Name_Pattern @tab string @tab Compiler @tab insensitive (language)
3444 @item Config_Spec_File_Name @tab string @tab Compiler @tab insensitive (language)
3445 @item Config_Spec_File_Name_Index @tab string @tab Compiler @tab insensitive (language)
3446 @item Config_Spec_File_Name_Pattern @tab string @tab Compiler @tab insensitive (language)
3447 @item Config_File_Unique @tab string @tab Compiler @tab insensitive (language)
3448 @item Dependency_Switches @tab list @tab Compiler @tab insensitive (language)
3449 @item Dependency_Driver @tab list @tab Compiler @tab insensitive (language)
3450 @item Include_Switches @tab list @tab Compiler @tab insensitive (language)
3451 @item Include_Path @tab string @tab Compiler @tab insensitive (language)
3452 @item Include_Path_File @tab string @tab Compiler @tab insensitive (language)
3453 @item Prefix @tab string @tab Binder @tab insensitive (language)
3454 @item Objects_Path @tab string @tab Binder @tab insensitive (language)
3455 @item Objects_Path_File @tab string @tab Binder @tab insensitive (language)
3456 @item Linker_Options @tab list @tab Linker @tab -
3457 @item Leading_Switches @tab list @tab Linker @tab -
3458 @item Map_File_Options @tab string @tab Linker @tab -
3459 @item Executable_Switches @tab list @tab Linker @tab -
3460 @item Lib_Dir_Switch @tab string @tab Linker @tab -
3461 @item Lib_Name_Switch @tab string @tab Linker @tab -
3462 @item Max_Command_Line_Length @tab string @tab Linker @tab -
3463 @item Response_File_Format @tab string @tab Linker @tab -
3464 @item Response_File_Switches @tab list @tab Linker @tab -
3465 @end multitable
3466
3467 @c ---------------------------------------------
3468 @node Case Statements
3469 @subsection Case Statements
3470 @c ---------------------------------------------
3471
3472 @noindent
3473 A @b{case} statement is used in a project file to effect conditional
3474 behavior. Through this statement, you can set the value of attributes
3475 and variables depending on the value previously assigned to a typed
3476 variable.
3477
3478 All choices in a choice list must be distinct. Unlike Ada, the choice
3479 lists of all alternatives do not need to include all values of the type.
3480 An @code{others} choice must appear last in the list of alternatives.
3481
3482 The syntax of a @code{case} construction is based on the Ada case statement
3483 (although the @code{null} statement for empty alternatives is optional).
3484
3485 The case expression must be a typed string variable, whose value is often
3486 given by an external reference (@pxref{External Values}).
3487
3488 Each alternative starts with the reserved word @code{when}, either a list of
3489 literal strings separated by the @code{"|"} character or the reserved word
3490 @code{others}, and the @code{"=>"} token.
3491 Each literal string must belong to the string type that is the type of the
3492 case variable.
3493 After each @code{=>}, there are zero or more statements.  The only
3494 statements allowed in a case construction are other case statements,
3495 attribute declarations and variable declarations. String type declarations and
3496 package declarations are not allowed. Variable declarations are restricted to
3497 variables that have already been declared before the case construction.
3498
3499 @smallexample
3500 case_statement ::=
3501   @i{case} @i{<typed_variable_>}name @i{is} @{case_item@} @i{end case} ;
3502
3503 case_item ::=
3504   @i{when} discrete_choice_list =>
3505     @{case_statement
3506       | attribute_declaration
3507       | variable_declaration
3508       | empty_declaration@}
3509
3510 discrete_choice_list ::= string_literal @{| string_literal@} | @i{others}
3511 @end smallexample
3512
3513 @noindent
3514 Here is a typical example:
3515
3516 @smallexample @c projectfile
3517 @group
3518 project MyProj is
3519    type OS_Type is ("GNU/Linux", "Unix", "NT", "VMS");
3520    OS : OS_Type := external ("OS", "GNU/Linux");
3521
3522    package Compiler is
3523      case OS is
3524        when "GNU/Linux" | "Unix" =>
3525          for Switches ("Ada") use ("-gnath");
3526        when "NT" =>
3527          for Switches ("Ada") use ("-gnatP");
3528        when others =>
3529          null;
3530      end case;
3531    end Compiler;
3532 end MyProj;
3533 @end group
3534 @end smallexample
3535
3536 @c ---------------------------------------------
3537 @node Tools Supporting Project Files
3538 @chapter Tools Supporting Project Files
3539 @c ---------------------------------------------
3540
3541 @noindent
3542
3543 @menu
3544 * gnatmake and Project Files::
3545 * The GNAT Driver and Project Files::
3546 * The Development Environments::
3547 * Cleaning up with GPRclean::
3548 @end menu
3549
3550 @c ---------------------------------------------
3551 @node gnatmake and Project Files
3552 @section gnatmake and Project Files
3553 @c ---------------------------------------------
3554
3555 @noindent
3556 This section covers several topics related to @command{gnatmake} and
3557 project files: defining ^switches^switches^ for @command{gnatmake}
3558 and for the tools that it invokes; specifying configuration pragmas;
3559 the use of the @code{Main} attribute; building and rebuilding library project
3560 files.
3561
3562 @menu
3563 * Switches Related to Project Files::
3564 * Switches and Project Files::
3565 * Specifying Configuration Pragmas::
3566 * Project Files and Main Subprograms::
3567 * Library Project Files::
3568 @end menu
3569
3570 @c ---------------------------------------------
3571 @node Switches Related to Project Files
3572 @subsection Switches Related to Project Files
3573 @c ---------------------------------------------
3574
3575 @noindent
3576 The following switches are used by GNAT tools that support project files:
3577
3578 @table @option
3579
3580 @item ^-P^/PROJECT_FILE=^@var{project}
3581 @cindex @option{^-P^/PROJECT_FILE^} (any project-aware tool)
3582 Indicates the name of a project file. This project file will be parsed with
3583 the verbosity indicated by @option{^-vP^MESSAGE_PROJECT_FILES=^@emph{x}},
3584 if any, and using the external references indicated
3585 by @option{^-X^/EXTERNAL_REFERENCE^} switches, if any.
3586 @ifclear vms
3587 There may zero, one or more spaces between @option{-P} and @var{project}.
3588 @end ifclear
3589
3590 There must be only one @option{^-P^/PROJECT_FILE^} switch on the command line.
3591
3592 Since the Project Manager parses the project file only after all the switches
3593 on the command line are checked, the order of the switches
3594 @option{^-P^/PROJECT_FILE^},
3595 @option{^-vP^/MESSAGES_PROJECT_FILE=^@emph{x}}
3596 or @option{^-X^/EXTERNAL_REFERENCE^} is not significant.
3597
3598 @item ^-X^/EXTERNAL_REFERENCE=^@var{name=value}
3599 @cindex @option{^-X^/EXTERNAL_REFERENCE^} (any project-aware tool)
3600 Indicates that external variable @var{name} has the value @var{value}.
3601 The Project Manager will use this value for occurrences of
3602 @code{external(name)} when parsing the project file.
3603
3604 @ifclear vms
3605 If @var{name} or @var{value} includes a space, then @var{name=value} should be
3606 put between quotes.
3607 @smallexample
3608   -XOS=NT
3609   -X"user=John Doe"
3610 @end smallexample
3611 @end ifclear
3612
3613 Several @option{^-X^/EXTERNAL_REFERENCE^} switches can be used simultaneously.
3614 If several @option{^-X^/EXTERNAL_REFERENCE^} switches specify the same
3615 @var{name}, only the last one is used.
3616
3617 An external variable specified with a @option{^-X^/EXTERNAL_REFERENCE^} switch
3618 takes precedence over the value of the same name in the environment.
3619
3620 @item ^-vP^/MESSAGES_PROJECT_FILE=^@emph{x}
3621 @cindex @option{^-vP^/MESSAGES_PROJECT_FILE^} (any project-aware tool)
3622 Indicates the verbosity of the parsing of GNAT project files.
3623
3624 @ifclear vms
3625 @option{-vP0} means Default;
3626 @option{-vP1} means Medium;
3627 @option{-vP2} means High.
3628 @end ifclear
3629
3630 @ifset vms
3631 There are three possible options for this qualifier: DEFAULT, MEDIUM and
3632 HIGH.
3633 @end ifset
3634
3635 The default is ^Default^DEFAULT^: no output for syntactically correct
3636 project files.
3637 If several @option{^-vP^/MESSAGES_PROJECT_FILE=^@emph{x}} switches are present,
3638 only the last one is used.
3639
3640 @item ^-aP^/ADD_PROJECT_SEARCH_DIR=^<dir>
3641 @cindex @option{^-aP^/ADD_PROJECT_SEARCH_DIR=^} (any project-aware tool)
3642 Add directory <dir> at the beginning of the project search path, in order,
3643 after the current working directory.
3644
3645 @ifclear vms
3646 @item -eL
3647 @cindex @option{-eL} (any project-aware tool)
3648 Follow all symbolic links when processing project files.
3649 @end ifclear
3650
3651 @item ^--subdirs^/SUBDIRS^=<subdir>
3652 @cindex @option{^--subdirs^/SUBDIRS^=} (gnatmake and gnatclean)
3653 This switch is recognized by gnatmake and gnatclean. It indicate that the real
3654 directories (except the source directories) are the subdirectories <subdir>
3655 of the directories specified in the project files. This applies in particular
3656 to object directories, library directories and exec directories. If the
3657 subdirectories do not exist, they are created automatically.
3658
3659 @end table
3660
3661 @c ---------------------------------------------
3662 @node Switches and Project Files
3663 @subsection Switches and Project Files
3664 @c ---------------------------------------------
3665
3666 @noindent
3667 @ifset vms
3668 It is not currently possible to specify VMS style qualifiers in the project
3669 files; only Unix style ^switches^switches^ may be specified.
3670 @end ifset
3671
3672 For each of the packages @code{Builder}, @code{Compiler}, @code{Binder}, and
3673 @code{Linker}, you can specify a @code{^Default_Switches^Default_Switches^}
3674 attribute, a @code{Switches} attribute, or both;
3675 as their names imply, these ^switch^switch^-related
3676 attributes affect the ^switches^switches^ that are used for each of these GNAT
3677 components when
3678 @command{gnatmake} is invoked.  As will be explained below, these
3679 component-specific ^switches^switches^ precede
3680 the ^switches^switches^ provided on the @command{gnatmake} command line.
3681
3682 The @code{^Default_Switches^Default_Switches^} attribute is an attribute
3683 indexed by language name (case insensitive) whose value is a string list.
3684 For example:
3685
3686 @smallexample @c projectfile
3687 @group
3688 package Compiler is
3689   for ^Default_Switches^Default_Switches^ ("Ada")
3690       use ("^-gnaty^-gnaty^",
3691            "^-v^-v^");
3692 end Compiler;
3693 @end group
3694 @end smallexample
3695
3696 @noindent
3697 The @code{Switches} attribute is indexed on a file name (which may or may
3698 not be case sensitive, depending
3699 on the operating system) whose value is a string list.  For example:
3700
3701 @smallexample @c projectfile
3702 @group
3703 package Builder is
3704    for Switches ("main1.adb")
3705        use ("^-O2^-O2^");
3706    for Switches ("main2.adb")
3707        use ("^-g^-g^");
3708 end Builder;
3709 @end group
3710 @end smallexample
3711
3712 @noindent
3713 For the @code{Builder} package, the file names must designate source files
3714 for main subprograms.  For the @code{Binder} and @code{Linker} packages, the
3715 file names must designate @file{ALI} or source files for main subprograms.
3716 In each case just the file name without an explicit extension is acceptable.
3717
3718 For each tool used in a program build (@command{gnatmake}, the compiler, the
3719 binder, and the linker), the corresponding package @dfn{contributes} a set of
3720 ^switches^switches^ for each file on which the tool is invoked, based on the
3721 ^switch^switch^-related attributes defined in the package.
3722 In particular, the ^switches^switches^
3723 that each of these packages contributes for a given file @var{f} comprise:
3724
3725 @itemize @bullet
3726 @item the value of attribute @code{Switches (@var{f})},
3727   if it is specified in the package for the given file,
3728 @item otherwise, the value of @code{^Default_Switches^Default_Switches^ ("Ada")},
3729   if it is specified in the package.
3730
3731 @end itemize
3732
3733 @noindent
3734 If neither of these attributes is defined in the package, then the package does
3735 not contribute any ^switches^switches^ for the given file.
3736
3737 When @command{gnatmake} is invoked on a file, the ^switches^switches^ comprise
3738 two sets, in the following order: those contributed for the file
3739 by the @code{Builder} package;
3740 and the switches passed on the command line.
3741
3742 When @command{gnatmake} invokes a tool (compiler, binder, linker) on a file,
3743 the ^switches^switches^ passed to the tool comprise three sets,
3744 in the following order:
3745
3746 @enumerate
3747 @item
3748 the applicable ^switches^switches^ contributed for the file
3749 by the @code{Builder} package in the project file supplied on the command line;
3750
3751 @item
3752 those contributed for the file by the package (in the relevant project file --
3753 see below) corresponding to the tool; and
3754
3755 @item
3756 the applicable switches passed on the command line.
3757 @end enumerate
3758
3759 The term @emph{applicable ^switches^switches^} reflects the fact that
3760 @command{gnatmake} ^switches^switches^ may or may not be passed to individual
3761 tools, depending on the individual ^switch^switch^.
3762
3763 @command{gnatmake} may invoke the compiler on source files from different
3764 projects. The Project Manager will use the appropriate project file to
3765 determine the @code{Compiler} package for each source file being compiled.
3766 Likewise for the @code{Binder} and @code{Linker} packages.
3767
3768 As an example, consider the following package in a project file:
3769
3770 @smallexample @c projectfile
3771 @group
3772 project Proj1 is
3773    package Compiler is
3774       for ^Default_Switches^Default_Switches^ ("Ada")
3775           use ("^-g^-g^");
3776       for Switches ("a.adb")
3777           use ("^-O1^-O1^");
3778       for Switches ("b.adb")
3779           use ("^-O2^-O2^",
3780                "^-gnaty^-gnaty^");
3781    end Compiler;
3782 end Proj1;
3783 @end group
3784 @end smallexample
3785
3786 @noindent
3787 If @command{gnatmake} is invoked with this project file, and it needs to
3788 compile, say, the files @file{a.adb}, @file{b.adb}, and @file{c.adb}, then
3789 @file{a.adb} will be compiled with the ^switch^switch^
3790 @option{^-O1^-O1^},
3791 @file{b.adb} with ^switches^switches^
3792 @option{^-O2^-O2^}
3793 and @option{^-gnaty^-gnaty^},
3794 and @file{c.adb} with @option{^-g^-g^}.
3795
3796 The following example illustrates the ordering of the ^switches^switches^
3797 contributed by different packages:
3798
3799 @smallexample @c projectfile
3800 @group
3801 project Proj2 is
3802    package Builder is
3803       for Switches ("main.adb")
3804           use ("^-g^-g^",
3805                "^-O1^-)1^",
3806                "^-f^-f^");
3807    end Builder;
3808 @end group
3809
3810 @group
3811    package Compiler is
3812       for Switches ("main.adb")
3813           use ("^-O2^-O2^");
3814    end Compiler;
3815 end Proj2;
3816 @end group
3817 @end smallexample
3818
3819 @noindent
3820 If you issue the command:
3821
3822 @smallexample
3823     gnatmake ^-Pproj2^/PROJECT_FILE=PROJ2^ -O0 main
3824 @end smallexample
3825
3826 @noindent
3827 then the compiler will be invoked on @file{main.adb} with the following
3828 sequence of ^switches^switches^
3829
3830 @smallexample
3831    ^-g -O1 -O2 -O0^-g -O1 -O2 -O0^
3832 @end smallexample
3833
3834 @noindent
3835 with the last @option{^-O^-O^}
3836 ^switch^switch^ having precedence over the earlier ones;
3837 several other ^switches^switches^
3838 (such as @option{^-c^-c^}) are added implicitly.
3839
3840 The ^switches^switches^
3841 @option{^-g^-g^}
3842 and @option{^-O1^-O1^} are contributed by package
3843 @code{Builder},  @option{^-O2^-O2^} is contributed
3844 by the package @code{Compiler}
3845 and @option{^-O0^-O0^} comes from the command line.
3846
3847 The @option{^-g^-g^}
3848 ^switch^switch^ will also be passed in the invocation of
3849 @command{Gnatlink.}
3850
3851 A final example illustrates switch contributions from packages in different
3852 project files:
3853
3854 @smallexample @c projectfile
3855 @group
3856 project Proj3 is
3857    for Source_Files use ("pack.ads", "pack.adb");
3858    package Compiler is
3859       for ^Default_Switches^Default_Switches^ ("Ada")
3860           use ("^-gnata^-gnata^");
3861    end Compiler;
3862 end Proj3;
3863 @end group
3864
3865 @group
3866 with "Proj3";
3867 project Proj4 is
3868    for Source_Files use ("foo_main.adb", "bar_main.adb");
3869    package Builder is
3870       for Switches ("foo_main.adb")
3871           use ("^-s^-s^",
3872                "^-g^-g^");
3873    end Builder;
3874 end Proj4;
3875 @end group
3876
3877 @group
3878 -- Ada source file:
3879 with Pack;
3880 procedure Foo_Main is
3881    @dots{}
3882 end Foo_Main;
3883 @end group
3884 @end smallexample
3885
3886 @noindent
3887 If the command is
3888 @smallexample
3889 gnatmake ^-PProj4^/PROJECT_FILE=PROJ4^ foo_main.adb -cargs -gnato
3890 @end smallexample
3891
3892 @noindent
3893 then the ^switches^switches^ passed to the compiler for @file{foo_main.adb} are
3894 @option{^-g^-g^} (contributed by the package @code{Proj4.Builder}) and
3895 @option{^-gnato^-gnato^} (passed on the command line).
3896 When the imported package @code{Pack} is compiled, the ^switches^switches^ used
3897 are @option{^-g^-g^} from @code{Proj4.Builder},
3898 @option{^-gnata^-gnata^} (contributed from package @code{Proj3.Compiler},
3899 and @option{^-gnato^-gnato^} from the command line.
3900
3901 When using @command{gnatmake} with project files, some ^switches^switches^ or
3902 arguments may be expressed as relative paths. As the working directory where
3903 compilation occurs may change, these relative paths are converted to absolute
3904 paths. For the ^switches^switches^ found in a project file, the relative paths
3905 are relative to the project file directory, for the switches on the command
3906 line, they are relative to the directory where @command{gnatmake} is invoked.
3907 The ^switches^switches^ for which this occurs are:
3908 ^-I^-I^,
3909 ^-A^-A^,
3910 ^-L^-L^,
3911 ^-aO^-aO^,
3912 ^-aL^-aL^,
3913 ^-aI^-aI^, as well as all arguments that are not switches (arguments to
3914 ^switch^switch^
3915 ^-o^-o^, object files specified in package @code{Linker} or after
3916 -largs on the command line). The exception to this rule is the ^switch^switch^
3917 ^--RTS=^--RTS=^ for which a relative path argument is never converted.
3918
3919 @c ---------------------------------------------
3920 @node Specifying Configuration Pragmas
3921 @subsection Specifying Configuration Pragmas
3922 @c ---------------------------------------------
3923
3924 @noindent
3925 When using @command{gnatmake} with project files, if there exists a file
3926 @file{gnat.adc} that contains configuration pragmas, this file will be
3927 ignored.
3928
3929 Configuration pragmas can be defined by means of the following attributes in
3930 project files: @code{Global_Configuration_Pragmas} in package @code{Builder}
3931 and @code{Local_Configuration_Pragmas} in package @code{Compiler}.
3932
3933 Both these attributes are single string attributes. Their values is the path
3934 name of a file containing configuration pragmas. If a path name is relative,
3935 then it is relative to the project directory of the project file where the
3936 attribute is defined.
3937
3938 When compiling a source, the configuration pragmas used are, in order,
3939 those listed in the file designated by attribute
3940 @code{Global_Configuration_Pragmas} in package @code{Builder} of the main
3941 project file, if it is specified, and those listed in the file designated by
3942 attribute @code{Local_Configuration_Pragmas} in package @code{Compiler} of
3943 the project file of the source, if it exists.
3944
3945 @c ---------------------------------------------
3946 @node Project Files and Main Subprograms
3947 @subsection Project Files and Main Subprograms
3948 @c ---------------------------------------------
3949
3950 @noindent
3951 When using a project file, you can invoke @command{gnatmake}
3952 with one or several main subprograms, by specifying their source files on the
3953 command line.
3954
3955 @smallexample
3956     gnatmake ^-P^/PROJECT_FILE=^prj main1 main2 main3
3957 @end smallexample
3958
3959 @noindent
3960 Each of these needs to be a source file of the same project, except
3961 when the switch ^-u^/UNIQUE^ is used.
3962
3963 When ^-u^/UNIQUE^ is not used, all the mains need to be sources of the
3964 same project, one of the project in the tree rooted at the project specified
3965 on the command line. The package @code{Builder} of this common project, the
3966 "main project" is the one that is considered by @command{gnatmake}.
3967
3968 When ^-u^/UNIQUE^ is used, the specified source files may be in projects
3969 imported directly or indirectly by the project specified on the command line.
3970 Note that if such a source file is not part of the project specified on the
3971 command line, the ^switches^switches^ found in package @code{Builder} of the
3972 project specified on the command line, if any, that are transmitted
3973 to the compiler will still be used, not those found in the project file of
3974 the source file.
3975
3976 When using a project file, you can also invoke @command{gnatmake} without
3977 explicitly specifying any main, and the effect depends on whether you have
3978 defined the @code{Main} attribute.  This attribute has a string list value,
3979 where each element in the list is the name of a source file (the file
3980 extension is optional) that contains a unit that can be a main subprogram.
3981
3982 If the @code{Main} attribute is defined in a project file as a non-empty
3983 string list and the switch @option{^-u^/UNIQUE^} is not used on the command
3984 line, then invoking @command{gnatmake} with this project file but without any
3985 main on the command line is equivalent to invoking @command{gnatmake} with all
3986 the file names in the @code{Main} attribute on the command line.
3987
3988 Example:
3989 @smallexample @c projectfile
3990 @group
3991    project Prj is
3992       for Main use ("main1", "main2", "main3");
3993    end Prj;
3994 @end group
3995 @end smallexample
3996
3997 @noindent
3998 With this project file, @code{"gnatmake ^-Pprj^/PROJECT_FILE=PRJ^"}
3999 is equivalent to
4000 @code{"gnatmake ^-Pprj^/PROJECT_FILE=PRJ^ main1 main2 main3"}.
4001
4002 When the project attribute @code{Main} is not specified, or is specified
4003 as an empty string list, or when the switch @option{-u} is used on the command
4004 line, then invoking @command{gnatmake} with no main on the command line will
4005 result in all immediate sources of the project file being checked, and
4006 potentially recompiled. Depending on the presence of the switch @option{-u},
4007 sources from other project files on which the immediate sources of the main
4008 project file depend are also checked and potentially recompiled. In other
4009 words, the @option{-u} switch is applied to all of the immediate sources of the
4010 main project file.
4011
4012 When no main is specified on the command line and attribute @code{Main} exists
4013 and includes several mains, or when several mains are specified on the
4014 command line, the default ^switches^switches^ in package @code{Builder} will
4015 be used for all mains, even if there are specific ^switches^switches^
4016 specified for one or several mains.
4017
4018 But the ^switches^switches^ from package @code{Binder} or @code{Linker} will be
4019 the specific ^switches^switches^ for each main, if they are specified.
4020
4021 @c ---------------------------------------------
4022 @node Library Project Files
4023 @subsection Library Project Files
4024 @c ---------------------------------------------
4025
4026 @noindent
4027 When @command{gnatmake} is invoked with a main project file that is a library
4028 project file, it is not allowed to specify one or more mains on the command
4029 line.
4030
4031 When a library project file is specified, switches ^-b^/ACTION=BIND^ and
4032 ^-l^/ACTION=LINK^ have special meanings.
4033
4034 @itemize @bullet
4035 @item ^-b^/ACTION=BIND^ is only allowed for stand-alone libraries. It indicates
4036   to @command{gnatmake} that @command{gnatbind} should be invoked for the
4037   library.
4038
4039 @item ^-l^/ACTION=LINK^ may be used for all library projects. It indicates
4040   to @command{gnatmake} that the binder generated file should be compiled
4041   (in the case of a stand-alone library) and that the library should be built.
4042 @end itemize
4043
4044 @c ---------------------------------------------
4045 @node The GNAT Driver and Project Files
4046 @section The GNAT Driver and Project Files
4047 @c ---------------------------------------------
4048
4049 @noindent
4050 A number of GNAT tools, other than @command{^gnatmake^gnatmake^}
4051 can benefit from project files:
4052 (@command{^gnatbind^gnatbind^},
4053 @command{^gnatcheck^gnatcheck^},
4054 @command{^gnatclean^gnatclean^},
4055 @command{^gnatelim^gnatelim^},
4056 @command{^gnatfind^gnatfind^},
4057 @command{^gnatlink^gnatlink^},
4058 @command{^gnatls^gnatls^},
4059 @command{^gnatmetric^gnatmetric^},
4060 @command{^gnatpp^gnatpp^},
4061 @command{^gnatstub^gnatstub^},
4062 and @command{^gnatxref^gnatxref^}). However, none of these tools can be invoked
4063 directly with a project file switch (@option{^-P^/PROJECT_FILE=^}).
4064 They must be invoked through the @command{gnat} driver.
4065
4066 The @command{gnat} driver is a wrapper that accepts a number of commands and
4067 calls the corresponding tool. It was designed initially for VMS platforms (to
4068 convert VMS qualifiers to Unix-style switches), but it is now available on all
4069 GNAT platforms.
4070
4071 On non-VMS platforms, the @command{gnat} driver accepts the following commands
4072 (case insensitive):
4073
4074 @itemize @bullet
4075 @item BIND to invoke @command{^gnatbind^gnatbind^}
4076 @item CHOP to invoke @command{^gnatchop^gnatchop^}
4077 @item CLEAN to invoke @command{^gnatclean^gnatclean^}
4078 @item COMP or COMPILE to invoke the compiler
4079 @item ELIM to invoke @command{^gnatelim^gnatelim^}
4080 @item FIND to invoke @command{^gnatfind^gnatfind^}
4081 @item KR or KRUNCH to invoke @command{^gnatkr^gnatkr^}
4082 @item LINK to invoke @command{^gnatlink^gnatlink^}
4083 @item LS or LIST to invoke @command{^gnatls^gnatls^}
4084 @item MAKE to invoke @command{^gnatmake^gnatmake^}
4085 @item NAME to invoke @command{^gnatname^gnatname^}
4086 @item PREP or PREPROCESS to invoke @command{^gnatprep^gnatprep^}
4087 @item PP or PRETTY to invoke @command{^gnatpp^gnatpp^}
4088 @item METRIC to invoke @command{^gnatmetric^gnatmetric^}
4089 @item STUB to invoke @command{^gnatstub^gnatstub^}
4090 @item XREF to invoke @command{^gnatxref^gnatxref^}
4091
4092 @end itemize
4093
4094 @noindent
4095 (note that the compiler is invoked using the command
4096 @command{^gnatmake -f -u -c^gnatmake -f -u -c^}).
4097
4098 On non-VMS platforms, between @command{gnat} and the command, two
4099 special switches may be used:
4100
4101 @itemize @bullet
4102 @item @command{-v} to display the invocation of the tool.
4103 @item @command{-dn} to prevent the @command{gnat} driver from removing
4104   the temporary files it has created. These temporary files are
4105   configuration files and temporary file list files.
4106
4107 @end itemize
4108
4109 @noindent
4110 The command may be followed by switches and arguments for the invoked
4111 tool.
4112
4113 @smallexample
4114   gnat bind -C main.ali
4115   gnat ls -a main
4116   gnat chop foo.txt
4117 @end smallexample
4118
4119 @noindent
4120 Switches may also be put in text files, one switch per line, and the text
4121 files may be specified with their path name preceded by '@@'.
4122
4123 @smallexample
4124    gnat bind @@args.txt main.ali
4125 @end smallexample
4126
4127 @noindent
4128 In addition, for commands BIND, COMP or COMPILE, FIND, ELIM, LS or LIST, LINK,
4129 METRIC, PP or PRETTY, STUB and XREF, the project file related switches
4130 (@option{^-P^/PROJECT_FILE^},
4131 @option{^-X^/EXTERNAL_REFERENCE^} and
4132 @option{^-vP^/MESSAGES_PROJECT_FILE=^x}) may be used in addition to
4133 the switches of the invoking tool.
4134
4135 When GNAT PP or GNAT PRETTY is used with a project file, but with no source
4136 specified on the command line, it invokes @command{^gnatpp^gnatpp^} with all
4137 the immediate sources of the specified project file.
4138
4139 When GNAT METRIC is used with a project file, but with no source
4140 specified on the command line, it invokes @command{^gnatmetric^gnatmetric^}
4141 with all the immediate sources of the specified project file and with
4142 @option{^-d^/DIRECTORY^} with the parameter pointing to the object directory
4143 of the project.
4144
4145 In addition, when GNAT PP, GNAT PRETTY or GNAT METRIC is used with
4146 a project file, no source is specified on the command line and
4147 switch ^-U^/ALL_PROJECTS^ is specified on the command line, then
4148 the underlying tool (^gnatpp^gnatpp^ or
4149 ^gnatmetric^gnatmetric^) is invoked for all sources of all projects,
4150 not only for the immediate sources of the main project.
4151 @ifclear vms
4152 (-U stands for Universal or Union of the project files of the project tree)
4153 @end ifclear
4154
4155 For each of the following commands, there is optionally a corresponding
4156 package in the main project.
4157
4158 @itemize @bullet
4159 @item package @code{Binder} for command BIND (invoking @code{^gnatbind^gnatbind^})
4160
4161 @item package @code{Check} for command CHECK (invoking
4162   @code{^gnatcheck^gnatcheck^})
4163
4164 @item package @code{Compiler} for command COMP or COMPILE (invoking the compiler)
4165
4166 @item package @code{Cross_Reference} for command XREF (invoking
4167   @code{^gnatxref^gnatxref^})
4168
4169 @item package @code{Eliminate} for command ELIM (invoking
4170   @code{^gnatelim^gnatelim^})
4171
4172 @item package @code{Finder} for command FIND (invoking @code{^gnatfind^gnatfind^})
4173
4174 @item package @code{Gnatls} for command LS or LIST (invoking @code{^gnatls^gnatls^})
4175
4176 @item package @code{Gnatstub} for command STUB
4177   (invoking @code{^gnatstub^gnatstub^})
4178
4179 @item package @code{Linker} for command LINK (invoking @code{^gnatlink^gnatlink^})
4180
4181 @item package @code{Check} for command CHECK
4182   (invoking @code{^gnatcheck^gnatcheck^})
4183
4184 @item package @code{Metrics} for command METRIC
4185   (invoking @code{^gnatmetric^gnatmetric^})
4186
4187 @item package @code{Pretty_Printer} for command PP or PRETTY
4188   (invoking @code{^gnatpp^gnatpp^})
4189
4190 @end itemize
4191
4192 @noindent
4193 Package @code{Gnatls} has a unique attribute @code{Switches},
4194 a simple variable with a string list value. It contains ^switches^switches^
4195 for the invocation of @code{^gnatls^gnatls^}.
4196
4197 @smallexample @c projectfile
4198 @group
4199 project Proj1 is
4200    package gnatls is
4201       for Switches
4202           use ("^-a^-a^",
4203                "^-v^-v^");
4204    end gnatls;
4205 end Proj1;
4206 @end group
4207 @end smallexample
4208
4209 @noindent
4210 All other packages have two attribute @code{Switches} and
4211 @code{^Default_Switches^Default_Switches^}.
4212
4213 @code{Switches} is an indexed attribute, indexed by the
4214 source file name, that has a string list value: the ^switches^switches^ to be
4215 used when the tool corresponding to the package is invoked for the specific
4216 source file.
4217
4218 @code{^Default_Switches^Default_Switches^} is an attribute,
4219 indexed by  the programming language that has a string list value.
4220 @code{^Default_Switches^Default_Switches^ ("Ada")} contains the
4221 ^switches^switches^ for the invocation of the tool corresponding
4222 to the package, except if a specific @code{Switches} attribute
4223 is specified for the source file.
4224
4225 @smallexample @c projectfile
4226 @group
4227 project Proj is
4228
4229    for Source_Dirs use ("**");
4230
4231    package gnatls is
4232       for Switches use
4233           ("^-a^-a^",
4234            "^-v^-v^");
4235    end gnatls;
4236 @end group
4237 @group
4238
4239    package Compiler is
4240       for ^Default_Switches^Default_Switches^ ("Ada")
4241           use ("^-gnatv^-gnatv^",
4242                "^-gnatwa^-gnatwa^");
4243    end Binder;
4244 @end group
4245 @group
4246
4247    package Binder is
4248       for ^Default_Switches^Default_Switches^ ("Ada")
4249           use ("^-C^-C^",
4250                "^-e^-e^");
4251    end Binder;
4252 @end group
4253 @group
4254
4255    package Linker is
4256       for ^Default_Switches^Default_Switches^ ("Ada")
4257           use ("^-C^-C^");
4258       for Switches ("main.adb")
4259           use ("^-C^-C^",
4260                "^-v^-v^",
4261                "^-v^-v^");
4262    end Linker;
4263 @end group
4264 @group
4265
4266    package Finder is
4267       for ^Default_Switches^Default_Switches^ ("Ada")
4268            use ("^-a^-a^",
4269                 "^-f^-f^");
4270    end Finder;
4271 @end group
4272 @group
4273
4274    package Cross_Reference is
4275       for ^Default_Switches^Default_Switches^ ("Ada")
4276           use ("^-a^-a^",
4277                "^-f^-f^",
4278                "^-d^-d^",
4279                "^-u^-u^");
4280    end Cross_Reference;
4281 end Proj;
4282 @end group
4283 @end smallexample
4284
4285 @noindent
4286 With the above project file, commands such as
4287
4288 @smallexample
4289    ^gnat comp -Pproj main^GNAT COMP /PROJECT_FILE=PROJ MAIN^
4290    ^gnat ls -Pproj main^GNAT LIST /PROJECT_FILE=PROJ MAIN^
4291    ^gnat xref -Pproj main^GNAT XREF /PROJECT_FILE=PROJ MAIN^
4292    ^gnat bind -Pproj main.ali^GNAT BIND /PROJECT_FILE=PROJ MAIN.ALI^
4293    ^gnat link -Pproj main.ali^GNAT LINK /PROJECT_FILE=PROJ MAIN.ALI^
4294 @end smallexample
4295
4296 @noindent
4297 will set up the environment properly and invoke the tool with the switches
4298 found in the package corresponding to the tool:
4299 @code{^Default_Switches^Default_Switches^ ("Ada")} for all tools,
4300 except @code{Switches ("main.adb")}
4301 for @code{^gnatlink^gnatlink^}.
4302 It is also possible to invoke some of the tools,
4303 (@code{^gnatcheck^gnatcheck^},
4304 @code{^gnatmetric^gnatmetric^},
4305 and @code{^gnatpp^gnatpp^})
4306 on a set of project units thanks to the combination of the switches
4307 @option{-P}, @option{-U} and possibly the main unit when one is interested
4308 in its closure. For instance,
4309 @smallexample
4310 gnat metric -Pproj
4311 @end smallexample
4312
4313 @noindent
4314 will compute the metrics for all the immediate units of project
4315 @code{proj}.
4316 @smallexample
4317 gnat metric -Pproj -U
4318 @end smallexample
4319
4320 @noindent
4321 will compute the metrics for all the units of the closure of projects
4322 rooted at @code{proj}.
4323 @smallexample
4324 gnat metric -Pproj -U main_unit
4325 @end smallexample
4326
4327 @noindent
4328 will compute the metrics for the closure of units rooted at
4329 @code{main_unit}. This last possibility relies implicitly
4330 on @command{gnatbind}'s option @option{-R}. But if the argument files for the
4331 tool invoked by the @command{gnat} driver are explicitly  specified
4332 either directly or through the tool @option{-files} option, then the tool
4333 is called only for these explicitly specified files.
4334
4335 @c ---------------------------------------------
4336 @node The Development Environments
4337 @section The Development Environments
4338 @c ---------------------------------------------
4339
4340 @noindent
4341 See the appropriate manuals for more details. These environments will
4342 store a number of settings in the project itself, when they are meant
4343 to be shared by the whole team working on the project. Here are the
4344 attributes defined in the package @b{IDE} in projects.
4345
4346 @table @code
4347 @item Remote_Host
4348 This is a simple attribute. Its value is a string that designates the remote
4349 host in a cross-compilation environment, to be used for remote compilation and
4350 debugging. This field should not be specified when running on the local
4351 machine.
4352
4353 @item Program_Host
4354 This is a simple attribute. Its value is a string that specifies the
4355 name of IP address of the embedded target in a cross-compilation environment,
4356 on which the program should execute.
4357
4358 @item Communication_Protocol
4359 This is a simple string attribute. Its value is the name of the protocol
4360 to use to communicate with the target in a cross-compilation environment,
4361 e.g.@: @code{"wtx"} or @code{"vxworks"}.
4362
4363 @item Compiler_Command
4364 This is an associative array attribute, whose domain is a language name. Its
4365 value is  string that denotes the command to be used to invoke the compiler.
4366 The value of @code{Compiler_Command ("Ada")} is expected to be compatible with
4367 gnatmake, in particular in the handling of switches.
4368
4369 @item Debugger_Command
4370 This is simple attribute, Its value is a string that specifies the name of
4371 the debugger to be used, such as gdb, powerpc-wrs-vxworks-gdb or gdb-4.
4372
4373 @item Default_Switches
4374 This is an associative array attribute. Its indexes are the name of the
4375 external tools that the GNAT Programming System (GPS) is supporting. Its
4376 value is a list of switches to use when invoking that tool.
4377
4378 @item  Gnatlist
4379 This is a simple attribute.  Its value is a string that specifies the name
4380 of the @command{gnatls} utility to be used to retrieve information about the
4381 predefined path; e.g., @code{"gnatls"}, @code{"powerpc-wrs-vxworks-gnatls"}.
4382
4383 @item VCS_Kind
4384 This is a simple attribute. Its value is a string used to specify the
4385 Version Control System (VCS) to be used for this project, e.g.@: CVS, RCS
4386 ClearCase or Perforce.
4387
4388 @item Gnat
4389 This is a simple attribute. Its value is a string that specifies the name
4390 of the @command{gnat} utility to be used when executing various tools from
4391 GPS, in particular @code{"gnat pp"}, @code{"gnat stub"},@dots{}
4392
4393 @item VCS_File_Check
4394 This is a simple attribute. Its value is a string that specifies the
4395 command used by the VCS to check the validity of a file, either
4396 when the user explicitly asks for a check, or as a sanity check before
4397 doing the check-in.
4398
4399 @item VCS_Log_Check
4400 This is a simple attribute. Its value is a string that specifies
4401 the command used by the VCS to check the validity of a log file.
4402
4403 @item VCS_Repository_Root
4404 The VCS repository root path. This is used to create tags or branches
4405 of the repository. For subversion the value should be the @code{URL}
4406 as specified to check-out the working copy of the repository.
4407
4408 @item VCS_Patch_Root
4409 The local root directory to use for building patch file. All patch chunks
4410 will be relative to this path. The root project directory is used if
4411 this value is not defined.
4412
4413 @end table
4414
4415 @c ---------------------------------------------
4416 @node Cleaning up with GPRclean
4417 @section Cleaning up with GPRclean
4418 @c ---------------------------------------------
4419
4420 @noindent
4421 The GPRclean tool removes the files created by GPRbuild.
4422 At a minimum, to invoke GPRclean you must specify a main project file
4423 in a command such as @code{gprclean proj.gpr} or @code{gprclean -P proj.gpr}.
4424
4425 Examples of invocation of GPRclean:
4426
4427 @smallexample
4428    gprclean -r prj1.gpr
4429    gprclean -c -P prj2.gpr
4430 @end smallexample
4431
4432 @menu
4433 * Switches for GPRclean::
4434 @end menu
4435
4436 @c ---------------------------------------------
4437 @node Switches for GPRclean
4438 @subsection Switches for GPRclean
4439 @c ---------------------------------------------
4440
4441 @noindent
4442 The switches for GPRclean are:
4443
4444 @itemize @bullet
4445 @item @option{--config=<main config project file name>} : Specify the
4446   configuration project file name
4447
4448 @item @option{--autoconf=<config project file name>}
4449
4450   This specifies a configuration project file name that already exists or will
4451   be created automatically. Option @option{--autoconf=}
4452   cannot be specified more than once. If the configuration project file
4453   specified with @option{--autoconf=} exists, then it is used. Otherwise,
4454   @value{gprconfig} is invoked to create it automatically.
4455
4456 @item @option{-c} : Only delete compiler-generated files. Do not delete
4457   executables and libraries.
4458
4459 @item @option{-f} : Force deletions of unwritable files
4460
4461 @item @option{-F} : Display full project path name in brief error messages
4462
4463 @item @option{-h} : Display this message
4464
4465 @item @option{-n} : Do not delete files, only list files to delete
4466
4467 @item @option{-P<proj>} : Use Project File @emph{<proj>}.
4468
4469 @item @option{-q} : Be quiet/terse. There is no output, except to report
4470   problems.
4471
4472 @item @option{-r} : (recursive) Clean all projects referenced by the main
4473   project directly or indirectly. Without this switch, GPRclean only
4474   cleans the main project.
4475
4476 @item @option{-v}  : Verbose mode
4477
4478 @item @option{-vPx} : Specify verbosity when parsing Project Files.
4479   x = 0 (default), 1 or 2.
4480
4481 @item @option{-Xnm=val} : Specify an external reference for Project Files.
4482
4483 @end itemize