OSDN Git Service

PR bootstrap/56258
[pf3gnuchains/gcc-fork.git] / gcc / ada / projects.texi
index 6f87ba5..dc5ed7b 100644 (file)
@@ -1,6 +1,7 @@
 @set gprconfig GPRconfig
 
 @c ------ projects.texi
+@c Copyright (C) 2002-2012, Free Software Foundation, Inc.
 @c This file is shared between the GNAT user's guide and gprbuild. It is not
 @c compilable on its own, you should instead compile the other two manuals.
 @c For that reason, there is no toplevel @menu
@@ -19,6 +20,7 @@
 * Library Projects::
 * Project Extension::
 * Aggregate Projects::
+* Aggregate Library Projects::
 * Project File Reference::
 @end menu
 
@@ -46,8 +48,7 @@ project files allow you to specify:
 @item Source file naming conventions; you can specify these either globally or for
   individual compilation units (@pxref{Naming Schemes}).
 @item Change any of the above settings depending on external values, thus enabling
-  the reuse of the projects in various @b{scenarios} (@pxref{Scenarios
-  in Projects}).
+  the reuse of the projects in various @b{scenarios} (@pxref{Scenarios in Projects}).
 @item Automatically build libraries as part of the build process
   (@pxref{Library Projects}).
 
@@ -351,8 +352,8 @@ locating the specified source files in the specified source directories.
 
 @item For various reasons, it is sometimes useful to have a project with no
   sources (most of the time because the attributes defined in the project
-  file will be reused in other projects, as explained in @pxref{Organizing
-  Projects into Subsystems}. To do this, the attribute
+  file will be reused in other projects, as explained in
+  @pxref{Organizing Projects into Subsystems}. To do this, the attribute
   @emph{Source_Files} is set to the empty list, i.e. @code{()}. Alternatively,
   @emph{Source_Dirs} can be set to the empty list, with the same
   result.
@@ -379,8 +380,9 @@ locating the specified source files in the specified source directories.
   This can be done thanks to the attribute @b{Excluded_Source_Files}
   (or its synonym @b{Locally_Removed_Files}).
   Its value is the list of file names that should not be taken into account.
-  This attribute is often used when extending a project, @xref{Project
-  Extension}. A similar attribute @b{Excluded_Source_List_File} plays the same
+  This attribute is often used when extending a project,
+  @xref{Project Extension}. A similar attribute
+  @b{Excluded_Source_List_File} plays the same
   role but takes the name of file containing file names similarly to
   @code{Source_List_File}.
 
@@ -401,12 +403,12 @@ If the order of the source directories is known statically, that is if
 be several files with the same source file name sitting in different
 directories of the project. In this case, only the file in the first directory
 is considered as a source of the project and the others are hidden. If
-@code{"**"} is not used in the string list @code{Source_Dirs}, it is an error
+@code{"**"} is used in the string list @code{Source_Dirs}, it is an error
 to have several files with the same source file name in the same directory
 @code{"**"} subtree, since there would be an ambiguity as to which one should
-be used. However, two files with the same source file name may in two single
-directories or directory subtrees. In this case, the one in the first directory
-or directory subtree is a source of the project.
+be used. However, two files with the same source file name may exist in two
+single directories or directory subtrees. In this case, the one in the first
+directory or directory subtree is a source of the project.
 
 @c ---------------------------------------------
 @node Object and Exec Directory
@@ -578,19 +580,19 @@ packages would be involved in the build process.
       @b{for} Object_Dir @b{use} "obj";
       @b{for} Exec_Dir @b{use} ".";
       @b{for} Main @b{use} ("proc.adb");
-   @b{end} Build;
 
-   @b{package} Builder @b{is}  --<<<  for gnatmake and gprbuild
-   @b{end} Builder;
+      @b{package} Builder @b{is}  --<<<  for gnatmake and gprbuild
+      @b{end} Builder;
 
-   @b{package} Compiler @b{is} --<<<  for the compiler
-   @b{end} Compiler;
+      @b{package} Compiler @b{is} --<<<  for the compiler
+      @b{end} Compiler;
 
-   @b{package} Binder @b{is}   --<<<  for the binder
-   @b{end} Binder;
+      @b{package} Binder @b{is}   --<<<  for the binder
+      @b{end} Binder;
 
-   @b{package} Linker @b{is}   --<<<  for the linker
-   @b{end} Linker;
+      @b{package} Linker @b{is}   --<<<  for the linker
+      @b{end} Linker;
+   @b{end} Build;
 @end smallexample
 
 @noindent
@@ -1524,10 +1526,11 @@ front of the @code{project} keyword.
 @item @b{Library_Name}:
 @cindex @code{Library_Name}
   This attribute is the name of the library to be built. There is no
-  restriction on the name of a library imposed by the project manager;
-  however, there may be system specific restrictions on the name.
-  In general, it is recommended to stick to alphanumeric characters
-  (and possibly underscores) to help portability.
+  restriction on the name of a library imposed by the project manager, except
+  for stand-alone libraries whose names must follow the syntax of Ada
+  identifiers; however, there may be system specific restrictions on the name.
+  In general, it is recommended to stick to alphanumeric characters (and
+  possibly single underscores) to help portability.
 
 @item @b{Library_Dir}:
 @cindex @code{Library_Dir}
@@ -1748,26 +1751,61 @@ transparent. However, stand-alone libraries are also useful when the main is in
 Ada: they provide a means for minimizing relinking & redeployment of complex
 systems when localized changes are made.
 
+The name of a stand-alone library, specified with attribute
+@code{Library_Name}, must have the syntax of an Ada identifier.
+
 The most prominent characteristic of a stand-alone library is that it offers a
 distinction between interface units and implementation units. Only the former
 are visible to units outside the library. A stand-alone library project is thus
-characterised by a third attribute, @b{Library_Interface}, in addition to the
-two attributes that make a project a Library Project (@code{Library_Name} and
-@code{Library_Dir}).
+characterised by a third attribute, usually @b{Library_Interface}, in addition
+to the two attributes that make a project a Library Project
+(@code{Library_Name} and @code{Library_Dir}). This third attribute may also be
+@b{Interfaces}. @b{Library_Interface} only works when the interface is in Ada
+and takes a list of units as parameter. @b{Interfaces} works for any supported
+language and takes a list of sources as parameter.
 
 @table @asis
 @item @b{Library_Interface}:
 @cindex @code{Library_Interface}
-  This attribute defines an explicit subset of the units of the project.
-  Projects importing this library project may only "with" units whose sources
-  are listed in the @code{Library_Interface}. Other sources are considered
-  implementation units.
+  This attribute defines an explicit subset of the units of the project. Units
+  from projects importing this library project may only "with" units whose
+  sources are listed in the @code{Library_Interface}. Other sources are
+  considered implementation units.
+
+@smallexample @c projectfile
+@group
+     for Library_Dir use "lib";
+     for Library_Name use "loggin";
+     for Library_Interface use ("lib1", "lib2");  --  unit names
+@end group
+@end smallexample
+
+@item @b{Interfaces}
+  This attribute defines an explicit subset of the source files of a project.
+  Sources from projects importing this project, can only depend on sources from
+  this subset. This attribute can be used on non library projects. It can also
+  be used as a replacement for attribute @code{Library_Interface}, in which
+  case, units have to be replaced by source files. For multi-language library
+  projects, it is the only way to make the project a Stand-Alone Library project
+  whose interface is not purely Ada.
+
+@item @b{Library_Standalone}:
+@cindex @code{Library_Standalone}
+  This attribute defines the kind of standalone library to
+  build. Values are either @code{standard} (the default), @code{no} or
+  @code{encapsulated}. When @code{standard} is used the code to elaborate and
+  finalize the library is embedded, when @code{encapsulated} is used the
+  library can furthermore only depends on static libraries (including
+  the GNAT runtime). This attribute can be set to @code{no} to make it clear
+  that the library should not be standalone in which case the
+  @code{Library_Interface} should not defined.
 
 @smallexample @c projectfile
 @group
      for Library_Dir use "lib";
      for Library_Name use "loggin";
      for Library_Interface use ("lib1", "lib2");  --  unit names
+     for Library_Standalone use "encapsulated";
 @end group
 @end smallexample
 
@@ -2009,8 +2047,16 @@ end Work;
 @end smallexample
 
 @noindent
-An extending project retains all the switches specified in the
-extended project.
+All packages that are not declared in the extending project are inherited from
+the project being extended, with their attributes, with the exception of
+@code{Linker'Linker_Options} which is never inherited. In particular, an
+extending project retains all the switches specified in the project being
+extended.
+
+At the project level, if they are not declared in the extending project, some
+attributes are inherited from the project being extended. They are:
+@code{Languages}, @code{Main} (for a root non library project) and
+@code{Library_Name} (for a project extending a library project)
 
 @menu
 * Project Hierarchy Extension::
@@ -2125,7 +2171,19 @@ meant to solve a few specific use cases that cannot be solved directly
 using standard projects. This section will go over a few of these use
 cases to try and explain what you can use aggregate projects for.
 
-@subsection Building all main units from a single project tree
+@menu
+* Building all main programs from a single project tree::
+* Building a set of projects with a single command::
+* Define a build environment::
+* Performance improvements in builder::
+* Syntax of aggregate projects::
+* package Builder in aggregate projects::
+@end menu
+
+@c -----------------------------------------------------------
+@node Building all main programs from a single project tree
+@subsection Building all main programs from a single project tree
+@c -----------------------------------------------------------
 
 Most often, an application is organized into modules and submodules,
 which are very conveniently represented as a project tree or graph
@@ -2143,7 +2201,7 @@ a syntax similar to
    gprbuild -PA.gpr
 @end smallexample
 
-this will only rebuild the main units of project A, not those of the
+this will only rebuild the main programs of project A, not those of the
 imported projects B and C. Therefore you have to spawn several
 gnatmake commands, one per project, to build all executables.
 This is a little inconvenient, but more importantly is inefficient
@@ -2160,7 +2218,7 @@ and C. Then, when you build with
     gprbuild -PAgg.gpr
 @end smallexample
 
-this will build all main units from A, B and C.
+this will build all mains from A, B and C.
 
 @smallexample @c projectfile
    aggregate project Agg is
@@ -2168,17 +2226,20 @@ this will build all main units from A, B and C.
    end Agg;
 @end smallexample
 
-If B or C do not define any main unit (through their Main
+If B or C do not define any main program (through their Main
 attribute), all their sources are build. When you do not group them
 in the aggregate project, only those sources that are needed by A
 will be build.
 
-If you add a main unit to a project P not already explicitly referenced in the
+If you add a main to a project P not already explicitly referenced in the
 aggregate project, you will need to add "p.gpr" in the list of project
-files for the aggregate project, or the main unit will not be built when
+files for the aggregate project, or the main will not be built when
 building the aggregate project.
 
+@c ---------------------------------------------------------
+@node Building a set of projects with a single command
 @subsection Building a set of projects with a single command
+@c ---------------------------------------------------------
 
 One other case is when you have multiple applications and libraries
 that are build independently from each other (but they can be build in
@@ -2217,7 +2278,10 @@ with Annex E.
    Aggregate projects can be used to build multiple partitions
 @end smallexample
 
+@c ---------------------------------------------
+@node Define a build environment
 @subsection Define a build environment
+@c ---------------------------------------------
 
 The environment variables at the time you launch gprbuild or gprbuild
 will influence the view these tools have of the project (PATH to find
@@ -2272,7 +2336,10 @@ project MyProject is
 end MyProject;
 @end smallexample
 
+@c --------------------------------------------
+@node Performance improvements in builder
 @subsection Performance improvements in builder
+@c --------------------------------------------
 
 The loading of aggregate projects is optimized in gprbuild and
 gnatmake, so that all files are searched for only once on the disk
@@ -2288,7 +2355,10 @@ can be compiled in parallel (through the usual -j switch) and this can
 be done while maximizing the use of CPUs (compared to launching
 multiple gprbuild and gnatmake commands in parallel).
 
+@c -------------------------------------
+@node Syntax of aggregate projects
 @subsection Syntax of aggregate projects
+@c -------------------------------------
 
 An aggregate project follows the general syntax of project files. The
 recommended extension is still @file{.gpr}. However, a special
@@ -2307,7 +2377,7 @@ attributes and packages are forbidden in an aggregate project. Here is the
 
 @itemize @bullet
 @item Languages
-@item Source_files, Source_List_File and other attributes dealing with
+@item Source_Files, Source_List_File and other attributes dealing with
   list of sources.
 @item Source_Dirs, Exec_Dir and Object_Dir
 @item Library_Dir, Library_Name and other library-related attributes
@@ -2317,7 +2387,7 @@ attributes and packages are forbidden in an aggregate project. Here is the
 @item Inherit_Source_Path
 @item Excluded_Source_Dirs
 @item Locally_Removed_Files
-@item Excluded_Source_Fies
+@item Excluded_Source_Files
 @item Excluded_Source_List_File
 @item Interfaces
 @end itemize
@@ -2344,7 +2414,7 @@ grouping standard projects, you can have both the root of a project tree
 within the tree.
 
 Basically, the idea is to specify all those projects that have
-main units you want to build and link, or libraries you want to
+main programs you want to build and link, or libraries you want to
 build. You can even specify projects that do not use the Main
 attribute nor the @code{Library_*} attributes, and the result will be to
 build all their source files (not just the ones needed by other
@@ -2486,7 +2556,10 @@ P, which in particular might impact the list of source files in P.
 
 @end table
 
+@c ----------------------------------------------
+@node package Builder in aggregate projects
 @subsection package Builder in aggregate projects
+@c ----------------------------------------------
 
 As we mentioned before, only the package Builder can be specified in
 an aggregate project. In this package, only the following attributes
@@ -2566,7 +2639,7 @@ both depend on C. Here is an extra for all of these projects:
 
       project C is
           package Compiler is
-             for Default_Switches ("Ada") use ("-O3, "-gnatn");
+             for Default_Switches ("Ada") use ("-O3", "-gnatn");
              for Switches ("c_file1.adb") use ("-O0", "-g");
           end Compiler;
       end C;
@@ -2604,10 +2677,120 @@ Projects can locally add to those by using the
 
 For projects that are build through the aggregate, the package Builder
 is ignored, except for the Executable attribute which specifies the
-name of the executables resulting from the link of the main units, and
+name of the executables resulting from the link of the main programs, and
 for the Executable_Suffix.
 
 @c ---------------------------------------------
+@node Aggregate Library Projects
+@section Aggregate Library Projects
+@c ---------------------------------------------
+
+@noindent
+
+Aggregate library projects make it possible to build a single library
+using object files built using other standard or library
+projects. This gives the flexibility to describe an application as
+having multiple modules (a GUI, database access, ...) using different
+project files (so possibly built with different compiler options) and
+yet create a single library (static or relocatable) out of the
+corresponding object files.
+
+@menu
+* Building aggregate library projects::
+* Syntax of aggregate library projects::
+@end menu
+
+@c ---------------------------------------------
+@node Building aggregate library projects
+@subsection Building aggregate library projects
+@c ---------------------------------------------
+
+For example, we can define an aggregate project Agg that groups A, B
+and C:
+
+@smallexample @c projectfile
+   aggregate library project Agg is
+      for Project_Files use ("a.gpr", "b.gpr", "c.gpr");
+      for Library_Name use ("agg");
+      for Library_Dir use ("lagg");
+   end Agg;
+@end smallexample
+
+Then, when you build with:
+
+@smallexample
+    gprbuild agg.gpr
+@end smallexample
+
+This will build all units from projects A, B and C and will create a
+static library named @file{libagg.a} into the @file{lagg}
+directory. An aggregate library project has the same set of
+restriction as a standard library project.
+
+Note that a shared aggregate library project cannot aggregates a
+static library project. In platforms where a compiler option is
+required to create relocatable object files, a Builder package in the
+aggregate library project may be used:
+
+@smallexample @c projectfile
+   aggregate library project Agg is
+      for Project_Files use ("a.gpr", "b.gpr", "c.gpr");
+      for Library_Name use ("agg");
+      for Library_Dir use ("lagg");
+      for Library_Kind use "relocatable";
+
+      package Builder is
+         for Global_Compilation_Switches ("Ada") use ("-fPIC");
+      end Builder;
+   end Agg;
+@end smallexample
+
+With the above aggregate library Builder package, the @code{-fPIC}
+option will be passed to the compiler when building any source code
+from projects @file{a.gpr}, @file{b.gpr} and @file{c.gpr}.
+
+@c ---------------------------------------------
+@node Syntax of aggregate library projects
+@subsection Syntax of aggregate library projects
+@c ---------------------------------------------
+
+An aggregate library project follows the general syntax of project
+files. The recommended extension is still @file{.gpr}. However, a special
+@code{aggregate library} qualifier must be put before the keyword
+@code{project}.
+
+An aggregate library project cannot @code{with} any other project
+(standard or aggregate), except an abstract project which can be used
+to share attribute values.
+
+An aggregate library project does not have any source files directly (only
+through other standard projects). Therefore a number of the standard
+attributes and packages are forbidden in an aggregate library
+project. Here is the (non exhaustive) list:
+
+@itemize @bullet
+@item Languages
+@item Source_Files, Source_List_File and other attributes dealing with
+  list of sources.
+@item Source_Dirs, Exec_Dir and Object_Dir
+@item Main
+@item Roots
+@item Externally_Built
+@item Inherit_Source_Path
+@item Excluded_Source_Dirs
+@item Locally_Removed_Files
+@item Excluded_Source_Files
+@item Excluded_Source_List_File
+@item Interfaces
+@end itemize
+
+The only package that is authorized (albeit optional) is Builder.
+
+The Project_Files attribute (See @pxref{Aggregate Projects}) is used to
+described the aggregated projects whose object files have to be
+included into the aggregate library.
+
+@c ---------------------------------------------
 @node Project File Reference
 @section Project File Reference
 @c ---------------------------------------------
@@ -2764,8 +2947,10 @@ The current list of qualifiers is:
   qualified abstract project.
 @item @b{standard}: a standard project is a non library project with sources.
   This is the default (implicit) qualifier.
-@item @b{aggregate}: for future extension
-@item @b{aggregate library}: for future extension
+@item @b{aggregate}: a project whose sources are aggregated from other
+project files.
+@item @b{aggregate library}: a library whose sources are aggregated
+from other project or library project files.
 @item @b{library}: a library project must declare both attributes
   @code{Library_Name} and @code{Library_Dir}.
 @item @b{configuration}: a configuration project cannot be in a project tree.
@@ -3544,7 +3729,6 @@ end MyProj;
 * gnatmake and Project Files::
 * The GNAT Driver and Project Files::
 * The Development Environments::
-* Cleaning up with GPRclean::
 @end menu
 
 @c ---------------------------------------------
@@ -3953,7 +4137,7 @@ with one or several main subprograms, by specifying their source files on the
 command line.
 
 @smallexample
-    gnatmake ^-P^/PROJECT_FILE=^prj main1 main2 main3
+    gnatmake ^-P^/PROJECT_FILE=^prj main1.adb main2.adb main3.adb
 @end smallexample
 
 @noindent
@@ -3989,7 +4173,7 @@ Example:
 @smallexample @c projectfile
 @group
    project Prj is
-      for Main use ("main1", "main2", "main3");
+      for Main use ("main1.adb", "main2.adb", "main3.adb");
    end Prj;
 @end group
 @end smallexample
@@ -3997,7 +4181,7 @@ Example:
 @noindent
 With this project file, @code{"gnatmake ^-Pprj^/PROJECT_FILE=PRJ^"}
 is equivalent to
-@code{"gnatmake ^-Pprj^/PROJECT_FILE=PRJ^ main1 main2 main3"}.
+@code{"gnatmake ^-Pprj^/PROJECT_FILE=PRJ^ main1.adb main2.adb main3.adb"}.
 
 When the project attribute @code{Main} is not specified, or is specified
 as an empty string list, or when the switch @option{-u} is used on the command
@@ -4411,73 +4595,3 @@ will be relative to this path. The root project directory is used if
 this value is not defined.
 
 @end table
-
-@c ---------------------------------------------
-@node Cleaning up with GPRclean
-@section Cleaning up with GPRclean
-@c ---------------------------------------------
-
-@noindent
-The GPRclean tool removes the files created by GPRbuild.
-At a minimum, to invoke GPRclean you must specify a main project file
-in a command such as @code{gprclean proj.gpr} or @code{gprclean -P proj.gpr}.
-
-Examples of invocation of GPRclean:
-
-@smallexample
-   gprclean -r prj1.gpr
-   gprclean -c -P prj2.gpr
-@end smallexample
-
-@menu
-* Switches for GPRclean::
-@end menu
-
-@c ---------------------------------------------
-@node Switches for GPRclean
-@subsection Switches for GPRclean
-@c ---------------------------------------------
-
-@noindent
-The switches for GPRclean are:
-
-@itemize @bullet
-@item @option{--config=<main config project file name>} : Specify the
-  configuration project file name
-
-@item @option{--autoconf=<config project file name>}
-
-  This specifies a configuration project file name that already exists or will
-  be created automatically. Option @option{--autoconf=}
-  cannot be specified more than once. If the configuration project file
-  specified with @option{--autoconf=} exists, then it is used. Otherwise,
-  @value{gprconfig} is invoked to create it automatically.
-
-@item @option{-c} : Only delete compiler-generated files. Do not delete
-  executables and libraries.
-
-@item @option{-f} : Force deletions of unwritable files
-
-@item @option{-F} : Display full project path name in brief error messages
-
-@item @option{-h} : Display this message
-
-@item @option{-n} : Do not delete files, only list files to delete
-
-@item @option{-P<proj>} : Use Project File @emph{<proj>}.
-
-@item @option{-q} : Be quiet/terse. There is no output, except to report
-  problems.
-
-@item @option{-r} : (recursive) Clean all projects referenced by the main
-  project directly or indirectly. Without this switch, GPRclean only
-  cleans the main project.
-
-@item @option{-v}  : Verbose mode
-
-@item @option{-vPx} : Specify verbosity when parsing Project Files.
-  x = 0 (default), 1 or 2.
-
-@item @option{-Xnm=val} : Specify an external reference for Project Files.
-
-@end itemize