1 @set gprconfig GPRconfig
3 @c ------ projects.texi
4 @c Copyright (C) 2002-2013, 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^/PROJECT_FILE=^@emph{projectfile}} and
84 @option{^-X^/EXTERNAL_REFERENCE=^@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
99 all OS dependencies in a small number of implementation units.
101 Project files can be used to achieve some of the effects of a source
102 versioning system (for example, defining separate projects for
103 the different sets of sources that comprise different releases) but the
104 Project Manager is independent of any source configuration management tool
105 that might be used by the developers.
107 The various sections below introduce the different concepts related to
108 projects. Each section starts with examples and use cases, and then goes into
109 the details of related project file capabilities.
111 @c ---------------------------------------------
112 @node Building With Projects
113 @section Building With Projects
114 @c ---------------------------------------------
117 In its simplest form, a unique project is used to build a single executable.
118 This section concentrates on such a simple setup. Later sections will extend
119 this basic model to more complex setups.
121 The following concepts are the foundation of project files, and will be further
122 detailed later in this documentation. They are summarized here as a reference.
125 @item @b{Project file}:
126 A text file using an Ada-like syntax, generally using the @file{.gpr}
127 extension. It defines build-related characteristics of an application.
128 The characteristics include the list of sources, the location of those
129 sources, the location for the generated object files, the name of
130 the main program, and the options for the various tools involved in the
133 @item @b{Project attribute}:
134 A specific project characteristic is defined by an attribute clause. Its
135 value is a string or a sequence of strings. All settings in a project
136 are defined through a list of predefined attributes with precise
137 semantics. @xref{Attributes}.
139 @item @b{Package in a project}:
140 Global attributes are defined at the top level of a project.
141 Attributes affecting specific tools are grouped in a
142 package whose name is related to tool's function. The most common
143 packages are @code{Builder}, @code{Compiler}, @code{Binder},
144 and @code{Linker}. @xref{Packages}.
146 @item @b{Project variables}:
147 In addition to attributes, a project can use variables to store intermediate
148 values and avoid duplication in complex expressions. It can be initialized
149 with a value coming from the environment.
150 A frequent use of variables is to define scenarios.
151 @xref{External Values}, @xref{Scenarios in Projects}, and @xref{Variables}.
153 @item @b{Source files} and @b{source directories}:
154 A source file is associated with a language through a naming convention. For
155 instance, @code{foo.c} is typically the name of a C source file;
156 @code{bar.ads} or @code{bar.1.ada} are two common naming conventions for a
157 file containing an Ada spec. A compilation unit is often composed of a main
158 source file and potentially several auxiliary ones, such as header files in C.
159 The naming conventions can be user defined @xref{Naming Schemes}, and will
160 drive the builder to call the appropriate compiler for the given source file.
161 Source files are searched for in the source directories associated with the
162 project through the @b{Source_Dirs} attribute. By default, all the files (in
163 these source directories) following the naming conventions associated with the
164 declared languages are considered to be part of the project. It is also
165 possible to limit the list of source files using the @b{Source_Files} or
166 @b{Source_List_File} attributes. Note that those last two attributes only
167 accept basenames with no directory information.
169 @item @b{Object files} and @b{object directory}:
170 An object file is an intermediate file produced by the compiler from a
171 compilation unit. It is used by post-compilation tools to produce
172 final executables or libraries. Object files produced in the context of
173 a given project are stored in a single directory that can be specified by the
174 @b{Object_Dir} attribute. In order to store objects in
175 two or more object directories, the system must be split into
176 distinct subsystems with their own project file.
180 The following subsections introduce gradually all the attributes of interest
181 for simple build needs. Here is the simple setup that will be used in the
184 The Ada source files @file{pack.ads}, @file{pack.adb}, and @file{proc.adb} are in
185 the @file{common/} directory. The file @file{proc.adb} contains an Ada main
186 subprogram @code{Proc} that @code{with}s package @code{Pack}. We want to compile
187 these source files with the switch @option{-O2}, and put the resulting files in
188 the directory @file{obj/}.
198 ^common/release/^[COMMON.RELEASE]^
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. This is the only settings that are needed by all
240 the tools that will use this project (builder, compiler, binder and linker for
241 the compilation, IDEs to edit the source files,@dots{}).
243 @cindex Source directories
244 First step is to declare the source directories, which are the directories
245 to be searched to find source files. In the case of the example,
246 the @file{common} directory is the only source directory.
248 @cindex @code{Source_Dirs}
249 There are several ways of defining source directories:
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 specific platform. For instance, when the same project
268 file is to be used both on Unix and Windows, "/" should be used as the
269 directory separator rather than "\".
271 @item The attribute @b{Source_Dirs} can automatically include subdirectories
272 using a special syntax inspired by some UNIX shells. If any of the path in
273 the list ends with @emph{"**"}, then that path and all its subdirectories
274 (recursively) are included in the list of source directories. For instance,
275 @file{**} and @file{./**} represent the complete directory tree rooted at ".".
276 @cindex Source directories, recursive
278 @cindex @code{Excluded_Source_Dirs}
279 When using that construct, it can sometimes be convenient to also use the
280 attribute @b{Excluded_Source_Dirs}, which is also a list of paths. Each entry
281 specifies a directory whose immediate content, not including subdirs, is to
282 be excluded. It is also possible to exclude a complete directory subtree
283 using the "**" notation.
285 @cindex @code{Ignore_Source_Sub_Dirs}
286 It is often desirable to remove, from the source directories, directory
287 subtrees rooted at some subdirectories. An example is the subdirectories
288 created by a Version Control System such as Subversion that creates directory
289 subtrees rooted at subdirectories ".svn". To do that, attribute
290 @b{Ignore_Source_Sub_Dirs} can be used. It specifies the list of simple
291 file names for the roots of these undesirable directory subtrees.
294 @b{for} Source_Dirs @b{use} ("./**");
295 @b{for} Ignore_Source_Sub_Dirs @b{use} (".svn");
301 When applied to the simple example, and because we generally prefer to have
302 the project file at the toplevel directory rather than mixed with the sources,
303 we will create the following file
307 @b{project} Build @b{is}
308 @b{for} Source_Dirs @b{use} ("common"); -- <<<<
313 Once source directories have been specified, one may need to indicate
314 source files of interest. By default, all source files present in the source
315 directories are considered by the project manager. When this is not desired,
316 it is possible to specify the list of sources to consider explicitly.
317 In such a case, only source file base names are indicated and not
318 their absolute or relative path names. The project manager is in charge of
319 locating the specified source files in the specified source directories.
322 @item By default, the project manager search for all source files of all
323 specified languages in all the source directories.
325 Since the project manager was initially developed for Ada environments, the
326 default language is usually Ada and the above project file is complete: it
327 defines without ambiguity the sources composing the project: that is to say,
328 all the sources in subdirectory "common" for the default language (Ada) using
329 the default naming convention.
331 @cindex @code{Languages}
332 However, when compiling a multi-language application, or a pure C
333 application, the project manager must be told which languages are of
334 interest, which is done by setting the @b{Languages} attribute to a list of
335 strings, each of which is the name of a language. Tools like
336 @command{gnatmake} only know about Ada, while other tools like
337 @command{gprbuild} know about many more languages such as C, C++, Fortran,
338 assembly and others can be added dynamically.
340 @cindex Naming scheme
341 Even when using only Ada, the default naming might not be suitable. Indeed,
342 how does the project manager recognizes an "Ada file" from any other
343 file? Project files can describe the naming scheme used for source files,
344 and override the default (@pxref{Naming Schemes}). The default is the
345 standard GNAT extension (@file{.adb} for bodies and @file{.ads} for
346 specs), which is what is used in our example, explaining why no naming scheme
347 is explicitly specified.
348 @xref{Naming Schemes}.
350 @item @code{Source_Files}
351 @cindex @code{Source_Files}
352 In some cases, source directories might contain files that should not be
353 included in a project. One can specify the explicit list of file names to
354 be considered through the @b{Source_Files} attribute.
355 When this attribute is defined, instead of looking at every file in the
356 source directories, the project manager takes only those names into
357 consideration reports errors if they cannot be found in the source
358 directories or does not correspond to the naming scheme.
360 @item For various reasons, it is sometimes useful to have a project with no
361 sources (most of the time because the attributes defined in the project
362 file will be reused in other projects, as explained in
363 @pxref{Organizing Projects into Subsystems}. To do this, the attribute
364 @emph{Source_Files} is set to the empty list, i.e. @code{()}. Alternatively,
365 @emph{Source_Dirs} can be set to the empty list, with the same
368 @item @code{Source_List_File}
369 @cindex @code{Source_List_File}
370 If there is a great number of files, it might be more convenient to use
371 the attribute @b{Source_List_File}, which specifies the full path of a file.
372 This file must contain a list of source file names (one per line, no
373 directory information) that are searched as if they had been defined
374 through @emph{Source_Files}. Such a file can easily be created through
377 A warning is issued if both attributes @code{Source_Files} and
378 @code{Source_List_File} are given explicit values. In this case, the
379 attribute @code{Source_Files} prevails.
381 @item @code{Excluded_Source_Files}
382 @cindex @code{Excluded_Source_Files}
383 @cindex @code{Locally_Removed_Files}
384 @cindex @code{Excluded_Source_List_File}
385 Specifying an explicit list of files is not always convenient.It might be
386 more convenient to use the default search rules with specific exceptions.
387 This can be done thanks to the attribute @b{Excluded_Source_Files}
388 (or its synonym @b{Locally_Removed_Files}).
389 Its value is the list of file names that should not be taken into account.
390 This attribute is often used when extending a project,
391 @xref{Project Extension}. A similar attribute
392 @b{Excluded_Source_List_File} plays the same
393 role but takes the name of file containing file names similarly to
394 @code{Source_List_File}.
399 In most simple cases, such as the above example, the default source file search
400 behavior provides the expected result, and we do not need to add anything after
401 setting @code{Source_Dirs}. The project manager automatically finds
402 @file{pack.ads}, @file{pack.adb} and @file{proc.adb} as source files of the
405 Note that by default a warning is issued when a project has no sources attached
406 to it and this is not explicitly indicated in the project file.
408 @c ---------------------------------------------
409 @node Duplicate Sources in Projects
410 @subsection Duplicate Sources in Projects
411 @c ---------------------------------------------
414 If the order of the source directories is known statically, that is if
415 @code{"/**"} is not used in the string list @code{Source_Dirs}, then there may
416 be several files with the same source file name sitting in different
417 directories of the project. In this case, only the file in the first directory
418 is considered as a source of the project and the others are hidden. If
419 @code{"/**"} is used in the string list @code{Source_Dirs}, it is an error
420 to have several files with the same source file name in the same directory
421 @code{"/**"} subtree, since there would be an ambiguity as to which one should
422 be used. However, two files with the same source file name may exist in two
423 single directories or directory subtrees. In this case, the one in the first
424 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} and @command{gprbuild}).
453 If the attribute @code{Object_Dir} is not specified, it defaults to
454 the project directory, that is the directory containing the project file.
456 For our example, we can specify the object dir in this way:
459 @b{project} Build @b{is}
460 @b{for} Source_Dirs @b{use} ("common");
461 @b{for} Object_Dir @b{use} "obj"; -- <<<<
466 As mentioned earlier, there is a single object directory per project. As a
467 result, if you have an existing system where the object files are spread in
468 several directories, you can either move all of them into the same directory if
469 you want to build it with a single project file, or study the section on
470 subsystems (@pxref{Organizing Projects into Subsystems}) to see how each
471 separate object directory can be associated with one of the subsystem
472 constituting the application.
474 When the @command{linker} is called, it usually creates an executable. By
475 default, this executable is placed in the object directory of the project. It
476 might be convenient to store it in its own directory.
478 @cindex @code{Exec_Dir}
479 This can be done through the @code{Exec_Dir} attribute, which, like
480 @emph{Object_Dir} contains a single absolute or relative path and must point to
481 an existing and writable directory, unless you ask the tool to create it on
482 your behalf. When not specified, It defaults to the object directory and
483 therefore to the project file's directory if neither @emph{Object_Dir} nor
484 @emph{Exec_Dir} was specified.
486 In the case of the example, let's place the executable in the root
487 of the hierarchy, ie the same directory as @file{build.gpr}. Hence
488 the project file is now
491 @b{project} Build @b{is}
492 @b{for} Source_Dirs @b{use} ("common");
493 @b{for} Object_Dir @b{use} "obj";
494 @b{for} Exec_Dir @b{use} "."; -- <<<<
498 @c ---------------------------------------------
499 @node Main Subprograms
500 @subsection Main Subprograms
501 @c ---------------------------------------------
504 In the previous section, executables were mentioned. The project manager needs
505 to be taught what they are. In a project file, an executable is indicated by
506 pointing to source file of the main subprogram. In C this is the file that
507 contains the @code{main} function, and in Ada the file that contains the main
510 There can be any number of such main files within a given project, and thus
511 several executables can be built in the context of a single project file. Of
512 course, one given executable might not (and in fact will not) need all the
513 source files referenced by the project. As opposed to other build environments
514 such as @command{makefile}, one does not need to specify the list of
515 dependencies of each executable, the project-aware builders knows enough of the
516 semantics of the languages to build ands link only the necessary elements.
519 The list of main files is specified via the @b{Main} attribute. It contains
520 a list of file names (no directories). If a project defines this
521 attribute, it is not necessary to identify main files on the
522 command line when invoking a builder, and editors like
523 @command{GPS} will be able to create extra menus to spawn or debug the
524 corresponding executables.
527 @b{project} Build @b{is}
528 @b{for} Source_Dirs @b{use} ("common");
529 @b{for} Object_Dir @b{use} "obj";
530 @b{for} Exec_Dir @b{use} ".";
531 @b{for} Main @b{use} ("proc.adb"); -- <<<<
536 If this attribute is defined in the project, then spawning the builder
537 with a command such as
540 gnatmake ^-Pbuild^/PROJECT_FILE=build^
544 automatically builds all the executables corresponding to the files
545 listed in the @emph{Main} attribute. It is possible to specify one
546 or more executables on the command line to build a subset of them.
548 @c ---------------------------------------------
549 @node Tools Options in Project Files
550 @subsection Tools Options in Project Files
551 @c ---------------------------------------------
554 We now have a project file that fully describes our environment, and can be
555 used to build the application with a simple @command{gnatmake} command as seen
556 in the previous section. In fact, the empty project we showed immediately at
557 the beginning (with no attribute at all) could already fulfill that need if it
558 was put in the @file{common} directory.
560 Of course, we always want more control. This section will show you how to
561 specify the compilation switches that the various tools involved in the
562 building of the executable should use.
564 @cindex command line length
565 Since source names and locations are described into the project file, it is not
566 necessary to use switches on the command line for this purpose (switches such
567 as -I for gcc). This removes a major source of command line length overflow.
568 Clearly, the builders will have to communicate this information one way or
569 another to the underlying compilers and tools they call but they usually use
570 response files for this and thus should not be subject to command line
573 Several tools are participating to the creation of an executable: the compiler
574 produces object files from the source files; the binder (in the Ada case)
575 creates an source file that takes care, among other things, of elaboration
576 issues and global variables initialization; and the linker gathers everything
577 into a single executable that users can execute. All these tools are known by
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 which 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
637 @option{-O2} switch, 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
657 @b{package} Compiler @b{is}
658 @b{for} Default_Switches ("Ada") @b{use} ("-O2");
659 @b{for} Switches ("proc.adb") @b{use} ("-O0");
664 @code{Switches} may take a pattern as an index, such as in:
667 @b{package} Compiler @b{is}
668 @b{for} Default_Switches ("Ada") @b{use} ("-O2");
669 @b{for} Switches ("pkg*") @b{use} ("-O0");
674 Sources @file{pkg.adb} and @file{pkg-child.adb} would be compiled with -O0,
678 @code{Switches} can also be given a language name as index instead of a file
679 name in which case it has the same semantics as @emph{Default_Switches}.
680 However, indexes with wild cards are never valid for language name.
682 @item @b{Local_Configuration_Pragmas}:
683 @cindex @code{Local_Configuration_Pragmas}
684 this attribute may specify the path
685 of a file containing configuration pragmas for use by the Ada compiler,
686 such as @code{pragma Restrictions (No_Tasking)}. These pragmas will be
687 used for all the sources of the project.
691 The switches for the other tools are defined in a similar manner through the
692 @b{Default_Switches} and @b{Switches} attributes, respectively in the
693 @emph{Builder} package (for @command{gnatmake} and @command{gprbuild}),
694 the @emph{Binder} package (binding Ada executables) and the @emph{Linker}
695 package (for linking executables).
697 @c ---------------------------------------------
698 @node Compiling with Project Files
699 @subsection Compiling with Project Files
700 @c ---------------------------------------------
703 Now that our project files are written, let's build our executable.
704 Here is the command we would use from the command line:
707 gnatmake ^-Pbuild^/PROJECT_FILE=build^
711 This will automatically build the executables specified through the
712 @emph{Main} attribute: for each, it will compile or recompile the
713 sources for which the object file does not exist or is not up-to-date; it
714 will then run the binder; and finally run the linker to create the
717 @command{gnatmake} only knows how to handle Ada files. By using
718 @command{gprbuild} as a builder, you could automatically manage C files the
719 same way: create the file @file{utils.c} in the @file{common} directory,
720 set the attribute @emph{Languages} to @code{"(Ada, C)"}, and run
723 gprbuild ^-Pbuild^/PROJECT_FILE=build^
727 Gprbuild knows how to recompile the C files and will
728 recompile them only if one of their dependencies has changed. No direct
729 indication on how to build the various elements is given in the
730 project file, which describes the project properties rather than a
731 set of actions to be executed. Here is the invocation of
732 @command{gprbuild} when building a multi-language program:
745 Notice the three steps described earlier:
748 @item The first three gcc commands correspond to the compilation phase.
749 @item The gprbind command corresponds to the post-compilation phase.
750 @item The last gcc command corresponds to the final link.
755 @cindex @option{-v} option (for GPRbuild)
756 The default output of GPRbuild's execution is kept reasonably simple and easy
757 to understand. In particular, some of the less frequently used commands are not
758 shown, and some parameters are abbreviated. So it is not possible to rerun the
759 effect of the @command{gprbuild} command by cut-and-pasting its output.
760 GPRbuild's option @code{-v} provides a much more verbose output which includes,
761 among other information, more complete compilation, post-compilation and link
764 @c ---------------------------------------------
765 @node Executable File Names
766 @subsection Executable File Names
767 @c ---------------------------------------------
770 @cindex @code{Executable}
771 By default, the executable name corresponding to a main file is
772 computed from the main source file name. Through the attribute
773 @b{Builder.Executable}, it is possible to change this default.
775 For instance, instead of building @command{proc} (or @command{proc.exe}
776 on Windows), we could configure our project file to build "proc1"
777 (resp proc1.exe) with the following addition:
779 @smallexample @c projectfile
781 ... -- same as before
783 for Executable ("proc.adb") use "proc1";
789 @cindex @code{Executable_Suffix}
790 Attribute @b{Executable_Suffix}, when specified, may change the suffix
791 of the executable files, when no attribute @code{Executable} applies:
792 its value replace the platform-specific executable suffix.
793 The default executable suffix is empty on UNIX and ".exe" on Windows.
795 It is also possible to change the name of the produced executable by using the
796 command line switch @option{-o}. When several mains are defined in the project,
797 it is not possible to use the @option{-o} switch and the only way to change the
798 names of the executable is provided by Attributes @code{Executable} and
799 @code{Executable_Suffix}.
801 @c ---------------------------------------------
802 @node Avoid Duplication With Variables
803 @subsection Avoid Duplication With Variables
804 @c ---------------------------------------------
807 To illustrate some other project capabilities, here is a slightly more complex
808 project using similar sources and a main program in C:
810 @smallexample @c projectfile
812 for Languages use ("Ada", "C");
813 for Source_Dirs use ("common");
814 for Object_Dir use "obj";
815 for Main use ("main.c");
817 C_Switches := ("-pedantic");
818 for Default_Switches ("C") use C_Switches;
819 for Default_Switches ("Ada") use ("-gnaty");
820 for Switches ("main.c") use C_Switches & ("-g");
826 This project has many similarities with the previous one.
827 As expected, its @code{Main} attribute now refers to a C source.
828 The attribute @emph{Exec_Dir} is now omitted, thus the resulting
829 executable will be put in the directory @file{obj}.
831 The most noticeable difference is the use of a variable in the
832 @emph{Compiler} package to store settings used in several attributes.
833 This avoids text duplication, and eases maintenance (a single place to
834 modify if we want to add new switches for C files). We will revisit
835 the use of variables in the context of scenarios (@pxref{Scenarios in
838 In this example, we see how the file @file{main.c} can be compiled with
839 the switches used for all the other C files, plus @option{-g}.
840 In this specific situation the use of a variable could have been
841 replaced by a reference to the @code{Default_Switches} attribute:
843 @smallexample @c projectfile
844 for Switches ("c_main.c") use Compiler'Default_Switches ("C") & ("-g");
848 Note the tick (@emph{'}) used to refer to attributes defined in a package.
850 Here is the output of the GPRbuild command using this project:
854 gcc -c -pedantic -g main.c
855 gcc -c -gnaty proc.adb
856 gcc -c -gnaty pack.adb
857 gcc -c -pedantic utils.c
864 The default switches for Ada sources,
865 the default switches for C sources (in the compilation of @file{lib.c}),
866 and the specific switches for @file{main.c} have all been taken into
869 @c ---------------------------------------------
871 @subsection Naming Schemes
872 @c ---------------------------------------------
875 Sometimes an Ada software system is ported from one compilation environment to
876 another (say GNAT), and the file are not named using the default GNAT
877 conventions. Instead of changing all the file names, which for a variety of
878 reasons might not be possible, you can define the relevant file naming scheme
879 in the @b{Naming} package of your project file.
881 The naming scheme has two distinct goals for the project manager: it
882 allows finding of source files when searching in the source
883 directories, and given a source file name it makes it possible to guess
884 the associated language, and thus the compiler to use.
886 Note that the use by the Ada compiler of pragmas Source_File_Name is not
887 supported when using project files. You must use the features described in this
888 paragraph. You can however specify other configuration pragmas.
890 The following attributes can be defined in package @code{Naming}:
894 @cindex @code{Casing}
895 Its value must be one of @code{"lowercase"} (the default if
896 unspecified), @code{"uppercase"} or @code{"mixedcase"}. It describes the
897 casing of file names with regards to the Ada unit name. Given an Ada unit
898 My_Unit, the file name will respectively be @file{my_unit.adb} (lowercase),
899 @file{MY_UNIT.ADB} (uppercase) or @file{My_Unit.adb} (mixedcase).
900 On Windows, file names are case insensitive, so this attribute is
903 @item @b{Dot_Replacement}:
904 @cindex @code{Dot_Replacement}
905 This attribute specifies the string that should replace the "." in unit
906 names. Its default value is @code{"-"} so that a unit
907 @code{Parent.Child} is expected to be found in the file
908 @file{parent-child.adb}. The replacement string must satisfy the following
909 requirements to avoid ambiguities in the naming scheme:
912 @item It must not be empty
913 @item It cannot start or end with an alphanumeric character
914 @item It cannot be a single underscore
915 @item It cannot start with an underscore followed by an alphanumeric
916 @item It cannot contain a dot @code{'.'} except if the entire string
921 @item @b{Spec_Suffix} and @b{Specification_Suffix}:
922 @cindex @code{Spec_Suffix}
923 @cindex @code{Specification_Suffix}
924 For Ada, these attributes give the suffix used in file names that contain
925 specifications. For other languages, they give the extension for files
926 that contain declaration (header files in C for instance). The attribute
927 is indexed on the language.
928 The two attributes are equivalent, but the latter is obsolescent.
930 If the value of the attribute is the empty string, it indicates to the
931 Project Manager that the only specifications/header files for the language
932 are those specified with attributes @code{Spec} or
933 @code{Specification_Exceptions}.
935 If @code{Spec_Suffix ("Ada")} is not specified, then the default is
936 @code{"^.ads^.ADS^"}.
938 A non empty value must satisfy the following requirements:
941 @item It must include at least one dot
942 @item If @code{Dot_Replacement} is a single dot, then it cannot include
946 @item @b{Body_Suffix} and @b{Implementation_Suffix}:
947 @cindex @code{Body_Suffix}
948 @cindex @code{Implementation_Suffix}
949 These attributes give the extension used for file names that contain
950 code (bodies in Ada). They are indexed on the language. The second
951 version is obsolescent and fully replaced by the first attribute.
953 For each language of a project, one of these two attributes need to be
954 specified, either in the project itself or in the configuration project file.
956 If the value of the attribute is the empty string, it indicates to the
957 Project Manager that the only source files for the language
958 are those specified with attributes @code{Body} or
959 @code{Implementation_Exceptions}.
961 These attributes must satisfy the same requirements as @code{Spec_Suffix}.
962 In addition, they must be different from any of the values in
964 If @code{Body_Suffix ("Ada")} is not specified, then the default is
965 @code{"^.adb^.ADB^"}.
967 If @code{Body_Suffix ("Ada")} and @code{Spec_Suffix ("Ada")} end with the
968 same string, then a file name that ends with the longest of these two
969 suffixes will be a body if the longest suffix is @code{Body_Suffix ("Ada")}
970 or a spec if the longest suffix is @code{Spec_Suffix ("Ada")}.
972 If the suffix does not start with a '.', a file with a name exactly equal to
973 the suffix will also be part of the project (for instance if you define the
974 suffix as @code{Makefile.in}, a file called @file{Makefile.in} will be part
975 of the project. This capability is usually not interesting when building.
976 However, it might become useful when a project is also used to
977 find the list of source files in an editor, like the GNAT Programming System
980 @item @b{Separate_Suffix}:
981 @cindex @code{Separate_Suffix}
982 This attribute is specific to Ada. It denotes the suffix used in file names
983 that contain separate bodies. If it is not specified, then it defaults to
984 same value as @code{Body_Suffix ("Ada")}.
986 The value of this attribute cannot be the empty string.
988 Otherwise, the same rules apply as for the
989 @code{Body_Suffix} attribute. The only accepted index is "Ada".
991 @item @b{Spec} or @b{Specification}:
993 @cindex @code{Specification}
994 This attribute @code{Spec} can be used to define the source file name for a
995 given Ada compilation unit's spec. The index is the literal name of the Ada
996 unit (case insensitive). The value is the literal base name of the file that
997 contains this unit's spec (case sensitive or insensitive depending on the
998 operating system). This attribute allows the definition of exceptions to the
999 general naming scheme, in case some files do not follow the usual
1002 When a source file contains several units, the relative position of the unit
1003 can be indicated. The first unit in the file is at position 1
1005 @smallexample @c projectfile
1006 for Spec ("MyPack.MyChild") use "mypack.mychild.spec";
1007 for Spec ("top") use "foo.a" at 1;
1008 for Spec ("foo") use "foo.a" at 2;
1011 @item @b{Body} or @b{Implementation}:
1013 @cindex @code{Implementation}
1014 These attribute play the same role as @emph{Spec} for Ada bodies.
1016 @item @b{Specification_Exceptions} and @b{Implementation_Exceptions}:
1017 @cindex @code{Specification_Exceptions}
1018 @cindex @code{Implementation_Exceptions}
1019 These attributes define exceptions to the naming scheme for languages
1020 other than Ada. They are indexed on the language name, and contain
1021 a list of file names respectively for headers and source code.
1026 For example, the following package models the Apex file naming rules:
1028 @smallexample @c projectfile
1031 for Casing use "lowercase";
1032 for Dot_Replacement use ".";
1033 for Spec_Suffix ("Ada") use ".1.ada";
1034 for Body_Suffix ("Ada") use ".2.ada";
1041 For example, the following package models the DEC Ada file naming rules:
1043 @smallexample @c projectfile
1046 for Casing use "lowercase";
1047 for Dot_Replacement use "__";
1048 for Spec_Suffix ("Ada") use "_.ada";
1049 for Body_Suffix ("Ada") use ".ada";
1055 (Note that @code{Casing} is @code{"lowercase"} because GNAT gets the file
1056 names in lower case)
1059 @c ---------------------------------------------
1061 @subsection Installation
1062 @c ---------------------------------------------
1065 After building an application or a library it is often required to
1066 install it into the development environment. For instance this step is
1067 required if the library is to be used by another application.
1068 The @command{gprinstall} tool provides an easy way to install
1069 libraries, executable or object code generated during the build. The
1070 @b{Install} package can be used to change the default locations.
1072 The following attributes can be defined in package @code{Install}:
1078 Whether the project is to be installed, values are @code{true}
1079 (default) or @code{false}.
1082 @cindex @code{Prefix}
1084 Root directory for the installation.
1086 @item @b{Exec_Subdir}
1088 Subdirectory of @b{Prefix} where executables are to be
1089 installed. Default is @b{bin}.
1091 @item @b{Lib_Subdir}
1093 Subdirectory of @b{Prefix} where directory with the library or object
1094 files is to be installed. Default is @b{lib}.
1096 @item @b{Sources_Subdir}
1098 Subdirectory of @b{Prefix} where directory with sources is to be
1099 installed. Default is @b{include}.
1101 @item @b{Project_Subdir}
1103 Subdirectory of @b{Prefix} where the generated project file is to be
1104 installed. Default is @b{share/gpr}.
1107 @c ---------------------------------------------
1108 @node Distributed support
1109 @subsection Distributed support
1110 @c ---------------------------------------------
1113 For large projects the compilation time can become a limitation in
1114 the development cycle. To cope with that, GPRbuild supports
1115 distributed compilation.
1117 The following attributes can be defined in package @code{Remote}:
1122 @cindex @code{Root_Dir}
1124 Root directory of the project's sources. The default value is the
1125 project's directory.
1129 @c ---------------------------------------------
1130 @node Organizing Projects into Subsystems
1131 @section Organizing Projects into Subsystems
1132 @c ---------------------------------------------
1135 A @b{subsystem} is a coherent part of the complete system to be built. It is
1136 represented by a set of sources and one single object directory. A system can
1137 be composed of a single subsystem when it is simple as we have seen in the
1138 first section. Complex systems are usually composed of several interdependent
1139 subsystems. A subsystem is dependent on another subsystem if knowledge of the
1140 other one is required to build it, and in particular if visibility on some of
1141 the sources of this other subsystem is required. Each subsystem is usually
1142 represented by its own project file.
1144 In this section, the previous example is being extended. Let's assume some
1145 sources of our @code{Build} project depend on other sources.
1146 For instance, when building a graphical interface, it is usual to depend upon
1147 a graphical library toolkit such as GtkAda. Furthermore, we also need
1148 sources from a logging module we had previously written.
1151 * Project Dependencies::
1152 * Cyclic Project Dependencies::
1153 * Sharing Between Projects::
1154 * Global Attributes::
1157 @c ---------------------------------------------
1158 @node Project Dependencies
1159 @subsection Project Dependencies
1160 @c ---------------------------------------------
1163 GtkAda comes with its own project file (appropriately called
1164 @file{gtkada.gpr}), and we will assume we have already built a project
1165 called @file{logging.gpr} for the logging module. With the information provided
1166 so far in @file{build.gpr}, building the application would fail with an error
1167 indicating that the gtkada and logging units that are relied upon by the sources
1168 of this project cannot be found.
1170 This is easily solved by adding the following @b{with} clauses at the beginning
1173 @smallexample @c projectfile
1175 with "a/b/logging.gpr";
1182 @cindex @code{Externally_Built}
1183 When such a project is compiled, @command{gnatmake} will automatically
1184 check the other projects and recompile their sources when needed. It will also
1185 recompile the sources from @code{Build} when needed, and finally create the
1186 executable. In some cases, the implementation units needed to recompile a
1187 project are not available, or come from some third-party and you do not want to
1188 recompile it yourself. In this case, the attribute @b{Externally_Built} to
1189 "true" can be set, indicating to the builder that this project can be assumed
1190 to be up-to-date, and should not be considered for recompilation. In Ada, if
1191 the sources of this externally built project were compiled with another version
1192 of the compiler or with incompatible options, the binder will issue an error.
1194 The project's @code{with} clause has several effects. It provides source
1195 visibility between projects during the compilation process. It also guarantees
1196 that the necessary object files from @code{Logging} and @code{GtkAda} are
1197 available when linking @code{Build}.
1199 As can be seen in this example, the syntax for importing projects is similar
1200 to the syntax for importing compilation units in Ada. However, project files
1201 use literal strings instead of names, and the @code{with} clause identifies
1202 project files rather than packages.
1204 Each literal string after @code{with} is the path
1205 (absolute or relative) to a project file. The @code{.gpr} extension is
1206 optional, although we recommend adding it. If no extension is specified,
1207 and no project file with the @file{^.gpr^.GPR^} extension is found, then
1208 the file is searched for exactly as written in the @code{with} clause,
1209 that is with no extension.
1211 As mentioned above, the path after a @code{with} has to be a literal
1212 string, and you cannot use concatenation, or lookup the value of external
1213 variables to change the directories from which a project is loaded.
1214 A solution if you need something like this is to use aggregate projects
1215 (@pxref{Aggregate Projects}).
1217 @cindex project path
1218 When a relative path or a base name is used, the
1219 project files are searched relative to each of the directories in the
1220 @b{project path}. This path includes all the directories found with the
1221 following algorithm, in that order, as soon as a matching file is found,
1225 @item First, the file is searched relative to the directory that contains the
1226 current project file.
1229 @cindex @code{GPR_PROJECT_PATH_FILE}
1230 @cindex @code{GPR_PROJECT_PATH}
1231 @cindex @code{ADA_PROJECT_PATH}
1232 Then it is searched relative to all the directories specified in the
1233 ^environment variables^logical names^ @b{GPR_PROJECT_PATH_FILE},
1234 @b{GPR_PROJECT_PATH} and @b{ADA_PROJECT_PATH} (in that order) if they exist.
1235 The value of @b{GPR_PROJECT_PATH_FILE}, when defined, is the path name of
1236 a text file that contains project directory path names, one per line.
1237 @b{GPR_PROJECT_PATH} and @b{ADA_PROJECT_PATH}, when defined, contain
1238 project directory path names separated by directory separators.
1239 @b{ADA_PROJECT_PATH} is used for compatibility, it is recommended to
1240 use @b{GPR_PROJECT_PATH_FILE} or @b{GPR_PROJECT_PATH}.
1242 @item Finally, it is searched relative to the default project directories.
1243 Such directories depends on the tool used. The different locations searched
1244 in the specified order are:
1247 @item @file{<prefix>/<target>/lib/gnat}
1248 (for @command{gnatmake} in all cases, and for @command{gprbuild} if option
1249 @option{--target} is specified)
1250 @item @file{<prefix>/share/gpr/}
1251 (for @command{gnatmake} and @command{gprbuild})
1252 @item @file{<prefix>/lib/gnat/}
1253 (for @command{gnatmake} and @command{gprbuild})
1256 In our example, @file{gtkada.gpr} is found in the predefined directory if
1257 it was installed at the same root as GNAT.
1261 Some tools also support extending the project path from the command line,
1262 generally through the @option{-aP}. You can see the value of the project
1263 path by using the @command{gnatls -v} command.
1265 Any symbolic link will be fully resolved in the directory of the
1266 importing project file before the imported project file is examined.
1268 Any source file in the imported project can be used by the sources of the
1269 importing project, transitively.
1270 Thus if @code{A} imports @code{B}, which imports @code{C}, the sources of
1271 @code{A} may depend on the sources of @code{C}, even if @code{A} does not
1272 import @code{C} explicitly. However, this is not recommended, because if
1273 and when @code{B} ceases to import @code{C}, some sources in @code{A} will
1274 no longer compile. @command{gprbuild} has a switch @option{--no-indirect-imports}
1275 that will report such indirect dependencies.
1277 One very important aspect of a project hierarchy is that
1278 @b{a given source can only belong to one project} (otherwise the project manager
1279 would not know which settings apply to it and when to recompile it). It means
1280 that different project files do not usually share source directories or
1281 when they do, they need to specify precisely which project owns which sources
1282 using attribute @code{Source_Files} or equivalent. By contrast, 2 projects
1283 can each own a source with the same base file name as long as they live in
1284 different directories. The latter is not true for Ada Sources because of the
1285 correlation between source files and Ada units.
1287 @c ---------------------------------------------
1288 @node Cyclic Project Dependencies
1289 @subsection Cyclic Project Dependencies
1290 @c ---------------------------------------------
1293 Cyclic dependencies are mostly forbidden:
1294 if @code{A} imports @code{B} (directly or indirectly) then @code{B}
1295 is not allowed to import @code{A}. However, there are cases when cyclic
1296 dependencies would be beneficial. For these cases, another form of import
1297 between projects exists: the @b{limited with}. A project @code{A} that
1298 imports a project @code{B} with a straight @code{with} may also be imported,
1299 directly or indirectly, by @code{B} through a @code{limited with}.
1301 The difference between straight @code{with} and @code{limited with} is that
1302 the name of a project imported with a @code{limited with} cannot be used in the
1303 project importing it. In particular, its packages cannot be renamed and
1304 its variables cannot be referred to.
1306 @smallexample @c 0projectfile
1310 For Exec_Dir use B'Exec_Dir; -- ok
1313 limited with "a.gpr"; -- Cyclic dependency: A -> B -> A
1315 For Exec_Dir use A'Exec_Dir; -- not ok
1322 limited with "a.gpr"; -- Cyclic dependency: A -> C -> D -> A
1324 For Exec_Dir use A'Exec_Dir; -- not ok
1328 @c ---------------------------------------------
1329 @node Sharing Between Projects
1330 @subsection Sharing Between Projects
1331 @c ---------------------------------------------
1334 When building an application, it is common to have similar needs in several of
1335 the projects corresponding to the subsystems under construction. For instance,
1336 they will all have the same compilation switches.
1338 As seen before (@pxref{Tools Options in Project Files}), setting compilation
1339 switches for all sources of a subsystem is simple: it is just a matter of
1340 adding a @code{Compiler.Default_Switches} attribute to each project files with
1341 the same value. Of course, that means duplication of data, and both places need
1342 to be changed in order to recompile the whole application with different
1343 switches. It can become a real problem if there are many subsystems and thus
1344 many project files to edit.
1346 There are two main approaches to avoiding this duplication:
1349 @item Since @file{build.gpr} imports @file{logging.gpr}, we could change it
1350 to reference the attribute in Logging, either through a package renaming,
1351 or by referencing the attribute. The following example shows both cases:
1353 @smallexample @c projectfile
1356 for Switches ("Ada") use ("-O2");
1359 for Switches ("Ada") use ("-E");
1365 package Compiler renames Logging.Compiler;
1367 for Switches ("Ada") use Logging.Binder'Switches ("Ada");
1373 The solution used for @code{Compiler} gets the same value for all
1374 attributes of the package, but you cannot modify anything from the
1375 package (adding extra switches or some exceptions). The second
1376 version is more flexible, but more verbose.
1378 If you need to refer to the value of a variable in an imported
1379 project, rather than an attribute, the syntax is similar but uses
1380 a "." rather than an apostrophe. For instance:
1382 @smallexample @c projectfile
1385 Var1 := Imported.Var;
1389 @item The second approach is to define the switches in a third project.
1390 That project is setup without any sources (so that, as opposed to
1391 the first example, none of the project plays a special role), and
1392 will only be used to define the attributes. Such a project is
1393 typically called @file{shared.gpr}.
1395 @smallexample @c projectfile
1396 abstract project Shared is
1397 for Source_Files use (); -- no project
1399 for Switches ("Ada") use ("-O2");
1405 package Compiler renames Shared.Compiler;
1410 package Compiler renames Shared.Compiler;
1415 As for the first example, we could have chosen to set the attributes
1416 one by one rather than to rename a package. The reason we explicitly
1417 indicate that @code{Shared} has no sources is so that it can be created
1418 in any directory and we are sure it shares no sources with @code{Build}
1419 or @code{Logging}, which of course would be invalid.
1421 @cindex project qualifier
1422 Note the additional use of the @b{abstract} qualifier in @file{shared.gpr}.
1423 This qualifier is optional, but helps convey the message that we do not
1424 intend this project to have sources (@pxref{Qualified Projects} for
1428 @c ---------------------------------------------
1429 @node Global Attributes
1430 @subsection Global Attributes
1431 @c ---------------------------------------------
1434 We have already seen many examples of attributes used to specify a special
1435 option of one of the tools involved in the build process. Most of those
1436 attributes are project specific. That it to say, they only affect the invocation
1437 of tools on the sources of the project where they are defined.
1439 There are a few additional attributes that apply to all projects in a
1440 hierarchy as long as they are defined on the "main" project.
1441 The main project is the project explicitly mentioned on the command-line.
1442 The project hierarchy is the "with"-closure of the main project.
1444 Here is a list of commonly used global attributes:
1447 @item @b{Builder.Global_Configuration_Pragmas}:
1448 @cindex @code{Global_Configuration_Pragmas}
1449 This attribute points to a file that contains configuration pragmas
1450 to use when building executables. These pragmas apply for all
1451 executables built from this project hierarchy. As we have seen before,
1452 additional pragmas can be specified on a per-project basis by setting the
1453 @code{Compiler.Local_Configuration_Pragmas} attribute.
1455 @item @b{Builder.Global_Compilation_Switches}:
1456 @cindex @code{Global_Compilation_Switches}
1457 This attribute is a list of compiler switches to use when compiling any
1458 source file in the project hierarchy. These switches are used in addition
1459 to the ones defined in the @code{Compiler} package, which only apply to
1460 the sources of the corresponding project. This attribute is indexed on
1461 the name of the language.
1465 Using such global capabilities is convenient. It can also lead to unexpected
1466 behavior. Especially when several subsystems are shared among different main
1467 projects and the different global attributes are not
1468 compatible. Note that using aggregate projects can be a safer and more powerful
1469 replacement to global attributes.
1471 @c ---------------------------------------------
1472 @node Scenarios in Projects
1473 @section Scenarios in Projects
1474 @c ---------------------------------------------
1477 Various aspects of the projects can be modified based on @b{scenarios}. These
1478 are user-defined modes that change the behavior of a project. Typical
1479 examples are the setup of platform-specific compiler options, or the use of
1480 a debug and a release mode (the former would activate the generation of debug
1481 information, when the second will focus on improving code optimization).
1483 Let's enhance our example to support a debug and a release modes.The issue is to
1484 let the user choose what kind of system he is building:
1485 use @option{-g} as compiler switches in debug mode and @option{-O2}
1486 in release mode. We will also setup the projects so that we do not share the
1487 same object directory in both modes, otherwise switching from one to the other
1488 might trigger more recompilations than needed or mix objects from the 2 modes.
1490 One naive approach is to create two different project files, say
1491 @file{build_debug.gpr} and @file{build_release.gpr}, that set the appropriate
1492 attributes as explained in previous sections. This solution does not scale well,
1493 because in presence of multiple projects depending on each other,
1494 you will also have to duplicate the complete hierarchy and adapt the project
1495 files to point to the right copies.
1498 Instead, project files support the notion of scenarios controlled
1499 by external values. Such values can come from several sources (in decreasing
1503 @item @b{Command line}:
1505 When launching @command{gnatmake} or @command{gprbuild}, the user can pass
1506 extra @option{-X} switches to define the external value. In
1507 our case, the command line might look like
1510 gnatmake -Pbuild.gpr -Xmode=debug
1511 or gnatmake -Pbuild.gpr -Xmode=release
1514 @item @b{^Environment variables^Logical names^}:
1515 When the external value does not come from the command line, it can come from
1516 the value of ^environment variables^logical names^ of the appropriate name.
1517 In our case, if ^an environment variable^a logical name^ called "mode"
1518 exist, its value will be taken into account.
1520 @item @b{External function second parameter}
1524 @cindex @code{external}
1525 We now need to get that value in the project. The general form is to use
1526 the predefined function @b{external} which returns the current value of
1527 the external. For instance, we could setup the object directory to point to
1528 either @file{obj/debug} or @file{obj/release} by changing our project to
1530 @smallexample @c projectfile
1532 for Object_Dir use "obj/" & external ("mode", "debug");
1538 The second parameter to @code{external} is optional, and is the default
1539 value to use if "mode" is not set from the command line or the environment.
1541 In order to set the switches according to the different scenarios, other
1542 constructs have to be introduced such as typed variables and case constructions.
1544 @cindex typed variable
1545 @cindex case construction
1546 A @b{typed variable} is a variable that
1547 can take only a limited number of values, similar to an enumeration in Ada.
1548 Such a variable can then be used in a @b{case construction} and create conditional
1549 sections in the project. The following example shows how this can be done:
1551 @smallexample @c projectfile
1553 type Mode_Type is ("debug", "release"); -- all possible values
1554 Mode : Mode_Type := external ("mode", "debug"); -- a typed variable
1559 for Switches ("Ada") use ("-g");
1561 for Switches ("Ada") use ("-O2");
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 may not 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 offers 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 The GNAT Project Manager takes complete care of the library build, rebuild and
1608 installation tasks, including recompilation of the source files for which
1609 objects do not exist or are not up to date, assembly of the library archive, and
1610 installation of the library (i.e., copying associated source, object and
1611 @file{ALI} files to the specified location).
1614 * Building Libraries::
1615 * Using Library Projects::
1616 * Stand-alone Library Projects::
1617 * Installing a library with project files::
1620 @c ---------------------------------------------
1621 @node Building Libraries
1622 @subsection Building Libraries
1623 @c ---------------------------------------------
1626 Let's enhance our example and transform the @code{logging} subsystem into a
1627 library. In order to do so, a few changes need to be made to @file{logging.gpr}.
1628 A number of specific attributes needs to be defined: at least @code{Library_Name}
1629 and @code{Library_Dir}; in addition, a number of other attributes can be used
1630 to specify specific aspects of the library. For readability, it is also
1631 recommended (although not mandatory), to use the qualifier @code{library} in
1632 front of the @code{project} keyword.
1635 @item @b{Library_Name}:
1636 @cindex @code{Library_Name}
1637 This attribute is the name of the library to be built. There is no
1638 restriction on the name of a library imposed by the project manager, except
1639 for stand-alone libraries whose names must follow the syntax of Ada
1640 identifiers; however, there may be system specific restrictions on the name.
1641 In general, it is recommended to stick to alphanumeric characters (and
1642 possibly single underscores) to help portability.
1644 @item @b{Library_Dir}:
1645 @cindex @code{Library_Dir}
1646 This attribute is the path (absolute or relative) of the directory where
1647 the library is to be installed. In the process of building a library,
1648 the sources are compiled, the object files end up in the explicit or
1649 implicit @code{Object_Dir} directory. When all sources of a library
1650 are compiled, some of the compilation artifacts, including the library itself,
1651 are copied to the library_dir directory. This directory must exists and be
1652 writable. It must also be different from the object directory so that cleanup
1653 activities in the Library_Dir do not affect recompilation needs.
1657 Here is the new version of @file{logging.gpr} that makes it a library:
1659 @smallexample @c projectfile
1660 library project Logging is -- "library" is optional
1661 for Library_Name use "logging"; -- will create "liblogging.a" on Unix
1662 for Object_Dir use "obj";
1663 for Library_Dir use "lib"; -- different from object_dir
1668 Once the above two attributes are defined, the library project is valid and
1669 is enough for building a library with default characteristics.
1670 Other library-related attributes can be used to change the defaults:
1673 @item @b{Library_Kind}:
1674 @cindex @code{Library_Kind}
1675 The value of this attribute must be either @code{"static"}, @code{"dynamic"} or
1676 @code{"relocatable"} (the latter is a synonym for dynamic). It indicates
1677 which kind of library should be built (the default is to build a
1678 static library, that is an archive of object files that can potentially
1679 be linked into a static executable). When the library is set to be dynamic,
1680 a separate image is created that will be loaded independently, usually
1681 at the start of the main program execution. Support for dynamic libraries is
1682 very platform specific, for instance on Windows it takes the form of a DLL
1683 while on GNU/Linux, it is a dynamic elf image whose suffix is usually
1684 @file{.so}. Library project files, on the other hand, can be written in
1685 a platform independent way so that the same project file can be used to build
1686 a library on different operating systems.
1688 If you need to build both a static and a dynamic library, it is recommended
1689 use two different object directories, since in some cases some extra code
1690 needs to be generated for the latter. For such cases, one can
1691 either define two different project files, or a single one which uses scenarios
1692 to indicate the various kinds of library to be built and their
1693 corresponding object_dir.
1695 @cindex @code{Library_ALI_Dir}
1696 @item @b{Library_ALI_Dir}:
1697 This attribute may be specified to indicate the directory where the ALI
1698 files of the library are installed. By default, they are copied into the
1699 @code{Library_Dir} directory, but as for the executables where we have a
1700 separate @code{Exec_Dir} attribute, you might want to put them in a separate
1701 directory since there can be hundreds of them. The same restrictions as for
1702 the @code{Library_Dir} attribute apply.
1704 @cindex @code{Library_Version}
1705 @item @b{Library_Version}:
1706 This attribute is platform dependent, and has no effect on VMS and Windows.
1707 On Unix, it is used only for dynamic libraries as the internal
1708 name of the library (the @code{"soname"}). If the library file name (built
1709 from the @code{Library_Name}) is different from the @code{Library_Version},
1710 then the library file will be a symbolic link to the actual file whose name
1711 will be @code{Library_Version}. This follows the usual installation schemes
1712 for dynamic libraries on many Unix systems.
1714 @smallexample @c projectfile
1718 for Library_Dir use "lib";
1719 for Library_Name use "logging";
1720 for Library_Kind use "dynamic";
1721 for Library_Version use "liblogging.so." & Version;
1727 After the compilation, the directory @file{lib} will contain both a
1728 @file{libdummy.so.1} library and a symbolic link to it called
1731 @cindex @code{Library_GCC}
1732 @item @b{Library_GCC}:
1733 This attribute is the name of the tool to use instead of "gcc" to link shared
1734 libraries. A common use of this attribute is to define a wrapper script that
1735 accomplishes specific actions before calling gcc (which itself is calling the
1736 linker to build the library image).
1738 @item @b{Library_Options}:
1739 @cindex @code{Library_Options}
1740 This attribute may be used to specify additional switches (last switches)
1741 when linking a shared library.
1743 @item @b{Leading_Library_Options}:
1744 @cindex @code{Leading_Library_Options}
1745 This attribute, that is taken into account only by @command{gprbuild}, may be
1746 used to specified leading options (first switches) when linking a shared
1749 @cindex @code{Linker_Options}
1750 @item @b{Linker.Linker_Options}:
1751 This attribute specifies additional switches to be given to the linker when
1752 linking an executable. It is ignored when defined in the main project and
1753 taken into account in all other projects that are imported directly or
1754 indirectly. These switches complement the @code{Linker.Switches}
1755 defined in the main project. This is useful when a particular subsystem
1756 depends on an external library: adding this dependency as a
1757 @code{Linker_Options} in the project of the subsystem is more convenient than
1758 adding it to all the @code{Linker.Switches} of the main projects that depend
1759 upon this subsystem.
1762 @c ---------------------------------------------
1763 @node Using Library Projects
1764 @subsection Using Library Projects
1765 @c ---------------------------------------------
1768 When the builder detects that a project file is a library project file, it
1769 recompiles all sources of the project that need recompilation and rebuild the
1770 library if any of the sources have been recompiled. It then groups all object
1771 files into a single file, which is a shared or a static library. This library
1772 can later on be linked with multiple executables. Note that the use
1773 of shard libraries reduces the size of the final executable and can also reduce
1774 the memory footprint at execution time when the library is shared among several
1777 It is also possible to build @b{multi-language libraries}. When using
1778 @command{gprbuild} as a builder, multi-language library projects allow naturally
1779 the creation of multi-language libraries . @command{gnatmake}, does not try to
1780 compile non Ada sources. However, when the project is multi-language, it will
1781 automatically link all object files found in the object directory, whether or
1782 not they were compiled from an Ada source file. This specific behavior does not
1783 apply to Ada-only projects which only take into account the objects
1784 corresponding to the sources of the project.
1786 A non-library project can import a library project. When the builder is invoked
1787 on the former, the library of the latter is only rebuilt when absolutely
1788 necessary. For instance, if a unit of the
1789 library is not up-to-date but non of the executables need this unit, then the
1790 unit is not recompiled and the library is not reassembled.
1791 For instance, let's assume in our example that logging has the following
1792 sources: @file{log1.ads}, @file{log1.adb}, @file{log2.ads} and
1793 @file{log2.adb}. If @file{log1.adb} has been modified, then the library
1794 @file{liblogging} will be rebuilt when compiling all the sources of
1795 @code{Build} only if @file{proc.ads}, @file{pack.ads} or @file{pack.adb}
1796 include a @code{"with Log1"}.
1798 To ensure that all the sources in the @code{Logging} library are
1799 up to date, and that all the sources of @code{Build} are also up to date,
1800 the following two commands needs to be used:
1803 gnatmake -Plogging.gpr
1804 gnatmake -Pbuild.gpr
1808 All @file{ALI} files will also be copied from the object directory to the
1809 library directory. To build executables, @command{gnatmake} will use the
1810 library rather than the individual object files.
1813 Library projects can also be useful to describe a library that need to be used
1814 but, for some reason, cannot be rebuilt. For instance, it is the case when some
1815 of the library sources are not available. Such library projects need simply to
1816 use the @code{Externally_Built} attribute as in the example below:
1818 @smallexample @c projectfile
1819 library project Extern_Lib is
1820 for Languages use ("Ada", "C");
1821 for Source_Dirs use ("lib_src");
1822 for Library_Dir use "lib2";
1823 for Library_Kind use "dynamic";
1824 for Library_Name use "l2";
1825 for Externally_Built use "true"; -- <<<<
1830 In the case of externally built libraries, the @code{Object_Dir}
1831 attribute does not need to be specified because it will never be
1834 The main effect of using such an externally built library project is mostly to
1835 affect the linker command in order to reference the desired library. It can
1836 also be achieved by using @code{Linker.Linker_Options} or @code{Linker.Switches}
1837 in the project corresponding to the subsystem needing this external library.
1838 This latter method is more straightforward in simple cases but when several
1839 subsystems depend upon the same external library, finding the proper place
1840 for the @code{Linker.Linker_Options} might not be easy and if it is
1841 not placed properly, the final link command is likely to present ordering issues.
1842 In such a situation, it is better to use the externally built library project
1843 so that all other subsystems depending on it can declare this dependency thanks
1844 to a project @code{with} clause, which in turn will trigger the builder to find
1845 the proper order of libraries in the final link command.
1848 @c ---------------------------------------------
1849 @node Stand-alone Library Projects
1850 @subsection Stand-alone Library Projects
1851 @c ---------------------------------------------
1854 @cindex standalone libraries
1855 A @b{stand-alone library} is a library that contains the necessary code to
1856 elaborate the Ada units that are included in the library. A stand-alone
1857 library is a convenient way to add an Ada subsystem to a more global system
1858 whose main is not in Ada since it makes the elaboration of the Ada part mostly
1859 transparent. However, stand-alone libraries are also useful when the main is in
1860 Ada: they provide a means for minimizing relinking & redeployment of complex
1861 systems when localized changes are made.
1863 The name of a stand-alone library, specified with attribute
1864 @code{Library_Name}, must have the syntax of an Ada identifier.
1866 The most prominent characteristic of a stand-alone library is that it offers a
1867 distinction between interface units and implementation units. Only the former
1868 are visible to units outside the library. A stand-alone library project is thus
1869 characterised by a third attribute, usually @b{Library_Interface}, in addition
1870 to the two attributes that make a project a Library Project
1871 (@code{Library_Name} and @code{Library_Dir}). This third attribute may also be
1872 @b{Interfaces}. @b{Library_Interface} only works when the interface is in Ada
1873 and takes a list of units as parameter. @b{Interfaces} works for any supported
1874 language and takes a list of sources as parameter.
1877 @item @b{Library_Interface}:
1878 @cindex @code{Library_Interface}
1879 This attribute defines an explicit subset of the units of the project. Units
1880 from projects importing this library project may only "with" units whose
1881 sources are listed in the @code{Library_Interface}. Other sources are
1882 considered implementation units.
1884 @smallexample @c projectfile
1886 for Library_Dir use "lib";
1887 for Library_Name use "loggin";
1888 for Library_Interface use ("lib1", "lib2"); -- unit names
1892 @item @b{Interfaces}
1893 This attribute defines an explicit subset of the source files of a project.
1894 Sources from projects importing this project, can only depend on sources from
1895 this subset. This attribute can be used on non library projects. It can also
1896 be used as a replacement for attribute @code{Library_Interface}, in which
1897 case, units have to be replaced by source files. For multi-language library
1898 projects, it is the only way to make the project a Stand-Alone Library project
1899 whose interface is not purely Ada.
1901 @item @b{Library_Standalone}:
1902 @cindex @code{Library_Standalone}
1903 This attribute defines the kind of standalone library to
1904 build. Values are either @code{standard} (the default), @code{no} or
1905 @code{encapsulated}. When @code{standard} is used the code to elaborate and
1906 finalize the library is embedded, when @code{encapsulated} is used the
1907 library can furthermore only depends on static libraries (including
1908 the GNAT runtime). This attribute can be set to @code{no} to make it clear
1909 that the library should not be standalone in which case the
1910 @code{Library_Interface} should not defined. Note that this attribute
1911 only applies to shared libraries, so @code{Library_Kind} must be set
1914 @smallexample @c projectfile
1916 for Library_Dir use "lib";
1917 for Library_Name use "loggin";
1918 for Library_Kind use "dynamic";
1919 for Library_Interface use ("lib1", "lib2"); -- unit names
1920 for Library_Standalone use "encapsulated";
1926 In order to include the elaboration code in the stand-alone library, the binder
1927 is invoked on the closure of the library units creating a package whose name
1928 depends on the library name (^b~logging.ads/b^B$LOGGING.ADS/B^ in the example).
1929 This binder-generated package includes @b{initialization} and @b{finalization}
1930 procedures whose names depend on the library name (@code{logginginit} and
1931 @code{loggingfinal} in the example). The object corresponding to this package is
1932 included in the library.
1935 @item @b{Library_Auto_Init}:
1936 @cindex @code{Library_Auto_Init}
1937 A dynamic stand-alone Library is automatically initialized
1938 if automatic initialization of Stand-alone Libraries is supported on the
1939 platform and if attribute @b{Library_Auto_Init} is not specified or
1940 is specified with the value "true". A static Stand-alone Library is never
1941 automatically initialized. Specifying "false" for this attribute
1942 prevent automatic initialization.
1944 When a non-automatically initialized stand-alone library is used in an
1945 executable, its initialization procedure must be called before any service of
1946 the library is used. When the main subprogram is in Ada, it may mean that the
1947 initialization procedure has to be called during elaboration of another
1950 @item @b{Library_Dir}:
1951 @cindex @code{Library_Dir}
1952 For a stand-alone library, only the @file{ALI} files of the interface units
1953 (those that are listed in attribute @code{Library_Interface}) are copied to
1954 the library directory. As a consequence, only the interface units may be
1955 imported from Ada units outside of the library. If other units are imported,
1956 the binding phase will fail.
1958 @item @b{Binder.Default_Switches}:
1959 When a stand-alone library is bound, the switches that are specified in
1960 the attribute @b{Binder.Default_Switches ("Ada")} are
1961 used in the call to @command{gnatbind}.
1963 @item @b{Library_Src_Dir}:
1964 @cindex @code{Library_Src_Dir}
1965 This attribute defines the location (absolute or relative to the project
1966 directory) where the sources of the interface units are copied at
1968 These sources includes the specs of the interface units along with the closure
1969 of sources necessary to compile them successfully. That may include bodies and
1970 subunits, when pragmas @code{Inline} are used, or when there is a generic
1971 units in the spec. This directory cannot point to the object directory or
1972 one of the source directories, but it can point to the library directory,
1973 which is the default value for this attribute.
1975 @item @b{Library_Symbol_Policy}:
1976 @cindex @code{Library_Symbol_Policy}
1977 This attribute controls the export of symbols and, on some platforms (like
1978 VMS) that have the notions of major and minor IDs built in the library
1979 files, it controls the setting of these IDs. It is not supported on all
1980 platforms (where it will just have no effect). It may have one of the
1984 @item @code{"autonomous"} or @code{"default"}: exported symbols are not controlled
1985 @item @code{"compliant"}: if attribute @b{Library_Reference_Symbol_File}
1986 is not defined, then it is equivalent to policy "autonomous". If there
1987 are exported symbols in the reference symbol file that are not in the
1988 object files of the interfaces, the major ID of the library is increased.
1989 If there are symbols in the object files of the interfaces that are not
1990 in the reference symbol file, these symbols are put at the end of the list
1991 in the newly created symbol file and the minor ID is increased.
1992 @item @code{"controlled"}: the attribute @b{Library_Reference_Symbol_File} must be
1993 defined. The library will fail to build if the exported symbols in the
1994 object files of the interfaces do not match exactly the symbol in the
1996 @item @code{"restricted"}: The attribute @b{Library_Symbol_File} must be defined.
1997 The library will fail to build if there are symbols in the symbol file that
1998 are not in the exported symbols of the object files of the interfaces.
1999 Additional symbols in the object files are not added to the symbol file.
2000 @item @code{"direct"}: The attribute @b{Library_Symbol_File} must be defined and
2001 must designate an existing file in the object directory. This symbol file
2002 is passed directly to the underlying linker without any symbol processing.
2006 @item @b{Library_Reference_Symbol_File}
2007 @cindex @code{Library_Reference_Symbol_File}
2008 This attribute may define the path name of a reference symbol file that is
2009 read when the symbol policy is either "compliant" or "controlled", on
2010 platforms that support symbol control, such as VMS, when building a
2011 stand-alone library. The path may be an absolute path or a path relative
2012 to the project directory.
2014 @item @b{Library_Symbol_File}
2015 @cindex @code{Library_Symbol_File}
2016 This attribute may define the name of the symbol file to be created when
2017 building a stand-alone library when the symbol policy is either "compliant",
2018 "controlled" or "restricted", on platforms that support symbol control,
2019 such as VMS. When symbol policy is "direct", then a file with this name
2020 must exist in the object directory.
2023 @c ---------------------------------------------
2024 @node Installing a library with project files
2025 @subsection Installing a library with project files
2026 @c ---------------------------------------------
2029 When using project files, a usable version of the library is created in the
2030 directory specified by the @code{Library_Dir} attribute of the library
2031 project file. Thus no further action is needed in order to make use of
2032 the libraries that are built as part of the general application build.
2034 You may want to install a library in a context different from where the library
2035 is built. This situation arises with third party suppliers, who may want
2036 to distribute a library in binary form where the user is not expected to be
2037 able to recompile the library. The simplest option in this case is to provide
2038 a project file slightly different from the one used to build the library, by
2039 using the @code{externally_built} attribute. @ref{Using Library Projects}
2041 Another option is to use @command{gprinstall} to install the library in a
2042 different context than the build location. A project to use this library is
2043 generated automatically by @command{gprinstall} which also copy, in the install
2044 location, the minimum set of sources needed to use the library.
2047 @c ---------------------------------------------
2048 @node Project Extension
2049 @section Project Extension
2050 @c ---------------------------------------------
2053 During development of a large system, it is sometimes necessary to use
2054 modified versions of some of the source files, without changing the original
2055 sources. This can be achieved through the @b{project extension} facility.
2057 Suppose for instance that our example @code{Build} project is built every night
2058 for the whole team, in some shared directory. A developer usually need to work
2059 on a small part of the system, and might not want to have a copy of all the
2060 sources and all the object files (mostly because that would require too much
2061 disk space, time to recompile everything). He prefers to be able to override
2062 some of the source files in his directory, while taking advantage of all the
2063 object files generated at night.
2065 Another example can be taken from large software systems, where it is common to have
2066 multiple implementations of a common interface; in Ada terms, multiple
2067 versions of a package body for the same spec. For example, one implementation
2068 might be safe for use in tasking programs, while another might only be used
2069 in sequential applications. This can be modeled in GNAT using the concept
2070 of @emph{project extension}. If one project (the ``child'') @emph{extends}
2071 another project (the ``parent'') then by default all source files of the
2072 parent project are inherited by the child, but the child project can
2073 override any of the parent's source files with new versions, and can also
2074 add new files or remove unnecessary ones.
2075 This facility is the project analog of a type extension in
2076 object-oriented programming. Project hierarchies are permitted (an extending
2077 project may itself be extended), and a project that
2078 extends a project can also import other projects.
2080 A third example is that of using project extensions to provide different
2081 versions of the same system. For instance, assume that a @code{Common}
2082 project is used by two development branches. One of the branches has now
2083 been frozen, and no further change can be done to it or to @code{Common}.
2084 However, the other development branch still needs evolution of @code{Common}.
2085 Project extensions provide a flexible solution to create a new version
2086 of a subsystem while sharing and reusing as much as possible from the original
2089 A project extension inherits implicitly all the sources and objects from the
2090 project it extends. It is possible to create a new version of some of the
2091 sources in one of the additional source dirs of the extending project. Those new
2092 versions hide the original versions. Adding new sources or removing existing
2093 ones is also possible. Here is an example on how to extend the project
2094 @code{Build} from previous examples:
2096 @smallexample @c projectfile
2097 project Work extends "../bld/build.gpr" is
2102 The project after @b{extends} is the one being extended. As usual, it can be
2103 specified using an absolute path, or a path relative to any of the directories
2104 in the project path (@pxref{Project Dependencies}). This project does not
2105 specify source or object directories, so the default value for these attribute
2106 will be used that is to say the current directory (where project @code{Work} is
2107 placed). We can already compile that project with
2114 If no sources have been placed in the current directory, this command
2115 won't do anything, since this project does not change the
2116 sources it inherited from @code{Build}, therefore all the object files
2117 in @code{Build} and its dependencies are still valid and are reused
2120 Suppose we now want to supply an alternate version of @file{pack.adb}
2121 but use the existing versions of @file{pack.ads} and @file{proc.adb}.
2122 We can create the new file Work's current directory (likely
2123 by copying the one from the @code{Build} project and making changes to
2124 it. If new packages are needed at the same time, we simply create
2125 new files in the source directory of the extending project.
2127 When we recompile, @command{gnatmake} will now automatically recompile
2128 this file (thus creating @file{pack.o} in the current directory) and
2129 any file that depends on it (thus creating @file{proc.o}). Finally, the
2130 executable is also linked locally.
2132 Note that we could have obtained the desired behavior using project import
2133 rather than project inheritance. A @code{base} project would contain the
2134 sources for @file{pack.ads} and @file{proc.adb}, and @code{Work} would
2135 import @code{base} and add @file{pack.adb}. In this scenario, @code{base}
2136 cannot contain the original version of @file{pack.adb} otherwise there would be
2137 2 versions of the same unit in the closure of the project and this is not
2138 allowed. Generally speaking, it is not recommended to put the spec and the
2139 body of a unit in different projects since this affects their autonomy and
2142 In a project file that extends another project, it is possible to
2143 indicate that an inherited source is @b{not part} of the sources of the
2144 extending project. This is necessary sometimes when a package spec has
2145 been overridden and no longer requires a body: in this case, it is
2146 necessary to indicate that the inherited body is not part of the sources
2147 of the project, otherwise there will be a compilation error
2148 when compiling the spec.
2150 @cindex @code{Excluded_Source_Files}
2151 @cindex @code{Excluded_Source_List_File}
2152 For that purpose, the attribute @b{Excluded_Source_Files} is used.
2153 Its value is a list of file names.
2154 It is also possible to use attribute @code{Excluded_Source_List_File}.
2155 Its value is the path of a text file containing one file name per
2158 @smallexample @c @projectfile
2159 project Work extends "../bld/build.gpr" is
2160 for Source_Files use ("pack.ads");
2161 -- New spec of Pkg does not need a completion
2162 for Excluded_Source_Files use ("pack.adb");
2167 All packages that are not declared in the extending project are inherited from
2168 the project being extended, with their attributes, with the exception of
2169 @code{Linker'Linker_Options} which is never inherited. In particular, an
2170 extending project retains all the switches specified in the project being
2173 At the project level, if they are not declared in the extending project, some
2174 attributes are inherited from the project being extended. They are:
2175 @code{Languages}, @code{Main} (for a root non library project) and
2176 @code{Library_Name} (for a project extending a library project)
2179 * Project Hierarchy Extension::
2182 @c ---------------------------------------------
2183 @node Project Hierarchy Extension
2184 @subsection Project Hierarchy Extension
2185 @c ---------------------------------------------
2188 One of the fundamental restrictions in project extension is the following:
2189 @b{A project is not allowed to import directly or indirectly at the same time an
2190 extending project and one of its ancestors}.
2192 By means of example, consider the following hierarchy of projects.
2195 a.gpr contains package A1
2196 b.gpr, imports a.gpr and contains B1, which depends on A1
2197 c.gpr, imports b.gpr and contains C1, which depends on B1
2201 If we want to locally extend the packages @code{A1} and @code{C1}, we need to
2202 create several extending projects:
2205 a_ext.gpr which extends a.gpr, and overrides A1
2206 b_ext.gpr which extends b.gpr and imports a_ext.gpr
2207 c_ext.gpr which extends c.gpr, imports b_ext.gpr and overrides C1
2211 @smallexample @c projectfile
2212 project A_Ext extends "a.gpr" is
2213 for Source_Files use ("a1.adb", "a1.ads");
2217 project B_Ext extends "b.gpr" is
2221 project C_Ext extends "c.gpr" is
2222 for Source_Files use ("c1.adb");
2227 The extension @file{b_ext.gpr} is required, even though we are not overriding
2228 any of the sources of @file{b.gpr} because otherwise @file{c_expr.gpr} would
2229 import @file{b.gpr} which itself knows nothing about @file{a_ext.gpr}.
2232 When extending a large system spanning multiple projects, it is often
2233 inconvenient to extend every project in the hierarchy that is impacted by a
2234 small change introduced in a low layer. In such cases, it is possible to create
2235 an @b{implicit extension} of entire hierarchy using @b{extends all}
2238 When the project is extended using @code{extends all} inheritance, all projects
2239 that are imported by it, both directly and indirectly, are considered virtually
2240 extended. That is, the project manager creates implicit projects
2241 that extend every project in the hierarchy; all these implicit projects do not
2242 control sources on their own and use the object directory of
2243 the "extending all" project.
2245 It is possible to explicitly extend one or more projects in the hierarchy
2246 in order to modify the sources. These extending projects must be imported by
2247 the "extending all" project, which will replace the corresponding virtual
2248 projects with the explicit ones.
2250 When building such a project hierarchy extension, the project manager will
2251 ensure that both modified sources and sources in implicit extending projects
2252 that depend on them, are recompiled.
2254 Thus, in our example we could create the following projects instead:
2257 a_ext.gpr, extends a.gpr and overrides A1
2258 c_ext.gpr, "extends all" c.gpr, imports a_ext.gpr and overrides C1
2263 @smallexample @c projectfile
2264 project A_Ext extends "a.gpr" is
2265 for Source_Files use ("a1.adb", "a1.ads");
2269 project C_Ext extends all "c.gpr" is
2270 for Source_Files use ("c1.adb");
2275 When building project @file{c_ext.gpr}, the entire modified project space is
2276 considered for recompilation, including the sources of @file{b.gpr} that are
2277 impacted by the changes in @code{A1} and @code{C1}.
2279 @c ---------------------------------------------
2280 @node Aggregate Projects
2281 @section Aggregate Projects
2282 @c ---------------------------------------------
2286 Aggregate projects are an extension of the project paradigm, and are
2287 meant to solve a few specific use cases that cannot be solved directly
2288 using standard projects. This section will go over a few of these use
2289 cases to try to explain what you can use aggregate projects for.
2292 * Building all main programs from a single project tree::
2293 * Building a set of projects with a single command::
2294 * Define a build environment::
2295 * Performance improvements in builder::
2296 * Syntax of aggregate projects::
2297 * package Builder in aggregate projects::
2300 @c -----------------------------------------------------------
2301 @node Building all main programs from a single project tree
2302 @subsection Building all main programs from a single project tree
2303 @c -----------------------------------------------------------
2305 Most often, an application is organized into modules and submodules,
2306 which are very conveniently represented as a project tree or graph
2307 (the root project A @code{with}s the projects for each modules (say B and C),
2308 which in turn @code{with} projects for submodules.
2310 Very often, modules will build their own executables (for testing
2311 purposes for instance), or libraries (for easier reuse in various
2314 However, if you build your project through @command{gnatmake} or
2315 @command{gprbuild}, using a syntax similar to
2321 this will only rebuild the main programs of project A, not those of the
2322 imported projects B and C. Therefore you have to spawn several
2323 @command{gnatmake} commands, one per project, to build all executables.
2324 This is a little inconvenient, but more importantly is inefficient
2325 because @command{gnatmake} needs to do duplicate work to ensure that sources are
2326 up-to-date, and cannot easily compile things in parallel when using
2329 Also libraries are always rebuilt when building a project.
2331 You could therefore define an aggregate project Agg that groups A, B
2332 and C. Then, when you build with
2338 this will build all mains from A, B and C.
2340 @smallexample @c projectfile
2341 aggregate project Agg is
2342 for Project_Files use ("a.gpr", "b.gpr", "c.gpr");
2346 If B or C do not define any main program (through their Main
2347 attribute), all their sources are built. When you do not group them
2348 in the aggregate project, only those sources that are needed by A
2351 If you add a main to a project P not already explicitly referenced in the
2352 aggregate project, you will need to add "p.gpr" in the list of project
2353 files for the aggregate project, or the main will not be built when
2354 building the aggregate project.
2356 @c ---------------------------------------------------------
2357 @node Building a set of projects with a single command
2358 @subsection Building a set of projects with a single command
2359 @c ---------------------------------------------------------
2361 One other case is when you have multiple applications and libraries
2362 that are built independently from each other (but can be built in
2363 parallel). For instance, you have a project tree rooted at A, and
2364 another one (which might share some subprojects) rooted at B.
2366 Using only @command{gprbuild}, you could do
2373 to build both. But again, @command{gprbuild} has to do some duplicate work for
2374 those files that are shared between the two, and cannot truly build
2375 things in parallel efficiently.
2377 If the two projects are really independent, share no sources other
2378 than through a common subproject, and have no source files with a
2379 common basename, you could create a project C that imports A and
2380 B. But these restrictions are often too strong, and one has to build
2381 them independently. An aggregate project does not have these
2382 limitations and can aggregate two project trees that have common
2385 This scenario is particularly useful in environments like VxWorks 653
2386 where the applications running in the multiple partitions can be built
2387 in parallel through a single @command{gprbuild} command. This also works nicely
2390 @c ---------------------------------------------
2391 @node Define a build environment
2392 @subsection Define a build environment
2393 @c ---------------------------------------------
2395 The environment variables at the time you launch @command{gprbuild} or
2396 @command{gnatmake} will influence the view these tools have of the project
2397 (PATH to find the compiler, ADA_PROJECT_PATH or GPR_PROJECT_PATH to find the
2398 projects, environment variables that are referenced in project files
2399 through the "external" statement,...). Several command line switches
2400 can be used to override those (-X or -aP), but on some systems and
2401 with some projects, this might make the command line too long, and on
2402 all systems often make it hard to read.
2404 An aggregate project can be used to set the environment for all
2405 projects built through that aggregate. One of the nice aspects is that
2406 you can put the aggregate project under configuration management, and
2407 make sure all your user have a consistent environment when
2408 building. The syntax looks like
2410 @smallexample @c projectfile
2411 aggregate project Agg is
2412 for Project_Files use ("A.gpr", "B.gpr");
2413 for Project_Path use ("../dir1", "../dir1/dir2");
2414 for External ("BUILD") use "PRODUCTION";
2417 for Switches ("Ada") use ("-q");
2422 One of the often requested features in projects is to be able to
2423 reference external variables in @code{with} statements, as in
2425 @smallexample @c projectfile
2426 with external("SETUP") & "path/prj.gpr"; -- ILLEGAL
2427 project MyProject is
2432 For various reasons, this isn't authorized. But using aggregate
2433 projects provide an elegant solution. For instance, you could
2434 use a project file like:
2436 @smallexample @c projectfile
2437 aggregate project Agg is
2438 for Project_Path use (external("SETUP") % "path");
2439 for Project_Files use ("myproject.gpr");
2442 with "prj.gpr"; -- searched on Agg'Project_Path
2443 project MyProject is
2448 @c --------------------------------------------
2449 @node Performance improvements in builder
2450 @subsection Performance improvements in builder
2451 @c --------------------------------------------
2453 The loading of aggregate projects is optimized in @command{gprbuild} and
2454 @command{gnatmake}, so that all files are searched for only once on the disk
2455 (thus reducing the number of system calls and contributing to faster
2456 compilation times especially on systems with sources on remote
2457 servers). As part of the loading, @command{gprbuild} and @command{gnatmake}
2458 compute how and where a source file should be compiled, and even if it is found
2459 several times in the aggregated projects it will be compiled only
2462 Since there is no ambiguity as to which switches should be used, files
2463 can be compiled in parallel (through the usual -j switch) and this can
2464 be done while maximizing the use of CPUs (compared to launching
2465 multiple @command{gprbuild} and @command{gnatmake} commands in parallel).
2467 @c -------------------------------------
2468 @node Syntax of aggregate projects
2469 @subsection Syntax of aggregate projects
2470 @c -------------------------------------
2472 An aggregate project follows the general syntax of project files. The
2473 recommended extension is still @file{.gpr}. However, a special
2474 @code{aggregate} qualifier must be put before the keyword
2477 An aggregate project cannot @code{with} any other project (standard or
2478 aggregate), except an abstract project which can be used to share
2479 attribute values. Building other aggregate projects from an aggregate
2480 project is done through the Project_Files attribute (see below).
2482 An aggregate project does not have any source files directly (only
2483 through other standard projects). Therefore a number of the standard
2484 attributes and packages are forbidden in an aggregate project. Here is the
2485 (non exhaustive) list:
2489 @item Source_Files, Source_List_File and other attributes dealing with
2491 @item Source_Dirs, Exec_Dir and Object_Dir
2492 @item Library_Dir, Library_Name and other library-related attributes
2495 @item Externally_Built
2496 @item Inherit_Source_Path
2497 @item Excluded_Source_Dirs
2498 @item Locally_Removed_Files
2499 @item Excluded_Source_Files
2500 @item Excluded_Source_List_File
2504 The only package that is authorized (albeit optional) is
2505 Builder. Other packages (in particular Compiler, Binder and Linker)
2506 are forbidden. It is an error to have any of these
2507 (and such an error prevents the proper loading of the aggregate
2510 Three new attributes have been created, which can only be used in the
2511 context of aggregate projects:
2514 @item @b{Project_Files}:
2515 @cindex @code{Project_Files}
2517 This attribute is compulsory (or else we are not aggregating any project,
2518 and thus not doing anything). It specifies a list of @file{.gpr} files
2519 that are grouped in the aggregate. The list may be empty. The project
2520 files can be either other aggregate projects, or standard projects. When
2521 grouping standard projects, you can have both the root of a project tree
2522 (and you do not need to specify all its imported projects), and any project
2525 Basically, the idea is to specify all those projects that have
2526 main programs you want to build and link, or libraries you want to
2527 build. You can even specify projects that do not use the Main
2528 attribute nor the @code{Library_*} attributes, and the result will be to
2529 build all their source files (not just the ones needed by other
2532 The file can include paths (absolute or relative). Paths are
2533 relative to the location of the aggregate project file itself (if
2534 you use a base name, we expect to find the .gpr file in the same
2535 directory as the aggregate project file). The extension @file{.gpr} is
2536 mandatory, since this attribute contains file names, not project names.
2538 Paths can also include the @code{"*"} and @code{"**"} globbing patterns. The
2539 latter indicates that any subdirectory (recursively) will be
2540 searched for matching files. The latter (@code{"**"}) can only occur at the
2541 last position in the directory part (ie @code{"a/**/*.gpr"} is supported, but
2542 not @code{"**/a/*.gpr"}). Starting the pattern with @code{"**"} is equivalent
2543 to starting with @code{"./**"}.
2545 For now, the pattern @code{"*"} is only allowed in the filename part, not
2546 in the directory part. This is mostly for efficiency reasons to limit the
2547 number of system calls that are needed.
2549 Here are a few valid examples:
2551 @smallexample @c projectfile
2552 for Project_Files use ("a.gpr", "subdir/b.gpr");
2553 -- two specific projects relative to the directory of agg.gpr
2555 for Project_Files use ("**/*.gpr");
2556 -- all projects recursively
2559 @item @b{Project_Path}:
2560 @cindex @code{Project_Path}
2562 This attribute can be used to specify a list of directories in
2563 which to look for project files in @code{with} statements.
2565 When you specify a project in Project_Files
2566 say @code{"x/y/a.gpr"}), and this projects imports a project "b.gpr", only
2567 b.gpr is searched in the project path. a.gpr must be exactly at
2568 <dir of the aggregate>/x/y/a.gpr.
2570 This attribute, however, does not affect the search for the aggregated
2571 project files specified with @code{Project_Files}.
2573 Each aggregate project has its own (that is if agg1.gpr includes
2574 agg2.gpr, they can potentially both have a different project path).
2576 This project path is defined as the concatenation, in that order, of:
2579 @item the current directory;
2580 @item followed by the command line -aP switches;
2581 @item then the directories from the GPR_PROJECT_PATH and ADA_PROJECT_PATH environment
2583 @item then the directories from the Project_Path attribute;
2584 @item and finally the predefined directories.
2587 In the example above, agg2.gpr's project path is not influenced by
2588 the attribute agg1'Project_Path, nor is agg1 influenced by
2591 This can potentially lead to errors. In the following example:
2594 +---------------+ +----------------+
2595 | Agg1.gpr |-=--includes--=-->| Agg2.gpr |
2596 | 'project_path| | 'project_path |
2598 +---------------+ +----------------+
2603 +-------+ +---------+
2604 | P.gpr |<---------- withs --------| Q.gpr |
2605 +-------+---------\ +---------+
2610 +-------+ +---------+
2611 | R.gpr | | R'.gpr |
2612 +-------+ +---------+
2615 When looking for p.gpr, both aggregates find the same physical file on
2616 the disk. However, it might happen that with their different project
2617 paths, both aggregate projects would in fact find a different r.gpr.
2618 Since we have a common project (p.gpr) "with"ing two different r.gpr,
2619 this will be reported as an error by the builder.
2621 Directories are relative to the location of the aggregate project file.
2623 Here are a few valid examples:
2625 @smallexample @c projectfile
2626 for Project_Path use ("/usr/local/gpr", "gpr/");
2630 @cindex @code{External}
2632 This attribute can be used to set the value of environment
2633 variables as retrieved through the @code{external} statement
2634 in projects. It does not affect the environment variables
2635 themselves (so for instance you cannot use it to change the value
2636 of your PATH as seen from the spawned compiler).
2638 This attribute affects the external values as seen in the rest of
2639 the aggreate projects, and in the aggregated projects.
2641 The exact value of external a variable comes from one of three
2642 sources (each level overrides the previous levels):
2645 @item An External attribute in aggregate project, for instance
2646 @code{for External ("BUILD_MODE") use "DEBUG"};
2648 @item Environment variables
2650 These override the value given by the attribute, so that
2651 users can override the value set in the (presumably shared
2652 with others in his team) aggregate project.
2654 @item The -X command line switch to @command{gprbuild} and @command{gnatmake}
2656 This always takes precedence.
2660 This attribute is only taken into account in the main aggregate
2661 project (i.e. the one specified on the command line to @command{gprbuild} or
2662 @command{gnatmake}), and ignored in other aggregate projects. It is invalid
2663 in standard projects.
2664 The goal is to have a consistent value in all
2665 projects that are built through the aggregate, which would not
2666 be the case in the diamond case: A groups the aggregate
2667 projects B and C, which both (either directly or indirectly)
2668 build the project P. If B and C could set different values for
2669 the environment variables, we would have two different views of
2670 P, which in particular might impact the list of source files in P.
2674 @c ----------------------------------------------
2675 @node package Builder in aggregate projects
2676 @subsection package Builder in aggregate projects
2677 @c ----------------------------------------------
2679 As we mentioned before, only the package Builder can be specified in
2680 an aggregate project. In this package, only the following attributes
2685 @cindex @code{Switches}
2686 This attribute gives the list of switches to use for the builder
2687 (@command{gprbuild} or @command{gnatmake}), depending on the language of the
2688 main file. For instance,
2690 @smallexample @c projectfile
2691 for Switches ("Ada") use ("-d", "-p");
2692 for Switches ("C") use ("-p");
2695 These switches are only read from the main aggregate project (the
2696 one passed on the command line), and ignored in all other aggregate
2697 projects or projects.
2699 It can only contain builder switches, not compiler switches.
2701 @item @b{Global_Compilation_Switches}
2702 @cindex @code{Global_Compilation_Switches}
2704 This attribute gives the list of compiler switches for the various
2705 languages. For instance,
2707 @smallexample @c projectfile
2708 for Global_Compilation_Switches ("Ada") use ("-O1", "-g");
2709 for Global_Compilation_Switches ("C") use ("-O2");
2712 This attribute is only taken into account in the aggregate project
2713 specified on the command line, not in other aggregate projects.
2715 In the projects grouped by that aggregate, the attribute
2716 Builder.Global_Compilation_Switches is also ignored. However, the
2717 attribute Compiler.Default_Switches will be taken into account (but
2718 that of the aggregate have higher priority). The attribute
2719 Compiler.Switches is also taken into account and can be used to
2720 override the switches for a specific file. As a result, it always
2723 The rules are meant to avoid ambiguities when compiling. For
2724 instance, aggregate project Agg groups the projects A and B, that
2725 both depend on C. Here is an extra for all of these projects:
2727 @smallexample @c projectfile
2728 aggregate project Agg is
2729 for Project_Files use ("a.gpr", "b.gpr");
2731 for Global_Compilation_Switches ("Ada") use ("-O2");
2738 for Global_Compilation_Switches ("Ada") use ("-O1");
2743 for Default_Switches ("Ada") use ("-O1", "-g");
2744 for Switches ("a_file1.adb") use ("-O0");
2751 for Default_Switches ("Ada") use ("-O0");
2757 for Default_Switches ("Ada") use ("-O3", "-gnatn");
2758 for Switches ("c_file1.adb") use ("-O0", "-g");
2763 then the following switches are used:
2766 @item all files from project A except a_file1.adb are compiled
2767 with "-O2 -g", since the aggregate project has priority.
2768 @item the file a_file1.adb is compiled with
2769 "-O0", since the Compiler.Switches has priority
2770 @item all files from project B are compiled with
2771 "-O2", since the aggregate project has priority
2772 @item all files from C are compiled with "-O2 -gnatn", except for
2773 c_file1.adb which is compiled with "-O0 -g"
2776 Even though C is seen through two paths (through A and through
2777 B), the switches used by the compiler are unambiguous.
2779 @item @b{Global_Configuration_Pragmas}
2780 @cindex @code{Global_Configuration_Pragmas}
2782 This attribute can be used to specify a file containing
2783 configuration pragmas, to be passed to the compiler. Since we
2784 ignore the package Builder in other aggregate projects and projects,
2785 only those pragmas defined in the main aggregate project will be
2788 Projects can locally add to those by using the
2789 @code{Compiler.Local_Configuration_Pragmas} attribute if they need.
2793 For projects that are built through the aggregate, the package Builder
2794 is ignored, except for the Executable attribute which specifies the
2795 name of the executables resulting from the link of the main programs, and
2796 for the Executable_Suffix.
2798 @c ---------------------------------------------
2799 @node Aggregate Library Projects
2800 @section Aggregate Library Projects
2801 @c ---------------------------------------------
2805 Aggregate library projects make it possible to build a single library
2806 using object files built using other standard or library
2807 projects. This gives the flexibility to describe an application as
2808 having multiple modules (a GUI, database access, ...) using different
2809 project files (so possibly built with different compiler options) and
2810 yet create a single library (static or relocatable) out of the
2811 corresponding object files.
2814 * Building aggregate library projects::
2815 * Syntax of aggregate library projects::
2818 @c ---------------------------------------------
2819 @node Building aggregate library projects
2820 @subsection Building aggregate library projects
2821 @c ---------------------------------------------
2823 For example, we can define an aggregate project Agg that groups A, B
2826 @smallexample @c projectfile
2827 aggregate library project Agg is
2828 for Project_Files use ("a.gpr", "b.gpr", "c.gpr");
2829 for Library_Name use ("agg");
2830 for Library_Dir use ("lagg");
2834 Then, when you build with:
2840 This will build all units from projects A, B and C and will create a
2841 static library named @file{libagg.a} into the @file{lagg}
2842 directory. An aggregate library project has the same set of
2843 restriction as a standard library project.
2845 Note that a shared aggregate library project cannot aggregates a
2846 static library project. In platforms where a compiler option is
2847 required to create relocatable object files, a Builder package in the
2848 aggregate library project may be used:
2850 @smallexample @c projectfile
2851 aggregate library project Agg is
2852 for Project_Files use ("a.gpr", "b.gpr", "c.gpr");
2853 for Library_Name use ("agg");
2854 for Library_Dir use ("lagg");
2855 for Library_Kind use "relocatable";
2858 for Global_Compilation_Switches ("Ada") use ("-fPIC");
2863 With the above aggregate library Builder package, the @code{-fPIC}
2864 option will be passed to the compiler when building any source code
2865 from projects @file{a.gpr}, @file{b.gpr} and @file{c.gpr}.
2867 @c ---------------------------------------------
2868 @node Syntax of aggregate library projects
2869 @subsection Syntax of aggregate library projects
2870 @c ---------------------------------------------
2872 An aggregate library project follows the general syntax of project
2873 files. The recommended extension is still @file{.gpr}. However, a special
2874 @code{aggregate library} qualifier must be put before the keyword
2877 An aggregate library project cannot @code{with} any other project
2878 (standard or aggregate), except an abstract project which can be used
2879 to share attribute values.
2881 An aggregate library project does not have any source files directly (only
2882 through other standard projects). Therefore a number of the standard
2883 attributes and packages are forbidden in an aggregate library
2884 project. Here is the (non exhaustive) list:
2888 @item Source_Files, Source_List_File and other attributes dealing with
2890 @item Source_Dirs, Exec_Dir and Object_Dir
2893 @item Externally_Built
2894 @item Inherit_Source_Path
2895 @item Excluded_Source_Dirs
2896 @item Locally_Removed_Files
2897 @item Excluded_Source_Files
2898 @item Excluded_Source_List_File
2902 The only package that is authorized (albeit optional) is Builder.
2904 The Project_Files attribute (See @pxref{Aggregate Projects}) is used to
2905 described the aggregated projects whose object files have to be
2906 included into the aggregate library.
2908 @c ---------------------------------------------
2909 @node Project File Reference
2910 @section Project File Reference
2911 @c ---------------------------------------------
2914 This section describes the syntactic structure of project files, the various
2915 constructs that can be used. Finally, it ends with a summary of all available
2919 * Project Declaration::
2920 * Qualified Projects::
2925 * Typed String Declaration::
2927 * Case Constructions::
2931 @c ---------------------------------------------
2932 @node Project Declaration
2933 @subsection Project Declaration
2934 @c ---------------------------------------------
2937 Project files have an Ada-like syntax. The minimal project file is:
2939 @smallexample @c projectfile
2947 The identifier @code{Empty} is the name of the project.
2948 This project name must be present after the reserved
2949 word @code{end} at the end of the project file, followed by a semi-colon.
2951 @b{Identifiers} (i.e.@: the user-defined names such as project or variable names)
2952 have the same syntax as Ada identifiers: they must start with a letter,
2953 and be followed by zero or more letters, digits or underscore characters;
2954 it is also illegal to have two underscores next to each other. Identifiers
2955 are always case-insensitive ("Name" is the same as "name").
2958 simple_name ::= identifier
2959 name ::= simple_name @{ . simple_name @}
2963 @b{Strings} are used for values of attributes or as indexes for these
2964 attributes. They are in general case sensitive, except when noted
2965 otherwise (in particular, strings representing file names will be case
2966 insensitive on some systems, so that "file.adb" and "File.adb" both
2967 represent the same file).
2969 @b{Reserved words} are the same as for standard Ada 95, and cannot
2970 be used for identifiers. In particular, the following words are currently
2971 used in project files, but others could be added later on. In bold are the
2972 extra reserved words in project files: @code{all, at, case, end, for, is,
2973 limited, null, others, package, renames, type, use, when, with, @b{extends},
2974 @b{external}, @b{project}}.
2976 @b{Comments} in project files have the same syntax as in Ada, two consecutive
2977 hyphens through the end of the line.
2979 A project may be an @b{independent project}, entirely defined by a single
2980 project file. Any source file in an independent project depends only
2981 on the predefined library and other source files in the same project.
2982 But a project may also depend on other projects, either by importing them
2983 through @b{with clauses}, or by @b{extending} at most one other project. Both
2984 types of dependency can be used in the same project.
2986 A path name denotes a project file. It can be absolute or relative.
2987 An absolute path name includes a sequence of directories, in the syntax of
2988 the host operating system, that identifies uniquely the project file in the
2989 file system. A relative path name identifies the project file, relative
2990 to the directory that contains the current project, or relative to a
2991 directory listed in the environment variables ADA_PROJECT_PATH and
2992 GPR_PROJECT_PATH. Path names are case sensitive if file names in the host
2993 operating system are case sensitive. As a special case, the directory
2994 separator can always be "/" even on Windows systems, so that project files
2995 can be made portable across architectures.
2996 The syntax of the environment variable ADA_PROJECT_PATH and
2997 GPR_PROJECT_PATH is a list of directory names separated by colons on UNIX and
2998 semicolons on Windows.
3000 A given project name can appear only once in a context clause.
3002 It is illegal for a project imported by a context clause to refer, directly
3003 or indirectly, to the project in which this context clause appears (the
3004 dependency graph cannot contain cycles), except when one of the with clause
3005 in the cycle is a @b{limited with}.
3006 @c ??? Need more details here
3008 @smallexample @c projectfile
3009 with "other_project.gpr";
3010 project My_Project extends "extended.gpr" is
3015 These dependencies form a @b{directed graph}, potentially cyclic when using
3016 @b{limited with}. The subprogram reflecting the @b{extends} relations is a
3019 A project's @b{immediate sources} are the source files directly defined by
3020 that project, either implicitly by residing in the project source directories,
3021 or explicitly through any of the source-related attributes.
3022 More generally, a project sources are the immediate sources of the project
3023 together with the immediate sources (unless overridden) of any
3024 project on which it depends directly or indirectly.
3026 A @b{project hierarchy} can be created, where projects are children of
3027 other projects. The name of such a child project must be @code{Parent.Child},
3028 where @code{Parent} is the name of the parent project. In particular, this
3029 makes all @code{with} clauses of the parent project automatically visible
3030 in the child project.
3033 project ::= context_clause project_declaration
3035 context_clause ::= @{with_clause@}
3036 with_clause ::= @i{with} path_name @{ , path_name @} ;
3037 path_name ::= string_literal
3039 project_declaration ::= simple_project_declaration | project_extension
3040 simple_project_declaration ::=
3041 @i{project} @i{<project_>}name @i{is}
3042 @{declarative_item@}
3043 @i{end} <project_>simple_name;
3046 @c ---------------------------------------------
3047 @node Qualified Projects
3048 @subsection Qualified Projects
3049 @c ---------------------------------------------
3052 Before the reserved @code{project}, there may be one or two @b{qualifiers}, that
3053 is identifiers or reserved words, to qualify the project.
3054 The current list of qualifiers is:
3057 @item @b{abstract}: qualifies a project with no sources. Such a
3058 project must either have no declaration of attributes @code{Source_Dirs},
3059 @code{Source_Files}, @code{Languages} or @code{Source_List_File}, or one of
3060 @code{Source_Dirs}, @code{Source_Files}, or @code{Languages} must be declared
3061 as empty. If it extends another project, the project it extends must also be a
3062 qualified abstract project.
3063 @item @b{standard}: a standard project is a non library project with sources.
3064 This is the default (implicit) qualifier.
3065 @item @b{aggregate}: a project whose sources are aggregated from other
3067 @item @b{aggregate library}: a library whose sources are aggregated
3068 from other project or library project files.
3069 @item @b{library}: a library project must declare both attributes
3070 @code{Library_Name} and @code{Library_Dir}.
3071 @item @b{configuration}: a configuration project cannot be in a project tree.
3072 It describes compilers and other tools to @command{gprbuild}.
3075 @c ---------------------------------------------
3077 @subsection Declarations
3078 @c ---------------------------------------------
3081 Declarations introduce new entities that denote types, variables, attributes,
3082 and packages. Some declarations can only appear immediately within a project
3083 declaration. Others can appear within a project or within a package.
3086 declarative_item ::= simple_declarative_item
3087 | typed_string_declaration
3088 | package_declaration
3090 simple_declarative_item ::= variable_declaration
3091 | typed_variable_declaration
3092 | attribute_declaration
3096 empty_declaration ::= @i{null} ;
3100 An empty declaration is allowed anywhere a declaration is allowed. It has
3103 @c ---------------------------------------------
3105 @subsection Packages
3106 @c ---------------------------------------------
3109 A project file may contain @b{packages}, that group attributes (typically
3110 all the attributes that are used by one of the GNAT tools).
3112 A package with a given name may only appear once in a project file.
3113 The following packages are currently supported in project files
3114 (See @pxref{Attributes} for the list of attributes that each can contain).
3118 This package specifies characteristics useful when invoking the binder either
3119 directly via the @command{gnat} driver or when using a builder such as
3120 @command{gnatmake} or @command{gprbuild}. @xref{Main Subprograms}.
3122 This package specifies the compilation options used when building an
3123 executable or a library for a project. Most of the options should be
3124 set in one of @code{Compiler}, @code{Binder} or @code{Linker} packages,
3125 but there are some general options that should be defined in this
3126 package. @xref{Main Subprograms}, and @pxref{Executable File Names} in
3129 This package specifies the options used when calling the checking tool
3130 @command{gnatcheck} via the @command{gnat} driver. Its attribute
3131 @b{Default_Switches} has the same semantics as for the package
3132 @code{Builder}. The first string should always be @code{-rules} to specify
3133 that all the other options belong to the @code{-rules} section of the
3134 parameters to @command{gnatcheck}.
3136 This package specifies the options used when cleaning a project or a project
3137 tree using the tools @command{gnatclean} or @command{gprclean}.
3139 This package specifies the compilation options used by the compiler for
3140 each languages. @xref{Tools Options in Project Files}.
3141 @item Cross_Reference
3142 This package specifies the options used when calling the library tool
3143 @command{gnatxref} via the @command{gnat} driver. Its attributes
3144 @b{Default_Switches} and @b{Switches} have the same semantics as for the
3145 package @code{Builder}.
3147 This package specifies the options used when calling the tool
3148 @command{gnatelim} via the @command{gnat} driver. Its attributes
3149 @b{Default_Switches} and @b{Switches} have the same semantics as for the
3150 package @code{Builder}.
3152 This package specifies the options used when calling the search tool
3153 @command{gnatfind} via the @command{gnat} driver. Its attributes
3154 @b{Default_Switches} and @b{Switches} have the same semantics as for the
3155 package @code{Builder}.
3157 This package the options to use when invoking @command{gnatls} via the
3158 @command{gnat} driver.
3160 This package specifies the options used when calling the tool
3161 @command{gnatstub} via the @command{gnat} driver. Its attributes
3162 @b{Default_Switches} and @b{Switches} have the same semantics as for the
3163 package @code{Builder}.
3165 This package specifies the options used when starting an integrated
3166 development environment, for instance @command{GPS} or @command{Gnatbench}.
3168 This package specifies the options used when installing a project
3169 with @command{gprinstall}. @xref{Installation}.
3171 This package specifies the options used by the linker.
3172 @xref{Main Subprograms}.
3174 This package specifies the options used when calling the tool
3175 @command{gnatmetric} via the @command{gnat} driver. Its attributes
3176 @b{Default_Switches} and @b{Switches} have the same semantics as for the
3177 package @code{Builder}.
3179 This package specifies the naming conventions that apply
3180 to the source files in a project. In particular, these conventions are
3181 used to automatically find all source files in the source directories,
3182 or given a file name to find out its language for proper processing.
3183 @xref{Naming Schemes}.
3184 @item Pretty_Printer
3185 This package specifies the options used when calling the formatting tool
3186 @command{gnatpp} via the @command{gnat} driver. Its attributes
3187 @b{Default_Switches} and @b{Switches} have the same semantics as for the
3188 package @code{Builder}.
3190 This package is used by @command{gprbuild} to describe how distributed
3191 compilation should be done.
3193 This package specifies the options used when calling the tool
3194 @command{gnatstack} via the @command{gnat} driver. Its attributes
3195 @b{Default_Switches} and @b{Switches} have the same semantics as for the
3196 package @code{Builder}.
3198 This package specifies the options used when calling the tool
3199 @command{gnatsync} via the @command{gnat} driver.
3203 In its simplest form, a package may be empty:
3205 @smallexample @c projectfile
3215 A package may contain @b{attribute declarations},
3216 @b{variable declarations} and @b{case constructions}, as will be
3219 When there is ambiguity between a project name and a package name,
3220 the name always designates the project. To avoid possible confusion, it is
3221 always a good idea to avoid naming a project with one of the
3222 names allowed for packages or any name that starts with @code{gnat}.
3224 A package can also be defined by a @b{renaming declaration}. The new package
3225 renames a package declared in a different project file, and has the same
3226 attributes as the package it renames. The name of the renamed package
3227 must be the same as the name of the renaming package. The project must
3228 contain a package declaration with this name, and the project
3229 must appear in the context clause of the current project, or be its parent
3230 project. It is not possible to add or override attributes to the renaming
3231 project. If you need to do so, you should use an @b{extending declaration}
3234 Packages that are renamed in other project files often come from project files
3235 that have no sources: they are just used as templates. Any modification in the
3236 template will be reflected automatically in all the project files that rename
3237 a package from the template. This is a very common way to share settings
3240 Finally, a package can also be defined by an @b{extending declaration}. This is
3241 similar to a @b{renaming declaration}, except that it is possible to add or
3242 override attributes.
3245 package_declaration ::= package_spec | package_renaming | package_extension
3247 @i{package} @i{<package_>}simple_name @i{is}
3248 @{simple_declarative_item@}
3249 @i{end} package_identifier ;
3250 package_renaming ::==
3251 @i{package} @i{<package_>}simple_name @i{renames} @i{<project_>}simple_name.package_identifier ;
3252 package_extension ::==
3253 @i{package} @i{<package_>}simple_name @i{extends} @i{<project_>}simple_name.package_identifier @i{is}
3254 @{simple_declarative_item@}
3255 @i{end} package_identifier ;
3258 @c ---------------------------------------------
3260 @subsection Expressions
3261 @c ---------------------------------------------
3264 An expression is any value that can be assigned to an attribute or a
3265 variable. It is either a literal value, or a construct requiring runtime
3266 computation by the project manager. In a project file, the computed value of
3267 an expression is either a string or a list of strings.
3269 A string value is one of:
3271 @item A literal string, for instance @code{"comm/my_proj.gpr"}
3272 @item The name of a variable that evaluates to a string (@pxref{Variables})
3273 @item The name of an attribute that evaluates to a string (@pxref{Attributes})
3274 @item An external reference (@pxref{External Values})
3275 @item A concatenation of the above, as in @code{"prefix_" & Var}.
3280 A list of strings is one of the following:
3283 @item A parenthesized comma-separated list of zero or more string expressions, for
3284 instance @code{(File_Name, "gnat.adc", File_Name & ".orig")} or @code{()}.
3285 @item The name of a variable that evaluates to a list of strings
3286 @item The name of an attribute that evaluates to a list of strings
3287 @item A concatenation of a list of strings and a string (as defined above), for
3288 instance @code{("A", "B") & "C"}
3289 @item A concatenation of two lists of strings
3294 The following is the grammar for expressions
3297 string_literal ::= "@{string_element@}" -- Same as Ada
3298 string_expression ::= string_literal
3301 | attribute_reference
3302 | ( string_expression @{ & string_expression @} )
3303 string_list ::= ( string_expression @{ , string_expression @} )
3304 | @i{string_variable}_name
3305 | @i{string_}attribute_reference
3306 term ::= string_expression | string_list
3307 expression ::= term @{ & term @} -- Concatenation
3311 Concatenation involves strings and list of strings. As soon as a list of
3312 strings is involved, the result of the concatenation is a list of strings. The
3313 following Ada declarations show the existing operators:
3315 @smallexample @c ada
3316 function "&" (X : String; Y : String) return String;
3317 function "&" (X : String_List; Y : String) return String_List;
3318 function "&" (X : String_List; Y : String_List) return String_List;
3322 Here are some specific examples:
3324 @smallexample @c projectfile
3326 List := () & File_Name; -- One string in this list
3327 List2 := List & (File_Name & ".orig"); -- Two strings
3328 Big_List := List & Lists2; -- Three strings
3329 Illegal := "gnat.adc" & List2; -- Illegal, must start with list
3333 @c ---------------------------------------------
3334 @node External Values
3335 @subsection External Values
3336 @c ---------------------------------------------
3339 An external value is an expression whose value is obtained from the command
3340 that invoked the processing of the current project file (typically a
3341 @command{gnatmake} or @command{gprbuild} command).
3343 There are two kinds of external values, one that returns a single string, and
3344 one that returns a string list.
3346 The syntax of a single string external value is:
3349 external_value ::= @i{external} ( string_literal [, string_literal] )
3353 The first string_literal is the string to be used on the command line or
3354 in the environment to specify the external value. The second string_literal,
3355 if present, is the default to use if there is no specification for this
3356 external value either on the command line or in the environment.
3358 Typically, the external value will either exist in the
3359 ^environment variables^logical name^
3360 or be specified on the command line through the
3361 @option{^-X^/EXTERNAL_REFERENCE=^@emph{vbl}=@emph{value}} switch. If both
3362 are specified, then the command line value is used, so that a user can more
3363 easily override the value.
3365 The function @code{external} always returns a string. It is an error if the
3366 value was not found in the environment and no default was specified in the
3367 call to @code{external}.
3369 An external reference may be part of a string expression or of a string
3370 list expression, and can therefore appear in a variable declaration or
3371 an attribute declaration.
3373 Most of the time, this construct is used to initialize typed variables, which
3374 are then used in @b{case} statements to control the value assigned to
3375 attributes in various scenarios. Thus such variables are often called
3376 @b{scenario variables}.
3378 The syntax for a string list external value is:
3381 external_value ::= @i{external_as_list} ( 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 is
3387 the separator between each component of the string list.
3389 If the external value does not exist in the environment or on the command line,
3390 the result is an empty list. This is also the case, if the separator is an
3391 empty string or if the external value is only one separator.
3393 Any separator at the beginning or at the end of the external value is
3394 discarded. Then, if there is no separator in the external value, the result is
3395 a string list with only one string. Otherwise, any string between the beginning
3396 and the first separator, between two consecutive separators and between the
3397 last separator and the end are components of the string list.
3400 @i{external_as_list} ("SWITCHES", ",")
3404 If the external value is "-O2,-g", the result is ("-O2", "-g").
3406 If the external value is ",-O2,-g,", the result is also ("-O2", "-g").
3408 if the external value is "-gnav", the result is ("-gnatv").
3410 If the external value is ",,", the result is ("").
3412 If the external value is ",", the result is (), the empty string list.
3414 @c ---------------------------------------------
3415 @node Typed String Declaration
3416 @subsection Typed String Declaration
3417 @c ---------------------------------------------
3420 A @b{type declaration} introduces a discrete set of string literals.
3421 If a string variable is declared to have this type, its value
3422 is restricted to the given set of literals. These are the only named
3423 types in project files. A string type may only be declared at the project
3424 level, not inside a package.
3427 typed_string_declaration ::=
3428 @i{type} @i{<typed_string_>}_simple_name @i{is} ( string_literal @{, string_literal@} );
3432 The string literals in the list are case sensitive and must all be different.
3433 They may include any graphic characters allowed in Ada, including spaces.
3434 Here is an example of a string type declaration:
3436 @smallexample @c projectfile
3437 type OS is ("NT", "nt", "Unix", "GNU/Linux", "other OS");
3441 Variables of a string type are called @b{typed variables}; all other
3442 variables are called @b{untyped variables}. Typed variables are
3443 particularly useful in @code{case} constructions, to support conditional
3444 attribute declarations. (@pxref{Case Constructions}).
3446 A string type may be referenced by its name if it has been declared in the same
3447 project file, or by an expanded name whose prefix is the name of the project
3448 in which it is declared.
3450 @c ---------------------------------------------
3452 @subsection Variables
3453 @c ---------------------------------------------
3456 @b{Variables} store values (strings or list of strings) and can appear
3457 as part of an expression. The declaration of a variable creates the
3458 variable and assigns the value of the expression to it. The name of the
3459 variable is available immediately after the assignment symbol, if you
3460 need to reuse its old value to compute the new value. Before the completion
3461 of its first declaration, the value of a variable defaults to the empty
3464 A @b{typed} variable can be used as part of a @b{case} expression to
3465 compute the value, but it can only be declared once in the project file,
3466 so that all case constructions see the same value for the variable. This
3467 provides more consistency and makes the project easier to understand.
3468 The syntax for its declaration is identical to the Ada syntax for an
3469 object declaration. In effect, a typed variable acts as a constant.
3471 An @b{untyped} variable can be declared and overridden multiple times
3472 within the same project. It is declared implicitly through an Ada
3473 assignment. The first declaration establishes the kind of the variable
3474 (string or list of strings) and successive declarations must respect
3475 the initial kind. Assignments are executed in the order in which they
3476 appear, so the new value replaces the old one and any subsequent reference
3477 to the variable uses the new value.
3479 A variable may be declared at the project file level, or within a package.
3482 typed_variable_declaration ::=
3483 @i{<typed_variable_>}simple_name : @i{<typed_string_>}name := string_expression;
3484 variable_declaration ::= @i{<variable_>}simple_name := expression;
3488 Here are some examples of variable declarations:
3490 @smallexample @c projectfile
3492 This_OS : OS := external ("OS"); -- a typed variable declaration
3493 That_OS := "GNU/Linux"; -- an untyped variable declaration
3495 Name := "readme.txt";
3496 Save_Name := Name & ".saved";
3499 List_With_One_Element := ("-gnaty");
3500 List_With_Two_Elements := List_With_One_Element & "-gnatg";
3501 Long_List := ("main.ada", "pack1_.ada", "pack1.ada", "pack2_.ada");
3506 A @b{variable reference} may take several forms:
3509 @item The simple variable name, for a variable in the current package (if any)
3510 or in the current project
3511 @item An expanded name, whose prefix is a context name.
3516 A @b{context} may be one of the following:
3519 @item The name of an existing package in the current project
3520 @item The name of an imported project of the current project
3521 @item The name of an ancestor project (i.e., a project extended by the current
3522 project, either directly or indirectly)
3523 @item An expanded name whose prefix is an imported/parent project name, and
3524 whose selector is a package name in that project.
3527 @c ---------------------------------------------
3528 @node Case Constructions
3529 @subsection Case Constructions
3530 @c ---------------------------------------------
3533 A @b{case} statement is used in a project file to effect conditional
3534 behavior. Through this statement, you can set the value of attributes
3535 and variables depending on the value previously assigned to a typed
3538 All choices in a choice list must be distinct. Unlike Ada, the choice
3539 lists of all alternatives do not need to include all values of the type.
3540 An @code{others} choice must appear last in the list of alternatives.
3542 The syntax of a @code{case} construction is based on the Ada case statement
3543 (although the @code{null} statement for empty alternatives is optional).
3545 The case expression must be a typed string variable, whose value is often
3546 given by an external reference (@pxref{External Values}).
3548 Each alternative starts with the reserved word @code{when}, either a list of
3549 literal strings separated by the @code{"|"} character or the reserved word
3550 @code{others}, and the @code{"=>"} token.
3551 Each literal string must belong to the string type that is the type of the
3553 After each @code{=>}, there are zero or more statements. The only
3554 statements allowed in a case construction are other case constructions,
3555 attribute declarations and variable declarations. String type declarations and
3556 package declarations are not allowed. Variable declarations are restricted to
3557 variables that have already been declared before the case construction.
3561 @i{case} @i{<typed_variable_>}name @i{is} @{case_item@} @i{end case} ;
3564 @i{when} discrete_choice_list =>
3566 | attribute_declaration
3567 | variable_declaration
3568 | empty_declaration@}
3570 discrete_choice_list ::= string_literal @{| string_literal@} | @i{others}
3574 Here is a typical example:
3576 @smallexample @c projectfile
3579 type OS_Type is ("GNU/Linux", "Unix", "NT", "VMS");
3580 OS : OS_Type := external ("OS", "GNU/Linux");
3584 when "GNU/Linux" | "Unix" =>
3585 for Switches ("Ada") use ("-gnath");
3587 for Switches ("Ada") use ("-gnatP");
3596 @c ---------------------------------------------
3598 @subsection Attributes
3599 @c ---------------------------------------------
3602 * Project Level Attributes::
3603 * Package Binder Attributes::
3604 * Package Builder Attributes::
3605 * Package Check Attributes::
3606 * Package Clean Attributes::
3607 * Package Compiler Attributes::
3608 * Package Cross_Reference Attributes::
3609 * Package Eliminate Attributes::
3610 * Package Finder Attributes::
3611 * Package gnatls Attributes::
3612 * Package gnatstub Attributes::
3613 * Package IDE Attributes::
3614 * Package Install Attributes::
3615 * Package Linker Attributes::
3616 * Package Metrics Attribute::
3617 * Package Naming Attributes::
3618 * Package Pretty_Printer Attributes::
3619 * Package Remote Attributes::
3620 * Package Stack Attributes::
3621 * Package Synchronize Attributes::
3625 A project (and its packages) may have @b{attributes} that define
3626 the project's properties. Some attributes have values that are strings;
3627 others have values that are string lists.
3630 attribute_declaration ::=
3631 simple_attribute_declaration | indexed_attribute_declaration
3632 simple_attribute_declaration ::= @i{for} attribute_designator @i{use} expression ;
3633 indexed_attribute_declaration ::=
3634 @i{for} @i{<indexed_attribute_>}simple_name ( string_literal) @i{use} expression ;
3635 attribute_designator ::=
3636 @i{<simple_attribute_>}simple_name
3637 | @i{<indexed_attribute_>}simple_name ( string_literal )
3641 There are two categories of attributes: @b{simple attributes}
3642 and @b{indexed attributes}.
3643 Each simple attribute has a default value: the empty string (for string
3644 attributes) and the empty list (for string list attributes).
3645 An attribute declaration defines a new value for an attribute, and overrides
3646 the previous value. The syntax of a simple attribute declaration is similar to
3647 that of an attribute definition clause in Ada.
3649 Some attributes are indexed. These attributes are mappings whose
3650 domain is a set of strings. They are declared one association
3651 at a time, by specifying a point in the domain and the corresponding image
3653 Like untyped variables and simple attributes, indexed attributes
3654 may be declared several times. Each declaration supplies a new value for the
3655 attribute, and replaces the previous setting.
3657 Here are some examples of attribute declarations:
3659 @smallexample @c projectfile
3660 -- simple attributes
3661 for Object_Dir use "objects";
3662 for Source_Dirs use ("units", "test/drivers");
3664 -- indexed attributes
3665 for Body ("main") use "Main.ada";
3666 for Switches ("main.ada") use ("-v", "-gnatv");
3667 for Switches ("main.ada") use Builder'Switches ("main.ada") & "-g";
3669 -- indexed attributes copy (from package Builder in project Default)
3670 -- The package name must always be specified, even if it is the current
3672 for Default_Switches use Default.Builder'Default_Switches;
3676 Attributes references may appear anywhere in expressions, and are used
3677 to retrieve the value previously assigned to the attribute. If an attribute
3678 has not been set in a given package or project, its value defaults to the
3679 empty string or the empty list.
3682 attribute_reference ::= attribute_prefix ' @i{<simple_attribute>_}simple_name [ (string_literal) ]
3683 attribute_prefix ::= @i{project}
3684 | @i{<project_>}simple_name
3685 | package_identifier
3686 | @i{<project_>}simple_name . package_identifier
3692 @smallexample @c projectfile
3694 Naming'Dot_Replacement
3695 Imported_Project'Source_Dirs
3696 Imported_Project.Naming'Casing
3697 Builder'Default_Switches ("Ada")
3701 The prefix of an attribute may be:
3704 @item @code{project} for an attribute of the current project
3705 @item The name of an existing package of the current project
3706 @item The name of an imported project
3707 @item The name of a parent project that is extended by the current project
3708 @item An expanded name whose prefix is imported/parent project name,
3709 and whose selector is a package name
3715 In the following sections, all predefined attributes are succinctly described,
3716 first the project level attributes, that is those attributes that are not in a
3717 package, then the attributes in the different packages.
3719 It is possible for different tools to create dynamically new packages with
3720 attributes, or new attribute in predefined packages. These attributes are
3721 not documented here.
3723 The attributes under Configuration headings are usually found only in
3724 configuration project files.
3726 The characteristics of each attribute are indicated as follows:
3730 @item @b{Type of value}
3732 The value of an attribute may be a single string, indicated by the word
3733 "single", or a string list, indicated by the word "list".
3737 When the attribute is read-only, that is when it is not allowed to declare
3738 the attribute, this is indicated by the words "read-only".
3740 @item @b{Optional index}
3742 If it is allowed in the value of the attribute (both single and list) to have
3743 an optional index, this is indicated by the words "optional index".
3745 @item @b{Indexed attribute}
3747 When an it is an indexed attribute, this is indicated by the word "indexed".
3749 @item @b{Case-sensitivity of the index}
3751 For an indexed attribute, if the index is case-insensitive, this is indicated
3752 by the words "case-insensitive index".
3754 @item @b{File name index}
3756 For an indexed attribute, when the index is a file name, this is indicated by
3757 the words "file name index". The index may or may not be case-sensitive,
3758 depending on the platform.
3760 @item @b{others allowed in index}
3762 For an indexed attribute, if it is allowed to use @b{others} as the index,
3763 this is indicated by the words "others allowed".
3767 @node Project Level Attributes
3768 @subsubsection Project Level Attributes
3777 @item @b{Name}: single, read-only
3779 The name of the project.
3781 @item @b{Project_Dir}: single, read-only
3783 The path name of the project directory.
3785 @item @b{Main}: list, optional index
3787 The list of main sources for the executables.
3789 @item @b{Languages}: list
3791 The list of languages of the sources of the project.
3793 @item @b{Roots}: list, indexed, file name index
3795 The index is the file name of an executable source. Indicates the list of units
3796 from the main project that need to be bound and linked with their closures
3797 with the executable. The index is either a file name, a language name or "*".
3798 The roots for an executable source are those in @b{Roots} with an index that
3799 is the executable source file name, if declared. Otherwise, they are those in
3800 @b{Roots} with an index that is the language name of the executable source,
3801 if present. Otherwise, they are those in @b{Roots ("*")}, if declared. If none
3802 of these three possibilities are declared, then there are no roots for the
3805 @item @b{Externally_Built}: single
3807 Indicates if the project is externally built.
3808 Only case-insensitive values allowed are "true" and "false", the default.
3813 @item @b{Directories}
3817 @item @b{Object_Dir}: single
3819 Indicates the object directory for the project.
3821 @item @b{Exec_Dir}: single
3823 Indicates the exec directory for the project, that is the directory where the
3826 @item @b{Source_Dirs}: list
3828 The list of source directories of the project.
3830 @item @b{Inherit_Source_Path}: list, indexed, case-insensitive index
3832 Index is a language name. Value is a list of language names. Indicates that
3833 in the source search path of the index language the source directories of
3834 the languages in the list should be included.
3838 for Inherit_Source_Path ("C++") use ("C");
3840 @item @b{Exclude_Source_Dirs}: list
3842 The list of directories that are included in Source_Dirs but are not source
3843 directories of the project.
3845 @item @b{Ignore_Source_Sub_Dirs}: list
3847 Value is a list of simple names for subdirectories that are removed from the
3848 list of source directories, including theur subdirectories.
3852 @item @b{Source Files}
3856 @item @b{Source_Files}: list
3858 Value is a list of source file simple names.
3860 @item @b{Locally_Removed_Files}: list
3862 Obsolescent. Equivalent to Excluded_Source_Files.
3864 @item @b{Excluded_Source_Files}: list
3866 Value is a list of simple file names that are not sources of the project.
3867 Allows to remove sources that are inherited or found in the source directories
3868 and that match the naming scheme.
3870 @item @b{Source_List_File}: single
3872 Value is a text file name that contains a list of source file simple names,
3875 @item @b{Excluded_Source_List_File}: single
3877 Value is a text file name that contains a list of file simple names that
3878 are not sources of the project.
3880 @item @b{Interfaces}: list
3882 Value is a list of file names that constitutes the interfaces of the project.
3886 @item @b{Aggregate Projects}
3890 @item @b{Project_Files}: list
3892 Value is the list of aggregated projects.
3894 @item @b{Project_Path}: list
3896 Value is a list of directories that are added to the project search path when
3897 looking for the aggregated projects.
3899 @item @b{External}: single, indexed
3901 Index is the name of an external reference. Value is the value of the
3902 external reference to be used when parsing the aggregated projects.
3910 @item @b{Library_Dir}: single
3912 Value is the name of the library directory. This attribute needs to be
3913 declared for each library project.
3915 @item @b{Library_Name}: single
3917 Value is the name of the library. This attribute needs to be declared or
3918 inherited for each library project.
3920 @item @b{Library_Kind}: single
3922 Specifies the kind of library: static library (archive) or shared library.
3923 Case-insensitive values must be one of "static" for archives (the default) or
3924 "dynamic" or "relocatable" for shared libraries.
3926 @item @b{Library_Version}: single
3928 Value is the name of the library file.
3930 @item @b{Library_Interface}: list
3932 Value is the list of unit names that constitutes the interfaces
3933 of a Stand-Alone Library project.
3935 @item @b{Library_Standalone}: single
3937 Specifies if a Stand-Alone Library (SAL) is encapsulated or not.
3938 Only authorized case-insensitive values are "standard" for non encapsulated
3939 SALs, "encapsulated" for encapsulated SALs or "no" for non SAL library project.
3941 @item @b{Library_Encapsulated_Options}: list
3943 Value is a list of options that need to be used when linking an encapsulated
3944 Stand-Alone Library.
3946 @item @b{Library_Encapsulated_Supported}: single
3948 Indicates if encapsulated Stand-Alone Libraries are supported. Only
3949 authorized case-insensitive values are "true" and "false" (the default).
3951 @item @b{Library_Auto_Init}: single
3953 Indicates if a Stand-Alone Library is auto-initialized. Only authorized
3954 case-insentive values are "true" and "false".
3956 @item @b{Leading_Library_Options}: list
3958 Value is a list of options that are to be used at the beginning of
3959 the command line when linking a shared library.
3961 @item @b{Library_Options}: list
3963 Value is a list of options that are to be used when linking a shared library.
3965 @item @b{Library_Src_Dir}: single
3967 Value is the name of the directory where copies of the sources of the
3968 interfaces of a Stand-Alone Library are to be copied.
3970 @item @b{Library_ALI_Dir}: single
3972 Value is the name of the directory where the ALI files of the interfaces
3973 of a Stand-Alone Library are to be copied. When this attribute is not declared,
3974 the directory is the library directory.
3976 @item @b{Library_gcc}: single
3978 Obsolescent attribute. Specify the linker driver used to link a shared library.
3979 Use instead attribute Linker'Driver.
3981 @item @b{Library_Symbol_File}: single
3983 Value is the name of the library symbol file.
3985 @item @b{Library_Symbol_Policy}: single
3987 Indicates the symbol policy kind. Only authorized case-insensitive values are
3988 "autonomous", "default", "compliant", "controlled" or "direct".
3990 @item @b{Library_Reference_Symbol_File}: single
3992 Value is the name of the reference symbol file.
3996 @item @b{Configuration - General}
4000 @item @b{Default_Language}: single
4002 Value is the case-insensitive name of the language of a project when attribute
4003 Languages is not specified.
4005 @item @b{Run_Path_Option}: list
4007 Value is the list of switches to be used when specifying the run path option
4010 @item @b{Run_Path_Origin}: single
4012 Value is the the string that may replace the path name of the executable
4013 directory in the run path options.
4015 @item @b{Separate_Run_Path_Options}: single
4017 Indicates if there may be or not several run path options specified when
4018 linking an executable. Only authorized case-insensitive b=values are "true" or
4019 "false" (the default).
4021 @item @b{Toolchain_Version}: single, indexed, case-insensitive index
4023 Index is a language name. Specify the version of a toolchain for a language.
4025 @item @b{Toolchain_Description}: single, indexed, case-insensitive index
4027 Obsolescent. No longer used.
4029 @item @b{Object_Generated}: single, indexed, case-insensitive index
4031 Index is a language name. Indicates if invoking the compiler for a language
4032 produces an object file. Only authorized case-insensitive values are "false"
4033 and "true" (the default).
4035 @item @b{Objects_Linked}: single, indexed, case-insensitive index
4037 Index is a language name. Indicates if the object files created by the compiler
4038 for a language need to be linked in the executable. Only authorized
4039 case-insensitive values are "false" and "true" (the default).
4041 @item @b{Target}: single
4043 Value is the name of the target platform.
4047 @item @b{Configuration - Libraries}
4051 @item @b{Library_Builder}: single
4053 Value is the path name of the application that is to be used to build
4054 libraries. Usually the path name of "gprlib".
4056 @item @b{Library_Support}: single
4058 Indicates the level of support of libraries. Only authorized case-insensitive
4059 values are "static_only", "full" or "none" (the default).
4063 @item @b{Configuration - Archives}
4067 @item @b{Archive_Builder}: list
4069 Value is the name of the application to be used to create a static library
4070 (archive), followed by the options to be used.
4072 @item @b{Archive_Builder_Append_Option}: list
4074 Value is the list of options to be used when invoking the archive builder
4075 to add project files into an archive.
4077 @item @b{Archive_Indexer}: list
4079 Value is the name of the archive indexer, followed by the required options.
4081 @item @b{Archive_Suffix}: single
4083 Value is the extension of archives. When not declared, the extension is ".a".
4085 @item @b{Library_Partial_Linker}: list
4087 Value is the name of the partial linker executable, followed by the required
4092 @item @b{Configuration - Shared Libraries}
4096 @item @b{Shared_Library_Prefix}: single
4098 Value is the prefix in the name of shared library files. When not declared,
4099 the prefix is "lib".
4101 @item @b{Shared_Library_Suffix}: single
4103 Value is the the extension of the name of shared library files. When not
4104 declared, the extension is ".so".
4106 @item @b{Symbolic_Link_Supported}: single
4108 Indicates if symbolic links are supported on the platform. Only authorized
4109 case-insensitive values are "true" and "false" (the default).
4111 @item @b{Library_Major_Minor_Id_Supported}: single
4113 Indicates if major and minor ids for shared library names are supported on
4114 the platform. Only authorized case-insensitive values are "true" and "false"
4117 @item @b{Library_Auto_Init_Supported}: single
4119 Indicates if auto-initialization of Stand-Alone Libraries is supported. Only
4120 authorized case-insensitive values are "true" and "false" (the default).
4122 @item @b{Shared_Library_Minimum_Switches}: list
4124 Value is the list of required switches when linking a shared library.
4126 @item @b{Library_Version_Switches}: list
4128 Value is the list of switches to specify a internal name for a shared library.
4130 @item @b{Library_Install_Name_Option}: single
4132 Value is the name of the option that needs to be used, concatenated with the
4133 path name of the library file, when linking a shared library.
4135 @item @b{Runtime_Library_Dir}: single, indexed, case-insensitive index
4137 Index is a language name. Value is the path name of the directory where the
4138 runtime libraries are located.
4140 @item @b{Runtime_Source_Dir}: single, indexed, case-insensitive index
4142 Index is a language name. Value is the path name of the directory where the
4143 sources of runtime libraries are located.
4149 @node Package Binder Attributes
4150 @subsubsection Package Binder Attributes
4158 @item @b{Default_Switches}: list, indexed, case-insensitive index
4160 Index is a language name. Value is the list of switches to be used when binding
4161 code of the language, if there is no applicable attribute Switches.
4163 @item @b{Switches}: list, optional index, indexed, case-insensitive index,
4166 Index is either a language name or a source file name. Value is the list of
4167 switches to be used when binding code. Index is either the source file name
4168 of the executable to be bound or the language name of the code to be bound.
4172 @item @b{Configuration - Binding}
4176 @item @b{Driver}: single, indexed, case-insensitive index
4178 Index is a language name. Value is the name of the application to be used when
4179 binding code of the language.
4181 @item @b{Required_Switches}: list, indexed, case-insensitive index
4183 Index is a language name. Value is the list of the required switches to be
4184 used when binding code of the language.
4186 @item @b{Prefix}: single, indexed, case-insensitive index
4188 Index is a language name. Value is a prefix to be used for the binder exchange
4189 file name for the language. Used to have different binder exchange file names
4190 when binding different languages.
4192 @item @b{Objects_Path}: single,indexed, case-insensitive index
4194 Index is a language name. Value is the name of the environment variable that
4195 contains the path for the object directories.
4197 @item @b{Object_Path_File}: single,indexed, case-insensitive index
4199 Index is a language name. Value is the name of the environment variable. The
4200 value of the environment variable is the path name of a text file that
4201 contains the list of object directories.
4207 @node Package Builder Attributes
4208 @subsubsection Package Builder Attributes
4212 @item @b{Default_Switches}: list, indexed, case-insensitive index
4214 Index is a language name. Value is the list of builder switches to be used when
4215 building an executable of the language, if there is no applicable attribute
4218 @item @b{Switches}: list, optional index, indexed, case-insensitive index,
4221 Index is either a language name or a source file name. Value is the list of
4222 builder switches to be used when building an executable. Index is either the
4223 source file name of the executable to be built or its language name.
4225 @item @b{Global_Compilation_Switches}: list, optional index, indexed,
4226 case-insensitive index
4228 Index is either a language name or a source file name. Value is the list of
4229 compilation switches to be used when building an executable. Index is either
4230 the source file name of the executable to be built or its language name.
4232 @item @b{Executable}: single, indexed, case-insensitive index
4234 Index is an executable source file name. Value is the simple file name of the
4235 executable to be built.
4237 @item @b{Executable_Suffix}: single
4239 Value is the extension of the file names of executable. When not specified,
4240 the extension is the default extension of executables on the platform.
4242 @item @b{Global_Configuration_Pragmas}: single
4244 Value is the file name of a configuration pragmas file that is specified to
4245 the Ada compiler when compiling any Ada source in the project tree.
4247 @item @b{Global_Config_File}: single, indexed, case-insensitive index
4249 Index is a language name. Value is the file name of a configuration file that
4250 is specified to the compiler when compiling any source of the language in the
4255 @node Package Check Attributes
4256 @subsubsection Package Check Attributes
4260 @item @b{Default_Switches}: list, indexed, case-insensitive index
4262 Index is a language name. Value is a list of switches to be used when invoking
4263 @code{gnatcheck} for a source of the language, if there is no applicable
4266 @item @b{Switches}: list, optional index, indexed, case-insensitive index,
4269 Index is a source file name. Value is the list of switches to be used when
4270 invoking @code{gnatcheck} for the source.
4274 @node Package Clean Attributes
4275 @subsubsection Package Clean Attributes
4279 @item @b{Switches}: list
4281 Value is a list of switches to be used by the cleaning application.
4283 @item @b{Source_Artifact_Extensions}: list, indexed, case-insensitive index
4285 Index is a language names. Value is the list of extensions for file names
4286 derived from object file names that need to be cleaned in the object
4287 directory of the project.
4289 @item @b{Object_Artifact_Extensions}: list, indexed, case-insensitive index
4291 Index is a language names. Value is the list of extensions for file names
4292 derived from source file names that need to be cleaned in the object
4293 directory of the project.
4297 @node Package Compiler Attributes
4298 @subsubsection Package Compiler Attributes
4306 @item @b{Default_Switches}: list, indexed, case-insensitive index
4308 Index is a language name. Value is a list of switches to be used when invoking
4309 the compiler for the language for a source of the project, if there is no
4310 applicable attribute Switches.
4312 @item @b{Switches}: list, optional index, indexed, case-insensitive index,
4315 Index is a source file name or a language name. Value is the list of switches
4316 to be used when invoking the compiler for the source or for its language.
4318 @item @b{Local_Configuration_Pragmas}: single
4320 Value is the file name of a configuration pragmas file that is specified to
4321 the Ada compiler when compiling any Ada source in the project.
4323 @item @b{Local_Config_File}: single, indexed, case-insensitive index
4325 Index is a language name. Value is the file name of a configuration file that
4326 is specified to the compiler when compiling any source of the language in the
4331 @item @b{Configuration - Compiling}
4335 @item @b{Driver}: single, indexed, case-insensitive index
4337 Index is a language name. Value is the name of the executable for the compiler
4340 @item @b{Language_Kind}: single, indexed, case-insensitive index
4342 Index is a language name. Indicates the kind of the language, either file based
4343 or unit based. Only authorized case-insensitive values are "unit_based" and
4344 "file_based" (the default).
4346 @item @b{Dependency_Kind}: : single, indexed, case-insensitive index
4348 Index is a language name. Indicates how the dependencies are handled for the
4349 language. Only authorized case-insensitive values are "makefile", "ali_file",
4350 "ali_closure" or "none" (the default.
4352 @item @b{Required_Switches}: list, indexed, case-insensitive index
4354 Equivalent to attribute Leading_Required_Switches.
4356 @item @b{Leading_Required_Switches}: list, indexed, case-insensitive index
4358 Index is a language name. Value is the list of the minimum switches to be used
4359 at the beginning of the command line when invoking the compiler for the
4362 @item @b{Trailing_Required_Switches}: list, indexed, case-insensitive index
4364 Index is a language name. Value is the list of the minimum switches to be used
4365 at the end of the command line when invoking the compiler for the language.
4367 @item @b{PIC_Option}: list, indexed, case-insensitive index
4369 Index is a language name. Value is the list of switches to be used when
4370 compiling a source of the language when the project is a shared library
4373 @item @b{Path_Syntax}: single, indexed, case-insensitive index
4375 Index is a language name. Value is the kind of path syntax to be used when
4376 invoking the compiler for the language. Only authorized case-insensitive
4377 values are "canonical" and "host" (the default).
4379 @item @b{Source_File_Switches}: single, indexed, case-insensitive index
4381 Index is a language name. Value is a list of switches to be used just before
4382 the path name of the source to compile when invoking the compiler for a source
4385 @item @b{Object_File_Suffix}: single, indexed, case-insensitive index
4387 Index is a language name. Value is the extension of the object files created
4388 by the compiler of the language. When not specified, the extension is the
4389 default one for the platform.
4391 @item @b{Object_File_Switches}: list, indexed, case-insensitive index
4393 Index is a language name. Value is the list of switches to be used by the
4394 compiler of the language to specify the path name of the object file. When not
4395 specified, the switch used is "-o".
4397 @item @b{Multi_Unit_Switches}: list, indexed, case-insensitive index
4399 Index is a language name. Value is the list of switches to be used to compile
4400 a unit in a multi unit source of the language. The index of the unit in the
4401 source is concatenated with the last switches in the list.
4403 @item @b{Multi_Unit_Object_Separator}: single, indexed, case-insensitive index
4405 Index is a language name. Value is the string to be used in the object file
4406 name before the index of the unit, when compiling a unit in a multi unit source
4411 @item @b{Configuration - Mapping Files}
4415 @item @b{Mapping_File_Switches}: list, indexed, case-insensitive index
4417 Index is a language name. Value is the list of switches to be used to specify
4418 a mapping file when invoking the compiler for a source of the language.
4420 @item @b{Mapping_Spec_Suffix}: single, indexed, case-insensitive index
4422 Index is a language name. Value is the suffix to be used in a mapping file
4423 to indicate that the source is a spec.
4425 @item @b{Mapping_Body_Suffix}: single, indexed, case-insensitive index
4427 Index is a language name. Value is the suffix to be used in a mapping file
4428 to indicate that the source is a body.
4432 @item @b{Configuration - Config Files}
4436 @item @b{Config_File_Switches}: list: single, indexed, case-insensitive index
4438 Index is a language name. Value is the list of switches to specify to the
4439 compiler of the language a configuration file.
4441 @item @b{Config_Body_File_Name}: single, indexed, case-insensitive index
4443 Index is a language name. Value is the template to be used to indicate a
4444 configuration specific to a body of the language in a configuration
4447 @item @b{Config_Body_File_Name_Index}: single, indexed, case-insensitive index
4449 Index is a language name. Value is the template to be used to indicate a
4450 configuration specific to the body a unit in a multi unit source of the
4451 language in a configuration file.
4453 @item @b{Config_Body_File_Name_Pattern}: single, indexed,
4454 case-insensitive index
4456 Index is a language name. Value is the template to be used to indicate a
4457 configuration for all bodies of the languages in a configuration file.
4459 @item @b{Config_Spec_File_Name}: single, indexed, case-insensitive index
4461 Index is a language name. Value is the template to be used to indicate a
4462 configuration specific to a spec of the language in a configuration
4465 @item @b{Config_Spec_File_Name_Index}: single, indexed, case-insensitive index
4467 Index is a language name. Value is the template to be used to indicate a
4468 configuration specific to the spec a unit in a multi unit source of the
4469 language in a configuration file.
4471 @item @b{Config_Spec_File_Name_Pattern}: single, indexed,
4472 case-insensitive index
4474 Index is a language name. Value is the template to be used to indicate a
4475 configuration for all specs of the languages in a configuration file.
4477 @item @b{Config_File_Unique}: single, indexed, case-insensitive index
4479 Index is a language name. Indicates if there should be only one configuration
4480 file specified to the compiler of the language. Only authorized
4481 case-insensitive values are "true" and "false" (the default).
4485 @item @b{Configuration - Dependencies}
4489 @item @b{Dependency_Switches}: list, indexed, case-insensitive index
4491 Index is a language name. Value is the list of switches to be used to specify
4492 to the compiler the dependency file when the dependency kind of the language is
4493 file based, and when Dependency_Driver is not specified for the language.
4495 @item @b{Dependency_Driver}: list, indexed, case-insensitive index
4497 Index is a language name. Value is the name of the executable to be used to
4498 create the dependency file for a source of the language, followed by the
4503 @item @b{Configuration - Search Paths}
4507 @item @b{Include_Switches}: list, indexed, case-insensitive index
4509 Index is a language name. Value is the list of switches to specify to the
4510 compiler of the language to indicate a directory to look for sources.
4512 @item @b{Include_Path}: single, indexed, case-insensitive index
4514 Index is a language name. Value is the name of an environment variable that
4515 contains the path of all the directories that the compiler of the language
4516 may search for sources.
4518 @item @b{Include_Path_File}: single, indexed, case-insensitive index
4520 Index is a language name. Value is the name of an environment variable the
4521 value of which is the path name of a text file that contains the directories
4522 that the compiler of the language may search for sources.
4524 @item @b{Object_Path_Switches}: list, indexed, case-insensitive index
4526 Index is a language name. Value is the list of switches to specify to the
4527 compiler of the language the name of a text file that contains the list of
4528 object directories. When this attribute is not declared, the text file is
4535 @node Package Cross_Reference Attributes
4536 @subsubsection Package Cross_Reference Attributes
4540 @item @b{Default_Switches}: list, indexed, case-insensitive index
4542 Index is a language name. Value is a list of switches to be used when invoking
4543 @code{gnatxref} for a source of the language, if there is no applicable
4546 @item @b{Switches}: list, optional index, indexed, case-insensitive index,
4549 Index is a source file name. Value is the list of switches to be used when
4550 invoking @code{gnatxref} for the source.
4554 @node Package Eliminate Attributes
4555 @subsubsection Package Eliminate Attributes
4559 @item @b{Default_Switches}: list, indexed, case-insensitive index
4561 Index is a language name. Value is a list of switches to be used when invoking
4562 @code{gnatelim} for a source of the language, if there is no applicable
4565 @item @b{Switches}: list, optional index, indexed, case-insensitive index,
4568 Index is a source file name. Value is the list of switches to be used when
4569 invoking @code{gnatelim} for the source.
4573 @node Package Finder Attributes
4574 @subsubsection Package Finder Attributes
4578 @item @b{Default_Switches}: list, indexed, case-insensitive index
4580 Index is a language name. Value is a list of switches to be used when invoking
4581 @code{gnatfind} for a source of the language, if there is no applicable
4584 @item @b{Switches}: list, optional index, indexed, case-insensitive index,
4587 Index is a source file name. Value is the list of switches to be used when
4588 invoking @code{gnatfind} for the source.
4592 @node Package gnatls Attributes
4593 @subsubsection Package gnatls Attributes
4597 @item @b{Switches}: list
4599 Value is a list of switches to be used when invoking @code{gnatls}.
4603 @node Package gnatstub Attributes
4604 @subsubsection Package gnatstub Attributes
4608 @item @b{Default_Switches}: list, indexed, case-insensitive index
4610 Index is a language name. Value is a list of switches to be used when invoking
4611 @code{gnatstub} for a source of the language, if there is no applicable
4614 @item @b{Switches}: list, optional index, indexed, case-insensitive index,
4617 Index is a source file name. Value is the list of switches to be used when
4618 invoking @code{gnatstub} for the source.
4622 @node Package IDE Attributes
4623 @subsubsection Package IDE Attributes
4627 @item @b{Default_Switches}: list, indexed
4629 Index is the name of an external tool that the GNAT Programming System (GPS)
4630 is supporting. Value is a list of switches to use when invoking that tool.
4632 @item @b{Remote_Host}: single
4634 Value is a string that designates the remote host in a cross-compilation
4635 environment, to be used for remote compilation and debugging. This attribute
4636 should not be specified when running on the local machine.
4638 @item @b{Program_Host}: single
4640 Value is a string that specifies the name of IP address of the embedded target
4641 in a cross-compilation environment, on which the program should execute.
4643 @item @b{Communication_Protocol}: single
4645 Value is the name of the protocol to use to communicate with the target
4646 in a cross-compilation environment, for example @code{"wtx"} or
4649 @item @b{Compiler_Command}: single, indexed, case-insensitive index
4651 Index is a language Name. Value is a string that denotes the command to be
4652 used to invoke the compiler. The value of @code{Compiler_Command ("Ada")} is
4653 expected to be compatible with @command{gnatmake}, in particular in
4654 the handling of switches.
4656 @item @b{Debugger_Command}: single
4658 Value is a string that specifies the name of the debugger to be used, such as
4659 gdb, powerpc-wrs-vxworks-gdb or gdb-4.
4661 @item @b{gnatlist}: single
4663 Value is a string that specifies the name of the @command{gnatls} utility
4664 to be used to retrieve information about the predefined path; for example,
4665 @code{"gnatls"}, @code{"powerpc-wrs-vxworks-gnatls"}.
4667 @item @b{VCS_Kind}: single
4669 Value is a string used to specify the Version Control System (VCS) to be used
4670 for this project, for example CVS, RCS, ClearCase or Perforce.
4672 @item @b{VCS_File_Check}: single
4674 Value is a string that specifies the command used by the VCS to check
4675 the validity of a file, either when the user explicitly asks for a check,
4676 or as a sanity check before doing the check-in.
4678 @item @b{VCS_Log_Check}: single
4680 Value is a string that specifies the command used by the VCS to check
4681 the validity of a log file.
4683 @item @b{Documentation_Dir}: single
4685 Value is the directory used to generate the documentation of source code.
4689 @node Package Install Attributes
4690 @subsubsection Package Install Attributes
4694 @item @b{Prefix}: single
4696 Value is the install destination directory.
4698 @item @b{Sources_Subdir}: single
4700 Value is the sources directory or subdirectory of Prefix.
4702 @item @b{Exec_Subdir}: single
4704 Value is the executables directory or subdirectory of Prefix.
4706 @item @b{Lib_Subdir}: single
4708 Value is library directory or subdirectory of Prefix.
4710 @item @b{Project_Subdir}: single
4712 Value is the project directory or subdirectory of Prefix.
4714 @item @b{Active}: single
4716 Indicates that the project is to be installed or not. Case-insensitive value
4717 "false" means that the project is not to be installed, all other values mean
4718 that the project is to be installed.
4722 @node Package Linker Attributes
4723 @subsubsection Package Linker Attributes
4731 @item @b{Required_Switches}: list
4733 Value is a list of switches that are required when invoking the linker to link
4736 @item @b{Default_Switches}: list, indexed, case-insensitive index
4738 Index is a language name. Value is a list of switches for the linker when
4739 linking an executable for a main source of the language, when there is no
4740 applicable Switches.
4742 @item @b{Leading_Switches}: list, optional index, indexed,
4743 case-insensitive index, others allowed
4745 Index is a source file name or a language name. Value is the list of switches
4746 to be used at the beginning of the command line when invoking the linker to
4747 build an executable for the source or for its language.
4749 @item @b{Switches}: list, optional index, indexed, case-insensitive index,
4752 Index is a source file name or a language name. Value is the list of switches
4753 to be used when invoking the linker to build an executable for the source or
4756 @item @b{Trailing_Switches}: list, optional index, indexed,
4757 case-insensitive index, others allowed
4759 Index is a source file name or a language name. Value is the list of switches
4760 to be used at the end of the command line when invoking the linker to
4761 build an executable for the source or for its language. These switches may
4762 override the Required_Switches.
4764 @item @b{Linker_Options}: list
4766 Value is a list of switches/options that are to be added when linking an
4767 executable from a project importing the current project directly or indirectly.
4768 Linker_Options are not used when linking an executable from the current
4771 @item @b{Map_File_Option}: single
4773 Value is the switch to specify the map file name that the linker needs to
4778 @item @b{Configuration - Linking}
4782 @item @b{Driver}: single
4784 Value is the name of the linker executable.
4788 @item @b{Configuration - Response Files}
4792 @item @b{Max_Command_Line_Length}: single
4794 Value is the maximum number of character in the command line when invoking
4795 the linker to link an executable.
4797 @item @b{Response_File_Format}: single
4799 Indicates the kind of response file to create when the length of the linking
4800 command line is too large. Only authorized case-insensitive values are "none",
4801 "gnu", "object_list", "gcc_gnu", "gcc_option_list" and "gcc_object_list".
4803 @item @b{Response_File_Switches}: list
4805 Value is the list of switches to specify a response file to the linker.
4811 @node Package Metrics Attribute
4812 @subsubsection Package Metrics Attribute
4816 @item @b{Default_Switches}: list, indexed, case-insensitive index
4818 Index is a language name. Value is a list of switches to be used when invoking
4819 @code{gnatmetric} for a source of the language, if there is no applicable
4822 @item @b{Switches}: list, optional index, indexed, case-insensitive index,
4825 Index is a source file name. Value is the list of switches to be used when
4826 invoking @code{gnatmetric} for the source.
4830 @node Package Naming Attributes
4831 @subsubsection Package Naming Attributes
4835 @item @b{Specification_Suffix}: single, indexed, case-insensitive index
4837 Equivalent to attribute Spec_Suffix.
4839 @item @b{Spec_Suffix}: single, indexed, case-insensitive index
4841 Index is a language name. Value is the extension of file names for specs of
4844 @item @b{Implementation_Suffix}: single, indexed, case-insensitive index
4846 Equivalent to attribute Body_Suffix.
4848 @item @b{Body_Suffix}: single, indexed, case-insensitive index
4850 Index is a language name. Value is the extension of file names for bodies of
4853 @item @b{Separate_Suffix}: single
4855 Value is the extension of file names for subunits of Ada.
4857 @item @b{Casing}: single
4859 Indicates the casing of sources of the Ada language. Only authorized
4860 case-insensitive values are "lowercase", "uppercase" and "mixedcase".
4862 @item @b{Dot_Replacement}: single
4864 Value is the string that replace the dot of unit names in the source file names
4865 of the Ada language.
4867 @item @b{Specification}: single, optional index, indexed,
4868 case-insensitive index
4870 Equivalent to attribute Spec.
4872 @item @b{Spec}: single, optional index, indexed, case-insensitive index
4874 Index is a unit name. Value is the file name of the spec of the unit.
4876 @item @b{Implementation}: single, optional index, indexed,
4877 case-insensitive index
4879 Equivalent to attribute Body.
4881 @item @b{Body}: single, optional index, indexed, case-insensitive index
4883 Index is a unit name. Value is the file name of the body of the unit.
4885 @item @b{Specification_Exceptions}: list, indexed, case-insensitive index
4887 Index is a language name. Value is a list of specs for the language that do not
4888 necessarily follow the naming scheme for the language and that may or may not
4889 be found in the source directories of the project.
4891 @item @b{Implementation_Exceptions}: list, indexed, case-insensitive index
4893 Index is a language name. Value is a list of bodies for the language that do not
4894 necessarily follow the naming scheme for the language and that may or may not
4895 be found in the source directories of the project.
4899 @node Package Pretty_Printer Attributes
4900 @subsubsection Package Pretty_Printer Attributes
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{gnatpp} 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{gnatpp} for the source.
4918 @node Package Remote Attributes
4919 @subsubsection Package Remote Attributes
4923 @item @b{Build_Slaves}: list
4925 Value is the list of machine names that are to be used in distributed
4928 @item @b{Root_Dir}: single
4930 Value is the root directory used by the slave machines.
4934 @node Package Stack Attributes
4935 @subsubsection Package Stack Attributes
4939 @item @b{Switches}: list
4941 Value is the list of switches to be used when invoking @code{gnatstack}.
4945 @node Package Synchronize Attributes
4946 @subsubsection Package Synchronize Attributes
4950 @item @b{Default_Switches}: list, indexed, case-insensitive index
4952 Index is a language name. Value is a list of switches to be used when invoking
4953 @code{gnatsync} for a source of the language, if there is no applicable
4956 @item @b{Switches}: list, optional index, indexed, case-insensitive index,
4959 Index is a source file name. Value is the list of switches to be used when
4960 invoking @code{gnatsync} for the source.