From Fedora Project Wiki

(Give basics)
(Reorg "see also")
Line 1: Line 1:
== Creating Package HOWTO ==
== Creating Package HOWTO ==


This page describes the mechanics of how to create an RPM package for Fedora, and in particular,
This page describes the mechanics of how to create an RPM package for Fedora (such as
how to create a .spec file.  It also gives some practical warnings about stuff that will or won't work,
how to create a .spec file).  It also gives some practical warnings about stuff that will or won't work,
which may save you hours of time later.
which may save you hours of time later.


Line 69: Line 69:
  cat > hello # Do not use in-line comments
  cat > hello # Do not use in-line comments
In-line comments sometimes don't work properly in a spec file (Just use a comment-only line instead).
In-line comments sometimes don't work properly in a spec file (Just use a comment-only line instead).
[[Packaging/ScriptletSnippets Scriptlet Snippets]] has some useful examples of scriptlets.


== Creating a RPMs from the spec file ==
== Creating a RPMs from the spec file ==
Line 81: Line 83:
When things go wrong, you can "cd" into the BUILD directory and see what's left over.
When things go wrong, you can "cd" into the BUILD directory and see what's left over.


== Guidelines and rules ==
When you create your packages, you'll need to follow the following rules and guidelines:
* [[PackageMaintainers/Join| How to join the Fedora Package Collection Maintainers]] - describes the process for becoming a Fedora package maintainer
* [[Packaging/Guidelines|Packaging Guidelines]]
* [[Packaging/NamingGuidelines| Package Naming Guidelines]]
* [[Packaging/DistTag| Dist Tag Guidelines]]
* [[Packaging/ReviewGuidelines| Package Review Guidelines]]


== For more information ==
== For more information ==


This page only discusses the mechanics of creating a package.
The [[PackageMaintainers|Package Maintainers]] page links to many other useful pages, and the
For more information about packaging, see
[[PackageMaintainers|Package Maintainers]] page, especially the
[[Packaging/Guidelines|Packaging Guidelines]] and
[[PackageMaintainers/Join| How to join the Fedora Package Collection Maintainers]]
(which explains how to become a package maintainer).
The [[PackageMaintainers/UpdatingPackageHowTo|Updating Package HOWTO]] describes how to update
The [[PackageMaintainers/UpdatingPackageHowTo|Updating Package HOWTO]] describes how to update
an existing package you maintain in Fedora.
an existing package you already maintain in Fedora.
[[Packaging/ScriptletSnippets Scriptlet Snippets]] has some useful examples of scriptlets.


For more information see:
For more information, outside of the Fedora Wiki, see:
* [http://www.g-loaded.eu/2006/04/05/how-to-build-rpm-packages-on-fedora/ How to build RPM packages on Fedora] - quick run-through
* [http://www.g-loaded.eu/2006/04/05/how-to-build-rpm-packages-on-fedora/ How to build RPM packages on Fedora] - quick run-through
* [http://www.redhatmagazine.com/2008/02/28/when-sally-met-eddie-the-fedora-package-story/ When Sally met Eddie]
* [http://www.redhatmagazine.com/2008/02/28/when-sally-met-eddie-the-fedora-package-story/ When Sally met Eddie]

Revision as of 20:58, 19 June 2008

Creating Package HOWTO

This page describes the mechanics of how to create an RPM package for Fedora (such as how to create a .spec file). It also gives some practical warnings about stuff that will or won't work, which may save you hours of time later.

Nearly all Linux distributions can install and uninstall programs as "packages". Fedora, and many other Linux distributions, use the "RPM" format for packages. There are tools that make it easy to create RPM packages; the key is to write a ".spec" file that explains to RPM how to build and install the program.

Setting up

Before you create RPM packages on Fedora, you need to install some core development tools and set up the account(s) you will use. As root:

 # yum groupinstall "Development Tools"
 # yum install rpmdevtools

It's strongly recommended that you create a new "dummy user" specifically for creating rpm packages. That way, if something goes terribly wrong, the program or build process can't trash your files, or send your private files/keys to the world. At the very least, you should normally not create your packages as user root. You can create a new user named "makerpm" quickly by doing:

 # /usr/sbin/useradd makerpm

Then log in as that special dummy user (makerpm).

Once you're logged in as the user who is creating packages, you then can then create the directory structure in your home directory by executing:

 $ rpmdev-setuptree

The "rpmdev-setuptree" program will create an "rpmbuild" directory in your $HOME directory. Underneath "rpmbuild" are a set of subdirectories (such as SPECS and BUILD), which you will use for creating your packages.

One you've set up your system and user account, you won't normally need to do these again.

Setting up to package a particular program

If there are special programs that are required to build or run it, install them and write down what they were (you'll need that information).

To package a program, you must package pristine (original) sources, along with the patches and build instructions. It's generally not okay to start with pre-compiled code. Install the file with the original source (usually a .tar.gz file) in the "~/rpmbuild/SOURCES" directory.

Creating a spec file

You now need to create a ".spec" file in the "~/rpmbuild/SPECS" directory. Generally, you'll name it after the program, e.g., "program.spec".

When you're creating a spec file for the first time, create its initial version using emacs or vim; they will automatically create a template for you. E.G.:

 $ cd ~/rpmbuild/SPECS
 $ vi program.spec

The RPM Guide, section on creating RPMs, describes the details of how to fill in a spec file.

Beware: Comments (beginning with #) do not work as you might expect. Avoid including macro references (words beginning with "%") in a comment, because they are expanded even inside comments, and if the macro is multi-line it will not work correctly. Also, don't use in-line comments like this:

cat > hello # Do not use in-line comments

In-line comments sometimes don't work properly in a spec file (Just use a comment-only line instead).

Packaging/ScriptletSnippets Scriptlet Snippets has some useful examples of scriptlets.

Creating a RPMs from the spec file

Once you've create a spec file, say "program.spec", you can create source and binary RPMs by simply running this:

 $ rpmbuild --clean -ba program.spec

If this is successful, you'll find your binary RPM(s) in the "~/rpmbuild/RPMS/" subdirectory, and the source RPM in "~/rpmbuild/SRPMS".

When things go wrong, you can "cd" into the BUILD directory and see what's left over.

Guidelines and rules

When you create your packages, you'll need to follow the following rules and guidelines:

For more information

The Package Maintainers page links to many other useful pages, and the The Updating Package HOWTO describes how to update an existing package you already maintain in Fedora.

For more information, outside of the Fedora Wiki, see: