From Fedora Project Wiki
(→‎File lists: update)
Line 94: Line 94:


== File lists ==
== File lists ==
You can generate filelists for libraries and profiling library subpackages using the following macro, rather than doing it by hand:
Filelists for shared, devel and profiling library subpackages are generated using the following macro:


<pre>
<pre>
Line 100: Line 100:
</pre>
</pre>


This macro takes one parameter, which is just a name prefix to be used for the file lists.  This same parameter must be used later in the files section.
It generates three filelists: <code>ghc-%{pkg_name}.files</code>, <code>ghc-%{pkg_name}-devel.files</code>, and <code>ghc-%{pkg_name}-prof.files</code>.
(This optional <code>name</code> and <code>version</code> macros are only needed if one is subpackaging multiple libraries one source package, which is not normal.)


The files section would then look something like this:
The files sections are boilerplate generated by <code>%ghc_lib_package</code> and <code>%ghc_binlib_package</code>.


<pre>
If you need to add additional files (e.g. extra %doc files or datadir files say) they can simply be added by echo'ing to the appropriate ".files" list.
%files -f %{name}.files
%defattr(-,root,root,-)
%doc LICENSE README
%{pkg_docdir}
 
%files -n %{name}-prof -f %{name}-prof.files
%defattr(-,root,root,-)
</pre>


=== Install scripts ===
=== Install scripts ===
Libraries must be registered with the installed ghc package.
Library devel packages include a ".conf" metadata file generated by <code>%cabal_pkg_conf</code> as part of <code>%ghc_lib_install</code>.
 
The <code>%post</code> and <code>%postun</code> scripts regenerate ghc's package cache by running:
To generate registration scripts that can be embedded in the package first include the following in %build:
<pre>
%ghc_gen_scripts
</pre>
and then in %install install them with:
<pre>
%ghc_install_scripts
</pre>


Finally the actual registering of packages must be done at install and uninstall time with the following scriplets:
<pre>
<pre>
%post -n ghc-%{pkg_name}
%ghc_pkg_recache
%ghc_register_pkg
 
%preun -n ghc-%{pkg_name}
if [ "$1" -eq 0 ] ; then
  %ghc_unregister_pkg
fi
</pre>
</pre>


=== Documentation ===
and also may regenerate the Haddock documentation index with
Normal doc files for a package should live in the usual place.  Haskell supports inline API docs using the <code>haddock</code> tool (bundled in the <code>ghc</code> package as of 6.10), for which the situation is somewhat different.  The master directory for Haddock files is <code>%{_docdir}/ghc/libraries</code>, with one directory per package under there.  The <code>index.html</code> file for this directory should be regenerated every time a package is installed, upgraded, or removed.  Since <code>%{_docdir}/ghc/libraries</code> is owned by <code>ghc-doc</code> it is recommended to subpackage haddock documentation in a <code>doc</code> subpackage, which can require <code>ghc-doc</code>.
 
 
The <code>%build</code> section should contain the following:
 
<pre>%cabal haddock</pre>
 
This will cause the HTML version of the Haddock documentation to be generated.  If built, it will automatically be installed to the correct location by <code>%cabal_install</code> without any further intervention.
 
To automatically update the master index of all Haddock documentation in <code>/usr/share/doc/ghc/libraries</code>, add the following to your <code>%post</code> and <code>%postun</code> scriptlets:


<pre>
<pre>
%post
%ghc_reindex_haddock
%ghc_reindex_haddock
%postun
if [ "$1" -eq 0 ] ; then
  %ghc_reindex_haddock
fi
</pre>
</pre>
The ghc haddock docs index will then be updated after installation, update, or removal of the package.


== References ==
== References ==

Revision as of 15:41, 4 February 2011

Haskell Packaging Guidelines

This page documents the guidelines and conventions for packaging Haskell projects in Fedora.

GHC (Glasgow Haskell Compiler) is the current mainstream Haskell compiler.

Most Haskell packages are now released on Haskage and use the Haskell Cabal package system. So currently these guidelines mostly focus on packaging for GHC using Cabal.

Spec file templates

There are three types of Haskell Cabal packages: binary only (Bin), library only (Lib), and binary and library (BinLib). Templates are provided for all three cases since they are slightly different:

It is recommended to use cabal2spec to create .spec files using these templates directly from a Cabal package or .cabal file for any of the three cases, since following the standard packaging templates lower the maintenance burden considerably across Fedora's Haskell packages. With minor editing the .spec files should then build for most general Cabal packages: for example it may be necessary to specify BuildRequires for build dependencies and Requires for any runtime dependencies. Please report any problems in bugzilla (in the cabal2spec component of the Fedora product).

Naming

Haskell Bin and BinLib packages should follow the usual Fedora Package Naming Guidelines for base package naming: ie follow the upstream name. Examples include projects like darcs and xmonad. BinLib packages SHOULD subpackage their libraries with naming following Lib packages.

For example the xmonad package has library subpackages ghc-xmonad, ghc-xmonad-devel, and ghc-xmonad-prof.

The name of Haskell Lib packages built for ghc are prefixed by "ghc-". For example the zlib library is named ghc-zlib, and the QuickCheck library is named ghc-QuickCheck.

If a library is packaged for more than one Haskell compiler or interpreter, the base name should instead be prefixed with haskell, e.g. haskell-X11. Such a package would then have subpackages for each compiler and/or interpreter it is built for (e.g. ghc-X11, hugs98-X11, etc).

Package naming preserves case to follow the upstream naming conventions as closely as possible.

Shared and static library linking

GHC uses static libraries by default, but now supports shared libraries. Lib and BinLib packages should provide static, shared, and profiling libraries. The shared libraries live in the base library package, static library and header files in the -devel subpackage and profiling libraries in the -prof subpackage.

Executables in Bin and BinLib packages should be dynamically linked to shared libraries.

Static linking means that when updating any library, all packages that depend on it will also need to be rebuilt before they see any changes, and in the event of a security advisory, all of them need to be rebuilt also.

This is not true for linking to other languages using the Foreign Function Interface (FFI). When linking to these libraries, the standard dynamic linker is used.

Note: the situation is similar to OCaml, and the usual rules that apply there apply here as well.

Keep in mind though, that some special packages may still do code generation at runtime in which case they may need Requires as well as BuildRequires for their dependencies: examples include xmonad and yi which may require their devel package to be present to allow user configuration or customization.

Debug Information

Objects compiled with ghc do not include useful debug info, so debuginfo packages should be disabled:

%global debug_package %{nil}

RPM Macros

The templates all have buildrequires for ghc-rpm-macros which provides macros.ghc to assist with packaging Haskell Cabal packages.

The main commonly used macros are:

  • %ghc_bin_build
  • %ghc_lib_build
  • %ghc_bin_install
  • %ghc_lib_install
  • %ghc_lib_package
  • %ghc_binlib_package

They are used in the templates and explained in more detail below.

Of course, these macros can be replaced by their macro expansions, but this should only be necessary when some exceptional package build customization is required to build a package for Fedora.

Bin packages

Bin packages use dynamic linking by default, but this can be disabled if necessary by defining the without_dynamic macro.

  • %ghc_bin_build is used to configure and build bin packages. It runs:
    • %cabal_configure: configure the package for building and dynamic linking.
    • %cabal build: builds the package.
  • %ghc_bin_install is used to install bin packages. It runs:
    • %cabal_install: installs the package.
    • %ghc_strip_dynlinked: strips the dynamically linked binary.

Lib and BinLib packages

  • %ghc_lib_build is used to configure, build and generate documentation for lib and binlib packages. It runs:
    • %cabal_configure --ghc -p: configures the package for building with ghc and profiling. Libraries should build profiling versions of their static libraries.
    • %cabal build: builds the package.
    • %cabal haddock: generates HTML library documentation from the source code. If necessary (if e.g. documentation is failing to build for some reason) this can be skipped by defining without_haddock.
  • %ghc_lib_install is used to install lib and binlib packages. It runs:
    • %cabal_install: installs the package without registering it in ghc-pkg.
    • %cabal_pkg_conf: creates ghc-pkg metadata for package installation time
    • %ghc_gen_filelists: generates rpm filelists.
    • %ghc_strip_dynlinked: strips dynamically linked objects.

Directories

GHC libraries are installed under %ghcpkgdir/%{pkg_name}-%{version}:

Library documentation lives under %ghclibdocdir/%{pkg_name}-%{version}.

File lists

Filelists for shared, devel and profiling library subpackages are generated using the following macro:

%ghc_gen_filelists [name] [version]

It generates three filelists: ghc-%{pkg_name}.files, ghc-%{pkg_name}-devel.files, and ghc-%{pkg_name}-prof.files. (This optional name and version macros are only needed if one is subpackaging multiple libraries one source package, which is not normal.)

The files sections are boilerplate generated by %ghc_lib_package and %ghc_binlib_package.

If you need to add additional files (e.g. extra %doc files or datadir files say) they can simply be added by echo'ing to the appropriate ".files" list.

Install scripts

Library devel packages include a ".conf" metadata file generated by %cabal_pkg_conf as part of %ghc_lib_install. The %post and %postun scripts regenerate ghc's package cache by running:

%ghc_pkg_recache

and also may regenerate the Haddock documentation index with

%ghc_reindex_haddock

References