OSDN Git Service

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