From Fedora Project Wiki

(Add link to new guidelines location.)
(11 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{autolang|base=yes}}
= Packaging Ada programs and libraries =


= Packaging Ada programs and libraries =
{{admon/warning | This is an old copy of a packaging guideline, preserved here in the wiki while we complete the transition to the Fedora documentation system.  The current version is located at https://docs.fedoraproject.org/en-US/packaging-guidelines/Ada/ .  Please update your bookmarks.}}


This document describes the current policies for packaging Ada programs and libraries for Fedora. These are Ada-specific amendments to the generic Packaging Guidelines. Ada packages must also conform to the [[Packaging:Guidelines|Packaging Guidelines]] and the [[Packaging:ReviewGuidelines|Review Guidelines]].
This document describes the current policies for packaging Ada programs and libraries for Fedora. These are Ada-specific amendments to the generic Packaging Guidelines. Ada packages must also conform to the [[Packaging:Guidelines|Packaging Guidelines]] and the [[Packaging:ReviewGuidelines|Review Guidelines]].
Line 7: Line 7:
== Compilation ==
== Compilation ==


Ada code in Fedora '''MUST''' be compiled using GNAT, the default Ada compiler in Fedora. All packages that contain Ada code MUST build-require the gcc-gnat package to ensure that the compiler is available. The RPM macro %{GNAT_optflags} '''MUST''' be used in the compilation. It contains the standard Fedora optimization flags adapted to GNAT.
<ul>
<li> Ada code in Fedora '''MUST''' be compiled using GNAT, the default Ada compiler in Fedora. All packages that contain Ada code '''MUST''' have "<code>BuildRequires: gcc-gnat</code>" to ensure that the compiler is available.</li>
 
<li> There are a number of RPM macros that contain Fedora's standard compiler and linker flags adapted for GNAT. The appropriate macro '''MUST''' be used in the build stage. The right macro to use depends on what build tools the package uses.
<ul><li> For packages that are built with <code>Gnatmake</code> or <code>GPRbuild</code> but without <code>Comfignat</code> there are the macros <code>%Gnatmake_optflags</code> and <code>%GPRbuild_optflags</code>, which contain builder, compiler and linker flags.</li>
<li>In case a package's build system invokes the underlying GNAT tools without using <code>Gnatmake</code> or <code>GPRbuild</code>, then the appropriate macro for each tool '''MUST''' be used. If for example Gnatlink is invoked directly, then the expansion of Gnatlink_flags shall be passed to it.</li>
<li> For packages whose build systems use <code>Comfignat</code> there is the macro <code>%Comfignat_make</code>. It expands to a Make command with appropriate values for <code>Comfignat</code>'s configuration variables, including builder, compiler and linker flags, directory variables and the directories project. Use it alone to build the default target:
<pre>
%build
%{Comfignat_make}
# If needed, a different target and/or additional variables may be appended:
%{Comfignat_make} demo_programs atomic_doodads=true
</pre>
For the installation stage of Comfignat-using packages, the macro <code>%make_install</code> ('''not''' <code>%makeinstall</code>) is recommended.</li>
</ul>
</li>
 
<li> The macro GNAT_arches expands to a list of architectures where GNAT packages are available in Fedora. Starting with Fedora 18, when there is a need to prevent attempts to build an Ada package on secondary architectures where GNAT has not been bootstrapped, this '''MUST''' be done with "<code>ExclusiveArch: %{GNAT_arches}</code>".</li>
 
<li> All packages that contain Ada code '''MUST''' have "<code>BuildRequires: fedora-gnat-project-common</code>" to ensure that the necessary RPM macros are defined.</li>
 
<li> If the upstream source package comes with a build system, for example a GNAT project file or makefiles and a configuration script, then it's probably best to use that if possible. If not, it is recommended that the packager write a GNAT project file to control the compilation.</li>
</ul>
 
== Runpaths ==


All packages that contain Ada code '''MUST''' build-require the fedora-gnat-project-common package to ensure that the necessary RPM macros are defined.
Gnatmake and GPRbuild both add a runpath to the built binaries by default. Fedora's builder flags normally include an option to disable the automatic runpath. There are however cases where it would be advantageous to allow a runpath. Libraries can have test suites or auxiliary programs that aren't installed but run during the build and need to link to the library in the build directory, and they may rely on an automatic runpath for this. In those cases the spec file may define a macro named <var>GNAT_add_rpath</var>. The builders will then be allowed to add a runpath in those parts of the spec file where <var>GNAT_add_rpath</var> is defined.


If the upstream source package comes with a build system, for example a GNAT project file or makefiles and a configuration script, then it's probably best to use that if possible. If not, it is recommended that the packager write a GNAT project file to control the compilation.
Packages that contain Ada code '''SHOULD''' run <code>%{_rpmconfigdir}/check-rpaths</code> as the last thing in the <code>%check</code> section. This is a precaution against packaging bugs and toolchain bugs that would cause binaries with runpaths to end up in packages. All packages that use <var>GNAT_add_rpath</var> '''MUST''' do this (and must therefore have a <code>%check</code> section).


== Devel packages ==
== Devel packages ==


* Ada library packages '''MUST''' have a -devel subpackage containing all the files that are necessary for compilation of code that uses the library. This includes Ada specification files (*.ads), Ada body files (*.adb), Ada library information files (*.ali) and GNAT project files (*.gpr).
* Ada library packages '''MUST''' have a -devel subpackage containing all the files that are necessary for compilation of code that uses the library. This includes Ada specification files (*.ads), Ada body files (*.adb), Ada library information files (*.ali) and GNAT project files (*.gpr). (There is no requirement to include all body files. Typically only some body files are needed.)
* The -devel package '''SHOULD NOT''' contain all the source files of the library, only those that are necessary for compilation of code that uses the library.
* The -devel package '''MUST NOT''' contain any makefiles or other files that are only used for recompiling the library.
* The -devel package '''SHOULD NOT''' contain any makefiles or other files that are only used for recompiling the library.
* The -devel package '''MUST NOT''' contain any *.o files.
* The -devel package '''SHOULD NOT''' contain any *.o files.


=== GNAT project files ===
=== GNAT project files ===
Line 24: Line 47:
* The -devel package '''MUST''' contain one or more GNAT project files to be imported by other projects that use the library.
* The -devel package '''MUST''' contain one or more GNAT project files to be imported by other projects that use the library.
* Project files '''MUST''' be architecture-independent. This means that the same project file must point to libraries in /usr/lib or /usr/lib64 depending on what target architecture the compiler is currently compiling for. This '''SHOULD''' be done by importing the "directories" project (that is, the project file directories.gpr) and using the variable Directories.Libdir which is defined there. The value of Directories.Libdir is set to either "/usr/lib" or "/usr/lib64" depending on the hardware platform.
* Project files '''MUST''' be architecture-independent. This means that the same project file must point to libraries in /usr/lib or /usr/lib64 depending on what target architecture the compiler is currently compiling for. This '''SHOULD''' be done by importing the "directories" project (that is, the project file directories.gpr) and using the variable Directories.Libdir which is defined there. The value of Directories.Libdir is set to either "/usr/lib" or "/usr/lib64" depending on the hardware platform.
* Project files '''SHOULD NOT''' contain hard-coded directory names, neither absolute nor relative; they should get them from some source. The source '''MAY''' be an Autoconf-generated configuration script or other build system. Project files that aren't pre-processed by such a build system '''SHOULD''' use the variable Directories.Includedir rather than a hard-coded "/usr/include".
* Project files '''MUST NOT''' contain hard-coded directory names, neither absolute nor relative; they should get them from some source. The source may be an Autoconf-generated configuration script or other build system. Project files that aren't pre-processed by such a build system '''SHOULD''' use the variable Directories.Includedir rather than a hard-coded "/usr/include".
* If the "directories" project is used, then the -devel package '''MUST''' have an explicit "<code>Requires: fedora-gnat-project-common >= 2</code>".
* If the "directories" project is used, then the -devel package '''MUST''' have an explicit "<code>Requires: fedora-gnat-project-common</code>".
* Project files '''MUST''' have an Externally_Built attribute equal to "true".
* Project files '''MUST''' have an Externally_Built attribute equal to "true".
Here's an example of what a project file installed with a library may look like:
Here's an example of what a project file installed with a library may look like:
Line 42: Line 65:
== File placement ==
== File placement ==


* Ada source files in -devel packages (*.ads and *.adb) '''SHOULD''' be placed in the <code>%{_includedir}</code> directory or a subdirectory thereof. Placing them directly in <code>%{_includedir}</code> may be appropriate if there are very few of them in the package and their names include the name of the library. Otherwise they should usually be placed  in a subdirectory, for example <code>%{_includedir}/%{name}</code>.
* Ada source files in -devel packages (*.ads and *.adb) '''MUST''' be placed in the <code>%{_includedir}</code> directory or a subdirectory thereof. Placing them directly in <code>%{_includedir}</code> may be appropriate if there are very few of them in the package and their names include the name of the library. Otherwise they should usually be placed  in a subdirectory, for example <code>%{_includedir}/%{name}</code>.
* Ada library information files (*.ali) '''SHOULD''' be placed in a subdirectory of <code>%{_libdir}</code>, for example <code>%{_libdir}/%{name}</code>.
* Ada library information files (*.ali) '''MUST''' be placed in a subdirectory of <code>%{_libdir}</code>, for example <code>%{_libdir}/%{name}</code>.
* GNAT projects files (*.gpr) '''MUST''' be placed in the <code>%{_GNAT_project_dir}</code> directory or a subdirectory thereof. A subdirectory, for example <code>%{_GNAT_project_dir}/%{name}</code>, may be a good idea if there are lots of project files in the same package or if they have generic names. Otherwise they should usually be placed directly in <code>%{_GNAT_project_dir}</code>. The name of the library '''SHOULD''' be included either in the name of each project file or in the name of the subdirectory where the project files are placed.
* GNAT projects files (*.gpr) '''MUST''' be placed in the <code>%{_GNAT_project_dir}</code> directory or a subdirectory thereof. A subdirectory, for example <code>%{_GNAT_project_dir}/%{name}</code>, may be a good idea if there are lots of project files in the same package or if they have generic names. Otherwise they should usually be placed directly in <code>%{_GNAT_project_dir}</code>. The name of the library '''MUST''' be included either in the name of each project file or in the name of the subdirectory where the project files are placed.
{{Admon/note | Note| The current value of <code>%{_GNAT_project_dir}</code> is <code>/usr/lib/gnat</code>. We intend to change it to <code>/usr/share/gpr</code>, which is more in line with FHS, if we can get GNAT to use that directory.}}


== Rpmlint and Ada packages ==
== Rpmlint and Ada packages ==
Rpmlint is a program that checks packages for common problems. For Ada packages, some of the rpmlint messages, such as "executable-stack", can be disregarded, because GNAT uses trampolines for pointers to nested functions. (See for example [http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24355 this entry in the GCC Bugzilla].)
Rpmlint is a program that checks packages for common problems. For Ada packages, some of the rpmlint messages, such as "executable-stack", can be disregarded, because GNAT uses trampolines for pointers to nested functions. (See for example [http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24355 this entry in the GCC Bugzilla].)


[[ Category:Packaging guidelines drafts ]]
[[Category: Packaging guidelines]]

Revision as of 20:51, 8 November 2018

Packaging Ada programs and libraries

Warning.png
This is an old copy of a packaging guideline, preserved here in the wiki while we complete the transition to the Fedora documentation system. The current version is located at https://docs.fedoraproject.org/en-US/packaging-guidelines/Ada/ . Please update your bookmarks.

This document describes the current policies for packaging Ada programs and libraries for Fedora. These are Ada-specific amendments to the generic Packaging Guidelines. Ada packages must also conform to the Packaging Guidelines and the Review Guidelines.

Compilation

  • Ada code in Fedora MUST be compiled using GNAT, the default Ada compiler in Fedora. All packages that contain Ada code MUST have "BuildRequires: gcc-gnat" to ensure that the compiler is available.
  • There are a number of RPM macros that contain Fedora's standard compiler and linker flags adapted for GNAT. The appropriate macro MUST be used in the build stage. The right macro to use depends on what build tools the package uses.
    • For packages that are built with Gnatmake or GPRbuild but without Comfignat there are the macros %Gnatmake_optflags and %GPRbuild_optflags, which contain builder, compiler and linker flags.
    • In case a package's build system invokes the underlying GNAT tools without using Gnatmake or GPRbuild, then the appropriate macro for each tool MUST be used. If for example Gnatlink is invoked directly, then the expansion of Gnatlink_flags shall be passed to it.
    • For packages whose build systems use Comfignat there is the macro %Comfignat_make. It expands to a Make command with appropriate values for Comfignat's configuration variables, including builder, compiler and linker flags, directory variables and the directories project. Use it alone to build the default target:
      %build
      %{Comfignat_make}
      # If needed, a different target and/or additional variables may be appended:
      %{Comfignat_make} demo_programs atomic_doodads=true
      
      For the installation stage of Comfignat-using packages, the macro %make_install (not %makeinstall) is recommended.
  • The macro GNAT_arches expands to a list of architectures where GNAT packages are available in Fedora. Starting with Fedora 18, when there is a need to prevent attempts to build an Ada package on secondary architectures where GNAT has not been bootstrapped, this MUST be done with "ExclusiveArch: %{GNAT_arches}".
  • All packages that contain Ada code MUST have "BuildRequires: fedora-gnat-project-common" to ensure that the necessary RPM macros are defined.
  • If the upstream source package comes with a build system, for example a GNAT project file or makefiles and a configuration script, then it's probably best to use that if possible. If not, it is recommended that the packager write a GNAT project file to control the compilation.

Runpaths

Gnatmake and GPRbuild both add a runpath to the built binaries by default. Fedora's builder flags normally include an option to disable the automatic runpath. There are however cases where it would be advantageous to allow a runpath. Libraries can have test suites or auxiliary programs that aren't installed but run during the build and need to link to the library in the build directory, and they may rely on an automatic runpath for this. In those cases the spec file may define a macro named GNAT_add_rpath. The builders will then be allowed to add a runpath in those parts of the spec file where GNAT_add_rpath is defined.

Packages that contain Ada code SHOULD run %{_rpmconfigdir}/check-rpaths as the last thing in the %check section. This is a precaution against packaging bugs and toolchain bugs that would cause binaries with runpaths to end up in packages. All packages that use GNAT_add_rpath MUST do this (and must therefore have a %check section).

Devel packages

  • Ada library packages MUST have a -devel subpackage containing all the files that are necessary for compilation of code that uses the library. This includes Ada specification files (*.ads), Ada body files (*.adb), Ada library information files (*.ali) and GNAT project files (*.gpr). (There is no requirement to include all body files. Typically only some body files are needed.)
  • The -devel package MUST NOT contain any makefiles or other files that are only used for recompiling the library.
  • The -devel package MUST NOT contain any *.o files.

GNAT project files

  • The -devel package MUST contain one or more GNAT project files to be imported by other projects that use the library.
  • Project files MUST be architecture-independent. This means that the same project file must point to libraries in /usr/lib or /usr/lib64 depending on what target architecture the compiler is currently compiling for. This SHOULD be done by importing the "directories" project (that is, the project file directories.gpr) and using the variable Directories.Libdir which is defined there. The value of Directories.Libdir is set to either "/usr/lib" or "/usr/lib64" depending on the hardware platform.
  • Project files MUST NOT contain hard-coded directory names, neither absolute nor relative; they should get them from some source. The source may be an Autoconf-generated configuration script or other build system. Project files that aren't pre-processed by such a build system SHOULD use the variable Directories.Includedir rather than a hard-coded "/usr/include".
  • If the "directories" project is used, then the -devel package MUST have an explicit "Requires: fedora-gnat-project-common".
  • Project files MUST have an Externally_Built attribute equal to "true".

Here's an example of what a project file installed with a library may look like:

with "directories";
project Example is
   for Library_Name use "example";
   for Source_Dirs use (Directories.Includedir & "/example");
   for Library_Dir use Directories.Libdir;
   for Library_ALI_Dir use Directories.Libdir & "/example";
   for Externally_Built use "true";
end Example;

File placement

  • Ada source files in -devel packages (*.ads and *.adb) MUST be placed in the %{_includedir} directory or a subdirectory thereof. Placing them directly in %{_includedir} may be appropriate if there are very few of them in the package and their names include the name of the library. Otherwise they should usually be placed in a subdirectory, for example %{_includedir}/%{name}.
  • Ada library information files (*.ali) MUST be placed in a subdirectory of %{_libdir}, for example %{_libdir}/%{name}.
  • GNAT projects files (*.gpr) MUST be placed in the %{_GNAT_project_dir} directory or a subdirectory thereof. A subdirectory, for example %{_GNAT_project_dir}/%{name}, may be a good idea if there are lots of project files in the same package or if they have generic names. Otherwise they should usually be placed directly in %{_GNAT_project_dir}. The name of the library MUST be included either in the name of each project file or in the name of the subdirectory where the project files are placed.

Rpmlint and Ada packages

Rpmlint is a program that checks packages for common problems. For Ada packages, some of the rpmlint messages, such as "executable-stack", can be disregarded, because GNAT uses trampolines for pointers to nested functions. (See for example this entry in the GCC Bugzilla.)