1 @set gprconfig GPRconfig
3 @c ------ projects.texi
4 @c Copyright (C) 2002-2014, 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 ---------------------------------------------
17 * Building With Projects::
18 * Organizing Projects into Subsystems::
19 * Scenarios in Projects::
22 * Aggregate Projects::
23 * Aggregate Library Projects::
24 * Project File Reference::
27 @c ---------------------------------------------
30 @c ---------------------------------------------
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:
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 in Projects}).
52 @item Automatically build libraries as part of the build process
53 (@pxref{Library Projects}).
58 Project files are written in a syntax close to that of Ada, using familiar
59 notions such as packages, context clauses, declarations, default values,
60 assignments, and inheritance (@pxref{Project File Reference}).
62 Project files can be built hierarchically from other project files, simplifying
63 complex system integration and project reuse (@pxref{Organizing Projects into
67 @item One project can import other projects containing needed source files.
68 More generally, the Project Manager lets you structure large development
69 efforts into hierarchical subsystems, where build decisions are delegated
70 to the subsystem level, and thus different compilation environments
71 (switch settings) used for different subsystems.
72 @item You can organize GNAT projects in a hierarchy: a child project
73 can extend a parent project, inheriting the parent's source files and
74 optionally overriding any of them with alternative versions
75 (@pxref{Project Extension}).
80 Several tools support project files, generally in addition to specifying
81 the information on the command line itself). They share common switches
82 to control the loading of the project (in particular
83 @option{-P@emph{projectfile}} and
84 @option{-X@emph{vbl}=@emph{value}}).
86 The Project Manager supports a wide range of development strategies,
87 for systems of all sizes. Here are some typical practices that are
91 @item Using a common set of source files and generating object files in different
92 directories via different switch settings. It can be used for instance, for
93 generating separate sets of object files for debugging and for production.
94 @item Using a mostly-shared set of source files with different versions of
95 some units or subunits. It can be used for instance, for grouping and hiding
96 all OS dependencies in a small number of implementation units.
100 Project files can be used to achieve some of the effects of a source
101 versioning system (for example, defining separate projects for
102 the different sets of sources that comprise different releases) but the
103 Project Manager is independent of any source configuration management tool
104 that might be used by the developers.
106 The various sections below introduce the different concepts related to
107 projects. Each section starts with examples and use cases, and then goes into
108 the details of related project file capabilities.
110 @c ---------------------------------------------
111 @node Building With Projects
112 @section Building With Projects
113 @c ---------------------------------------------
116 In its simplest form, a unique project is used to build a single executable.
117 This section concentrates on such a simple setup. Later sections will extend
118 this basic model to more complex setups.
120 The following concepts are the foundation of project files, and will be further
121 detailed later in this documentation. They are summarized here as a reference.
124 @item @b{Project file}:
125 A text file using an Ada-like syntax, generally using the @file{.gpr}
126 extension. It defines build-related characteristics of an application.
127 The characteristics include the list of sources, the location of those
128 sources, the location for the generated object files, the name of
129 the main program, and the options for the various tools involved in the
132 @item @b{Project attribute}:
133 A specific project characteristic is defined by an attribute clause. Its
134 value is a string or a sequence of strings. All settings in a project
135 are defined through a list of predefined attributes with precise
136 semantics. @xref{Attributes}.
138 @item @b{Package in a project}:
139 Global attributes are defined at the top level of a project.
140 Attributes affecting specific tools are grouped in a
141 package whose name is related to tool's function. The most common
142 packages are @code{Builder}, @code{Compiler}, @code{Binder},
143 and @code{Linker}. @xref{Packages}.
145 @item @b{Project variables}:
146 In addition to attributes, a project can use variables to store intermediate
147 values and avoid duplication in complex expressions. It can be initialized
148 with a value coming from the environment.
149 A frequent use of variables is to define scenarios.
150 @xref{External Values}, @xref{Scenarios in Projects}, and @xref{Variables}.
152 @item @b{Source files} and @b{source directories}:
153 A source file is associated with a language through a naming convention. For
154 instance, @code{foo.c} is typically the name of a C source file;
155 @code{bar.ads} or @code{bar.1.ada} are two common naming conventions for a
156 file containing an Ada spec. A compilation unit is often composed of a main
157 source file and potentially several auxiliary ones, such as header files in C.
158 The naming conventions can be user defined @xref{Naming Schemes}, and will
159 drive the builder to call the appropriate compiler for the given source file.
160 Source files are searched for in the source directories associated with the
161 project through the @b{Source_Dirs} attribute. By default, all the files (in
162 these source directories) following the naming conventions associated with the
163 declared languages are considered to be part of the project. It is also
164 possible to limit the list of source files using the @b{Source_Files} or
165 @b{Source_List_File} attributes. Note that those last two attributes only
166 accept basenames with no directory information.
168 @item @b{Object files} and @b{object directory}:
169 An object file is an intermediate file produced by the compiler from a
170 compilation unit. It is used by post-compilation tools to produce
171 final executables or libraries. Object files produced in the context of
172 a given project are stored in a single directory that can be specified by the
173 @b{Object_Dir} attribute. In order to store objects in
174 two or more object directories, the system must be split into
175 distinct subsystems with their own project file.
179 The following subsections introduce gradually all the attributes of interest
180 for simple build needs. Here is the simple setup that will be used in the
183 The Ada source files @file{pack.ads}, @file{pack.adb}, and @file{proc.adb} are in
184 the @file{common/} directory. The file @file{proc.adb} contains an Ada main
185 subprogram @code{Proc} that @code{with}s package @code{Pack}. We want to compile
186 these source files with the switch
187 @option{-O2}, and put the resulting files in
188 the directory @file{obj/}.
199 proc.ali, proc.o pack.ali, pack.o
204 Our project is to be called @emph{Build}. The name of the
205 file is the name of the project (case-insensitive) with the
206 @file{.gpr} extension, therefore the project file name is @file{build.gpr}. This
207 is not mandatory, but a warning is issued when this convention is not followed.
209 This is a very simple example, and as stated above, a single project
210 file is enough for it. We will thus create a new file, that for now
211 should contain the following code:
214 @b{project} Build @b{is}
219 * Source Files and Directories::
220 * Duplicate Sources in Projects::
221 * Object and Exec Directory::
223 * Tools Options in Project Files::
224 * Compiling with Project Files::
225 * Executable File Names::
226 * Avoid Duplication With Variables::
229 * Distributed support::
232 @c ---------------------------------------------
233 @node Source Files and Directories
234 @subsection Source Files and Directories
235 @c ---------------------------------------------
238 When you create a new project, the first thing to describe is how to find the
239 corresponding source files. These are 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 The 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:
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.
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 the specific platform. For instance, when the same
268 project file is to be used both on Unix and Windows, "/" should be used as
269 the 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 paths in
273 the list ends with "@file{**}", 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 the directory in which the project file resides.
277 @cindex Source directories, recursive
279 @cindex @code{Excluded_Source_Dirs}
280 When using that construct, it can sometimes be convenient to also use the
281 attribute @b{Excluded_Source_Dirs}, which is also a list of paths. Each entry
282 specifies a directory whose immediate content, not including subdirs, is to
283 be excluded. It is also possible to exclude a complete directory subtree
284 using the "**" notation.
286 @cindex @code{Ignore_Source_Sub_Dirs}
287 It is often desirable to remove, from the source directories, directory
288 subtrees rooted at some subdirectories. An example is the subdirectories
289 created by a Version Control System such as Subversion that creates directory
290 subtrees rooted at subdirectories ".svn". To do that, attribute
291 @b{Ignore_Source_Sub_Dirs} can be used. It specifies the list of simple
292 file names for the roots of these undesirable directory subtrees.
295 @b{for} Source_Dirs @b{use} ("./**");
296 @b{for} Ignore_Source_Sub_Dirs @b{use} (".svn");
302 When applied to the simple example, and because we generally prefer to have
303 the project file at the toplevel directory rather than mixed with the sources,
304 we will create the following file
308 @b{project} Build @b{is}
309 @b{for} Source_Dirs @b{use} ("common"); -- <<<<
314 Once source directories have been specified, one may need to indicate
315 source files of interest. By default, all source files present in the source
316 directories are considered by the project manager. When this is not desired,
317 it is possible to specify the list of sources to consider explicitly.
318 In such a case, only source file base names are indicated and not
319 their absolute or relative path names. The project manager is in charge of
320 locating the specified source files in the specified source directories.
323 @item By default, the project manager searches for all source files of all
324 specified languages in all the source directories.
326 Since the project manager was initially developed for Ada environments, the
327 default language is usually Ada and the above project file is complete: it
328 defines without ambiguity the sources composing the project: that is to say,
329 all the sources in subdirectory "common" for the default language (Ada) using
330 the default naming convention.
332 @cindex @code{Languages}
333 However, when compiling a multi-language application, or a pure C
334 application, the project manager must be told which languages are of
335 interest, which is done by setting the @b{Languages} attribute to a list of
336 strings, each of which is the name of a language. Tools like
337 @command{gnatmake} only know about Ada, while other tools like
338 @command{gprbuild} know about many more languages such as C, C++, Fortran,
339 assembly and others can be added dynamically.
341 @cindex Naming scheme
342 Even when using only Ada, the default naming might not be suitable. Indeed,
343 how does the project manager recognizes an "Ada file" from any other
344 file? Project files can describe the naming scheme used for source files,
345 and override the default (@pxref{Naming Schemes}). The default is the
346 standard GNAT extension (@file{.adb} for bodies and @file{.ads} for
347 specs), which is what is used in our example, explaining why no naming scheme
348 is explicitly specified.
349 @xref{Naming Schemes}.
351 @item @code{Source_Files}
352 @cindex @code{Source_Files}
353 In some cases, source directories might contain files that should not be
354 included in a project. One can specify the explicit list of file names to
355 be considered through the @b{Source_Files} attribute.
356 When this attribute is defined, instead of looking at every file in the
357 source directories, the project manager takes only those names into
358 consideration reports errors if they cannot be found in the source
359 directories or does not correspond to the naming scheme.
361 @item For various reasons, it is sometimes useful to have a project with no
362 sources (most of the time because the attributes defined in the project
363 file will be reused in other projects, as explained in
364 @pxref{Organizing Projects into Subsystems}. To do this, the attribute
365 @emph{Source_Files} is set to the empty list, i.e. @code{()}. Alternatively,
366 @emph{Source_Dirs} can be set to the empty list, with the same
369 @item @code{Source_List_File}
370 @cindex @code{Source_List_File}
371 If there is a great number of files, it might be more convenient to use
372 the attribute @b{Source_List_File}, which specifies the full path of a file.
373 This file must contain a list of source file names (one per line, no
374 directory information) that are searched as if they had been defined
375 through @emph{Source_Files}. Such a file can easily be created through
378 A warning is issued if both attributes @code{Source_Files} and
379 @code{Source_List_File} are given explicit values. In this case, the
380 attribute @code{Source_Files} prevails.
382 @item @code{Excluded_Source_Files}
383 @cindex @code{Excluded_Source_Files}
384 @cindex @code{Locally_Removed_Files}
385 @cindex @code{Excluded_Source_List_File}
386 Specifying an explicit list of files is not always convenient.It might be
387 more convenient to use the default search rules with specific exceptions.
388 This can be done thanks to the attribute @b{Excluded_Source_Files}
389 (or its synonym @b{Locally_Removed_Files}).
390 Its value is the list of file names that should not be taken into account.
391 This attribute is often used when extending a project,
392 @xref{Project Extension}. A similar attribute
393 @b{Excluded_Source_List_File} plays the same
394 role but takes the name of file containing file names similarly to
395 @code{Source_List_File}.
400 In most simple cases, such as the above example, the default source file search
401 behavior provides the expected result, and we do not need to add anything after
402 setting @code{Source_Dirs}. The project manager automatically finds
403 @file{pack.ads}, @file{pack.adb} and @file{proc.adb} as source files of the
406 Note that by default a warning is issued when a project has no sources attached
407 to it and this is not explicitly indicated in the project file.
409 @c ---------------------------------------------
410 @node Duplicate Sources in Projects
411 @subsection Duplicate Sources in Projects
412 @c ---------------------------------------------
415 If the order of the source directories is known statically, that is if
416 @code{"/**"} is not used in the string list @code{Source_Dirs}, then there may
417 be several files with the same name sitting in different directories of the
418 project. In this case, only the file in the first directory is considered as a
419 source of the project and the others are hidden. If @code{"/**"} is used in the
420 string list @code{Source_Dirs}, it is an error to have several files with the
421 same name in the same directory @code{"/**"} subtree, since there would be an
422 ambiguity as to which one should be used. However, two files with the same name
423 may exist in two single directories or directory subtrees. In this case, the
424 one in the first directory or directory subtree is a source of the project.
426 If there are two sources in different directories of the same @code{"/**"}
427 subtree, one way to resolve the problem is to exclude the directory of the
428 file that should not be used as a source of the project.
430 @c ---------------------------------------------
431 @node Object and Exec Directory
432 @subsection Object and Exec Directory
433 @c ---------------------------------------------
436 The next step when writing a project is to indicate where the compiler should
437 put the object files. In fact, the compiler and other tools might create
438 several different kind of files (for GNAT, there is the object file and the ALI
439 file for instance). One of the important concepts in projects is that most
440 tools may consider source directories as read-only and do not attempt to create
441 new or temporary files there. Instead, all files are created in the object
442 directory. It is of course not true for project-aware IDEs, whose purpose it is
443 to create the source files.
445 @cindex @code{Object_Dir}
446 The object directory is specified through the @b{Object_Dir} attribute.
447 Its value is the path to the object directory, either absolute or
448 relative to the directory containing the project file. This
449 directory must already exist and be readable and writable, although
450 some tools have a switch to create the directory if needed (See
451 the switch @code{-p} for @command{gnatmake}
452 and @command{gprbuild}).
454 If the attribute @code{Object_Dir} is not specified, it defaults to
455 the project directory, that is the directory containing the project file.
457 For our example, we can specify the object dir in this way:
460 @b{project} Build @b{is}
461 @b{for} Source_Dirs @b{use} ("common");
462 @b{for} Object_Dir @b{use} "obj"; -- <<<<
467 As mentioned earlier, there is a single object directory per project. As a
468 result, if you have an existing system where the object files are spread across
469 several directories, you can either move all of them into the same directory if
470 you want to build it with a single project file, or study the section on
471 subsystems (@pxref{Organizing Projects into Subsystems}) to see how each
472 separate object directory can be associated with one of the subsystems
473 constituting the application.
475 When the @command{linker} is called, it usually creates an executable. By
476 default, this executable is placed in the object directory of the project. It
477 might be convenient to store it in its own directory.
479 @cindex @code{Exec_Dir}
480 This can be done through the @code{Exec_Dir} attribute, which, like
481 @emph{Object_Dir} contains a single absolute or relative path and must point to
482 an existing and writable directory, unless you ask the tool to create it on
483 your behalf. When not specified, It defaults to the object directory and
484 therefore to the project file's directory if neither @emph{Object_Dir} nor
485 @emph{Exec_Dir} was specified.
487 In the case of the example, let's place the executable in the root
488 of the hierarchy, ie the same directory as @file{build.gpr}. Hence
489 the project file is now
492 @b{project} Build @b{is}
493 @b{for} Source_Dirs @b{use} ("common");
494 @b{for} Object_Dir @b{use} "obj";
495 @b{for} Exec_Dir @b{use} "."; -- <<<<
499 @c ---------------------------------------------
500 @node Main Subprograms
501 @subsection Main Subprograms
502 @c ---------------------------------------------
505 In the previous section, executables were mentioned. The project manager needs
506 to be taught what they are. In a project file, an executable is indicated by
507 pointing to the source file of a main subprogram. In C this is the file that
508 contains the @code{main} function, and in Ada the file that contains the main
511 There can be any number of such main files within a given project, and thus
512 several executables can be built in the context of a single project file. Of
513 course, one given executable might not (and in fact will not) need all the
514 source files referenced by the project. As opposed to other build environments
515 such as @command{makefile}, one does not need to specify the list of
516 dependencies of each executable, the project-aware builder knows enough of the
517 semantics of the languages to build and link only the necessary elements.
520 The list of main files is specified via the @b{Main} attribute. It contains
521 a list of file names (no directories). If a project defines this
522 attribute, it is not necessary to identify main files on the
523 command line when invoking a builder, and editors like
524 @command{GPS} will be able to create extra menus to spawn or debug the
525 corresponding executables.
528 @b{project} Build @b{is}
529 @b{for} Source_Dirs @b{use} ("common");
530 @b{for} Object_Dir @b{use} "obj";
531 @b{for} Exec_Dir @b{use} ".";
532 @b{for} Main @b{use} ("proc.adb"); -- <<<<
537 If this attribute is defined in the project, then spawning the builder
538 with a command such as
545 automatically builds all the executables corresponding to the files
546 listed in the @emph{Main} attribute. It is possible to specify one
547 or more executables on the command line to build a subset of them.
549 @c ---------------------------------------------
550 @node Tools Options in Project Files
551 @subsection Tools Options in Project Files
552 @c ---------------------------------------------
555 We now have a project file that fully describes our environment, and can be
556 used to build the application with a simple @command{gprbuild} command as seen
557 in the previous section. In fact, the empty project we showed immediately at
558 the beginning (with no attribute at all) could already fulfill that need if it
559 was put in the @file{common} directory.
561 Of course, we might want more control. This section shows you how to specify
562 the compilation switches that the various tools involved in the building of the
563 executable should use.
565 @cindex command line length
566 Since source names and locations are described in the project file, it is not
567 necessary to use switches on the command line for this purpose (switches such
568 as -I for gcc). This removes a major source of command line length overflow.
569 Clearly, the builders will have to communicate this information one way or
570 another to the underlying compilers and tools they call but they usually use
571 response files for this and thus are not subject to command line overflows.
573 Several tools participate to the creation of an executable: the compiler
574 produces object files from the source files; the binder (in the Ada case)
575 creates a "source" file that takes care, among other things, of elaboration
576 issues and global variable initialization; and the linker gathers everything
577 into a single executable that users can execute. All these tools are known to
578 the project manager and will be called with user defined switches from the
579 project files. However, we need to introduce a new project file concept to
580 express the switches to be used for any of the tools involved in the build.
582 @cindex project file packages
583 A project file is subdivided into zero or more @b{packages}, each of which
584 contains the attributes specific to one tool (or one set of tools). Project
585 files use an Ada-like syntax for packages. Package names permitted in project
586 files are restricted to a predefined set (@pxref{Packages}), and the contents
587 of packages are limited to a small set of constructs and attributes
588 (@pxref{Attributes}).
590 Our example project file can be extended with the following empty packages. At
591 this stage, they could all be omitted since they are empty, but they show which
592 packages would be involved in the build process.
595 @b{project} Build @b{is}
596 @b{for} Source_Dirs @b{use} ("common");
597 @b{for} Object_Dir @b{use} "obj";
598 @b{for} Exec_Dir @b{use} ".";
599 @b{for} Main @b{use} ("proc.adb");
601 @b{package} Builder @b{is} --<<< for gnatmake and gprbuild
604 @b{package} Compiler @b{is} --<<< for the compiler
607 @b{package} Binder @b{is} --<<< for the binder
610 @b{package} Linker @b{is} --<<< for the linker
616 Let's first examine the compiler switches. As stated in the initial description
617 of the example, we want to compile all files with @option{-O2}. This is a
618 compiler switch, although it is usual, on the command line, to pass it to the
619 builder which then passes it to the compiler. It is recommended to use directly
620 the right package, which will make the setup easier to understand for other
623 Several attributes can be used to specify the switches:
626 @item @b{Default_Switches}:
627 @cindex @code{Default_Switches}
628 This is the first mention in this manual of an @b{indexed attribute}. When
629 this attribute is defined, one must supply an @emph{index} in the form of a
631 In the case of @emph{Default_Switches}, the index is the name of the
632 language to which the switches apply (since a different compiler will
633 likely be used for each language, and each compiler has its own set of
634 switches). The value of the attribute is a list of switches.
636 In this example, we want to compile all Ada source files with the switch
637 @option{-O2}, and the resulting project file is as follows
638 (only the @code{Compiler} package is shown):
641 @b{package} Compiler @b{is}
642 @b{for} Default_Switches ("Ada") @b{use} ("-O2");
647 @cindex @code{Switches}
648 in some cases, we might want to use specific switches
649 for one or more files. For instance, compiling @file{proc.adb} might not be
650 possible at high level of optimization because of a compiler issue.
651 In such a case, the @emph{Switches}
652 attribute (indexed on the file name) can be used and will override the
653 switches defined by @emph{Default_Switches}. Our project file would
658 for Default_Switches ("Ada")
660 for Switches ("proc.adb")
666 @code{Switches} may take a pattern as an index, such as in:
670 for Default_Switches ("Ada")
672 for Switches ("pkg*")
678 Sources @file{pkg.adb} and @file{pkg-child.adb} would be compiled with -O0,
682 @code{Switches} can also be given a language name as index instead of a file
683 name in which case it has the same semantics as @emph{Default_Switches}.
684 However, indexes with wild cards are never valid for language name.
686 @item @b{Local_Configuration_Pragmas}:
687 @cindex @code{Local_Configuration_Pragmas}
688 this attribute may specify the path
689 of a file containing configuration pragmas for use by the Ada compiler,
690 such as @code{pragma Restrictions (No_Tasking)}. These pragmas will be
691 used for all the sources of the project.
695 The switches for the other tools are defined in a similar manner through the
696 @b{Default_Switches} and @b{Switches} attributes, respectively in the
697 @emph{Builder} package (for @command{gnatmake} and @command{gprbuild}),
698 the @emph{Binder} package (binding Ada executables) and the @emph{Linker}
699 package (for linking executables).
701 @c ---------------------------------------------
702 @node Compiling with Project Files
703 @subsection Compiling with Project Files
704 @c ---------------------------------------------
707 Now that our project files are written, let's build our executable.
708 Here is the command we would use from the command line:
715 This will automatically build the executables specified through the
716 @emph{Main} attribute: for each, it will compile or recompile the
717 sources for which the object file does not exist or is not up-to-date; it
718 will then run the binder; and finally run the linker to create the
721 @command{gnatmake} only knows how to handle Ada files. By using
722 @command{gprbuild} as a builder, you could automatically manage C files the
723 same way: create the file @file{utils.c} in the @file{common} directory,
724 set the attribute @emph{Languages} to @code{"(Ada, C)"}, and run
731 Gprbuild knows how to recompile the C files and will
732 recompile them only if one of their dependencies has changed. No direct
733 indication on how to build the various elements is given in the
734 project file, which describes the project properties rather than a
735 set of actions to be executed. Here is the invocation of
736 @command{gprbuild} when building a multi-language program:
749 Notice the three steps described earlier:
752 @item The first three gcc commands correspond to the compilation phase.
753 @item The gprbind command corresponds to the post-compilation phase.
754 @item The last gcc command corresponds to the final link.
759 @cindex @option{-v} option (for GPRbuild)
760 The default output of GPRbuild's execution is kept reasonably simple and easy
761 to understand. In particular, some of the less frequently used commands are not
762 shown, and some parameters are abbreviated. So it is not possible to rerun the
763 effect of the @command{gprbuild} command by cut-and-pasting its output.
764 GPRbuild's option @code{-v} provides a much more verbose output which includes,
765 among other information, more complete compilation, post-compilation and link
768 @c ---------------------------------------------
769 @node Executable File Names
770 @subsection Executable File Names
771 @c ---------------------------------------------
774 @cindex @code{Executable}
775 By default, the executable name corresponding to a main file is
776 computed from the main source file name. Through the attribute
777 @b{Builder.Executable}, it is possible to change this default.
779 For instance, instead of building @command{proc} (or @command{proc.exe}
780 on Windows), we could configure our project file to build "proc1"
781 (resp proc1.exe) with the following addition:
783 @smallexample @c projectfile
784 @b{project} Build @b{is}
785 ... --@i{ same as before}
786 @b{package} Builder @b{is}
787 @b{for} Executable ("proc.adb") @b{use} "proc1";
793 @cindex @code{Executable_Suffix}
794 Attribute @b{Executable_Suffix}, when specified, may change the suffix
795 of the executable files, when no attribute @code{Executable} applies:
796 its value replaces the platform-specific executable suffix.
797 The default executable suffix is empty on UNIX and ".exe" on Windows.
799 It is also possible to change the name of the produced executable by using the
800 command line switch @option{-o}. When several mains are defined in the project,
801 it is not possible to use the @option{-o} switch and the only way to change the
802 names of the executable is provided by Attributes @code{Executable} and
803 @code{Executable_Suffix}.
805 @c ---------------------------------------------
806 @node Avoid Duplication With Variables
807 @subsection Avoid Duplication With Variables
808 @c ---------------------------------------------
811 To illustrate some other project capabilities, here is a slightly more complex
812 project using similar sources and a main program in C:
814 @smallexample @c projectfile
815 @b{project} C_Main @b{is}
816 @b{for} Languages @b{use} ("Ada", "C");
817 @b{for} Source_Dirs @b{use} ("common");
818 @b{for} Object_Dir @b{use} "obj";
819 @b{for} Main @b{use} ("main.c");
820 @b{package} Compiler @b{is}
821 C_Switches := ("-pedantic");
822 @b{for} Default_Switches ("C") @b{use} C_Switches;
823 @b{for} Default_Switches ("Ada") @b{use} ("-gnaty");
824 @b{for} Switches ("main.c") @b{use} C_Switches & ("-g");
830 This project has many similarities with the previous one.
831 As expected, its @code{Main} attribute now refers to a C source.
832 The attribute @emph{Exec_Dir} is now omitted, thus the resulting
833 executable will be put in the directory @file{obj}.
835 The most noticeable difference is the use of a variable in the
836 @emph{Compiler} package to store settings used in several attributes.
837 This avoids text duplication, and eases maintenance (a single place to
838 modify if we want to add new switches for C files). We will revisit
839 the use of variables in the context of scenarios (@pxref{Scenarios in
842 In this example, we see how the file @file{main.c} can be compiled with
843 the switches used for all the other C files, plus @option{-g}.
844 In this specific situation the use of a variable could have been
845 replaced by a reference to the @code{Default_Switches} attribute:
847 @smallexample @c projectfile
848 @b{for} Switches ("c_main.c") @b{use} Compiler'Default_Switches ("C") & ("-g");
852 Note the tick (@emph{'}) used to refer to attributes defined in a package.
854 Here is the output of the GPRbuild command using this project:
858 gcc -c -pedantic -g main.c
859 gcc -c -gnaty proc.adb
860 gcc -c -gnaty pack.adb
861 gcc -c -pedantic utils.c
868 The default switches for Ada sources,
869 the default switches for C sources (in the compilation of @file{lib.c}),
870 and the specific switches for @file{main.c} have all been taken into
873 @c ---------------------------------------------
875 @subsection Naming Schemes
876 @c ---------------------------------------------
879 Sometimes an Ada software system is ported from one compilation environment to
880 another (say GNAT), and the file are not named using the default GNAT
881 conventions. Instead of changing all the file names, which for a variety of
882 reasons might not be possible, you can define the relevant file naming scheme
883 in the @b{Naming} package of your project file.
885 The naming scheme has two distinct goals for the project manager: it
886 allows finding of source files when searching in the source
887 directories, and given a source file name it makes it possible to guess
888 the associated language, and thus the compiler to use.
890 Note that the use by the Ada compiler of pragmas Source_File_Name is not
891 supported when using project files. You must use the features described in this
892 paragraph. You can however specify other configuration pragmas.
894 The following attributes can be defined in package @code{Naming}:
898 @cindex @code{Casing}
899 Its value must be one of @code{"lowercase"} (the default if
900 unspecified), @code{"uppercase"} or @code{"mixedcase"}. It describes the
901 casing of file names with regards to the Ada unit name. Given an Ada unit
902 My_Unit, the file name will respectively be @file{my_unit.adb} (lowercase),
903 @file{MY_UNIT.ADB} (uppercase) or @file{My_Unit.adb} (mixedcase).
904 On Windows, file names are case insensitive, so this attribute is
907 @item @b{Dot_Replacement}:
908 @cindex @code{Dot_Replacement}
909 This attribute specifies the string that should replace the "." in unit
910 names. Its default value is @code{"-"} so that a unit
911 @code{Parent.Child} is expected to be found in the file
912 @file{parent-child.adb}. The replacement string must satisfy the following
913 requirements to avoid ambiguities in the naming scheme:
916 @item It must not be empty
917 @item It cannot start or end with an alphanumeric character
918 @item It cannot be a single underscore
919 @item It cannot start with an underscore followed by an alphanumeric
920 @item It cannot contain a dot @code{'.'} except if the entire string
925 @item @b{Spec_Suffix} and @b{Specification_Suffix}:
926 @cindex @code{Spec_Suffix}
927 @cindex @code{Specification_Suffix}
928 For Ada, these attributes give the suffix used in file names that contain
929 specifications. For other languages, they give the extension for files
930 that contain declaration (header files in C for instance). The attribute
931 is indexed on the language.
932 The two attributes are equivalent, but the latter is obsolescent.
934 If the value of the attribute is the empty string, it indicates to the
935 Project Manager that the only specifications/header files for the language
936 are those specified with attributes @code{Spec} or
937 @code{Specification_Exceptions}.
939 If @code{Spec_Suffix ("Ada")} is not specified, then the default is
942 A non empty value must satisfy the following requirements:
945 @item It must include at least one dot
946 @item If @code{Dot_Replacement} is a single dot, then it cannot include
950 @item @b{Body_Suffix} and @b{Implementation_Suffix}:
951 @cindex @code{Body_Suffix}
952 @cindex @code{Implementation_Suffix}
953 These attributes give the extension used for file names that contain
954 code (bodies in Ada). They are indexed on the language. The second
955 version is obsolescent and fully replaced by the first attribute.
957 For each language of a project, one of these two attributes need to be
958 specified, either in the project itself or in the configuration project file.
960 If the value of the attribute is the empty string, it indicates to the
961 Project Manager that the only source files for the language
962 are those specified with attributes @code{Body} or
963 @code{Implementation_Exceptions}.
965 These attributes must satisfy the same requirements as @code{Spec_Suffix}.
966 In addition, they must be different from any of the values in
968 If @code{Body_Suffix ("Ada")} is not specified, then the default is
971 If @code{Body_Suffix ("Ada")} and @code{Spec_Suffix ("Ada")} end with the
972 same string, then a file name that ends with the longest of these two
973 suffixes will be a body if the longest suffix is @code{Body_Suffix ("Ada")}
974 or a spec if the longest suffix is @code{Spec_Suffix ("Ada")}.
976 If the suffix does not start with a '.', a file with a name exactly equal to
977 the suffix will also be part of the project (for instance if you define the
978 suffix as @code{Makefile.in}, a file called @file{Makefile.in} will be part
979 of the project. This capability is usually not interesting when building.
980 However, it might become useful when a project is also used to
981 find the list of source files in an editor, like the GNAT Programming System
984 @item @b{Separate_Suffix}:
985 @cindex @code{Separate_Suffix}
986 This attribute is specific to Ada. It denotes the suffix used in file names
987 that contain separate bodies. If it is not specified, then it defaults to
988 same value as @code{Body_Suffix ("Ada")}.
990 The value of this attribute cannot be the empty string.
992 Otherwise, the same rules apply as for the
993 @code{Body_Suffix} attribute. The only accepted index is "Ada".
995 @item @b{Spec} or @b{Specification}:
997 @cindex @code{Specification}
998 This attribute @code{Spec} can be used to define the source file name for a
999 given Ada compilation unit's spec. The index is the literal name of the Ada
1000 unit (case insensitive). The value is the literal base name of the file that
1001 contains this unit's spec (case sensitive or insensitive depending on the
1002 operating system). This attribute allows the definition of exceptions to the
1003 general naming scheme, in case some files do not follow the usual
1006 When a source file contains several units, the relative position of the unit
1007 can be indicated. The first unit in the file is at position 1
1009 @smallexample @c projectfile
1010 for Spec ("MyPack.MyChild") use "mypack.mychild.spec";
1011 for Spec ("top") use "foo.a" at 1;
1012 for Spec ("foo") use "foo.a" at 2;
1015 @item @b{Body} or @b{Implementation}:
1017 @cindex @code{Implementation}
1018 These attribute play the same role as @emph{Spec} for Ada bodies.
1020 @item @b{Specification_Exceptions} and @b{Implementation_Exceptions}:
1021 @cindex @code{Specification_Exceptions}
1022 @cindex @code{Implementation_Exceptions}
1023 These attributes define exceptions to the naming scheme for languages
1024 other than Ada. They are indexed on the language name, and contain
1025 a list of file names respectively for headers and source code.
1030 For example, the following package models the Apex file naming rules:
1032 @smallexample @c projectfile
1034 @b{package} Naming @b{is}
1035 @b{for} Casing @b{use} "lowercase";
1036 @b{for} Dot_Replacement @b{use} ".";
1037 @b{for} Spec_Suffix ("Ada") @b{use} ".1.ada";
1038 @b{for} Body_Suffix ("Ada") @b{use} ".2.ada";
1044 @c ---------------------------------------------
1046 @subsection Installation
1047 @c ---------------------------------------------
1050 After building an application or a library it is often required to
1051 install it into the development environment. For instance this step is
1052 required if the library is to be used by another application.
1053 The @command{gprinstall} tool provides an easy way to install
1054 libraries, executable or object code generated during the build. The
1055 @b{Install} package can be used to change the default locations.
1057 The following attributes can be defined in package @code{Install}:
1063 Whether the project is to be installed, values are @code{true}
1064 (default) or @code{false}.
1067 @cindex @code{Artifacts}
1069 An array attribute to declare a set of files not part of the sources
1070 to be installed. The array discriminant is the directory where the
1071 file is to be installed. If a relative directory then Prefix (see
1072 below) is prepended.
1075 @cindex @code{Prefix}
1077 Root directory for the installation.
1079 @item @b{Exec_Subdir}
1081 Subdirectory of @b{Prefix} where executables are to be
1082 installed. Default is @b{bin}.
1084 @item @b{Lib_Subdir}
1086 Subdirectory of @b{Prefix} where directory with the library or object
1087 files is to be installed. Default is @b{lib}.
1089 @item @b{Sources_Subdir}
1091 Subdirectory of @b{Prefix} where directory with sources is to be
1092 installed. Default is @b{include}.
1094 @item @b{Project_Subdir}
1096 Subdirectory of @b{Prefix} where the generated project file is to be
1097 installed. Default is @b{share/gpr}.
1100 @c ---------------------------------------------
1101 @node Distributed support
1102 @subsection Distributed support
1103 @c ---------------------------------------------
1106 For large projects the compilation time can become a limitation in
1107 the development cycle. To cope with that, GPRbuild supports
1108 distributed compilation.
1110 The following attributes can be defined in package @code{Remote}:
1115 @cindex @code{Root_Dir}
1117 Root directory of the project's sources. The default value is the
1118 project's directory.
1122 @c ---------------------------------------------
1123 @node Organizing Projects into Subsystems
1124 @section Organizing Projects into Subsystems
1125 @c ---------------------------------------------
1128 A @b{subsystem} is a coherent part of the complete system to be built. It is
1129 represented by a set of sources and one single object directory. A system can
1130 be composed of a single subsystem when it is simple as we have seen in the
1131 first section. Complex systems are usually composed of several interdependent
1132 subsystems. A subsystem is dependent on another subsystem if knowledge of the
1133 other one is required to build it, and in particular if visibility on some of
1134 the sources of this other subsystem is required. Each subsystem is usually
1135 represented by its own project file.
1137 In this section, the previous example is being extended. Let's assume some
1138 sources of our @code{Build} project depend on other sources.
1139 For instance, when building a graphical interface, it is usual to depend upon
1140 a graphical library toolkit such as GtkAda. Furthermore, we also need
1141 sources from a logging module we had previously written.
1144 * Project Dependencies::
1145 * Cyclic Project Dependencies::
1146 * Sharing Between Projects::
1147 * Global Attributes::
1150 @c ---------------------------------------------
1151 @node Project Dependencies
1152 @subsection Project Dependencies
1153 @c ---------------------------------------------
1156 GtkAda comes with its own project file (appropriately called
1157 @file{gtkada.gpr}), and we will assume we have already built a project
1158 called @file{logging.gpr} for the logging module. With the information provided
1159 so far in @file{build.gpr}, building the application would fail with an error
1160 indicating that the gtkada and logging units that are relied upon by the sources
1161 of this project cannot be found.
1163 This is solved by adding the following @b{with} clauses at the beginning of our
1166 @smallexample @c projectfile
1167 @b{with} "gtkada.gpr";
1168 @b{with} "a/b/logging.gpr";
1169 @b{project} Build @b{is}
1170 ... --@i{ as before}
1175 @cindex @code{Externally_Built}
1176 When such a project is compiled, @command{gprbuild} will automatically check
1177 the other projects and recompile their sources when needed. It will also
1178 recompile the sources from @code{Build} when needed, and finally create the
1179 executable. In some cases, the implementation units needed to recompile a
1180 project are not available, or come from some third party and you do not want to
1181 recompile it yourself. In this case, set the attribute @b{Externally_Built} to
1182 "true", indicating to the builder that this project can be assumed to be
1183 up-to-date, and should not be considered for recompilation. In Ada, if the
1184 sources of this externally built project were compiled with another version of
1185 the compiler or with incompatible options, the binder will issue an error.
1187 The project's @code{with} clause has several effects. It provides source
1188 visibility between projects during the compilation process. It also guarantees
1189 that the necessary object files from @code{Logging} and @code{GtkAda} are
1190 available when linking @code{Build}.
1192 As can be seen in this example, the syntax for importing projects is similar
1193 to the syntax for importing compilation units in Ada. However, project files
1194 use literal strings instead of names, and the @code{with} clause identifies
1195 project files rather than packages.
1197 Each literal string after @code{with} is the path
1198 (absolute or relative) to a project file. The @code{.gpr} extension is
1199 optional, although we recommend adding it. If no extension is specified,
1200 and no project file with the @file{.gpr} extension is found, then
1201 the file is searched for exactly as written in the @code{with} clause,
1202 that is with no extension.
1204 As mentioned above, the path after a @code{with} has to be a literal
1205 string, and you cannot use concatenation, or lookup the value of external
1206 variables to change the directories from which a project is loaded.
1207 A solution if you need something like this is to use aggregate projects
1208 (@pxref{Aggregate Projects}).
1210 @cindex project path
1211 When a relative path or a base name is used, the
1212 project files are searched relative to each of the directories in the
1213 @b{project path}. This path includes all the directories found with the
1214 following algorithm, in this order; the first matching file is used:
1217 @item First, the file is searched relative to the directory that contains the
1218 current project file.
1221 @cindex @code{GPR_PROJECT_PATH_FILE}
1222 @cindex @code{GPR_PROJECT_PATH}
1223 @cindex @code{ADA_PROJECT_PATH}
1224 Then it is searched relative to all the directories specified in the
1225 environment variables @b{GPR_PROJECT_PATH_FILE},
1226 @b{GPR_PROJECT_PATH} and @b{ADA_PROJECT_PATH} (in that order) if they exist.
1227 The value of @b{GPR_PROJECT_PATH_FILE}, when defined, is the path name of
1228 a text file that contains project directory path names, one per line.
1229 @b{GPR_PROJECT_PATH} and @b{ADA_PROJECT_PATH}, when defined, contain
1230 project directory path names separated by directory separators.
1231 @b{ADA_PROJECT_PATH} is used for compatibility, it is recommended to
1232 use @b{GPR_PROJECT_PATH_FILE} or @b{GPR_PROJECT_PATH}.
1234 @item Finally, it is searched relative to the default project directories.
1235 Such directories depend on the tool used. The locations searched in the
1236 specified order are:
1239 @item @file{<prefix>/<target>/lib/gnat}
1240 (for @command{gnatmake} in all cases, and for @command{gprbuild} if option
1241 @option{--target} is specified)
1242 @item @file{<prefix>/<target>/share/gpr}
1243 (for @command{gnatmake} in all cases, and for @command{gprbuild} if option
1244 @option{--target} is specified)
1245 @item @file{<prefix>/share/gpr/}
1246 (for @command{gnatmake} and @command{gprbuild})
1247 @item @file{<prefix>/lib/gnat/}
1248 (for @command{gnatmake} and @command{gprbuild})
1251 In our example, @file{gtkada.gpr} is found in the predefined directory if
1252 it was installed at the same root as GNAT.
1256 Some tools also support extending the project path from the command line,
1257 generally through the @option{-aP}. You can see the value of the project
1258 path by using the @command{gnatls -v} command.
1260 Any symbolic link will be fully resolved in the directory of the
1261 importing project file before the imported project file is examined.
1263 Any source file in the imported project can be used by the sources of the
1264 importing project, transitively.
1265 Thus if @code{A} imports @code{B}, which imports @code{C}, the sources of
1266 @code{A} may depend on the sources of @code{C}, even if @code{A} does not
1267 import @code{C} explicitly. However, this is not recommended, because if
1268 and when @code{B} ceases to import @code{C}, some sources in @code{A} will
1269 no longer compile. @command{gprbuild} has a switch @option{--no-indirect-imports}
1270 that will report such indirect dependencies.
1272 One very important aspect of a project hierarchy is that
1273 @b{a given source can only belong to one project} (otherwise the project manager
1274 would not know which settings apply to it and when to recompile it). It means
1275 that different project files do not usually share source directories or
1276 when they do, they need to specify precisely which project owns which sources
1277 using attribute @code{Source_Files} or equivalent. By contrast, 2 projects
1278 can each own a source with the same base file name as long as they live in
1279 different directories. The latter is not true for Ada Sources because of the
1280 correlation between source files and Ada units.
1282 @c ---------------------------------------------
1283 @node Cyclic Project Dependencies
1284 @subsection Cyclic Project Dependencies
1285 @c ---------------------------------------------
1288 Cyclic dependencies are mostly forbidden:
1289 if @code{A} imports @code{B} (directly or indirectly) then @code{B}
1290 is not allowed to import @code{A}. However, there are cases when cyclic
1291 dependencies would be beneficial. For these cases, another form of import
1292 between projects exists: the @b{limited with}. A project @code{A} that
1293 imports a project @code{B} with a straight @code{with} may also be imported,
1294 directly or indirectly, by @code{B} through a @code{limited with}.
1296 The difference between straight @code{with} and @code{limited with} is that
1297 the name of a project imported with a @code{limited with} cannot be used in the
1298 project importing it. In particular, its packages cannot be renamed and
1299 its variables cannot be referred to.
1301 @smallexample @c 0projectfile
1305 For Exec_Dir use B'Exec_Dir; -- ok
1308 limited with "a.gpr"; -- Cyclic dependency: A -> B -> A
1310 For Exec_Dir use A'Exec_Dir; -- not ok
1317 limited with "a.gpr"; -- Cyclic dependency: A -> C -> D -> A
1319 For Exec_Dir use A'Exec_Dir; -- not ok
1323 @c ---------------------------------------------
1324 @node Sharing Between Projects
1325 @subsection Sharing Between Projects
1326 @c ---------------------------------------------
1329 When building an application, it is common to have similar needs in several of
1330 the projects corresponding to the subsystems under construction. For instance,
1331 they will all have the same compilation switches.
1333 As seen before (@pxref{Tools Options in Project Files}), setting compilation
1334 switches for all sources of a subsystem is simple: it is just a matter of
1335 adding a @code{Compiler.Default_Switches} attribute to each project files with
1336 the same value. Of course, that means duplication of data, and both places need
1337 to be changed in order to recompile the whole application with different
1338 switches. It can become a real problem if there are many subsystems and thus
1339 many project files to edit.
1341 There are two main approaches to avoiding this duplication:
1344 @item Since @file{build.gpr} imports @file{logging.gpr}, we could change it
1345 to reference the attribute in Logging, either through a package renaming,
1346 or by referencing the attribute. The following example shows both cases:
1348 @smallexample @c projectfile
1351 for Switches ("Ada")
1355 for Switches ("Ada")
1362 package Compiler renames Logging.Compiler;
1364 for Switches ("Ada") use Logging.Binder'Switches ("Ada");
1370 The solution used for @code{Compiler} gets the same value for all
1371 attributes of the package, but you cannot modify anything from the
1372 package (adding extra switches or some exceptions). The second
1373 version is more flexible, but more verbose.
1375 If you need to refer to the value of a variable in an imported
1376 project, rather than an attribute, the syntax is similar but uses
1377 a "." rather than an apostrophe. For instance:
1379 @smallexample @c projectfile
1382 Var1 := Imported.Var;
1386 @item The second approach is to define the switches in a third project.
1387 That project is set up without any sources (so that, as opposed to
1388 the first example, none of the project plays a special role), and
1389 will only be used to define the attributes. Such a project is
1390 typically called @file{shared.gpr}.
1392 @smallexample @c projectfile
1393 abstract project Shared is
1394 for Source_Files use (); -- no sources
1396 for Switches ("Ada")
1403 package Compiler renames Shared.Compiler;
1408 package Compiler renames Shared.Compiler;
1413 As for the first example, we could have chosen to set the attributes
1414 one by one rather than to rename a package. The reason we explicitly
1415 indicate that @code{Shared} has no sources is so that it can be created
1416 in any directory and we are sure it shares no sources with @code{Build}
1417 or @code{Logging}, which of course would be invalid.
1419 @cindex project qualifier
1420 Note the additional use of the @b{abstract} qualifier in @file{shared.gpr}.
1421 This qualifier is optional, but helps convey the message that we do not
1422 intend this project to have sources (@pxref{Qualified Projects} for
1426 @c ---------------------------------------------
1427 @node Global Attributes
1428 @subsection Global Attributes
1429 @c ---------------------------------------------
1432 We have already seen many examples of attributes used to specify a special
1433 option of one of the tools involved in the build process. Most of those
1434 attributes are project specific. That it to say, they only affect the invocation
1435 of tools on the sources of the project where they are defined.
1437 There are a few additional attributes that apply to all projects in a
1438 hierarchy as long as they are defined on the "main" project.
1439 The main project is the project explicitly mentioned on the command-line.
1440 The project hierarchy is the "with"-closure of the main project.
1442 Here is a list of commonly used global attributes:
1445 @item @b{Builder.Global_Configuration_Pragmas}:
1446 @cindex @code{Global_Configuration_Pragmas}
1447 This attribute points to a file that contains configuration pragmas
1448 to use when building executables. These pragmas apply for all
1449 executables built from this project hierarchy. As we have seen before,
1450 additional pragmas can be specified on a per-project basis by setting the
1451 @code{Compiler.Local_Configuration_Pragmas} attribute.
1453 @item @b{Builder.Global_Compilation_Switches}:
1454 @cindex @code{Global_Compilation_Switches}
1455 This attribute is a list of compiler switches to use when compiling any
1456 source file in the project hierarchy. These switches are used in addition
1457 to the ones defined in the @code{Compiler} package, which only apply to
1458 the sources of the corresponding project. This attribute is indexed on
1459 the name of the language.
1463 Using such global capabilities is convenient. It can also lead to unexpected
1464 behavior. Especially when several subsystems are shared among different main
1465 projects and the different global attributes are not
1466 compatible. Note that using aggregate projects can be a safer and more powerful
1467 replacement to global attributes.
1469 @c ---------------------------------------------
1470 @node Scenarios in Projects
1471 @section Scenarios in Projects
1472 @c ---------------------------------------------
1475 Various aspects of the projects can be modified based on @b{scenarios}. These
1476 are user-defined modes that change the behavior of a project. Typical
1477 examples are the setup of platform-specific compiler options, or the use of
1478 a debug and a release mode (the former would activate the generation of debug
1479 information, while the second will focus on improving code optimization).
1481 Let's enhance our example to support debug and release modes. The issue is to
1482 let the user choose what kind of system he is building: use @option{-g} as
1483 compiler switches in debug mode and @option{-O2} in release mode. We will also
1484 set up the projects so that we do not share the same object directory in both
1485 modes; otherwise switching from one to the other might trigger more
1486 recompilations than needed or mix objects from the two modes.
1488 One naive approach is to create two different project files, say
1489 @file{build_debug.gpr} and @file{build_release.gpr}, that set the appropriate
1490 attributes as explained in previous sections. This solution does not scale
1491 well, because in the presence of multiple projects depending on each other, you
1492 will also have to duplicate the complete hierarchy and adapt the project files
1493 to point to the right copies.
1496 Instead, project files support the notion of scenarios controlled
1497 by external values. Such values can come from several sources (in decreasing
1501 @item @b{Command line}:
1503 When launching @command{gnatmake} or @command{gprbuild}, the user can pass
1504 extra @option{-X} switches to define the external value. In
1505 our case, the command line might look like
1508 gnatmake -Pbuild.gpr -Xmode=debug
1509 or gnatmake -Pbuild.gpr -Xmode=release
1512 @item @b{Environment variables}:
1513 When the external value does not come from the command line, it can come from
1514 the value of environment variables of the appropriate name.
1515 In our case, if an environment variable called "mode"
1516 exists, its value will be taken into account.
1518 @item @b{External function second parameter}.
1522 @cindex @code{external}
1523 We now need to get that value in the project. The general form is to use
1524 the predefined function @b{external} which returns the current value of
1525 the external. For instance, we could set up the object directory to point to
1526 either @file{obj/debug} or @file{obj/release} by changing our project to
1528 @smallexample @c projectfile
1529 @b{project} Build @b{is}
1530 @b{for} Object_Dir @b{use} "obj/" & @b{external} ("mode", "debug");
1531 ... --@i{ as before}
1536 The second parameter to @code{external} is optional, and is the default
1537 value to use if "mode" is not set from the command line or the environment.
1539 In order to set the switches according to the different scenarios, other
1540 constructs have to be introduced such as typed variables and case constructions.
1542 @cindex typed variable
1543 @cindex case construction
1544 A @b{typed variable} is a variable that
1545 can take only a limited number of values, similar to an enumeration in Ada.
1546 Such a variable can then be used in a @b{case construction} and create conditional
1547 sections in the project. The following example shows how this can be done:
1549 @smallexample @c projectfile
1550 @b{project} Build @b{is}
1551 @b{type} Mode_Type @b{is} ("debug", "release"); --@i{ all possible values}
1552 Mode : Mode_Type := @b{external} ("mode", "debug"); --@i{ a typed variable}
1554 @b{package} Compiler @b{is}
1555 @b{case} Mode @b{is}
1557 @b{for} Switches ("Ada")
1559 @b{when} "release" =>
1560 @b{for} Switches ("Ada")
1568 The project has suddenly grown in size, but has become much more flexible.
1569 @code{Mode_Type} defines the only valid values for the @code{mode} variable. If
1570 any other value is read from the environment, an error is reported and the
1571 project is considered as invalid.
1573 The @code{Mode} variable is initialized with an external value
1574 defaulting to @code{"debug"}. This default could be omitted and that would
1575 force the user to define the value. Finally, we can use a case construction to set the
1576 switches depending on the scenario the user has chosen.
1578 Most aspects of the projects can depend on scenarios. The notable exception
1579 are project dependencies (@code{with} clauses), which cannot depend on a scenario.
1581 Scenarios work the same way with @b{project hierarchies}: you can either
1582 duplicate a variable similar to @code{Mode} in each of the project (as long
1583 as the first argument to @code{external} is always the same and the type is
1584 the same), or simply set the variable in the @file{shared.gpr} project
1585 (@pxref{Sharing Between Projects}).
1587 @c ---------------------------------------------
1588 @node Library Projects
1589 @section Library Projects
1590 @c ---------------------------------------------
1593 So far, we have seen examples of projects that create executables. However,
1594 it is also possible to create libraries instead. A @b{library} is a specific
1595 type of subsystem where, for convenience, objects are grouped together
1596 using system-specific means such as archives or windows DLLs.
1598 Library projects provide a system- and language-independent way of building both @b{static}
1599 and @b{dynamic} libraries. They also support the concept of @b{standalone
1600 libraries} (SAL) which offer two significant properties: the elaboration
1601 (e.g. initialization) of the library is either automatic or very simple;
1603 implementation part of the library implies minimal post-compilation actions on
1604 the complete system and potentially no action at all for the rest of the
1605 system in the case of dynamic SALs.
1607 There is a restriction on shared library projects: by default, they are only
1608 allowed to import other shared library projects. They are not allowed to
1609 import non library projects or static library projects.
1611 The GNAT Project Manager takes complete care of the library build, rebuild and
1612 installation tasks, including recompilation of the source files for which
1613 objects do not exist or are not up to date, assembly of the library archive, and
1614 installation of the library (i.e., copying associated source, object and
1615 @file{ALI} files to the specified location).
1618 * Building Libraries::
1619 * Using Library Projects::
1620 * Stand-alone Library Projects::
1621 * Installing a library with project files::
1624 @c ---------------------------------------------
1625 @node Building Libraries
1626 @subsection Building Libraries
1627 @c ---------------------------------------------
1630 Let's enhance our example and transform the @code{logging} subsystem into a
1631 library. In order to do so, a few changes need to be made to
1632 @file{logging.gpr}. Some attributes need to be defined: at least
1633 @code{Library_Name} and @code{Library_Dir}; in addition, some other attributes
1634 can be used to specify specific aspects of the library. For readability, it is
1635 also recommended (although not mandatory), to use the qualifier @code{library}
1636 in front of the @code{project} keyword.
1639 @item @b{Library_Name}:
1640 @cindex @code{Library_Name}
1641 This attribute is the name of the library to be built. There is no
1642 restriction on the name of a library imposed by the project manager, except
1643 for stand-alone libraries whose names must follow the syntax of Ada
1644 identifiers; however, there may be system-specific restrictions on the name.
1645 In general, it is recommended to stick to alphanumeric characters (and
1646 possibly single underscores) to help portability.
1648 @item @b{Library_Dir}:
1649 @cindex @code{Library_Dir}
1650 This attribute is the path (absolute or relative) of the directory where
1651 the library is to be installed. In the process of building a library,
1652 the sources are compiled, the object files end up in the explicit or
1653 implicit @code{Object_Dir} directory. When all sources of a library
1654 are compiled, some of the compilation artifacts, including the library itself,
1655 are copied to the library_dir directory. This directory must exist and be
1656 writable. It must also be different from the object directory so that cleanup
1657 activities in the Library_Dir do not affect recompilation needs.
1661 Here is the new version of @file{logging.gpr} that makes it a library:
1663 @smallexample @c projectfile
1664 library @b{project} Logging @b{is} --@i{ "library" is optional}
1665 @b{for} Library_Name @b{use} "logging"; --@i{ will create "liblogging.a" on Unix}
1666 @b{for} Object_Dir @b{use} "obj";
1667 @b{for} Library_Dir @b{use} "lib"; --@i{ different from object_dir}
1672 Once the above two attributes are defined, the library project is valid and
1673 is enough for building a library with default characteristics.
1674 Other library-related attributes can be used to change the defaults:
1677 @item @b{Library_Kind}:
1678 @cindex @code{Library_Kind}
1679 The value of this attribute must be either @code{"static"}, @code{"dynamic"} or
1680 @code{"relocatable"} (the latter is a synonym for dynamic). It indicates
1681 which kind of library should be built (the default is to build a
1682 static library, that is an archive of object files that can potentially
1683 be linked into a static executable). When the library is set to be dynamic,
1684 a separate image is created that will be loaded independently, usually
1685 at the start of the main program execution. Support for dynamic libraries is
1686 very platform specific, for instance on Windows it takes the form of a DLL
1687 while on GNU/Linux, it is a dynamic elf image whose suffix is usually
1688 @file{.so}. Library project files, on the other hand, can be written in
1689 a platform independent way so that the same project file can be used to build
1690 a library on different operating systems.
1692 If you need to build both a static and a dynamic library, it is recommended
1693 to use two different object directories, since in some cases some extra code
1694 needs to be generated for the latter. For such cases, one can either define
1695 two different project files, or a single one that uses scenarios to indicate
1696 the various kinds of library to be built and their corresponding object_dir.
1698 @cindex @code{Library_ALI_Dir}
1699 @item @b{Library_ALI_Dir}:
1700 This attribute may be specified to indicate the directory where the ALI
1701 files of the library are installed. By default, they are copied into the
1702 @code{Library_Dir} directory, but as for the executables where we have a
1703 separate @code{Exec_Dir} attribute, you might want to put them in a separate
1704 directory since there can be hundreds of them. The same restrictions as for
1705 the @code{Library_Dir} attribute apply.
1707 @cindex @code{Library_Version}
1708 @item @b{Library_Version}:
1709 This attribute is platform dependent, and has no effect on Windows.
1710 On Unix, it is used only for dynamic libraries as the internal
1711 name of the library (the @code{"soname"}). If the library file name (built
1712 from the @code{Library_Name}) is different from the @code{Library_Version},
1713 then the library file will be a symbolic link to the actual file whose name
1714 will be @code{Library_Version}. This follows the usual installation schemes
1715 for dynamic libraries on many Unix systems.
1717 @smallexample @c projectfile
1719 @b{project} Logging @b{is}
1721 @b{for} Library_Dir @b{use} "lib";
1722 @b{for} Library_Name @b{use} "logging";
1723 @b{for} Library_Kind @b{use} "dynamic";
1724 @b{for} Library_Version @b{use} "liblogging.so." & Version;
1730 After the compilation, the directory @file{lib} will contain both a
1731 @file{libdummy.so.1} library and a symbolic link to it called
1734 @cindex @code{Library_GCC}
1735 @item @b{Library_GCC}:
1736 This attribute is the name of the tool to use instead of "gcc" to link shared
1737 libraries. A common use of this attribute is to define a wrapper script that
1738 accomplishes specific actions before calling gcc (which itself calls the
1739 linker to build the library image).
1741 @item @b{Library_Options}:
1742 @cindex @code{Library_Options}
1743 This attribute may be used to specify additional switches (last switches)
1744 when linking a shared library.
1746 It may also be used to add foreign object files to a static library.
1747 Each string in Library_Options is an absolute or relative path of an object
1748 file. When a relative path, it is relative to the object directory.
1750 @item @b{Leading_Library_Options}:
1751 @cindex @code{Leading_Library_Options}
1752 This attribute, that is taken into account only by @command{gprbuild}, may be
1753 used to specified leading options (first switches) when linking a shared
1756 @cindex @code{Linker_Options}
1757 @item @b{Linker.Linker_Options}:
1758 This attribute specifies additional switches to be given to the linker when
1759 linking an executable. It is ignored when defined in the main project and
1760 taken into account in all other projects that are imported directly or
1761 indirectly. These switches complement the @code{Linker.Switches}
1762 defined in the main project. This is useful when a particular subsystem
1763 depends on an external library: adding this dependency as a
1764 @code{Linker_Options} in the project of the subsystem is more convenient than
1765 adding it to all the @code{Linker.Switches} of the main projects that depend
1766 upon this subsystem.
1769 @c ---------------------------------------------
1770 @node Using Library Projects
1771 @subsection Using Library Projects
1772 @c ---------------------------------------------
1775 When the builder detects that a project file is a library project file, it
1776 recompiles all sources of the project that need recompilation and rebuild the
1777 library if any of the sources have been recompiled. It then groups all object
1778 files into a single file, which is a shared or a static library. This library
1779 can later on be linked with multiple executables. Note that the use
1780 of shard libraries reduces the size of the final executable and can also reduce
1781 the memory footprint at execution time when the library is shared among several
1784 It is also possible to build @b{multi-language libraries}. When using
1785 @command{gprbuild} as a builder, multi-language library projects allow naturally
1786 the creation of multi-language libraries . @command{gnatmake}, does not try to
1787 compile non Ada sources. However, when the project is multi-language, it will
1788 automatically link all object files found in the object directory, whether or
1789 not they were compiled from an Ada source file. This specific behavior does not
1790 apply to Ada-only projects which only take into account the objects
1791 corresponding to the sources of the project.
1793 A non-library project can import a library project. When the builder is invoked
1794 on the former, the library of the latter is only rebuilt when absolutely
1795 necessary. For instance, if a unit of the library is not up-to-date but none of
1796 the executables need this unit, then the unit is not recompiled and the library
1797 is not reassembled. For instance, let's assume in our example that logging has
1798 the following sources: @file{log1.ads}, @file{log1.adb}, @file{log2.ads} and
1799 @file{log2.adb}. If @file{log1.adb} has been modified, then the library
1800 @file{liblogging} will be rebuilt when compiling all the sources of
1801 @code{Build} only if @file{proc.ads}, @file{pack.ads} or @file{pack.adb}
1802 include a @code{"with Log1"}.
1804 To ensure that all the sources in the @code{Logging} library are
1805 up to date, and that all the sources of @code{Build} are also up to date,
1806 the following two commands need to be used:
1809 gnatmake -Plogging.gpr
1810 gnatmake -Pbuild.gpr
1814 All @file{ALI} files will also be copied from the object directory to the
1815 library directory. To build executables, @command{gnatmake} will use the
1816 library rather than the individual object files.
1818 Library projects can also be useful to describe a library that needs to be used
1819 but, for some reason, cannot be rebuilt. For instance, it is the case when some
1820 of the library sources are not available. Such library projects need to use the
1821 @code{Externally_Built} attribute as in the example below:
1823 @smallexample @c projectfile
1824 library @b{project} Extern_Lib @b{is}
1825 @b{for} Languages @b{use} ("Ada", "C");
1826 @b{for} Source_Dirs @b{use} ("lib_src");
1827 @b{for} Library_Dir @b{use} "lib2";
1828 @b{for} Library_Kind @b{use} "dynamic";
1829 @b{for} Library_Name @b{use} "l2";
1830 @b{for} Externally_Built @b{use} "true"; --@i{ <<<<}
1835 In the case of externally built libraries, the @code{Object_Dir}
1836 attribute does not need to be specified because it will never be
1839 The main effect of using such an externally built library project is mostly to
1840 affect the linker command in order to reference the desired library. It can
1841 also be achieved by using @code{Linker.Linker_Options} or @code{Linker.Switches}
1842 in the project corresponding to the subsystem needing this external library.
1843 This latter method is more straightforward in simple cases but when several
1844 subsystems depend upon the same external library, finding the proper place
1845 for the @code{Linker.Linker_Options} might not be easy and if it is
1846 not placed properly, the final link command is likely to present ordering issues.
1847 In such a situation, it is better to use the externally built library project
1848 so that all other subsystems depending on it can declare this dependency thanks
1849 to a project @code{with} clause, which in turn will trigger the builder to find
1850 the proper order of libraries in the final link command.
1852 @c ---------------------------------------------
1853 @node Stand-alone Library Projects
1854 @subsection Stand-alone Library Projects
1855 @c ---------------------------------------------
1858 @cindex standalone libraries
1859 A @b{stand-alone library} is a library that contains the necessary code to
1860 elaborate the Ada units that are included in the library. A stand-alone
1861 library is a convenient way to add an Ada subsystem to a more global system
1862 whose main is not in Ada since it makes the elaboration of the Ada part mostly
1863 transparent. However, stand-alone libraries are also useful when the main is in
1864 Ada: they provide a means for minimizing relinking & redeployment of complex
1865 systems when localized changes are made.
1867 The name of a stand-alone library, specified with attribute
1868 @code{Library_Name}, must have the syntax of an Ada identifier.
1870 The most prominent characteristic of a stand-alone library is that it offers a
1871 distinction between interface units and implementation units. Only the former
1872 are visible to units outside the library. A stand-alone library project is thus
1873 characterised by a third attribute, usually @b{Library_Interface}, in addition
1874 to the two attributes that make a project a Library Project
1875 (@code{Library_Name} and @code{Library_Dir}). This third attribute may also be
1876 @b{Interfaces}. @b{Library_Interface} only works when the interface is in Ada
1877 and takes a list of units as parameter. @b{Interfaces} works for any supported
1878 language and takes a list of sources as parameter.
1881 @item @b{Library_Interface}:
1882 @cindex @code{Library_Interface}
1883 This attribute defines an explicit subset of the units of the project. Units
1884 from projects importing this library project may only "with" units whose
1885 sources are listed in the @code{Library_Interface}. Other sources are
1886 considered implementation units.
1888 @smallexample @c projectfile
1890 @b{for} Library_Dir @b{use} "lib";
1891 @b{for} Library_Name @b{use} "logging";
1892 @b{for} Library_Interface @b{use} ("lib1", "lib2"); --@i{ unit names}
1896 @item @b{Interfaces}
1897 This attribute defines an explicit subset of the source files of a project.
1898 Sources from projects importing this project, can only depend on sources from
1899 this subset. This attribute can be used on non library projects. It can also
1900 be used as a replacement for attribute @code{Library_Interface}, in which
1901 case, units have to be replaced by source files. For multi-language library
1902 projects, it is the only way to make the project a Stand-Alone Library project
1903 whose interface is not purely Ada.
1905 @item @b{Library_Standalone}:
1906 @cindex @code{Library_Standalone}
1907 This attribute defines the kind of standalone library to
1908 build. Values are either @code{standard} (the default), @code{no} or
1909 @code{encapsulated}. When @code{standard} is used the code to elaborate and
1910 finalize the library is embedded, when @code{encapsulated} is used the
1911 library can furthermore depend only on static libraries (including
1912 the GNAT runtime). This attribute can be set to @code{no} to make it clear
1913 that the library should not be standalone in which case the
1914 @code{Library_Interface} should not defined. Note that this attribute
1915 only applies to shared libraries, so @code{Library_Kind} must be set
1918 @smallexample @c projectfile
1920 @b{for} Library_Dir @b{use} "lib";
1921 @b{for} Library_Name @b{use} "logging";
1922 @b{for} Library_Kind @b{use} "dynamic";
1923 @b{for} Library_Interface @b{use} ("lib1", "lib2"); --@i{ unit names}
1924 @b{for} Library_Standalone @b{use} "encapsulated";
1930 In order to include the elaboration code in the stand-alone library, the binder
1931 is invoked on the closure of the library units creating a package whose name
1932 depends on the library name (b~logging.ads/b in the example).
1933 This binder-generated package includes @b{initialization} and @b{finalization}
1934 procedures whose names depend on the library name (@code{logginginit} and
1935 @code{loggingfinal} in the example). The object corresponding to this package is
1936 included in the library.
1939 @item @b{Library_Auto_Init}:
1940 @cindex @code{Library_Auto_Init}
1941 A dynamic stand-alone Library is automatically initialized
1942 if automatic initialization of Stand-alone Libraries is supported on the
1943 platform and if attribute @b{Library_Auto_Init} is not specified or
1944 is specified with the value "true". A static Stand-alone Library is never
1945 automatically initialized. Specifying "false" for this attribute
1946 prevents automatic initialization.
1948 When a non-automatically initialized stand-alone library is used in an
1949 executable, its initialization procedure must be called before any service of
1950 the library is used. When the main subprogram is in Ada, it may mean that the
1951 initialization procedure has to be called during elaboration of another
1954 @item @b{Library_Dir}:
1955 @cindex @code{Library_Dir}
1956 For a stand-alone library, only the @file{ALI} files of the interface units
1957 (those that are listed in attribute @code{Library_Interface}) are copied to
1958 the library directory. As a consequence, only the interface units may be
1959 imported from Ada units outside of the library. If other units are imported,
1960 the binding phase will fail.
1962 @item @b{Binder.Default_Switches}:
1963 When a stand-alone library is bound, the switches that are specified in
1964 the attribute @b{Binder.Default_Switches ("Ada")} are
1965 used in the call to @command{gnatbind}.
1967 @item @b{Library_Src_Dir}:
1968 @cindex @code{Library_Src_Dir}
1969 This attribute defines the location (absolute or relative to the project
1970 directory) where the sources of the interface units are copied at
1972 These sources includes the specs of the interface units along with the
1973 closure of sources necessary to compile them successfully. That may include
1974 bodies and subunits, when pragmas @code{Inline} are used, or when there are
1975 generic units in specs. This directory cannot point to the object directory
1976 or one of the source directories, but it can point to the library directory,
1977 which is the default value for this attribute.
1979 @item @b{Library_Symbol_Policy}:
1980 @cindex @code{Library_Symbol_Policy}
1981 This attribute controls the export of symbols and, on some platforms (like
1982 VMS) that have the notions of major and minor IDs built in the library
1983 files, it controls the setting of these IDs. It is not supported on all
1984 platforms (where it will just have no effect). It may have one of the
1988 @item @code{"autonomous"} or @code{"default"}: exported symbols are not controlled
1989 @item @code{"compliant"}: if attribute @b{Library_Reference_Symbol_File}
1990 is not defined, then it is equivalent to policy "autonomous". If there
1991 are exported symbols in the reference symbol file that are not in the
1992 object files of the interfaces, the major ID of the library is increased.
1993 If there are symbols in the object files of the interfaces that are not
1994 in the reference symbol file, these symbols are put at the end of the list
1995 in the newly created symbol file and the minor ID is increased.
1996 @item @code{"controlled"}: the attribute @b{Library_Reference_Symbol_File} must be
1997 defined. The library will fail to build if the exported symbols in the
1998 object files of the interfaces do not match exactly the symbol in the
2000 @item @code{"restricted"}: The attribute @b{Library_Symbol_File} must be defined.
2001 The library will fail to build if there are symbols in the symbol file that
2002 are not in the exported symbols of the object files of the interfaces.
2003 Additional symbols in the object files are not added to the symbol file.
2004 @item @code{"direct"}: The attribute @b{Library_Symbol_File} must be defined and
2005 must designate an existing file in the object directory. This symbol file
2006 is passed directly to the underlying linker without any symbol processing.
2010 @item @b{Library_Reference_Symbol_File}
2011 @cindex @code{Library_Reference_Symbol_File}
2012 This attribute may define the path name of a reference symbol file that is
2013 read when the symbol policy is either "compliant" or "controlled", on
2014 platforms that support symbol control, such as VMS, when building a
2015 stand-alone library. The path may be an absolute path or a path relative
2016 to the project directory.
2018 @item @b{Library_Symbol_File}
2019 @cindex @code{Library_Symbol_File}
2020 This attribute may define the name of the symbol file to be created when
2021 building a stand-alone library when the symbol policy is either "compliant",
2022 "controlled" or "restricted", on platforms that support symbol control,
2023 such as VMS. When symbol policy is "direct", then a file with this name
2024 must exist in the object directory.
2027 @c ---------------------------------------------
2028 @node Installing a library with project files
2029 @subsection Installing a library with project files
2030 @c ---------------------------------------------
2033 When using project files, a usable version of the library is created in the
2034 directory specified by the @code{Library_Dir} attribute of the library
2035 project file. Thus no further action is needed in order to make use of
2036 the libraries that are built as part of the general application build.
2038 You may want to install a library in a context different from where the library
2039 is built. This situation arises with third party suppliers, who may want
2040 to distribute a library in binary form where the user is not expected to be
2041 able to recompile the library. The simplest option in this case is to provide
2042 a project file slightly different from the one used to build the library, by
2043 using the @code{externally_built} attribute. @ref{Using Library Projects}
2045 Another option is to use @command{gprinstall} to install the library in a
2046 different context than the build location. @command{gprinstall} automatically
2047 generates a project to use this library, and also copies the minimum set of
2048 sources needed to use the library to the install location.
2051 @c ---------------------------------------------
2052 @node Project Extension
2053 @section Project Extension
2054 @c ---------------------------------------------
2057 During development of a large system, it is sometimes necessary to use
2058 modified versions of some of the source files, without changing the original
2059 sources. This can be achieved through the @b{project extension} facility.
2061 Suppose for instance that our example @code{Build} project is built every night
2062 for the whole team, in some shared directory. A developer usually needs to work
2063 on a small part of the system, and might not want to have a copy of all the
2064 sources and all the object files (mostly because that would require too much
2065 disk space, time to recompile everything). He prefers to be able to override
2066 some of the source files in his directory, while taking advantage of all the
2067 object files generated at night.
2069 Another example can be taken from large software systems, where it is common to have
2070 multiple implementations of a common interface; in Ada terms, multiple
2071 versions of a package body for the same spec. For example, one implementation
2072 might be safe for use in tasking programs, while another might be used only
2073 in sequential applications. This can be modeled in GNAT using the concept
2074 of @emph{project extension}. If one project (the ``child'') @emph{extends}
2075 another project (the ``parent'') then by default all source files of the
2076 parent project are inherited by the child, but the child project can
2077 override any of the parent's source files with new versions, and can also
2078 add new files or remove unnecessary ones.
2079 This facility is the project analog of a type extension in
2080 object-oriented programming. Project hierarchies are permitted (an extending
2081 project may itself be extended), and a project that
2082 extends a project can also import other projects.
2084 A third example is that of using project extensions to provide different
2085 versions of the same system. For instance, assume that a @code{Common}
2086 project is used by two development branches. One of the branches has now
2087 been frozen, and no further change can be done to it or to @code{Common}.
2088 However, the other development branch still needs evolution of @code{Common}.
2089 Project extensions provide a flexible solution to create a new version
2090 of a subsystem while sharing and reusing as much as possible from the original
2093 A project extension implicitly inherits all the sources and objects from the
2094 project it extends. It is possible to create a new version of some of the
2095 sources in one of the additional source directories of the extending
2096 project. Those new versions hide the original versions. Adding new sources or
2097 removing existing ones is also possible. Here is an example on how to extend
2098 the project @code{Build} from previous examples:
2100 @smallexample @c projectfile
2101 @b{project} Work @b{extends} "../bld/build.gpr" @b{is}
2106 The project after @b{extends} is the one being extended. As usual, it can be
2107 specified using an absolute path, or a path relative to any of the directories
2108 in the project path (@pxref{Project Dependencies}). This project does not
2109 specify source or object directories, so the default values for these
2110 attributes will be used that is to say the current directory (where project
2111 @code{Work} is placed). We can compile that project with
2118 If no sources have been placed in the current directory, this command
2119 won't do anything, since this project does not change the
2120 sources it inherited from @code{Build}, therefore all the object files
2121 in @code{Build} and its dependencies are still valid and are reused
2124 Suppose we now want to supply an alternate version of @file{pack.adb} but use
2125 the existing versions of @file{pack.ads} and @file{proc.adb}. We can create
2126 the new file in Work's current directory (likely by copying the one from the
2127 @code{Build} project and making changes to it. If new packages are needed at
2128 the same time, we simply create new files in the source directory of the
2131 When we recompile, @command{gprbuild} will now automatically recompile
2132 this file (thus creating @file{pack.o} in the current directory) and
2133 any file that depends on it (thus creating @file{proc.o}). Finally, the
2134 executable is also linked locally.
2136 Note that we could have obtained the desired behavior using project import
2137 rather than project inheritance. A @code{base} project would contain the
2138 sources for @file{pack.ads} and @file{proc.adb}, and @code{Work} would
2139 import @code{base} and add @file{pack.adb}. In this scenario, @code{base}
2140 cannot contain the original version of @file{pack.adb} otherwise there would be
2141 2 versions of the same unit in the closure of the project and this is not
2142 allowed. Generally speaking, it is not recommended to put the spec and the
2143 body of a unit in different projects since this affects their autonomy and
2146 In a project file that extends another project, it is possible to
2147 indicate that an inherited source is @b{not part} of the sources of the
2148 extending project. This is necessary sometimes when a package spec has
2149 been overridden and no longer requires a body: in this case, it is
2150 necessary to indicate that the inherited body is not part of the sources
2151 of the project, otherwise there will be a compilation error
2152 when compiling the spec.
2154 @cindex @code{Excluded_Source_Files}
2155 @cindex @code{Excluded_Source_List_File}
2156 For that purpose, the attribute @b{Excluded_Source_Files} is used.
2157 Its value is a list of file names.
2158 It is also possible to use attribute @code{Excluded_Source_List_File}.
2159 Its value is the path of a text file containing one file name per
2162 @smallexample @c @projectfile
2163 project Work extends "../bld/build.gpr" is
2164 for Source_Files use ("pack.ads");
2165 -- New spec of Pkg does not need a completion
2166 for Excluded_Source_Files use ("pack.adb");
2171 All packages that are not declared in the extending project are inherited from
2172 the project being extended, with their attributes, with the exception of
2173 @code{Linker'Linker_Options} which is never inherited. In particular, an
2174 extending project retains all the switches specified in the project being
2177 At the project level, if they are not declared in the extending project, some
2178 attributes are inherited from the project being extended. They are:
2179 @code{Languages}, @code{Main} (for a root non library project) and
2180 @code{Library_Name} (for a project extending a library project).
2183 * Project Hierarchy Extension::
2186 @c ---------------------------------------------
2187 @node Project Hierarchy Extension
2188 @subsection Project Hierarchy Extension
2189 @c ---------------------------------------------
2192 One of the fundamental restrictions in project extension is the following:
2193 @b{A project is not allowed to import directly or indirectly at the same time an
2194 extending project and one of its ancestors}.
2196 By means of example, consider the following hierarchy of projects.
2199 a.gpr contains package A1
2200 b.gpr, imports a.gpr and contains B1, which depends on A1
2201 c.gpr, imports b.gpr and contains C1, which depends on B1
2205 If we want to locally extend the packages @code{A1} and @code{C1}, we need to
2206 create several extending projects:
2209 a_ext.gpr which extends a.gpr, and overrides A1
2210 b_ext.gpr which extends b.gpr and imports a_ext.gpr
2211 c_ext.gpr which extends c.gpr, imports b_ext.gpr and overrides C1
2215 @smallexample @c projectfile
2216 @b{project} A_Ext @b{extends} "a.gpr" @b{is}
2217 @b{for} Source_Files @b{use} ("a1.adb", "a1.ads");
2220 @b{with} "a_ext.gpr";
2221 @b{project} B_Ext @b{extends} "b.gpr" @b{is}
2224 @b{with} "b_ext.gpr";
2225 @b{project} C_Ext @b{extends} "c.gpr" @b{is}
2226 @b{for} Source_Files @b{use} ("c1.adb");
2231 The extension @file{b_ext.gpr} is required, even though we are not overriding
2232 any of the sources of @file{b.gpr} because otherwise @file{c_expr.gpr} would
2233 import @file{b.gpr} which itself knows nothing about @file{a_ext.gpr}.
2236 When extending a large system spanning multiple projects, it is often
2237 inconvenient to extend every project in the hierarchy that is impacted by a
2238 small change introduced in a low layer. In such cases, it is possible to create
2239 an @b{implicit extension} of an entire hierarchy using @b{extends all}
2242 When the project is extended using @code{extends all} inheritance, all projects
2243 that are imported by it, both directly and indirectly, are considered virtually
2244 extended. That is, the project manager creates implicit projects
2245 that extend every project in the hierarchy; all these implicit projects do not
2246 control sources on their own and use the object directory of
2247 the "extending all" project.
2249 It is possible to explicitly extend one or more projects in the hierarchy
2250 in order to modify the sources. These extending projects must be imported by
2251 the "extending all" project, which will replace the corresponding virtual
2252 projects with the explicit ones.
2254 When building such a project hierarchy extension, the project manager will
2255 ensure that both modified sources and sources in implicit extending projects
2256 that depend on them are recompiled.
2258 Thus, in our example we could create the following projects instead:
2261 a_ext.gpr, extends a.gpr and overrides A1
2262 c_ext.gpr, "extends all" c.gpr, imports a_ext.gpr and overrides C1
2267 @smallexample @c projectfile
2268 @b{project} A_Ext @b{extends} "a.gpr" @b{is}
2269 @b{for} Source_Files @b{use} ("a1.adb", "a1.ads");
2272 @b{with} "a_ext.gpr";
2273 @b{project} C_Ext @b{extends} @b{all} "c.gpr" @b{is}
2274 @b{for} Source_Files @b{use} ("c1.adb");
2279 When building project @file{c_ext.gpr}, the entire modified project space is
2280 considered for recompilation, including the sources of @file{b.gpr} that are
2281 impacted by the changes in @code{A1} and @code{C1}.
2283 @c ---------------------------------------------
2284 @node Aggregate Projects
2285 @section Aggregate Projects
2286 @c ---------------------------------------------
2290 Aggregate projects are an extension of the project paradigm, and are
2291 meant to solve a few specific use cases that cannot be solved directly
2292 using standard projects. This section will go over a few of these use
2293 cases to try to explain what you can use aggregate projects for.
2296 * Building all main programs from a single project tree::
2297 * Building a set of projects with a single command::
2298 * Define a build environment::
2299 * Performance improvements in builder::
2300 * Syntax of aggregate projects::
2301 * package Builder in aggregate projects::
2304 @c -----------------------------------------------------------
2305 @node Building all main programs from a single project tree
2306 @subsection Building all main programs from a single project tree
2307 @c -----------------------------------------------------------
2309 Most often, an application is organized into modules and submodules,
2310 which are very conveniently represented as a project tree or graph
2311 (the root project A @code{with}s the projects for each modules (say B and C),
2312 which in turn @code{with} projects for submodules.
2314 Very often, modules will build their own executables (for testing
2315 purposes for instance), or libraries (for easier reuse in various
2318 However, if you build your project through @command{gnatmake} or
2319 @command{gprbuild}, using a syntax similar to
2325 this will only rebuild the main programs of project A, not those of the
2326 imported projects B and C. Therefore you have to spawn several
2327 @command{gnatmake} commands, one per project, to build all executables.
2328 This is a little inconvenient, but more importantly is inefficient
2329 because @command{gnatmake} needs to do duplicate work to ensure that sources are
2330 up-to-date, and cannot easily compile things in parallel when using
2333 Also libraries are always rebuilt when building a project.
2335 You could therefore define an aggregate project Agg that groups A, B
2336 and C. Then, when you build with
2342 this will build all mains from A, B and C.
2344 @smallexample @c projectfile
2345 aggregate @b{project} Agg @b{is}
2346 @b{for} Project_Files @b{use} ("a.gpr", "b.gpr", "c.gpr");
2350 If B or C do not define any main program (through their Main
2351 attribute), all their sources are built. When you do not group them
2352 in the aggregate project, only those sources that are needed by A
2355 If you add a main to a project P not already explicitly referenced in the
2356 aggregate project, you will need to add "p.gpr" in the list of project
2357 files for the aggregate project, or the main will not be built when
2358 building the aggregate project.
2360 Aggregate projects are supported only with @command{gprbuild}, not with
2363 @c ---------------------------------------------------------
2364 @node Building a set of projects with a single command
2365 @subsection Building a set of projects with a single command
2366 @c ---------------------------------------------------------
2368 One other case is when you have multiple applications and libraries
2369 that are built independently from each other (but can be built in
2370 parallel). For instance, you have a project tree rooted at A, and
2371 another one (which might share some subprojects) rooted at B.
2373 Using only @command{gprbuild}, you could do
2380 to build both. But again, @command{gprbuild} has to do some duplicate work for
2381 those files that are shared between the two, and cannot truly build
2382 things in parallel efficiently.
2384 If the two projects are really independent, share no sources other
2385 than through a common subproject, and have no source files with a
2386 common basename, you could create a project C that imports A and
2387 B. But these restrictions are often too strong, and one has to build
2388 them independently. An aggregate project does not have these
2389 limitations and can aggregate two project trees that have common
2392 This scenario is particularly useful in environments like VxWorks 653
2393 where the applications running in the multiple partitions can be built
2394 in parallel through a single @command{gprbuild} command. This also works nicely
2397 @c ---------------------------------------------
2398 @node Define a build environment
2399 @subsection Define a build environment
2400 @c ---------------------------------------------
2402 The environment variables at the time you launch @command{gprbuild}
2403 will influence the view these tools have of the project
2404 (PATH to find the compiler, ADA_PROJECT_PATH or GPR_PROJECT_PATH to find the
2405 projects, environment variables that are referenced in project files
2406 through the "external" built-in function, ...). Several command line switches
2407 can be used to override those (-X or -aP), but on some systems and
2408 with some projects, this might make the command line too long, and on
2409 all systems often make it hard to read.
2411 An aggregate project can be used to set the environment for all
2412 projects built through that aggregate. One of the nice aspects is that
2413 you can put the aggregate project under configuration management, and
2414 make sure all your user have a consistent environment when
2415 building. The syntax looks like
2417 @smallexample @c projectfile
2418 aggregate @b{project} Agg @b{is}
2419 @b{for} Project_Files @b{use} ("A.gpr", "B.gpr");
2420 @b{for} Project_Path @b{use} ("../dir1", "../dir1/dir2");
2421 @b{for} External ("BUILD") @b{use} "PRODUCTION";
2423 @b{package} Builder @b{is}
2424 @b{for} Switches ("Ada") @b{use} ("-q");
2429 One of the often requested features in projects is to be able to
2430 reference external variables in @code{with} declarations, as in
2432 @smallexample @c projectfile
2433 @b{with} @b{external}("SETUP") & "path/prj.gpr"; --@i{ ILLEGAL}
2434 @b{project} MyProject @b{is}
2439 For various reasons, this is not allowed. But using aggregate projects provide
2440 an elegant solution. For instance, you could use a project file like:
2442 @smallexample @c projectfile
2443 aggregate @b{project} Agg @b{is}
2444 @b{for} Project_Path @b{use} (@b{external}("SETUP") & "path");
2445 @b{for} Project_Files @b{use} ("myproject.gpr");
2448 @b{with} "prj.gpr"; --@i{ searched on Agg'Project_Path}
2449 @b{project} MyProject @b{is}
2454 @c --------------------------------------------
2455 @node Performance improvements in builder
2456 @subsection Performance improvements in builder
2457 @c --------------------------------------------
2459 The loading of aggregate projects is optimized in @command{gprbuild},
2460 so that all files are searched for only once on the disk
2461 (thus reducing the number of system calls and contributing to faster
2462 compilation times, especially on systems with sources on remote
2463 servers). As part of the loading, @command{gprbuild}
2464 computes how and where a source file should be compiled, and even if it is
2465 found several times in the aggregated projects it will be compiled only
2468 Since there is no ambiguity as to which switches should be used, files
2469 can be compiled in parallel (through the usual -j switch) and this can
2470 be done while maximizing the use of CPUs (compared to launching
2471 multiple @command{gprbuild} and @command{gnatmake} commands in parallel).
2473 @c -------------------------------------
2474 @node Syntax of aggregate projects
2475 @subsection Syntax of aggregate projects
2476 @c -------------------------------------
2478 An aggregate project follows the general syntax of project files. The
2479 recommended extension is still @file{.gpr}. However, a special
2480 @code{aggregate} qualifier must be put before the keyword
2483 An aggregate project cannot @code{with} any other project (standard or
2484 aggregate), except an abstract project which can be used to share attribute
2485 values. Also, aggregate projects cannot be extended or imported though a
2486 @code{with} clause by any other project. Building other aggregate projects from
2487 an aggregate project is done through the Project_Files attribute (see below).
2489 An aggregate project does not have any source files directly (only
2490 through other standard projects). Therefore a number of the standard
2491 attributes and packages are forbidden in an aggregate project. Here is the
2492 (non exhaustive) list:
2496 @item Source_Files, Source_List_File and other attributes dealing with
2498 @item Source_Dirs, Exec_Dir and Object_Dir
2499 @item Library_Dir, Library_Name and other library-related attributes
2502 @item Externally_Built
2503 @item Inherit_Source_Path
2504 @item Excluded_Source_Dirs
2505 @item Locally_Removed_Files
2506 @item Excluded_Source_Files
2507 @item Excluded_Source_List_File
2511 The only package that is authorized (albeit optional) is
2512 Builder. Other packages (in particular Compiler, Binder and Linker)
2515 The following three attributes can be used only in an aggregate project:
2518 @item @b{Project_Files}:
2519 @cindex @code{Project_Files}
2521 This attribute is compulsory (or else we are not aggregating any project,
2522 and thus not doing anything). It specifies a list of @file{.gpr} files
2523 that are grouped in the aggregate. The list may be empty. The project
2524 files can be either other aggregate projects, or standard projects. When
2525 grouping standard projects, you can have both the root of a project tree
2526 (and you do not need to specify all its imported projects), and any project
2529 Basically, the idea is to specify all those projects that have
2530 main programs you want to build and link, or libraries you want to
2531 build. You can even specify projects that do not use the Main
2532 attribute nor the @code{Library_*} attributes, and the result will be to
2533 build all their source files (not just the ones needed by other
2536 The file can include paths (absolute or relative). Paths are relative to
2537 the location of the aggregate project file itself (if you use a base name,
2538 we expect to find the .gpr file in the same directory as the aggregate
2539 project file). The environment variables @code{ADA_PROJECT_PATH},
2540 @code{GPR_PROJECT_PATH} and @code{GPR_PROJECT_PATH_FILE} are not used to find
2541 the project files. The extension @file{.gpr} is mandatory, since this attribute
2542 contains file names, not project names.
2544 Paths can also include the @code{"*"} and @code{"**"} globbing patterns. The
2545 latter indicates that any subdirectory (recursively) will be
2546 searched for matching files. The latter (@code{"**"}) can only occur at the
2547 last position in the directory part (ie @code{"a/**/*.gpr"} is supported, but
2548 not @code{"**/a/*.gpr"}). Starting the pattern with @code{"**"} is equivalent
2549 to starting with @code{"./**"}.
2551 For now, the pattern @code{"*"} is only allowed in the filename part, not
2552 in the directory part. This is mostly for efficiency reasons to limit the
2553 number of system calls that are needed.
2555 Here are a few valid examples:
2557 @smallexample @c projectfile
2558 @b{for} Project_Files @b{use} ("a.gpr", "subdir/b.gpr");
2559 --@i{ two specific projects relative to the directory of agg.gpr}
2561 @b{for} Project_Files @b{use} ("**/*.gpr");
2562 --@i{ all projects recursively}
2565 @item @b{Project_Path}:
2566 @cindex @code{Project_Path}
2568 This attribute can be used to specify a list of directories in
2569 which to look for project files in @code{with} declarations.
2571 When you specify a project in Project_Files (say @code{x/y/a.gpr}), and
2572 @code{a.gpr} imports a project @code{b.gpr}, only @code{b.gpr} is searched in
2573 the project path. @code{a.gpr} must be exactly at
2574 @code{<dir of the aggregate>/x/y/a.gpr}.
2576 This attribute, however, does not affect the search for the aggregated
2577 project files specified with @code{Project_Files}.
2579 Each aggregate project has its own @code{Project_Path} (that is if
2580 @code{agg1.gpr} includes @code{agg2.gpr}, they can potentially both have a
2581 different @code{Project_Path}).
2583 This project path is defined as the concatenation, in that order, of:
2586 @item the current directory;
2587 @item followed by the command line -aP switches;
2588 @item then the directories from the GPR_PROJECT_PATH and ADA_PROJECT_PATH environment
2590 @item then the directories from the Project_Path attribute;
2591 @item and finally the predefined directories.
2594 In the example above, agg2.gpr's project path is not influenced by
2595 the attribute agg1'Project_Path, nor is agg1 influenced by
2598 This can potentially lead to errors. In the following example:
2601 +---------------+ +----------------+
2602 | Agg1.gpr |-=--includes--=-->| Agg2.gpr |
2603 | 'project_path| | 'project_path |
2605 +---------------+ +----------------+
2610 +-------+ +---------+
2611 | P.gpr |<---------- withs --------| Q.gpr |
2612 +-------+---------\ +---------+
2617 +-------+ +---------+
2618 | R.gpr | | R'.gpr |
2619 +-------+ +---------+
2622 When looking for p.gpr, both aggregates find the same physical file on
2623 the disk. However, it might happen that with their different project
2624 paths, both aggregate projects would in fact find a different r.gpr.
2625 Since we have a common project (p.gpr) "with"ing two different r.gpr,
2626 this will be reported as an error by the builder.
2628 Directories are relative to the location of the aggregate project file.
2632 @smallexample @c projectfile
2633 @b{for} Project_Path @b{use} ("/usr/local/gpr", "gpr/");
2637 @cindex @code{External}
2639 This attribute can be used to set the value of environment
2640 variables as retrieved through the @code{external} function
2641 in projects. It does not affect the environment variables
2642 themselves (so for instance you cannot use it to change the value
2643 of your PATH as seen from the spawned compiler).
2645 This attribute affects the external values as seen in the rest of
2646 the aggreate projects, and in the aggregated projects.
2648 The exact value of external a variable comes from one of three
2649 sources (each level overrides the previous levels):
2652 @item An External attribute in aggregate project, for instance
2653 @code{for External ("BUILD_MODE") use "DEBUG"};
2655 @item Environment variables
2657 These override the value given by the attribute, so that
2658 users can override the value set in the (presumably shared
2659 with others team members) aggregate project.
2661 @item The -X command line switch to @command{gprbuild}
2663 This always takes precedence.
2667 This attribute is only taken into account in the main aggregate
2668 project (i.e. the one specified on the command line to @command{gprbuild}),
2669 and ignored in other aggregate projects. It is invalid
2670 in standard projects.
2671 The goal is to have a consistent value in all
2672 projects that are built through the aggregate, which would not
2673 be the case in the diamond case: A groups the aggregate
2674 projects B and C, which both (either directly or indirectly)
2675 build the project P. If B and C could set different values for
2676 the environment variables, we would have two different views of
2677 P, which in particular might impact the list of source files in P.
2681 @c ----------------------------------------------
2682 @node package Builder in aggregate projects
2683 @subsection package Builder in aggregate projects
2684 @c ----------------------------------------------
2686 As we mentioned before, only the package Builder can be specified in
2687 an aggregate project. In this package, only the following attributes
2692 @cindex @code{Switches}
2693 This attribute gives the list of switches to use for @command{gprbuild}.
2694 Because no mains can be specified for aggregate projects, the only possible
2695 index for attribute @code{Switches} is @code{others}. All other indexes will
2700 @smallexample @c projectfile
2701 @b{for} Switches (@b{others}) @b{use} ("-v", "-k", "-j8");
2704 These switches are only read from the main aggregate project (the
2705 one passed on the command line), and ignored in all other aggregate
2706 projects or projects.
2708 It can only contain builder switches, not compiler switches.
2710 @item @b{Global_Compilation_Switches}
2711 @cindex @code{Global_Compilation_Switches}
2713 This attribute gives the list of compiler switches for the various
2714 languages. For instance,
2716 @smallexample @c projectfile
2717 @b{for} Global_Compilation_Switches ("Ada") @b{use} ("O1", "-g");
2718 @b{for} Global_Compilation_Switches ("C") @b{use} ("-O2");
2721 This attribute is only taken into account in the aggregate project
2722 specified on the command line, not in other aggregate projects.
2724 In the projects grouped by that aggregate, the attribute
2725 Builder.Global_Compilation_Switches is also ignored. However, the
2726 attribute Compiler.Default_Switches will be taken into account (but
2727 that of the aggregate have higher priority). The attribute
2728 Compiler.Switches is also taken into account and can be used to
2729 override the switches for a specific file. As a result, it always
2732 The rules are meant to avoid ambiguities when compiling. For
2733 instance, aggregate project Agg groups the projects A and B, that
2734 both depend on C. Here is an extra for all of these projects:
2736 @smallexample @c projectfile
2737 aggregate @b{project} Agg @b{is}
2738 @b{for} Project_Files @b{use} ("a.gpr", "b.gpr");
2739 @b{package} Builder @b{is}
2740 @b{for} Global_Compilation_Switches ("Ada") @b{use} ("-O2");
2745 @b{project} A @b{is}
2746 @b{package} Builder @b{is}
2747 @b{for} Global_Compilation_Switches ("Ada") @b{use} ("-O1");
2751 @b{package} Compiler @b{is}
2752 @b{for} Default_Switches ("Ada")
2753 @b{use} ("-O1", "-g");
2754 @b{for} Switches ("a_file1.adb")
2760 @b{project} B @b{is}
2761 @b{package} Compiler @b{is}
2762 @b{for} Default_Switches ("Ada") @b{use} ("-O0");
2766 @b{project} C @b{is}
2767 @b{package} Compiler @b{is}
2768 @b{for} Default_Switches ("Ada")
2771 @b{for} Switches ("c_file1.adb")
2772 @b{use} ("-O0", "-g");
2777 then the following switches are used:
2780 @item all files from project A except a_file1.adb are compiled
2781 with "-O2 -g", since the aggregate project has priority.
2782 @item the file a_file1.adb is compiled with
2783 "-O0", since the Compiler.Switches has priority
2784 @item all files from project B are compiled with
2785 "-O2", since the aggregate project has priority
2786 @item all files from C are compiled with "-O2 -gnatn", except for
2787 c_file1.adb which is compiled with "-O0 -g"
2790 Even though C is seen through two paths (through A and through
2791 B), the switches used by the compiler are unambiguous.
2793 @item @b{Global_Configuration_Pragmas}
2794 @cindex @code{Global_Configuration_Pragmas}
2796 This attribute can be used to specify a file containing
2797 configuration pragmas, to be passed to the Ada compiler. Since we
2798 ignore the package Builder in other aggregate projects and projects,
2799 only those pragmas defined in the main aggregate project will be
2802 Projects can locally add to those by using the
2803 @code{Compiler.Local_Configuration_Pragmas} attribute if they need.
2805 @item @b{Global_Config_File}
2806 @cindex @code{Global_Config_File}
2808 This attribute, indexed with a language name, can be used to specify a config
2809 when compiling sources of the language. For Ada, these files are configuration
2814 For projects that are built through the aggregate, the package Builder
2815 is ignored, except for the Executable attribute which specifies the
2816 name of the executables resulting from the link of the main programs, and
2817 for the Executable_Suffix.
2819 @c ---------------------------------------------
2820 @node Aggregate Library Projects
2821 @section Aggregate Library Projects
2822 @c ---------------------------------------------
2826 Aggregate library projects make it possible to build a single library
2827 using object files built using other standard or library
2828 projects. This gives the flexibility to describe an application as
2829 having multiple modules (a GUI, database access, ...) using different
2830 project files (so possibly built with different compiler options) and
2831 yet create a single library (static or relocatable) out of the
2832 corresponding object files.
2835 * Building aggregate library projects::
2836 * Syntax of aggregate library projects::
2839 @c ---------------------------------------------
2840 @node Building aggregate library projects
2841 @subsection Building aggregate library projects
2842 @c ---------------------------------------------
2844 For example, we can define an aggregate project Agg that groups A, B
2847 @smallexample @c projectfile
2848 aggregate library @b{project} Agg @b{is}
2849 @b{for} Project_Files @b{use} ("a.gpr", "b.gpr", "c.gpr");
2850 @b{for} Library_Name @b{use} ("agg");
2851 @b{for} Library_Dir @b{use} ("lagg");
2855 Then, when you build with:
2861 This will build all units from projects A, B and C and will create a
2862 static library named @file{libagg.a} in the @file{lagg}
2863 directory. An aggregate library project has the same set of
2864 restriction as a standard library project.
2866 Note that a shared aggregate library project cannot aggregate a
2867 static library project. In platforms where a compiler option is
2868 required to create relocatable object files, a Builder package in the
2869 aggregate library project may be used:
2871 @smallexample @c projectfile
2872 aggregate library @b{project} Agg @b{is}
2873 @b{for} Project_Files @b{use} ("a.gpr", "b.gpr", "c.gpr");
2874 @b{for} Library_Name @b{use} ("agg");
2875 @b{for} Library_Dir @b{use} ("lagg");
2876 @b{for} Library_Kind @b{use} "relocatable";
2878 @b{package} Builder @b{is}
2879 @b{for} Global_Compilation_Switches ("Ada") @b{use} ("-fPIC");
2884 With the above aggregate library Builder package, the @code{-fPIC}
2885 option will be passed to the compiler when building any source code
2886 from projects @file{a.gpr}, @file{b.gpr} and @file{c.gpr}.
2888 @c ---------------------------------------------
2889 @node Syntax of aggregate library projects
2890 @subsection Syntax of aggregate library projects
2891 @c ---------------------------------------------
2893 An aggregate library project follows the general syntax of project
2894 files. The recommended extension is still @file{.gpr}. However, a special
2895 @code{aggregate library} qualifier must be put before the keyword
2898 An aggregate library project cannot @code{with} any other project
2899 (standard or aggregate), except an abstract project which can be used
2900 to share attribute values.
2902 An aggregate library project does not have any source files directly (only
2903 through other standard projects). Therefore a number of the standard
2904 attributes and packages are forbidden in an aggregate library
2905 project. Here is the (non exhaustive) list:
2909 @item Source_Files, Source_List_File and other attributes dealing with
2911 @item Source_Dirs, Exec_Dir and Object_Dir
2914 @item Externally_Built
2915 @item Inherit_Source_Path
2916 @item Excluded_Source_Dirs
2917 @item Locally_Removed_Files
2918 @item Excluded_Source_Files
2919 @item Excluded_Source_List_File
2923 The only package that is authorized (albeit optional) is Builder.
2925 The Project_Files attribute (See @pxref{Aggregate Projects}) is used to
2926 described the aggregated projects whose object files have to be
2927 included into the aggregate library. The environment variables
2928 @code{ADA_PROJECT_PATH}, @code{GPR_PROJECT_PATH} and
2929 @code{GPR_PROJECT_PATH_FILE} are not used to find the project files.
2931 @c ---------------------------------------------
2932 @node Project File Reference
2933 @section Project File Reference
2934 @c ---------------------------------------------
2937 This section describes the syntactic structure of project files, the various
2938 constructs that can be used. Finally, it ends with a summary of all available
2942 * Project Declaration::
2943 * Qualified Projects::
2948 * Typed String Declaration::
2950 * Case Constructions::
2954 @c ---------------------------------------------
2955 @node Project Declaration
2956 @subsection Project Declaration
2957 @c ---------------------------------------------
2960 Project files have an Ada-like syntax. The minimal project file is:
2962 @smallexample @c projectfile
2964 @b{project} Empty @b{is}
2970 The identifier @code{Empty} is the name of the project.
2971 This project name must be present after the reserved
2972 word @code{end} at the end of the project file, followed by a semi-colon.
2974 @b{Identifiers} (i.e.@: the user-defined names such as project or variable names)
2975 have the same syntax as Ada identifiers: they must start with a letter,
2976 and be followed by zero or more letters, digits or underscore characters;
2977 it is also illegal to have two underscores next to each other. Identifiers
2978 are always case-insensitive ("Name" is the same as "name").
2981 simple_name ::= identifier
2982 name ::= simple_name @{ . simple_name @}
2986 @b{Strings} are used for values of attributes or as indexes for these
2987 attributes. They are in general case sensitive, except when noted
2988 otherwise (in particular, strings representing file names will be case
2989 insensitive on some systems, so that "file.adb" and "File.adb" both
2990 represent the same file).
2992 @b{Reserved words} are the same as for standard Ada 95, and cannot
2993 be used for identifiers. In particular, the following words are currently
2994 used in project files, but others could be added later on. In bold are the
2995 extra reserved words in project files: @code{all, at, case, end, for, is,
2996 limited, null, others, package, renames, type, use, when, with, @b{extends},
2997 @b{external}, @b{project}}.
2999 @b{Comments} in project files have the same syntax as in Ada, two consecutive
3000 hyphens through the end of the line.
3002 A project may be an @b{independent project}, entirely defined by a single
3003 project file. Any source file in an independent project depends only
3004 on the predefined library and other source files in the same project.
3005 But a project may also depend on other projects, either by importing them
3006 through @b{with clauses}, or by @b{extending} at most one other project. Both
3007 types of dependency can be used in the same project.
3009 A path name denotes a project file. It can be absolute or relative.
3010 An absolute path name includes a sequence of directories, in the syntax of
3011 the host operating system, that identifies uniquely the project file in the
3012 file system. A relative path name identifies the project file, relative
3013 to the directory that contains the current project, or relative to a
3014 directory listed in the environment variables ADA_PROJECT_PATH and
3015 GPR_PROJECT_PATH. Path names are case sensitive if file names in the host
3016 operating system are case sensitive. As a special case, the directory
3017 separator can always be "/" even on Windows systems, so that project files
3018 can be made portable across architectures.
3019 The syntax of the environment variables ADA_PROJECT_PATH and
3020 GPR_PROJECT_PATH is a list of directory names separated by colons on UNIX and
3021 semicolons on Windows.
3023 A given project name can appear only once in a context clause.
3025 It is illegal for a project imported by a context clause to refer, directly
3026 or indirectly, to the project in which this context clause appears (the
3027 dependency graph cannot contain cycles), except when one of the with clauses
3028 in the cycle is a @b{limited with}.
3029 @c ??? Need more details here
3031 @smallexample @c projectfile
3032 @b{with} "other_project.gpr";
3033 @b{project} My_Project @b{extends} "extended.gpr" @b{is}
3038 These dependencies form a @b{directed graph}, potentially cyclic when using
3039 @b{limited with}. The subgraph reflecting the @b{extends} relations is a tree.
3041 A project's @b{immediate sources} are the source files directly defined by
3042 that project, either implicitly by residing in the project source directories,
3043 or explicitly through any of the source-related attributes.
3044 More generally, a project's @b{sources} are the immediate sources of the
3045 project together with the immediate sources (unless overridden) of any project
3046 on which it depends directly or indirectly.
3048 A @b{project hierarchy} can be created, where projects are children of
3049 other projects. The name of such a child project must be @code{Parent.Child},
3050 where @code{Parent} is the name of the parent project. In particular, this
3051 makes all @code{with} clauses of the parent project automatically visible
3052 in the child project.
3055 project ::= context_clause project_declaration
3057 context_clause ::= @{with_clause@}
3058 with_clause ::= @i{with} path_name @{ , path_name @} ;
3059 path_name ::= string_literal
3061 project_declaration ::= simple_project_declaration | project_extension
3062 simple_project_declaration ::=
3063 @i{project} @i{<project_>}name @i{is}
3064 @{declarative_item@}
3065 @i{end} <project_>simple_name;
3068 @c ---------------------------------------------
3069 @node Qualified Projects
3070 @subsection Qualified Projects
3071 @c ---------------------------------------------
3074 Before the reserved @code{project}, there may be one or two @b{qualifiers}, that
3075 is identifiers or reserved words, to qualify the project.
3076 The current list of qualifiers is:
3079 @item @b{abstract}: qualifies a project with no sources. Such a
3080 project must either have no declaration of attributes @code{Source_Dirs},
3081 @code{Source_Files}, @code{Languages} or @code{Source_List_File}, or one of
3082 @code{Source_Dirs}, @code{Source_Files}, or @code{Languages} must be declared
3083 as empty. If it extends another project, the project it extends must also be a
3084 qualified abstract project.
3085 @item @b{standard}: a standard project is a non library project with sources.
3086 This is the default (implicit) qualifier.
3087 @item @b{aggregate}: a project whose sources are aggregated from other
3089 @item @b{aggregate library}: a library whose sources are aggregated
3090 from other project or library project files.
3091 @item @b{library}: a library project must declare both attributes
3092 @code{Library_Name} and @code{Library_Dir}.
3093 @item @b{configuration}: a configuration project cannot be in a project tree.
3094 It describes compilers and other tools to @command{gprbuild}.
3097 @c ---------------------------------------------
3099 @subsection Declarations
3100 @c ---------------------------------------------
3103 Declarations introduce new entities that denote types, variables, attributes,
3104 and packages. Some declarations can only appear immediately within a project
3105 declaration. Others can appear within a project or within a package.
3108 declarative_item ::= simple_declarative_item
3109 | typed_string_declaration
3110 | package_declaration
3112 simple_declarative_item ::= variable_declaration
3113 | typed_variable_declaration
3114 | attribute_declaration
3118 empty_declaration ::= @i{null} ;
3122 An empty declaration is allowed anywhere a declaration is allowed. It has
3125 @c ---------------------------------------------
3127 @subsection Packages
3128 @c ---------------------------------------------
3131 A project file may contain @b{packages}, that group attributes (typically
3132 all the attributes that are used by one of the GNAT tools).
3134 A package with a given name may only appear once in a project file.
3135 The following packages are currently supported in project files
3136 (See @pxref{Attributes} for the list of attributes that each can contain).
3140 This package specifies characteristics useful when invoking the binder either
3141 directly via the @command{gnat} driver or when using a builder such as
3142 @command{gnatmake} or @command{gprbuild}. @xref{Main Subprograms}.
3144 This package specifies the compilation options used when building an
3145 executable or a library for a project. Most of the options should be
3146 set in one of @code{Compiler}, @code{Binder} or @code{Linker} packages,
3147 but there are some general options that should be defined in this
3148 package. @xref{Main Subprograms}, and @pxref{Executable File Names} in
3152 This package specifies the options used when calling the checking tool
3153 @command{gnatcheck} via the @command{gnat} driver. Its attribute
3154 @b{Default_Switches} has the same semantics as for the package
3155 @code{Builder}. The first string should always be @code{-rules} to specify
3156 that all the other options belong to the @code{-rules} section of the
3157 parameters to @command{gnatcheck}.
3160 This package specifies the options used when cleaning a project or a project
3161 tree using the tools @command{gnatclean} or @command{gprclean}.
3163 This package specifies the compilation options used by the compiler for
3164 each languages. @xref{Tools Options in Project Files}.
3165 @item Cross_Reference
3166 This package specifies the options used when calling the library tool
3167 @command{gnatxref} via the @command{gnat} driver. Its attributes
3168 @b{Default_Switches} and @b{Switches} have the same semantics as for the
3169 package @code{Builder}.
3172 This package specifies the options used when calling the tool
3173 @command{gnatelim} via the @command{gnat} driver. Its attributes
3174 @b{Default_Switches} and @b{Switches} have the same semantics as for the
3175 package @code{Builder}.
3178 This package specifies the options used when calling the search tool
3179 @command{gnatfind} via the @command{gnat} driver. Its attributes
3180 @b{Default_Switches} and @b{Switches} have the same semantics as for the
3181 package @code{Builder}.
3183 This package specifies the options to use when invoking @command{gnatls}
3184 via the @command{gnat} driver.
3187 This package specifies the options used when calling the tool
3188 @command{gnatstub} via the @command{gnat} driver. Its attributes
3189 @b{Default_Switches} and @b{Switches} have the same semantics as for the
3190 package @code{Builder}.
3193 This package specifies the options used when starting an integrated
3194 development environment, for instance @command{GPS} or @command{Gnatbench}.
3196 This package specifies the options used when installing a project
3197 with @command{gprinstall}. @xref{Installation}.
3199 This package specifies the options used by the linker.
3200 @xref{Main Subprograms}.
3203 This package specifies the options used when calling the tool
3204 @command{gnatmetric} via the @command{gnat} driver. Its attributes
3205 @b{Default_Switches} and @b{Switches} have the same semantics as for the
3206 package @code{Builder}.
3209 This package specifies the naming conventions that apply
3210 to the source files in a project. In particular, these conventions are
3211 used to automatically find all source files in the source directories,
3212 or given a file name to find out its language for proper processing.
3213 @xref{Naming Schemes}.
3215 @item Pretty_Printer
3216 This package specifies the options used when calling the formatting tool
3217 @command{gnatpp} via the @command{gnat} driver. Its attributes
3218 @b{Default_Switches} and @b{Switches} have the same semantics as for the
3219 package @code{Builder}.
3222 This package is used by @command{gprbuild} to describe how distributed
3223 compilation should be done.
3225 This package specifies the options used when calling the tool
3226 @command{gnatstack} via the @command{gnat} driver. Its attributes
3227 @b{Default_Switches} and @b{Switches} have the same semantics as for the
3228 package @code{Builder}.
3230 This package specifies the options used when calling the tool
3231 @command{gnatsync} via the @command{gnat} driver.
3235 In its simplest form, a package may be empty:
3237 @smallexample @c projectfile
3239 @b{project} Simple @b{is}
3240 @b{package} Builder @b{is}
3247 A package may contain @b{attribute declarations},
3248 @b{variable declarations} and @b{case constructions}, as will be
3251 When there is ambiguity between a project name and a package name,
3252 the name always designates the project. To avoid possible confusion, it is
3253 always a good idea to avoid naming a project with one of the
3254 names allowed for packages or any name that starts with @code{gnat}.
3256 A package can also be defined by a @b{renaming declaration}. The new package
3257 renames a package declared in a different project file, and has the same
3258 attributes as the package it renames. The name of the renamed package
3259 must be the same as the name of the renaming package. The project must
3260 contain a package declaration with this name, and the project
3261 must appear in the context clause of the current project, or be its parent
3262 project. It is not possible to add or override attributes to the renaming
3263 project. If you need to do so, you should use an @b{extending declaration}
3266 Packages that are renamed in other project files often come from project files
3267 that have no sources: they are just used as templates. Any modification in the
3268 template will be reflected automatically in all the project files that rename
3269 a package from the template. This is a very common way to share settings
3272 Finally, a package can also be defined by an @b{extending declaration}. This is
3273 similar to a @b{renaming declaration}, except that it is possible to add or
3274 override attributes.
3277 package_declaration ::= package_spec | package_renaming | package_extension
3279 @i{package} @i{<package_>}simple_name @i{is}
3280 @{simple_declarative_item@}
3281 @i{end} package_identifier ;
3282 package_renaming ::==
3283 @i{package} @i{<package_>}simple_name @i{renames} @i{<project_>}simple_name.package_identifier ;
3284 package_extension ::==
3285 @i{package} @i{<package_>}simple_name @i{extends} @i{<project_>}simple_name.package_identifier @i{is}
3286 @{simple_declarative_item@}
3287 @i{end} package_identifier ;
3290 @c ---------------------------------------------
3292 @subsection Expressions
3293 @c ---------------------------------------------
3296 An expression is any value that can be assigned to an attribute or a
3297 variable. It is either a literal value, or a construct requiring runtime
3298 computation by the project manager. In a project file, the computed value of
3299 an expression is either a string or a list of strings.
3301 A string value is one of:
3303 @item A literal string, for instance @code{"comm/my_proj.gpr"}
3304 @item The name of a variable that evaluates to a string (@pxref{Variables})
3305 @item The name of an attribute that evaluates to a string (@pxref{Attributes})
3306 @item An external reference (@pxref{External Values})
3307 @item A concatenation of the above, as in @code{"prefix_" & Var}.
3312 A list of strings is one of the following:
3315 @item A parenthesized comma-separated list of zero or more string expressions, for
3316 instance @code{(File_Name, "gnat.adc", File_Name & ".orig")} or @code{()}.
3317 @item The name of a variable that evaluates to a list of strings
3318 @item The name of an attribute that evaluates to a list of strings
3319 @item A concatenation of a list of strings and a string (as defined above), for
3320 instance @code{("A", "B") & "C"}
3321 @item A concatenation of two lists of strings
3326 The following is the grammar for expressions
3329 string_literal ::= "@{string_element@}" -- Same as Ada
3330 string_expression ::= string_literal
3333 | attribute_reference
3334 | ( string_expression @{ & string_expression @} )
3335 string_list ::= ( string_expression @{ , string_expression @} )
3336 | @i{string_variable}_name
3337 | @i{string_}attribute_reference
3338 term ::= string_expression | string_list
3339 expression ::= term @{ & term @} -- Concatenation
3343 Concatenation involves strings and list of strings. As soon as a list of
3344 strings is involved, the result of the concatenation is a list of strings. The
3345 following Ada declarations show the existing operators:
3347 @smallexample @c ada
3348 @b{function} "&" (X : String; Y : String) @b{return} String;
3349 @b{function} "&" (X : String_List; Y : String) @b{return} String_List;
3350 @b{function} "&" (X : String_List; Y : String_List) @b{return} String_List;
3354 Here are some specific examples:
3356 @smallexample @c projectfile
3358 List := () & File_Name; --@i{ One string in this list}
3359 List2 := List & (File_Name & ".orig"); --@i{ Two strings}
3360 Big_List := List & Lists2; --@i{ Three strings}
3361 Illegal := "gnat.adc" & List2; --@i{ Illegal, must start with list}
3365 @c ---------------------------------------------
3366 @node External Values
3367 @subsection External Values
3368 @c ---------------------------------------------
3371 An external value is an expression whose value is obtained from the command
3372 that invoked the processing of the current project file (typically a
3373 @command{gnatmake} or @command{gprbuild} command).
3375 There are two kinds of external values, one that returns a single string, and
3376 one that returns a string list.
3378 The syntax of a single string external value is:
3381 external_value ::= @i{external} ( string_literal [, string_literal] )
3385 The first string_literal is the string to be used on the command line or
3386 in the environment to specify the external value. The second string_literal,
3387 if present, is the default to use if there is no specification for this
3388 external value either on the command line or in the environment.
3390 Typically, the external value will either exist in the
3391 environment variables
3392 or be specified on the command line through the
3393 @option{-X@emph{vbl}=@emph{value}} switch. If both
3394 are specified, then the command line value is used, so that a user can more
3395 easily override the value.
3397 The function @code{external} always returns a string. It is an error if the
3398 value was not found in the environment and no default was specified in the
3399 call to @code{external}.
3401 An external reference may be part of a string expression or of a string
3402 list expression, and can therefore appear in a variable declaration or
3403 an attribute declaration.
3405 Most of the time, this construct is used to initialize typed variables, which
3406 are then used in @b{case} constructions to control the value assigned to
3407 attributes in various scenarios. Thus such variables are often called
3408 @b{scenario variables}.
3410 The syntax for a string list external value is:
3413 external_value ::= @i{external_as_list} ( string_literal , string_literal )
3417 The first string_literal is the string to be used on the command line or
3418 in the environment to specify the external value. The second string_literal is
3419 the separator between each component of the string list.
3421 If the external value does not exist in the environment or on the command line,
3422 the result is an empty list. This is also the case, if the separator is an
3423 empty string or if the external value is only one separator.
3425 Any separator at the beginning or at the end of the external value is
3426 discarded. Then, if there is no separator in the external value, the result is
3427 a string list with only one string. Otherwise, any string between the beginning
3428 and the first separator, between two consecutive separators and between the
3429 last separator and the end are components of the string list.
3432 @i{external_as_list} ("SWITCHES", ",")
3436 If the external value is "-O2,-g",
3437 the result is ("-O2", "-g").
3439 If the external value is ",-O2,-g,",
3440 the result is also ("-O2", "-g").
3442 if the external value is "-gnatv",
3443 the result is ("-gnatv").
3445 If the external value is ",,", the result is ("").
3447 If the external value is ",", the result is (), the empty string list.
3449 @c ---------------------------------------------
3450 @node Typed String Declaration
3451 @subsection Typed String Declaration
3452 @c ---------------------------------------------
3455 A @b{type declaration} introduces a discrete set of string literals.
3456 If a string variable is declared to have this type, its value
3457 is restricted to the given set of literals. These are the only named
3458 types in project files. A string type may only be declared at the project
3459 level, not inside a package.
3462 typed_string_declaration ::=
3463 @i{type} @i{<typed_string_>}_simple_name @i{is} ( string_literal @{, string_literal@} );
3467 The string literals in the list are case sensitive and must all be different.
3468 They may include any graphic characters allowed in Ada, including spaces.
3469 Here is an example of a string type declaration:
3471 @smallexample @c projectfile
3472 @b{type} OS @b{is} ("NT", "nt", "Unix", "GNU/Linux", "other OS");
3476 Variables of a string type are called @b{typed variables}; all other
3477 variables are called @b{untyped variables}. Typed variables are
3478 particularly useful in @code{case} constructions, to support conditional
3479 attribute declarations. (@pxref{Case Constructions}).
3481 A string type may be referenced by its name if it has been declared in the same
3482 project file, or by an expanded name whose prefix is the name of the project
3483 in which it is declared.
3485 @c ---------------------------------------------
3487 @subsection Variables
3488 @c ---------------------------------------------
3491 @b{Variables} store values (strings or list of strings) and can appear
3492 as part of an expression. The declaration of a variable creates the
3493 variable and assigns the value of the expression to it. The name of the
3494 variable is available immediately after the assignment symbol, if you
3495 need to reuse its old value to compute the new value. Before the completion
3496 of its first declaration, the value of a variable defaults to the empty
3499 A @b{typed} variable can be used as part of a @b{case} expression to
3500 compute the value, but it can only be declared once in the project file,
3501 so that all case constructions see the same value for the variable. This
3502 provides more consistency and makes the project easier to understand.
3503 The syntax for its declaration is identical to the Ada syntax for an
3504 object declaration. In effect, a typed variable acts as a constant.
3506 An @b{untyped} variable can be declared and overridden multiple times
3507 within the same project. It is declared implicitly through an Ada
3508 assignment. The first declaration establishes the kind of the variable
3509 (string or list of strings) and successive declarations must respect
3510 the initial kind. Assignments are executed in the order in which they
3511 appear, so the new value replaces the old one and any subsequent reference
3512 to the variable uses the new value.
3514 A variable may be declared at the project file level, or within a package.
3517 typed_variable_declaration ::=
3518 @i{<typed_variable_>}simple_name : @i{<typed_string_>}name := string_expression;
3519 variable_declaration ::= @i{<variable_>}simple_name := expression;
3523 Here are some examples of variable declarations:
3525 @smallexample @c projectfile
3527 This_OS : OS := @b{external} ("OS"); --@i{ a typed variable declaration}
3528 That_OS := "GNU/Linux"; --@i{ an untyped variable declaration}
3530 Name := "readme.txt";
3531 Save_Name := Name & ".saved";
3534 List_With_One_Element := ("-gnaty");
3535 List_With_Two_Elements := List_With_One_Element & "-gnatg";
3536 Long_List := ("main.ada", "pack1_.ada", "pack1.ada", "pack2_.ada");
3541 A @b{variable reference} may take several forms:
3544 @item The simple variable name, for a variable in the current package (if any)
3545 or in the current project
3546 @item An expanded name, whose prefix is a context name.
3551 A @b{context} may be one of the following:
3554 @item The name of an existing package in the current project
3555 @item The name of an imported project of the current project
3556 @item The name of an ancestor project (i.e., a project extended by the current
3557 project, either directly or indirectly)
3558 @item An expanded name whose prefix is an imported/parent project name, and
3559 whose selector is a package name in that project.
3562 @c ---------------------------------------------
3563 @node Case Constructions
3564 @subsection Case Constructions
3565 @c ---------------------------------------------
3568 A @b{case} construction is used in a project file to effect conditional
3569 behavior. Through this construction, you can set the value of attributes
3570 and variables depending on the value previously assigned to a typed
3573 All choices in a choice list must be distinct. Unlike Ada, the choice
3574 lists of all alternatives do not need to include all values of the type.
3575 An @code{others} choice must appear last in the list of alternatives.
3577 The syntax of a @code{case} construction is based on the Ada case construction
3578 (although the @code{null} declaration for empty alternatives is optional).
3580 The case expression must be a string variable, either typed or not, whose value
3581 is often given by an external reference (@pxref{External Values}).
3583 Each alternative starts with the reserved word @code{when}, either a list of
3584 literal strings separated by the @code{"|"} character or the reserved word
3585 @code{others}, and the @code{"=>"} token.
3586 When the case expression is a typed string variable, each literal string must
3587 belong to the string type that is the type of the case variable.
3588 After each @code{=>}, there are zero or more declarations. The only
3589 declarations allowed in a case construction are other case constructions,
3590 attribute declarations and variable declarations. String type declarations and
3591 package declarations are not allowed. Variable declarations are restricted to
3592 variables that have already been declared before the case construction.
3595 case_construction ::=
3596 @i{case} @i{<variable_>}name @i{is} @{case_item@} @i{end case} ;
3599 @i{when} discrete_choice_list =>
3601 | attribute_declaration
3602 | variable_declaration
3603 | empty_declaration@}
3605 discrete_choice_list ::= string_literal @{| string_literal@} | @i{others}
3609 Here is a typical example, with a typed string variable:
3611 @smallexample @c projectfile
3613 @b{project} MyProj @b{is}
3614 @b{type} OS_Type @b{is} ("GNU/Linux", "Unix", "NT", "VMS");
3615 OS : OS_Type := @b{external} ("OS", "GNU/Linux");
3617 @b{package} Compiler @b{is}
3619 @b{when} "GNU/Linux" | "Unix" =>
3620 @b{for} Switches ("Ada")
3623 @b{for} Switches ("Ada")
3625 @b{when} @b{others} =>
3633 @c ---------------------------------------------
3635 @subsection Attributes
3636 @c ---------------------------------------------
3639 * Project Level Attributes::
3640 * Package Binder Attributes::
3641 * Package Builder Attributes::
3643 * Package Check Attributes::
3645 * Package Clean Attributes::
3646 * Package Compiler Attributes::
3647 * Package Cross_Reference Attributes::
3649 * Package Eliminate Attributes::
3651 * Package Finder Attributes::
3652 * Package gnatls Attributes::
3654 * Package gnatstub Attributes::
3656 * Package IDE Attributes::
3657 * Package Install Attributes::
3658 * Package Linker Attributes::
3660 * Package Metrics Attribute::
3662 * Package Naming Attributes::
3664 * Package Pretty_Printer Attributes::
3666 * Package Remote Attributes::
3667 * Package Stack Attributes::
3668 * Package Synchronize Attributes::
3672 A project (and its packages) may have @b{attributes} that define
3673 the project's properties. Some attributes have values that are strings;
3674 others have values that are string lists.
3677 attribute_declaration ::=
3678 simple_attribute_declaration | indexed_attribute_declaration
3679 simple_attribute_declaration ::= @i{for} attribute_designator @i{use} expression ;
3680 indexed_attribute_declaration ::=
3681 @i{for} @i{<indexed_attribute_>}simple_name ( string_literal) @i{use} expression ;
3682 attribute_designator ::=
3683 @i{<simple_attribute_>}simple_name
3684 | @i{<indexed_attribute_>}simple_name ( string_literal )
3688 There are two categories of attributes: @b{simple attributes}
3689 and @b{indexed attributes}.
3690 Each simple attribute has a default value: the empty string (for string
3691 attributes) and the empty list (for string list attributes).
3692 An attribute declaration defines a new value for an attribute, and overrides
3693 the previous value. The syntax of a simple attribute declaration is similar to
3694 that of an attribute definition clause in Ada.
3696 Some attributes are indexed. These attributes are mappings whose
3697 domain is a set of strings. They are declared one association
3698 at a time, by specifying a point in the domain and the corresponding image
3700 Like untyped variables and simple attributes, indexed attributes
3701 may be declared several times. Each declaration supplies a new value for the
3702 attribute, and replaces the previous setting.
3704 Here are some examples of attribute declarations:
3706 @smallexample @c projectfile
3707 --@i{ simple attributes}
3708 @b{for} Object_Dir @b{use} "objects";
3709 @b{for} Source_Dirs @b{use} ("units", "test/drivers");
3711 --@i{ indexed attributes}
3712 @b{for} Body ("main") @b{use} "Main.ada";
3713 @b{for} Switches ("main.ada")
3714 @b{use} ("-v", "-gnatv");
3715 @b{for} Switches ("main.ada") @b{use} Builder'Switches ("main.ada") & "-g";
3717 --@i{ indexed attributes copy (from package Builder in project Default)}
3718 --@i{ The package name must always be specified, even if it is the current}
3720 @b{for} Default_Switches @b{use} Default.Builder'Default_Switches;
3724 Attributes references may appear anywhere in expressions, and are used
3725 to retrieve the value previously assigned to the attribute. If an attribute
3726 has not been set in a given package or project, its value defaults to the
3727 empty string or the empty list, with some exceptions.
3730 attribute_reference ::=
3731 attribute_prefix ' @i{<simple_attribute>_}simple_name [ (string_literal) ]
3732 attribute_prefix ::= @i{project}
3733 | @i{<project_>}simple_name
3734 | package_identifier
3735 | @i{<project_>}simple_name . package_identifier
3741 @smallexample @c projectfile
3742 @b{project}'Object_Dir
3743 Naming'Dot_Replacement
3744 Imported_Project'Source_Dirs
3745 Imported_Project.Naming'Casing
3746 Builder'Default_Switches ("Ada")
3749 The exceptions to the empty defaults are:
3752 @item Object_Dir: default is "."
3753 @item Exec_Dir: default is 'Object_Dir, that is the value of attribute
3754 Object_Dir in the same project, declared or defaulted.
3755 @item Source_Dirs: default is (".")
3759 The prefix of an attribute may be:
3762 @item @code{project} for an attribute of the current project
3763 @item The name of an existing package of the current project
3764 @item The name of an imported project
3765 @item The name of a parent project that is extended by the current project
3766 @item An expanded name whose prefix is imported/parent project name,
3767 and whose selector is a package name
3773 In the following sections, all predefined attributes are succinctly described,
3774 first the project level attributes, that is those attributes that are not in a
3775 package, then the attributes in the different packages.
3777 It is possible for different tools to dynamically create new packages with
3778 attributes, or new attributes in predefined packages. These attributes are
3779 not documented here.
3781 The attributes under Configuration headings are usually found only in
3782 configuration project files.
3784 The characteristics of each attribute are indicated as follows:
3788 @item @b{Type of value}
3790 The value of an attribute may be a single string, indicated by the word
3791 "single", or a string list, indicated by the word "list".
3795 When the attribute is read-only, that is when it is not allowed to declare
3796 the attribute, this is indicated by the words "read-only".
3798 @item @b{Optional index}
3800 If it is allowed in the value of the attribute (both single and list) to have
3801 an optional index, this is indicated by the words "optional index".
3803 @item @b{Indexed attribute}
3805 When an it is an indexed attribute, this is indicated by the word "indexed".
3807 @item @b{Case-sensitivity of the index}
3809 For an indexed attribute, if the index is case-insensitive, this is indicated
3810 by the words "case-insensitive index".
3812 @item @b{File name index}
3814 For an indexed attribute, when the index is a file name, this is indicated by
3815 the words "file name index". The index may or may not be case-sensitive,
3816 depending on the platform.
3818 @item @b{others allowed in index}
3820 For an indexed attribute, if it is allowed to use @b{others} as the index,
3821 this is indicated by the words "others allowed".
3823 When @b{others} is used as the index of an indexed attribute, the value of
3824 the attribute indexed by @b{others} is used when no other index would apply.
3828 @node Project Level Attributes
3829 @subsubsection Project Level Attributes
3838 @item @b{Name}: single, read-only
3840 The name of the project.
3842 @item @b{Project_Dir}: single, read-only
3844 The path name of the project directory.
3846 @item @b{Main}: list, optional index
3848 The list of main sources for the executables.
3850 @item @b{Languages}: list
3852 The list of languages of the sources of the project.
3854 @item @b{Roots}: list, indexed, file name index
3856 The index is the file name of an executable source. Indicates the list of units
3857 from the main project that need to be bound and linked with their closures
3858 with the executable. The index is either a file name, a language name or "*".
3859 The roots for an executable source are those in @b{Roots} with an index that
3860 is the executable source file name, if declared. Otherwise, they are those in
3861 @b{Roots} with an index that is the language name of the executable source,
3862 if present. Otherwise, they are those in @b{Roots ("*")}, if declared. If none
3863 of these three possibilities are declared, then there are no roots for the
3866 @item @b{Externally_Built}: single
3868 Indicates if the project is externally built.
3869 Only case-insensitive values allowed are "true" and "false", the default.
3874 @item @b{Directories}
3878 @item @b{Object_Dir}: single
3880 Indicates the object directory for the project.
3882 @item @b{Exec_Dir}: single
3884 Indicates the exec directory for the project, that is the directory where the
3887 @item @b{Source_Dirs}: list
3889 The list of source directories of the project.
3891 @item @b{Inherit_Source_Path}: list, indexed, case-insensitive index
3893 Index is a language name. Value is a list of language names. Indicates that
3894 in the source search path of the index language the source directories of
3895 the languages in the list should be included.
3899 for Inherit_Source_Path ("C++") use ("C");
3901 @item @b{Exclude_Source_Dirs}: list
3903 The list of directories that are included in Source_Dirs but are not source
3904 directories of the project.
3906 @item @b{Ignore_Source_Sub_Dirs}: list
3908 Value is a list of simple names for subdirectories that are removed from the
3909 list of source directories, including theur subdirectories.
3913 @item @b{Source Files}
3917 @item @b{Source_Files}: list
3919 Value is a list of source file simple names.
3921 @item @b{Locally_Removed_Files}: list
3923 Obsolescent. Equivalent to Excluded_Source_Files.
3925 @item @b{Excluded_Source_Files}: list
3927 Value is a list of simple file names that are not sources of the project.
3928 Allows to remove sources that are inherited or found in the source directories
3929 and that match the naming scheme.
3931 @item @b{Source_List_File}: single
3933 Value is a text file name that contains a list of source file simple names,
3936 @item @b{Excluded_Source_List_File}: single
3938 Value is a text file name that contains a list of file simple names that
3939 are not sources of the project.
3941 @item @b{Interfaces}: list
3943 Value is a list of file names that constitutes the interfaces of the project.
3947 @item @b{Aggregate Projects}
3951 @item @b{Project_Files}: list
3953 Value is the list of aggregated projects.
3955 @item @b{Project_Path}: list
3957 Value is a list of directories that are added to the project search path when
3958 looking for the aggregated projects.
3960 @item @b{External}: single, indexed
3962 Index is the name of an external reference. Value is the value of the
3963 external reference to be used when parsing the aggregated projects.
3971 @item @b{Library_Dir}: single
3973 Value is the name of the library directory. This attribute needs to be
3974 declared for each library project.
3976 @item @b{Library_Name}: single
3978 Value is the name of the library. This attribute needs to be declared or
3979 inherited for each library project.
3981 @item @b{Library_Kind}: single
3983 Specifies the kind of library: static library (archive) or shared library.
3984 Case-insensitive values must be one of "static" for archives (the default) or
3985 "dynamic" or "relocatable" for shared libraries.
3987 @item @b{Library_Version}: single
3989 Value is the name of the library file.
3991 @item @b{Library_Interface}: list
3993 Value is the list of unit names that constitutes the interfaces
3994 of a Stand-Alone Library project.
3996 @item @b{Library_Standalone}: single
3998 Specifies if a Stand-Alone Library (SAL) is encapsulated or not.
3999 Only authorized case-insensitive values are "standard" for non encapsulated
4000 SALs, "encapsulated" for encapsulated SALs or "no" for non SAL library project.
4002 @item @b{Library_Encapsulated_Options}: list
4004 Value is a list of options that need to be used when linking an encapsulated
4005 Stand-Alone Library.
4007 @item @b{Library_Encapsulated_Supported}: single
4009 Indicates if encapsulated Stand-Alone Libraries are supported. Only
4010 authorized case-insensitive values are "true" and "false" (the default).
4012 @item @b{Library_Auto_Init}: single
4014 Indicates if a Stand-Alone Library is auto-initialized. Only authorized
4015 case-insentive values are "true" and "false".
4017 @item @b{Leading_Library_Options}: list
4019 Value is a list of options that are to be used at the beginning of
4020 the command line when linking a shared library.
4022 @item @b{Library_Options}: list
4024 Value is a list of options that are to be used when linking a shared library.
4026 @item @b{Library_Rpath_Options}: list, indexed, case-insensitive index
4028 Index is a language name. Value is a list of options for an invocation of the
4029 compiler of the language. This invocation is done for a shared library project
4030 with sources of the language. The output of the invocation is the path name
4031 of a shared library file. The directory name is to be put in the run path
4032 option switch when linking the shared library for the project.
4034 @item @b{Library_Src_Dir}: single
4036 Value is the name of the directory where copies of the sources of the
4037 interfaces of a Stand-Alone Library are to be copied.
4039 @item @b{Library_ALI_Dir}: single
4041 Value is the name of the directory where the ALI files of the interfaces
4042 of a Stand-Alone Library are to be copied. When this attribute is not declared,
4043 the directory is the library directory.
4045 @item @b{Library_gcc}: single
4047 Obsolescent attribute. Specify the linker driver used to link a shared library.
4048 Use instead attribute Linker'Driver.
4050 @item @b{Library_Symbol_File}: single
4052 Value is the name of the library symbol file.
4054 @item @b{Library_Symbol_Policy}: single
4056 Indicates the symbol policy kind. Only authorized case-insensitive values are
4057 "autonomous", "default", "compliant", "controlled" or "direct".
4059 @item @b{Library_Reference_Symbol_File}: single
4061 Value is the name of the reference symbol file.
4065 @item @b{Configuration - General}
4069 @item @b{Default_Language}: single
4071 Value is the case-insensitive name of the language of a project when attribute
4072 Languages is not specified.
4074 @item @b{Run_Path_Option}: list
4076 Value is the list of switches to be used when specifying the run path option
4079 @item @b{Run_Path_Origin}: single
4081 Value is the the string that may replace the path name of the executable
4082 directory in the run path options.
4084 @item @b{Separate_Run_Path_Options}: single
4086 Indicates if there may be several run path options specified when linking an
4087 executable. Only authorized case-insensitive values are "true" or "false" (the
4090 @item @b{Toolchain_Version}: single, indexed, case-insensitive index
4092 Index is a language name. Specify the version of a toolchain for a language.
4094 @item @b{Toolchain_Description}: single, indexed, case-insensitive index
4096 Obsolescent. No longer used.
4098 @item @b{Object_Generated}: single, indexed, case-insensitive index
4100 Index is a language name. Indicates if invoking the compiler for a language
4101 produces an object file. Only authorized case-insensitive values are "false"
4102 and "true" (the default).
4104 @item @b{Objects_Linked}: single, indexed, case-insensitive index
4106 Index is a language name. Indicates if the object files created by the compiler
4107 for a language need to be linked in the executable. Only authorized
4108 case-insensitive values are "false" and "true" (the default).
4110 @item @b{Target}: single
4112 Value is the name of the target platform.
4116 @item @b{Configuration - Libraries}
4120 @item @b{Library_Builder}: single
4122 Value is the path name of the application that is to be used to build
4123 libraries. Usually the path name of "gprlib".
4125 @item @b{Library_Support}: single
4127 Indicates the level of support of libraries. Only authorized case-insensitive
4128 values are "static_only", "full" or "none" (the default).
4132 @item @b{Configuration - Archives}
4136 @item @b{Archive_Builder}: list
4138 Value is the name of the application to be used to create a static library
4139 (archive), followed by the options to be used.
4141 @item @b{Archive_Builder_Append_Option}: list
4143 Value is the list of options to be used when invoking the archive builder
4144 to add project files into an archive.
4146 @item @b{Archive_Indexer}: list
4148 Value is the name of the archive indexer, followed by the required options.
4150 @item @b{Archive_Suffix}: single
4152 Value is the extension of archives. When not declared, the extension is ".a".
4154 @item @b{Library_Partial_Linker}: list
4156 Value is the name of the partial linker executable, followed by the required
4161 @item @b{Configuration - Shared Libraries}
4165 @item @b{Shared_Library_Prefix}: single
4167 Value is the prefix in the name of shared library files. When not declared,
4168 the prefix is "lib".
4170 @item @b{Shared_Library_Suffix}: single
4172 Value is the the extension of the name of shared library files. When not
4173 declared, the extension is ".so".
4175 @item @b{Symbolic_Link_Supported}: single
4177 Indicates if symbolic links are supported on the platform. Only authorized
4178 case-insensitive values are "true" and "false" (the default).
4180 @item @b{Library_Major_Minor_Id_Supported}: single
4182 Indicates if major and minor ids for shared library names are supported on
4183 the platform. Only authorized case-insensitive values are "true" and "false"
4186 @item @b{Library_Auto_Init_Supported}: single
4188 Indicates if auto-initialization of Stand-Alone Libraries is supported. Only
4189 authorized case-insensitive values are "true" and "false" (the default).
4191 @item @b{Shared_Library_Minimum_Switches}: list
4193 Value is the list of required switches when linking a shared library.
4195 @item @b{Library_Version_Switches}: list
4197 Value is the list of switches to specify a internal name for a shared library.
4199 @item @b{Library_Install_Name_Option}: single
4201 Value is the name of the option that needs to be used, concatenated with the
4202 path name of the library file, when linking a shared library.
4204 @item @b{Runtime_Library_Dir}: single, indexed, case-insensitive index
4206 Index is a language name. Value is the path name of the directory where the
4207 runtime libraries are located.
4209 @item @b{Runtime_Source_Dir}: single, indexed, case-insensitive index
4211 Index is a language name. Value is the path name of the directory where the
4212 sources of runtime libraries are located.
4218 @node Package Binder Attributes
4219 @subsubsection Package Binder Attributes
4227 @item @b{Default_Switches}: list, indexed, case-insensitive index
4229 Index is a language name. Value is the list of switches to be used when binding
4230 code of the language, if there is no applicable attribute Switches.
4232 @item @b{Switches}: list, optional index, indexed,
4233 case-insensitive index, others allowed
4235 Index is either a language name or a source file name. Value is the list of
4236 switches to be used when binding code. Index is either the source file name
4237 of the executable to be bound or the language name of the code to be bound.
4241 @item @b{Configuration - Binding}
4245 @item @b{Driver}: single, indexed, case-insensitive index
4247 Index is a language name. Value is the name of the application to be used when
4248 binding code of the language.
4250 @item @b{Required_Switches}: list, indexed, case-insensitive index
4252 Index is a language name. Value is the list of the required switches to be
4253 used when binding code of the language.
4255 @item @b{Prefix}: single, indexed, case-insensitive index
4257 Index is a language name. Value is a prefix to be used for the binder exchange
4258 file name for the language. Used to have different binder exchange file names
4259 when binding different languages.
4261 @item @b{Objects_Path}: single,indexed, case-insensitive index
4263 Index is a language name. Value is the name of the environment variable that
4264 contains the path for the object directories.
4266 @item @b{Object_Path_File}: single,indexed, case-insensitive index
4268 Index is a language name. Value is the name of the environment variable. The
4269 value of the environment variable is the path name of a text file that
4270 contains the list of object directories.
4276 @node Package Builder Attributes
4277 @subsubsection Package Builder Attributes
4281 @item @b{Default_Switches}: list, indexed, case-insensitive index
4283 Index is a language name. Value is the list of builder switches to be used when
4284 building an executable of the language, if there is no applicable attribute
4287 @item @b{Switches}: list, optional index, indexed, case-insensitive index,
4290 Index is either a language name or a source file name. Value is the list of
4291 builder switches to be used when building an executable. Index is either the
4292 source file name of the executable to be built or its language name.
4294 @item @b{Global_Compilation_Switches}: list, optional index, indexed,
4295 case-insensitive index
4297 Index is either a language name or a source file name. Value is the list of
4298 compilation switches to be used when building an executable. Index is either
4299 the source file name of the executable to be built or its language name.
4301 @item @b{Executable}: single, indexed, case-insensitive index
4303 Index is an executable source file name. Value is the simple file name of the
4304 executable to be built.
4306 @item @b{Executable_Suffix}: single
4308 Value is the extension of the file names of executable. When not specified,
4309 the extension is the default extension of executables on the platform.
4311 @item @b{Global_Configuration_Pragmas}: single
4313 Value is the file name of a configuration pragmas file that is specified to
4314 the Ada compiler when compiling any Ada source in the project tree.
4316 @item @b{Global_Config_File}: single, indexed, case-insensitive index
4318 Index is a language name. Value is the file name of a configuration file that
4319 is specified to the compiler when compiling any source of the language in the
4325 @node Package Check Attributes
4326 @subsubsection Package Check Attributes
4330 @item @b{Default_Switches}: list, indexed, case-insensitive index
4332 Index is a language name. Value is a list of switches to be used when invoking
4333 @code{gnatcheck} for a source of the language, if there is no applicable
4336 @item @b{Switches}: list, optional index, indexed, case-insensitive index,
4339 Index is a source file name. Value is the list of switches to be used when
4340 invoking @code{gnatcheck} for the source.
4345 @node Package Clean Attributes
4346 @subsubsection Package Clean Attributes
4350 @item @b{Switches}: list
4352 Value is a list of switches to be used by the cleaning application.
4354 @item @b{Source_Artifact_Extensions}: list, indexed, case-insensitive index
4356 Index is a language names. Value is the list of extensions for file names
4357 derived from object file names that need to be cleaned in the object
4358 directory of the project.
4360 @item @b{Object_Artifact_Extensions}: list, indexed, case-insensitive index
4362 Index is a language names. Value is the list of extensions for file names
4363 derived from source file names that need to be cleaned in the object
4364 directory of the project.
4366 @item @b{Artifacts_In_Object_Dir}: single
4368 Value is a list of file names expressed as regular expressions that are to be
4369 deleted by gprclean in the object directory of the project.
4371 @item @b{Artifacts_In_Exec_Dir}: single
4373 Value is list of file names expressed as regular expressions that are to be
4374 deleted by gprclean in the exec directory of the main project.
4378 @node Package Compiler Attributes
4379 @subsubsection Package Compiler Attributes
4387 @item @b{Default_Switches}: list, indexed, case-insensitive index
4389 Index is a language name. Value is a list of switches to be used when invoking
4390 the compiler for the language for a source of the project, if there is no
4391 applicable attribute Switches.
4393 @item @b{Switches}: list, optional index, indexed, case-insensitive index,
4396 Index is a source file name or a language name. Value is the list of switches
4397 to be used when invoking the compiler for the source or for its language.
4399 @item @b{Local_Configuration_Pragmas}: single
4401 Value is the file name of a configuration pragmas file that is specified to
4402 the Ada compiler when compiling any Ada source in the project.
4404 @item @b{Local_Config_File}: single, indexed, case-insensitive index
4406 Index is a language name. Value is the file name of a configuration file that
4407 is specified to the compiler when compiling any source of the language in the
4412 @item @b{Configuration - Compiling}
4416 @item @b{Driver}: single, indexed, case-insensitive index
4418 Index is a language name. Value is the name of the executable for the compiler
4421 @item @b{Language_Kind}: single, indexed, case-insensitive index
4423 Index is a language name. Indicates the kind of the language, either file based
4424 or unit based. Only authorized case-insensitive values are "unit_based" and
4425 "file_based" (the default).
4427 @item @b{Dependency_Kind}: single, indexed, case-insensitive index
4429 Index is a language name. Indicates how the dependencies are handled for the
4430 language. Only authorized case-insensitive values are "makefile", "ali_file",
4431 "ali_closure" or "none" (the default).
4433 @item @b{Required_Switches}: list, indexed, case-insensitive index
4435 Equivalent to attribute Leading_Required_Switches.
4437 @item @b{Leading_Required_Switches}: list, indexed, case-insensitive index
4439 Index is a language name. Value is the list of the minimum switches to be used
4440 at the beginning of the command line when invoking the compiler for the
4443 @item @b{Trailing_Required_Switches}: list, indexed, case-insensitive index
4445 Index is a language name. Value is the list of the minimum switches to be used
4446 at the end of the command line when invoking the compiler for the language.
4448 @item @b{PIC_Option}: list, indexed, case-insensitive index
4450 Index is a language name. Value is the list of switches to be used when
4451 compiling a source of the language when the project is a shared library
4454 @item @b{Path_Syntax}: single, indexed, case-insensitive index
4456 Index is a language name. Value is the kind of path syntax to be used when
4457 invoking the compiler for the language. Only authorized case-insensitive
4458 values are "canonical" and "host" (the default).
4460 @item @b{Source_File_Switches}: single, indexed, case-insensitive index
4462 Index is a language name. Value is a list of switches to be used just before
4463 the path name of the source to compile when invoking the compiler for a source
4466 @item @b{Object_File_Suffix}: single, indexed, case-insensitive index
4468 Index is a language name. Value is the extension of the object files created
4469 by the compiler of the language. When not specified, the extension is the
4470 default one for the platform.
4472 @item @b{Object_File_Switches}: list, indexed, case-insensitive index
4474 Index is a language name. Value is the list of switches to be used by the
4475 compiler of the language to specify the path name of the object file. When not
4476 specified, the switch used is "-o".
4478 @item @b{Multi_Unit_Switches}: list, indexed, case-insensitive index
4480 Index is a language name. Value is the list of switches to be used to compile
4481 a unit in a multi unit source of the language. The index of the unit in the
4482 source is concatenated with the last switches in the list.
4484 @item @b{Multi_Unit_Object_Separator}: single, indexed, case-insensitive index
4486 Index is a language name. Value is the string to be used in the object file
4487 name before the index of the unit, when compiling a unit in a multi unit source
4492 @item @b{Configuration - Mapping Files}
4496 @item @b{Mapping_File_Switches}: list, indexed, case-insensitive index
4498 Index is a language name. Value is the list of switches to be used to specify
4499 a mapping file when invoking the compiler for a source of the language.
4501 @item @b{Mapping_Spec_Suffix}: single, indexed, case-insensitive index
4503 Index is a language name. Value is the suffix to be used in a mapping file
4504 to indicate that the source is a spec.
4506 @item @b{Mapping_Body_Suffix}: single, indexed, case-insensitive index
4508 Index is a language name. Value is the suffix to be used in a mapping file
4509 to indicate that the source is a body.
4513 @item @b{Configuration - Config Files}
4517 @item @b{Config_File_Switches}: list: single, indexed, case-insensitive index
4519 Index is a language name. Value is the list of switches to specify to the
4520 compiler of the language a configuration file.
4522 @item @b{Config_Body_File_Name}: single, indexed, case-insensitive index
4524 Index is a language name. Value is the template to be used to indicate a
4525 configuration specific to a body of the language in a configuration
4528 @item @b{Config_Body_File_Name_Index}: single, indexed, case-insensitive index
4530 Index is a language name. Value is the template to be used to indicate a
4531 configuration specific to the body a unit in a multi unit source of the
4532 language in a configuration file.
4534 @item @b{Config_Body_File_Name_Pattern}: single, indexed,
4535 case-insensitive index
4537 Index is a language name. Value is the template to be used to indicate a
4538 configuration for all bodies of the languages in a configuration file.
4540 @item @b{Config_Spec_File_Name}: single, indexed, case-insensitive index
4542 Index is a language name. Value is the template to be used to indicate a
4543 configuration specific to a spec of the language in a configuration
4546 @item @b{Config_Spec_File_Name_Index}: single, indexed, case-insensitive index
4548 Index is a language name. Value is the template to be used to indicate a
4549 configuration specific to the spec a unit in a multi unit source of the
4550 language in a configuration file.
4552 @item @b{Config_Spec_File_Name_Pattern}: single, indexed,
4553 case-insensitive index
4555 Index is a language name. Value is the template to be used to indicate a
4556 configuration for all specs of the languages in a configuration file.
4558 @item @b{Config_File_Unique}: single, indexed, case-insensitive index
4560 Index is a language name. Indicates if there should be only one configuration
4561 file specified to the compiler of the language. Only authorized
4562 case-insensitive values are "true" and "false" (the default).
4566 @item @b{Configuration - Dependencies}
4570 @item @b{Dependency_Switches}: list, indexed, case-insensitive index
4572 Index is a language name. Value is the list of switches to be used to specify
4573 to the compiler the dependency file when the dependency kind of the language is
4574 file based, and when Dependency_Driver is not specified for the language.
4576 @item @b{Dependency_Driver}: list, indexed, case-insensitive index
4578 Index is a language name. Value is the name of the executable to be used to
4579 create the dependency file for a source of the language, followed by the
4584 @item @b{Configuration - Search Paths}
4588 @item @b{Include_Switches}: list, indexed, case-insensitive index
4590 Index is a language name. Value is the list of switches to specify to the
4591 compiler of the language to indicate a directory to look for sources.
4593 @item @b{Include_Path}: single, indexed, case-insensitive index
4595 Index is a language name. Value is the name of an environment variable that
4596 contains the path of all the directories that the compiler of the language
4597 may search for sources.
4599 @item @b{Include_Path_File}: single, indexed, case-insensitive index
4601 Index is a language name. Value is the name of an environment variable the
4602 value of which is the path name of a text file that contains the directories
4603 that the compiler of the language may search for sources.
4605 @item @b{Object_Path_Switches}: list, indexed, case-insensitive index
4607 Index is a language name. Value is the list of switches to specify to the
4608 compiler of the language the name of a text file that contains the list of
4609 object directories. When this attribute is not declared, the text file is
4616 @node Package Cross_Reference Attributes
4617 @subsubsection Package Cross_Reference Attributes
4621 @item @b{Default_Switches}: list, indexed, case-insensitive index
4623 Index is a language name. Value is a list of switches to be used when invoking
4624 @code{gnatxref} for a source of the language, if there is no applicable
4627 @item @b{Switches}: list, optional index, indexed, case-insensitive index,
4630 Index is a source file name. Value is the list of switches to be used when
4631 invoking @code{gnatxref} for the source.
4636 @node Package Eliminate Attributes
4637 @subsubsection Package Eliminate Attributes
4641 @item @b{Default_Switches}: list, indexed, case-insensitive index
4643 Index is a language name. Value is a list of switches to be used when invoking
4644 @code{gnatelim} for a source of the language, if there is no applicable
4647 @item @b{Switches}: list, optional index, indexed, case-insensitive index,
4650 Index is a source file name. Value is the list of switches to be used when
4651 invoking @code{gnatelim} for the source.
4656 @node Package Finder Attributes
4657 @subsubsection Package Finder Attributes
4661 @item @b{Default_Switches}: list, indexed, case-insensitive index
4663 Index is a language name. Value is a list of switches to be used when invoking
4664 @code{gnatfind} for a source of the language, if there is no applicable
4667 @item @b{Switches}: list, optional index, indexed, case-insensitive index,
4670 Index is a source file name. Value is the list of switches to be used when
4671 invoking @code{gnatfind} for the source.
4675 @node Package gnatls Attributes
4676 @subsubsection Package gnatls Attributes
4680 @item @b{Switches}: list
4682 Value is a list of switches to be used when invoking @code{gnatls}.
4687 @node Package gnatstub Attributes
4688 @subsubsection Package gnatstub Attributes
4692 @item @b{Default_Switches}: list, indexed, case-insensitive index
4694 Index is a language name. Value is a list of switches to be used when invoking
4695 @code{gnatstub} for a source of the language, if there is no applicable
4698 @item @b{Switches}: list, optional index, indexed, case-insensitive index,
4701 Index is a source file name. Value is the list of switches to be used when
4702 invoking @code{gnatstub} for the source.
4707 @node Package IDE Attributes
4708 @subsubsection Package IDE Attributes
4712 @item @b{Default_Switches}: list, indexed
4714 Index is the name of an external tool that the GNAT Programming System (GPS)
4715 is supporting. Value is a list of switches to use when invoking that tool.
4717 @item @b{Remote_Host}: single
4719 Value is a string that designates the remote host in a cross-compilation
4720 environment, to be used for remote compilation and debugging. This attribute
4721 should not be specified when running on the local machine.
4723 @item @b{Program_Host}: single
4725 Value is a string that specifies the name of IP address of the embedded target
4726 in a cross-compilation environment, on which the program should execute.
4728 @item @b{Communication_Protocol}: single
4730 Value is the name of the protocol to use to communicate with the target
4731 in a cross-compilation environment, for example @code{"wtx"} or
4734 @item @b{Compiler_Command}: single, indexed, case-insensitive index
4736 Index is a language Name. Value is a string that denotes the command to be
4737 used to invoke the compiler. The value of @code{Compiler_Command ("Ada")} is
4738 expected to be compatible with @command{gnatmake}, in particular in
4739 the handling of switches.
4741 @item @b{Debugger_Command}: single
4743 Value is a string that specifies the name of the debugger to be used, such as
4744 gdb, powerpc-wrs-vxworks-gdb or gdb-4.
4746 @item @b{gnatlist}: single
4748 Value is a string that specifies the name of the @command{gnatls} utility
4749 to be used to retrieve information about the predefined path; for example,
4750 @code{"gnatls"}, @code{"powerpc-wrs-vxworks-gnatls"}.
4752 @item @b{VCS_Kind}: single
4754 Value is a string used to specify the Version Control System (VCS) to be used
4755 for this project, for example "Subversion", "ClearCase". If the
4756 value is set to "Auto", the IDE will try to detect the actual VCS used
4757 on the list of supported ones.
4759 @item @b{VCS_File_Check}: single
4761 Value is a string that specifies the command used by the VCS to check
4762 the validity of a file, either when the user explicitly asks for a check,
4763 or as a sanity check before doing the check-in.
4765 @item @b{VCS_Log_Check}: single
4767 Value is a string that specifies the command used by the VCS to check
4768 the validity of a log file.
4770 @item @b{Documentation_Dir}: single
4772 Value is the directory used to generate the documentation of source code.
4776 @node Package Install Attributes
4777 @subsubsection Package Install Attributes
4781 @item @b{Prefix}: single
4783 Value is the install destination directory.
4785 @item @b{Sources_Subdir}: single
4787 Value is the sources directory or subdirectory of Prefix.
4789 @item @b{Exec_Subdir}: single
4791 Value is the executables directory or subdirectory of Prefix.
4793 @item @b{Lib_Subdir}: single
4795 Value is library directory or subdirectory of Prefix.
4797 @item @b{Project_Subdir}: single
4799 Value is the project directory or subdirectory of Prefix.
4801 @item @b{Active}: single
4803 Indicates that the project is to be installed or not. Case-insensitive value
4804 "false" means that the project is not to be installed, all other values mean
4805 that the project is to be installed.
4809 @node Package Linker Attributes
4810 @subsubsection Package Linker Attributes
4818 @item @b{Required_Switches}: list
4820 Value is a list of switches that are required when invoking the linker to link
4823 @item @b{Default_Switches}: list, indexed, case-insensitive index
4825 Index is a language name. Value is a list of switches for the linker when
4826 linking an executable for a main source of the language, when there is no
4827 applicable Switches.
4829 @item @b{Leading_Switches}: list, optional index, indexed,
4830 case-insensitive index, others allowed
4832 Index is a source file name or a language name. Value is the list of switches
4833 to be used at the beginning of the command line when invoking the linker to
4834 build an executable for the source or for its language.
4836 @item @b{Switches}: list, optional index, indexed, case-insensitive index,
4839 Index is a source file name or a language name. Value is the list of switches
4840 to be used when invoking the linker to build an executable for the source or
4843 @item @b{Trailing_Switches}: list, optional index, indexed,
4844 case-insensitive index, others allowed
4846 Index is a source file name or a language name. Value is the list of switches
4847 to be used at the end of the command line when invoking the linker to
4848 build an executable for the source or for its language. These switches may
4849 override the Required_Switches.
4851 @item @b{Linker_Options}: list
4853 Value is a list of switches/options that are to be added when linking an
4854 executable from a project importing the current project directly or indirectly.
4855 Linker_Options are not used when linking an executable from the current
4858 @item @b{Map_File_Option}: single
4860 Value is the switch to specify the map file name that the linker needs to
4865 @item @b{Configuration - Linking}
4869 @item @b{Driver}: single
4871 Value is the name of the linker executable.
4875 @item @b{Configuration - Response Files}
4879 @item @b{Max_Command_Line_Length}: single
4881 Value is the maximum number of character in the command line when invoking
4882 the linker to link an executable.
4884 @item @b{Response_File_Format}: single
4886 Indicates the kind of response file to create when the length of the linking
4887 command line is too large. Only authorized case-insensitive values are "none",
4888 "gnu", "object_list", "gcc_gnu", "gcc_option_list" and "gcc_object_list".
4890 @item @b{Response_File_Switches}: list
4892 Value is the list of switches to specify a response file to the linker.
4899 @node Package Metrics Attribute
4900 @subsubsection Package Metrics Attribute
4904 @item @b{Default_Switches}: list, indexed, case-insensitive index
4906 Index is a language name. Value is a list of switches to be used when invoking
4907 @code{gnatmetric} for a source of the language, if there is no applicable
4910 @item @b{Switches}: list, optional index, indexed, case-insensitive index,
4913 Index is a source file name. Value is the list of switches to be used when
4914 invoking @code{gnatmetric} for the source.
4919 @node Package Naming Attributes
4920 @subsubsection Package Naming Attributes
4924 @item @b{Specification_Suffix}: single, indexed, case-insensitive index
4926 Equivalent to attribute Spec_Suffix.
4928 @item @b{Spec_Suffix}: single, indexed, case-insensitive index
4930 Index is a language name. Value is the extension of file names for specs of
4933 @item @b{Implementation_Suffix}: single, indexed, case-insensitive index
4935 Equivalent to attribute Body_Suffix.
4937 @item @b{Body_Suffix}: single, indexed, case-insensitive index
4939 Index is a language name. Value is the extension of file names for bodies of
4942 @item @b{Separate_Suffix}: single
4944 Value is the extension of file names for subunits of Ada.
4946 @item @b{Casing}: single
4948 Indicates the casing of sources of the Ada language. Only authorized
4949 case-insensitive values are "lowercase", "uppercase" and "mixedcase".
4951 @item @b{Dot_Replacement}: single
4953 Value is the string that replace the dot of unit names in the source file names
4954 of the Ada language.
4956 @item @b{Specification}: single, optional index, indexed,
4957 case-insensitive index
4959 Equivalent to attribute Spec.
4961 @item @b{Spec}: single, optional index, indexed, case-insensitive index
4963 Index is a unit name. Value is the file name of the spec of the unit.
4965 @item @b{Implementation}: single, optional index, indexed,
4966 case-insensitive index
4968 Equivalent to attribute Body.
4970 @item @b{Body}: single, optional index, indexed, case-insensitive index
4972 Index is a unit name. Value is the file name of the body of the unit.
4974 @item @b{Specification_Exceptions}: list, indexed, case-insensitive index
4976 Index is a language name. Value is a list of specs for the language that do not
4977 necessarily follow the naming scheme for the language and that may or may not
4978 be found in the source directories of the project.
4980 @item @b{Implementation_Exceptions}: list, indexed, case-insensitive index
4982 Index is a language name. Value is a list of bodies for the language that do not
4983 necessarily follow the naming scheme for the language and that may or may not
4984 be found in the source directories of the project.
4989 @node Package Pretty_Printer Attributes
4990 @subsubsection Package Pretty_Printer Attributes
4994 @item @b{Default_Switches}: list, indexed, case-insensitive index
4996 Index is a language name. Value is a list of switches to be used when invoking
4997 @code{gnatpp} for a source of the language, if there is no applicable
5000 @item @b{Switches}: list, optional index, indexed, case-insensitive index,
5003 Index is a source file name. Value is the list of switches to be used when
5004 invoking @code{gnatpp} for the source.
5009 @node Package Remote Attributes
5010 @subsubsection Package Remote Attributes
5014 @item @b{Included_Patterns}: list
5016 If this attribute is defined it sets the patterns to
5017 synchronized from the master to the slaves. It is exclusive
5018 with Excluded_Patterns, that is it is an error to define
5021 @item @b{Included_Artifact_Patterns}: list
5023 If this attribute is defined it sets the patterns of compilation
5024 artifacts to synchronized from the slaves to the build master.
5025 This attribute replace the default hard-coded patterns.
5027 @item @b{Excluded_Patterns}: list
5029 Set of patterns to ignore when synchronizing sources from the build
5030 master to the slaves. A set of predefined patterns are supported
5031 (e.g. *.o, *.ali, *.exe, etc.), this attributes make it possible to
5032 add some more patterns.
5034 @item @b{Root_Dir}: single
5036 Value is the root directory used by the slave machines.
5040 @node Package Stack Attributes
5041 @subsubsection Package Stack Attributes
5045 @item @b{Switches}: list
5047 Value is the list of switches to be used when invoking @code{gnatstack}.
5051 @node Package Synchronize Attributes
5052 @subsubsection Package Synchronize Attributes
5056 @item @b{Default_Switches}: list, indexed, case-insensitive index
5058 Index is a language name. Value is a list of switches to be used when invoking
5059 @code{gnatsync} for a source of the language, if there is no applicable
5062 @item @b{Switches}: list, optional index, indexed, case-insensitive index,
5065 Index is a source file name. Value is the list of switches to be used when
5066 invoking @code{gnatsync} for the source.