From Fedora Project Wiki

No edit summary
m (Note that the document doesn't apply after Fedora 12.)
Line 8: Line 8:
The purpose of this document is to promote good practice in packaging add-ons for GNU Emacs and XEmacs, and to encourage the submission of more Emacs add-on packages to the package collection by providing easy to use spec file templates.
The purpose of this document is to promote good practice in packaging add-ons for GNU Emacs and XEmacs, and to encourage the submission of more Emacs add-on packages to the package collection by providing easy to use spec file templates.


This document refers to packaging for Fedora 8 onwards.
This document refers to packaging for Fedora 8 until Fedora 12, inclusive.  [[Packaging:Emacs]] should be used for any modern Fedora version.


== Packaging add-ons for (X)Emacs ==
== Packaging add-ons for (X)Emacs ==

Revision as of 19:25, 11 May 2011

Packaging of add-ons for GNU Emacs and XEmacs

Purpose

The purpose of this document is to promote good practice in packaging add-ons for GNU Emacs and XEmacs, and to encourage the submission of more Emacs add-on packages to the package collection by providing easy to use spec file templates.

This document refers to packaging for Fedora 8 until Fedora 12, inclusive. Packaging:Emacs should be used for any modern Fedora version.

Packaging add-ons for (X)Emacs

Executive summary of Guidelines

The following list contains the key points of the guidelines. More detail on each of these may be found in the subsequent sections.


1. Where an add-on package foo is for both GNU Emacs and XEmacs, the main package should be called emacs-common-foo. This main package should contain files common to both GNU Emacs and XEmacs such as documentation etc. Files specific to each of GNU Emacs and XEmacs should be placed in sub-packages as detailed in points 4 and 5 below.

2. Where a package is specific only to one flavour of (X)Emacs, the main package should be called emacs-foo or xemacs-foo. In both cases, elisp source should be packaged in separate sub-packages as detailed below.

3. Where a package which is not primarily an (X)Emacs add-on package but contains auxillary (X)Emacs components, these should be placed in sub-packages following the guidelines below.

4. Files specific to GNU Emacs should be placed in two sub-packages:

  • emacs-foo: this sub-package should contain compiled elisp and other files needed to use the add-on package with GNU Emacs only. It should not contain any source elisp files which are not required to run the package.
  • emacs-foo-el: this sub-package contains the source elisp files used to build the add-on package for GNU Emacs. Files in this package should not be required to use the add-on package.

5. Files specific to XEmacs should be placed in two sub-packages:

  • xemacs-foo: this sub-package should contain compiled elisp and other files needed to use the add-on package with XEmacs only. It should not contain any source elisp files which are not required to run the package.
  • xemacs-foo-el: this sub-package contains the source elisp files used to build the add-on package for XEmacs. Files in this package should not be required to use the add-on package.

6. File locations for GNU Emacs add-on packages:

  • All elisp and related files for the add-on package should be installed in the directory /usr/share/emacs/site-lisp/foo.
  • /usr/share/emacs/site-lisp/foo should be owned by the package emacs-foo.
  • If the package requires a startup file this should be called foo-init.el and be placed in /usr/share/emacs/site-lisp/site-start.d/.

7. Files locations for XEmacs add-on packages:

  • All elisp and related files for the add-on package should be installed in the directory /usr/share/xemacs/site-packages/lisp.
  • /usr/share/xemacs/site-packages/lisp should be owned by xemacs-foo.
  • If the package requires a startup file this should be called foo-init.el and be placed in /usr/share/xemacs/site-packages/lisp/site-start.d/.

8. emacs-foo-el must have Requires: emacs-foo = %{version}-%{release}.

9. xemacs-foo-el must have Requires: xemacs-foo = %{version}-%{release}.

10. Where it is relevant, emacs-foo and xemacs-foo must have Requires: emacs-common-foo = %{version}-%{release}.

11. emacs-foo must have Requires: emacs(bin) >= X, where X is the version of GNU Emacs used to build the package.

12. xemacs-foo must have Requires: xemacs(bin) >= Y, where Y is the version of GNU Emacs used to build the package.

13. If an add-on package requires only byte compilation of elisp then BuildArch: noarch should be used.

Principles

The existence of the GNU Emacs and XEmacs variants makes packaging Emacs add-on packaging slightly complex. GNU Emacs and XEmacs have different philosophies regarding add-on packages.

XEmacs has its own packaging system and maintains and distributes its own library of third party add-on modules. These are distributed in Fedora in the xemacs-packages-base and xemacs-packages-extra packages. GNU Emacs doesn't have any equivalent system, and third party add-ons are left for the user or distribution to install.

The packaging naming guidelines state that:

Packages of emacs add-on components (code that adds additional functionality to emacs compatible editors) have their own naming scheme. It is often the case that a component will add functionality to several different compatible editors, such as GNU Emacs and XEmacs (and possibly development versions of these editors). The package name should take into account the upstream name of the emacs component.

Where a component adds functionality to more than one emacs compatible editor, the package name should be of the form emacs-common-$NAME. In this case, the main package should contain only files common to all emacs compatible editors, and the code specific to each should be placed in a subpackage reflecting the specific editor $EDITOR-$NAME eg. xemacs-$NAME, emacs-$NAME (the latter being the package specific to GNU Emacs). An example of this scheme can be found in the package emacs-common-muse.

Where a component is designed to add functionality to only a single emacs compatible editor, the main package name should reflect this by being called $EDITOR-$NAME. An example of this situation can be found in the package emacs-auctex, which is built only for GNU Emacs.

Wherever possible, we encourage making an add-on package available for both GNU Emacs and XEmacs. One common case where that is not desireable is when an add-on package is already available for XEmacs in either xemacs-packages-base or xemacs-packages-extra. For example VM (a mail reader for Emacs) is provided for XEmacs in the xemacs-packages-extra package, but is not included in the emacs or emacs-common packages. Therefore it is sensible to create a package called emacs-vm which is the VM package for GNU Emacs only. Another such example is AUCTeX.

Location of installed files

GNU Emacs

For GNU Emacs, files for add-on package foo should be placed in /usr/share/emacs/site-lisp/foo.

Usually an add-on package will require a startup file, and this should be called foo-init.el and be placed in /usr/share/emacs/site-lisp/site-start.d/.

The following code snippet show how to use macros to determine these at package build time:

%if %($(pkg-config emacs) ; echo $?)
%global emacs_lispdir %{_datadir}/emacs/site-lisp
%global emacs_startdir %{_datadir}/emacs/site-lisp/site-start.d
%else
%global emacs_lispdir %(pkg-config emacs --variable sitepkglispdir)
%global emacs_startdir %(pkg-config emacs --variable sitestartdir)
%endif
...
BuildRequires: emacs-el
...

XEmacs

For XEmacs, files for add-on package foo should be placed in /usr/share/xemacs/site-packages/lisp/foo.

Usually an add-on package will require a startup file, and this should be called foo-init.el and be placed in /usr/share/xemacs/site-packages/lisp/site-start.d/.

The following code snippet show how to use macros to determine these at package build time:

%if %($(pkg-config xemacs) ; echo $?)
%global xemacs_lispdir %{_datadir}/xemacs/site-packages/lisp
%global xemacs_startdir %{_datadir}/xemacs/site-packages/lisp/site-start.d
%else
%global xemacs_lispdir %(pkg-config xemacs --variable sitepkglispdir)
%global xemacs_startdir %(pkg-config xemacs --variable sitestartdir)
%endif
...
BuildRequires: xemacs-devel
...

Packaging of source elisp files

Typically, an Emacs add-on package will be compiled from source elisp files. The resulting compiled elisp files will then be included in the relevant emacs-foo and xemacs-foo packages. However, these packages SHOULD NOT contain uncompiled elisp source files which are not required for the program to run. Rather, following the precedent set by GNU Emacs packaging, the elisp source files should be placed in their own sub-packages, named emacs-foo-el and xemacs-foo-el.

The (x)emacs-foo-el packages are similar in many ways to the -devel subpackages for system libraries. It is often the case that byte compiling the elisp source for one add-on will require the presence of the elisp source for another add-on package at build time for example.

BuildArch for (X)Emacs add-on packages

You should set BuildArch: noarch for add-on packages which only compile elisp files during building.

If the package building process also compiles programs in other languages, you may need to not set BuildArch.

Requires for GNU Emacs and XEmacs

Add-on packages should have appropriate Requires entries for the flavour of (X)Emacs they are targeted at. Both GNU Emacs and XEmacs are available in two different packages - some details of these packages follow. 1. GNU Emacs is packaged as two variants. The emacs package is built with Xorg support to allow the user to run Emacs in a windowed environment. The emacs-nox package is built without Xorg support and hence allows Emacs to be run only in a console. Note:

  • Both the emacs and emacs-nox packages have Requires: emacs-common.
  • Both emacs and emacs-nox have a virtual Provides: emacs(bin)

2. XEmacs is packaged as two variants. The xemacs package is built with Xorg support to allow the user to run Emacs in a windowed environment. The xemacs-nox package is built without Xorg support and hence allows Emacs to be run only in a console. Note:

  • Both the xemacs and xemacs-nox packages have Requires: xemacs-common.
  • Both xemacs and xemacs-nox have a virtual Provides: xemacs(bin)

Assuming your add-on package will work in both a windowed and a console (X)Emacs session, it is wrong to have Requires: emacs or Requires: xemacs as that would pull in a dependency on Xorg even if the console variants of (X)Emacs was installed. Rather you should use Requires: xemacs(bin) for XEmacs add-on packages, and Requires: emacs(bin) for GNU Emacs add-on packages.

If the package ONLY works with Xorg support built into (X)Emacs, then the packages should have Requires: emacs or Requires: xemacs. This is very uncommon.

Why we need versioned Requires

Many elisp packages aim for backwards source level compatibility by checking whether some features exist in the (X)Emacs in use when the package is being run or byte-compiled. If yes, they use what's available. If no, they provide their own versions of missing functions, macros etc. This propagates into *.elc during byte compilation, and quite a few functions do get added between upstream (X)Emacs releases.

So let's say I byte-compile a package into *.elc with XEmacs 21.5.28. Elisp package quux checks if the foo-bar function is available in the XEmacs being used to byte-compile it. Yes, it is, so the internal backwards compat version of foo-bar included in quux does not end up in the *.elc. Now, let's assume foo-bar was added in XEmacs 21.5.28 and didn't exist in 21.5.27 and we're trying to run the *.elc with 21.5.27 -> boom, foo-bar is not available. Note: this wouldn't happen if only *.el were shipped - *.elc are the potential and likely problem. Requiring >= version of the XEmacs used to byte-compile the *.elc is not the only solution (nor enough for all corner cases), but is the best one we currently have available.

The main package and subpackages will need to have appropriately version Requires to ensure that a recent enough version of (X)Emacs is installed. (X)Emacs byte compiled lisp is usually forward compatible with later (X)Emacs versions, but is frequently not compatible with earlier versions of (X)Emacs.

Determining the Required (X)Emacs version at package build time

It is recommended to derive greater-than-or-equal-to valued versioned dependencies from the version of (X)Emacs used to byte-compile the package at package build time. The mechanism for doing so is provided by pkg-config (when available).

For Emacs add-ons you will need to add BuildRequires: emacs-el and use the macro below

%if %($(pkg-config emacs) ; echo $?)
%global emacs_version 22.1
%else
%global emacs_version %(pkg-config emacs --modversion)
%endif
...
Requires: emacs(bin) >= emacs_version
BuildRequires: emacs-el
...

For Xemacs you will need to add BuildRequires: xemacs-devel and use the macro below

%if %($(pkg-config xemacs) ; echo $?)
%global xemacs_version 21.5
%else
%global xemacs_version %(pkg-config xemacs --modversion)
%endif
...
Requires: xemacs(bin) >= xemacs_version
BuildRequires: xemacs-devel
...

Other packages containing Emacsen add-ons

It is often the case that a software package, while not being primarily an Emacs add-on package, will contain components for (X)Emacs. For example, the Gnuplot program contains some elisp files for editing Gnuplot input files in GNU Emacs and running Gnuplot from GNU Emacs.

Where a package contains add-on components for (X)Emacs, in general these components should be packaged in a sub-package consistent with the guidelines here for main (X)Emacs packages.

In other words, if a package foo contains components for (X)Emacs, the subpackages containing the files to run the (X)Emmacs components should be called emacs-foo and emacs-foo-el, which own the directories /usr/share/emacs/site-lisp/foo and /usr/share/xemacs/site-packages/lisp/foo respectively. Elisp source files not needed for running the add-ons should be packaged in separate sub-packages emacs-foo-el and xemacs-foo-el, which should Require emacs-foo and xemacs-foo respectively.

Templates for Emacsen add-on package spec files

Template for a package for both GNU Emacs and XEmacs

This spec-file template for the add-on package "foo" creates 5 packages:

1. emacs-common-foo is the main package. This should contain files which are common to both the emacs-foo and xemacs-foo subpackages below. Examples of what this file would contain are the package documentation, the COPYING file, the CHANGELOG file etc.

2. emacs-foo. This sub-package Requires emacs-common-foo and contains the files needed to run foo with Emacs only. This package owns the director /usr/share/emacs/site-lisp/foo.

3. emacs-foo-el. This sub-package contains the elisp source files corresponding to the compiled elisp files in package emacs-foo. This sub-package Requires: emacs-foo, as the directory in which the elisp source files are installed to is owned by emacs-foo.

4. xemacs-foo. This sub-package Requires emacs-common-foo and contains the files needed to run foo with Emacs only. This package owns the director /usr/share/emacs/site-packages/lisp/foo.

5. xemacs-foo-el. This sub-package contains the elisp source files corresponding to the compiled elisp files in package xemacs-foo. This sub-package Requires: xemacs-foo, as the directory in which the elisp source files are installed to is owned by xemacs-foo.

For the Requires mentioned in 1-5 above, the exact %{version}-%{release} should be matched.

For convenience, there are two macros at the top of the file which you should customise to your package. You do not have to use the macros placed at the top of the file, but they help readability and make writing a spec file for a new package much quicker.

%global pkg foo
%global pkgname Foo

%if %($(pkg-config emacs) ; echo $?)
%global emacs_version 22.1
%global emacs_lispdir %{_datadir}/emacs/site-lisp
%global emacs_startdir %{_datadir}/emacs/site-lisp/site-start.d
%else
%global emacs_version %(pkg-config emacs --modversion)
%global emacs_lispdir %(pkg-config emacs --variable sitepkglispdir)
%global emacs_startdir %(pkg-config emacs --variable sitestartdir)
%endif

%if %($(pkg-config xemacs) ; echo $?)
%global xemacs_version 21.5
%global xemacs_lispdir %{_datadir}/xemacs/site-packages/lisp
%global xemacs_startdir %{_datadir}/xemacs/site-packages/lisp/site-start.d
%else
%global xemacs_version %(pkg-config xemacs --modversion)
%global xemacs_lispdir %(pkg-config xemacs --variable sitepkglispdir)
%global xemacs_startdir %(pkg-config xemacs --variable sitestartdir)
%endif

Name:           emacs-common-%{pkg}
Version:
Release:        1%{?dist}
Summary:

Group:
License:
URL:
Source0:
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

BuildArch:	noarch
BuildRequires:  emacs emacs-el
BuildRequires:  xemacs xemacs-devel
Requires:

%description
%{pkgname} is an add-on package for GNU Emacs and XEmacs. It does wonderful things...

This package contains the files common to both the GNU Emacs and XEmacs %{pkgname}
packages.

%package -n emacs-%{pkg}
Summary:	Compiled elisp files to run %{pkgname} under GNU Emacs
Group:
Requires:	emacs(bin) >= %{emacs_version}
Requires:       emacs-common-%{pkg} = %{version}-%{release}

%description -n emacs-%{pkg}
This package contains the byte compiled elisp packages to run %{pkgname} with GNU
Emacs.


%package -n emacs-%{pkg}-el
Summary:	Elisp source files for %{pkgname} under GNU Emacs
Group:
Requires:	emacs-%{pkg} = %{version}-%{release}

%description -n emacs-%{pkg}-el
This package contains the elisp source files for %{pkgname} under GNU Emacs. You
do not need to install this package to run %{pkgname}. Install the emacs-%{pkg}
package to use %{pkgname} with GNU Emacs.


%package -n xemacs-%{pkg}
Summary:	Compiled elisp files to run %{pkgname} under XEmacs
Group:
Requires:	xemacs(bin) >= %{xemacs_version}
Requires:       emacs-common-%{pkg} = %{version}-%{release}

%description -n xemacs-%{pkg}
This package contains the byte compiled elisp packages to use %{pkgname} with
XEmacs.


%package -n xemacs-%{pkg}-el
Summary:	Elisp source files for %{pkgname} under XEmacs
Group:
Requires:	xemacs-%{pkg} = %{version}-%{release}

%description -n xemacs-%{pkg}-el
This package contains the elisp source files for %{pkgname} under XEmacs. You do
not need to install this package to run %{pkgname}. Install the xemacs-%{pkg}
package to use %{pkgname} with XEmacs.


%prep
%setup -q -n %{pkg}-%{version}

%build


%install
rm -rf $RPM_BUILD_ROOT


%clean
rm -rf $RPM_BUILD_ROOT


%post


%preun


%files
%doc


%files -n emacs-%{pkg}
%{emacs_lispdir}/%{pkg}/*.elc
%{emacs_startdir/*.el
%dir %{emacs_lispdir}/%{pkg}


%files -n emacs-%{pkg}-el
%{emacs_lispdir}/%{pkg}/*.el


%files -n xemacs-%{pkg}
%{xemacs_lispdir}/%{pkg}/*.elc
%{xemacs_startdir}/*.el
%dir %{xemacs_lispdir}/%{pkg}


%files -n xemacs-%{pkg}-el
%{xemacs_lispdir}/%{pkg}/*.el


%changelog

Template for a add-on package for GNU Emacs only

This is a template for a package for GNU Emacs only. The main package is called emacs-foo and contains all files needed to run package foo with GNU Emacs. There is a subpackage called emacs-foo-el which installs the elisp source files. emacs-foo owns the directory into which it is installed (/usr/share/emacs/site-lisp/foo), and so emacs-foo-el Requires emacs-foo with the matching version and release tag.

%global pkg foo
%global pkgname Foo

%if %($(pkg-config emacs) ; echo $?)
%global emacs_version 22.1
%global emacs_lispdir %{_datadir}/emacs/site-lisp
%global emacs_startdir %{_datadir}/emacs/site-lisp/site-start.d
%else
%global emacs_version %(pkg-config emacs --modversion)
%global emacs_lispdir %(pkg-config emacs --variable sitepkglispdir)
%global emacs_startdir %(pkg-config emacs --variable sitestartdir)
%endif

Name:           emacs-%{pkg}
Version:
Release:        1%{?dist}
Summary:

Group:
License:
URL:
Source0:
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

BuildArch:      noarch
BuildRequires:  emacs emacs-el
Requires:       emacs(bin) >= %{emacs_version}

%description
%{pkgname} is an add-on package for GNU Emacs. It does wonderful things...

%package -n %{name}-el
Summary:        Elisp source files for %{pkgname} under GNU Emacs
Group:
Requires:       %{name} = %{version}-%{release}

%description -n %{name}-el
This package contains the elisp source files for %{pkgname} under GNU Emacs. You
do not need to install this package to run %{pkgname}. Install the %{name}
package to use %{pkgname} with GNU Emacs.

%prep
%setup -q -n %{pkg}-%{version}

%build


%install
rm -rf $RPM_BUILD_ROOT


%clean
rm -rf $RPM_BUILD_ROOT


%post


%preun


%files
%doc
%{emacs_lispdir}/%{pkg}/*.elc
%{emacs_startdir}/*.el
%dir %{emacs_lispdir}/%{pkg}

%files -n %{name}-el
%{emacs_lispdir}/%{pkg}/*.el

%changelog