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