Fix RPM pckging.

This commit is contained in:
Robert Krátký 2018-01-21 18:40:25 +01:00
parent 46e675ef15
commit 6db037aa19
7 changed files with 126 additions and 1680 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,11 +0,0 @@
include::modules/con_rpm_packaging_overview.adoc[]
include::modules/proc_rpm_preparing_your_system.adoc[]
include::modules/proc_rpm_creating_a_rpm.adoc[]
include::modules/con_rpm_spec_file_overview.adoc[]
include::create-an-rpm-old.adoc[]

View file

@ -0,0 +1,12 @@
[id='creating-rpm-packages']
= Creating RPM packages
Learn the basics of RPM packaging.
include::modules/con_rpm_packaging_overview.adoc[leveloffset=+1]
include::modules/proc_rpm_preparing_your_system.adoc[leveloffset=+1]
include::modules/proc_rpm_creating_an_rpm.adoc[leveloffset=+1]
include::modules/con_rpm_spec_file_overview.adoc[leveloffset=+1]

View file

@ -1,60 +1,49 @@
[[introduction]]
== RPM Packaging Overview
[[rpm-packaging-overview]]
= RPM Packaging Overview
Use this guide to create RPM packages and `.spec` files. Despite the focus on Fedora, you can apply much of this document to other RPM-based
distributions.
Use this guide to create RPM packages and `.spec` files. Despite the focus on Fedora, you can apply much of this document to other RPM-based distributions.
Fedora Documentation had released a draft guide for packagers, see
http://docs-old.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/Packagers_Guide[Packagers
Guide]. It is archived.
[NOTE]
This document is not an official Fedora packaging guideline. This page
is open for editing by the general Fedora packaging community. For a general-purpose RPM building guide for packagers on Fedora, CentOS and Red Hat Enterprise Linux, see the https://rpm-packaging-guide.github.io/[RPM Packaging Guide].
NOTE: For a general-purpose RPM building guide for packagers on Fedora, CentOS, and Red Hat Enterprise Linux, see the https://rpm-packaging-guide.github.io/[RPM Packaging Guide].
For more information about packaging guidelines, see the following guides:
* https://fedoraproject.org/wiki/Packaging:Guidelines[Packaging Guidelines]
* http://fedoraproject.org/wiki/Packaging:LicensingGuidelines[Licensing Guidelines]
* http://fedoraproject.org/wiki/Packaging:Naming[ Package Naming Guidelines]
* http://fedoraproject.org/wiki/Packaging:DistTag[ Dist Tag Guidelines]
* http://fedoraproject.org/wiki/Packaging:ReviewGuidelines[ Package Review Guidelines]
* http://fedoraproject.org/wiki/Packaging:Scriptlets[ Recipes for RPM scriptlets]
* http://fedoraproject.org/wiki/Packaging:Naming[Package Naming Guidelines]
* http://fedoraproject.org/wiki/Packaging:DistTag[Dist Tag Guidelines]
* http://fedoraproject.org/wiki/Packaging:ReviewGuidelines[Package Review Guidelines]
* http://fedoraproject.org/wiki/Packaging:Scriptlets[Recipes for RPM scriptlets]
If you plan to submit a package to the official Fedora repository, follow the procedure in http://fedoraproject.org/wiki/Join_the_package_collection_maintainers[Join the package collection
maintainers].
If you plan to submit a package to the official Fedora repository, follow the procedure in http://fedoraproject.org/wiki/Join_the_package_collection_maintainers[Join the package collection maintainers].
Before you begin, select a text editor that you want to use, and ensure that you understand the following terminology.
[[some-terminology]]
[[rpm-terminology]]
== RPM terminology
.RPM
RPM::
The package manager used by Fedora, Red Hat Enterprise Linux, Mageia, OpenSUSE and others. Originally RPM stood for "Red Hat Package Manager" but now it is a recursive acronym "RPM Package Manager".
.spec file
spec file::
A plain text file that contains information about a package and instructions that RPM uses for compiling the package's software. To name the file, use the name of the package with the file extension `.spec`.
.tag
tag::
A string, generally capitalized and followed by a colon, which appears at the top of the `.spec` file to provide some important data about the RPM, such as `Name:`, `Version:` or `Summary:`.
.section
section::
A segment of the `.spec` file that tells RPM how to perform some portion of the package construction process. Many, but not all, sections contain code that is simply passed to the shell, though RPM has significant flexibility around this that is outside of the scope of this document.
.section header
section header::
A short string, starting with `%` at the beginning of a line, which introduces a section. Examples include `%description`, `%prep` and `%files`.
.macro
macro::
A short string, always prefixed by `%` and generally surrounded by curly brackets `{}` which RPM converts to a different and usually longer string. Some macros can take arguments and some arguments are quite complex. Some macros are provided by RPM, some are part of https://apps.fedoraproject.org/packages/redhat-rpm-config[redhat-rpm-config] and https://apps.fedoraproject.org/packages/fedora-rpm-macros[fedora-rpm-macros] packages, but many other packages also provide macros. You can run `rpm --showrc` to view all of the macros currently available on your system, but you do not need to run most of the macros you see there.
+
+
For a full list of guidelines related to macros, see http://fedoraproject.org/wiki/Packaging:Guidelines#Macros[Macros] in the Packaging Guidelines.
.mock
mock::
A system for building RPMs locally within your own Fedora installation. This avoids the need to install a full set of build dependencies on your operating system installation, and allows you to build packages for different Fedora releases.
.koji
koji::
The main Fedora build system: https://koji.fedoraproject.org[1].

View file

@ -1,111 +1,96 @@
== Spec file overview
[[con_rpm_spec_file_overview]]
[[con_rpm-spec-file-overview]]
= RPM spec file overview
Use this guide for information about the specific macros in a `.spec` file.
Use this guide for information about the specific macros in a `.spec` file.
NOTE: You can use the macros `%{name}`, `%{version}` and `%{release}` to refer to the Name, Version and Release tags respectively. When you change the tag, the macros automatically update to use the new value.
[NOTE]
You can use the macros `%{name}`, `%{version}` and `%{release}` to refer to the Name, Version and Release tags respectively. When you change the tag, the macros automatically update to use the new value.
.Name
`Name`::
Add the base name of the package, which must match the `.spec` file name. Follow the http://fedoraproject.org/wiki/Packaging:Naming[Package Naming Guidelines] and write the file name in lower-case letters.
.Version
`Version`::
Add the upstream version number. See http://fedoraproject.org/wiki/Packaging:Versioning[Package Versioning]. If the version contains tags that are non-numeric, you might need to include the non-numeric characters in the `Release` tag. If upstream uses full dates to distinguish versions, consider using version numbers of the form. For example, `yy.mm[dd]` where `2008-05-01` becomes `8.05`.
.Release
`Release`::
Set the initial value to `1%{?dist}`. Increment the number every time you release a new package for the same version of software. When a new upstream version is released, change the `Version` tag to match and reset the `Release` number to `1`. For more information, see the http://fedoraproject.org/wiki/Packaging:Versioning[Versioning Guide] of the packaging guidelines.
.Summary
`Summary`::
Enter a brief, one-line summary of the package. Use American English. Do not end with a period.
.Group
`Group`::
This tag is deprecated since Fedora 17. See https://docs-old.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/Packagers_Guide/chap-Packagers_Guide-Spec_File_Reference-Preamble.html[Spec
File Reference Preamble]
.License
Enter an open source software license. Do not use the old Copyright tag. Use a standard abbreviation, for example, "`GPLv2+`" and be specific. For example, use "`GPLv2+`" for GPL version 2 or greater rather than "`GPL`" or "`GPLv2`" where it's true). For more information, see the http://fedoraproject.org/wiki/Packaging:LicensingGuidelines[Licensing Guidelines].
`License`::
Enter an open source software license. Do not use the old Copyright tag. Use a standard abbreviation, for example, `GPLv2+` and be specific. For example, use `GPLv2+` for GPL version 2 or greater rather than `GPL` or `GPLv2` where it's true). For more information, see the http://fedoraproject.org/wiki/Packaging:LicensingGuidelines[Licensing Guidelines].
+
You can list multiple licenses by combining them with `and` and `or` (e.g. `GPLv2 and BSD`).
You can list multiple licenses by combining them with "`and`" and "`or`" (e.g. "`GPLv2 and BSD`".
`URL`::
The full URL for more information about the program. For example, the project website.
+
NOTE: Do not add a link to the original source code. Add the link to the source code to the `Source0` tag.
.URL
The full URL for more information about the program. For example, the project website.
`Source0`::
Enter the full URL for the compressed archive that contains the original, pristine source code, as upstream released it. "`Source`" is synonymous with "`Source0`".
+
The full URL basename is used when looking in the `SOURCES` directory. If possible, embed `%{name}` and `%{version}`, so that changes to the go to the right place. Preserve the timestamps when downloading source files. For more information, see http://fedoraproject.org/wiki/Packaging:Guidelines#Timestamps[Preserve timestamps].
+
If there is more than one source, name them `Source1`, `Source2`.
+
If you add whole new files in addition to the pristine sources, list them as sources after the pristine sources. A copy of each of these sources is included in any source RPM (SRPM) you create, unless you specifically direct otherwise. For more information on special cases, for example, revision control, see https://fedoraproject.org/wiki/Packaging:SourceURL?rd=Packaging/SourceURL[Source URL].
[NOTE]
Do not add a link to the original source code. Add the link to the source code to the `Source0` tag.
.Source0
Enter the full URL for the compressed archive that contains the original, pristine source code, as upstream released it. "`Source`" is synonymous with "`Source0`".
The full URL basename is used when looking in the `SOURCES` directory. If possible, embed `%{name}` and `%{version}`, so that changes to the go to the right place. Preserve the timestamps when downloading source files. For more information, see http://fedoraproject.org/wiki/Packaging:Guidelines#Timestamps[Preserve timestamps].
If there is more than one source, name them `Source1`, `Source2`.
If you add whole new files in addition to the pristine sources, list them as sources after the pristine sources. A copy of each of these sources is included in any source RPM (SRPM) you create, unless you specifically direct otherwise. For more information on special cases, for example, revision control, see https://fedoraproject.org/wiki/Packaging:SourceURL?rd=Packaging/SourceURL[Source URL].
.Patch0
`Patch0`::
Enter the name of the first patch to apply to the source code. If you must patch the files after you extract them, edit the files and save their differences as a `.patch` file in your `~/rpmbuild/SOURCES` directory. Patches must make only one logical change each, so it's quite possible to have multiple patch files.
.BuildArch
`BuildArch`::
If you package files that are architecture-independent, for example shell scripts, data files, then add `BuildArch: noarch`. The architecture for the binary RPM is then `noarch`.
.BuildRoot
This is now redundant in Fedora and is only needed for EPEL5. By default, the build root is placed in "`%{_topdir}/BUILDROOT/`".
`BuildRoot`::
This is now redundant in Fedora and is only needed for EPEL5. By default, the build root is placed in `%{_topdir}/BUILDROOT/`.
+
In EPEL5, this is where files are installed during the %install process (after the %build process).
.BuildRequires
`BuildRequires`::
Add a comma-separated list of packages that are required for compiling the program. Usually, this field is repeated on multiple lines. These dependencies are not automatically determined. You must include everything that the package needs to build the program.
Verify that you have specified all the necessary build requirementss by link:Using_Mock_to_test_package_builds[performing a "mock
build"] of your package. You can specify a minimum version if necessary, for example, `ocaml >= 3.08`.
+
Verify that you have specified all the necessary build requirements by performing a "mock build" of your package. You can specify a minimum version if necessary, for example, `ocaml >= 3.08`.
+
If you need the file `/EGGS`, determine the package that owns it by running `rpm -qf /EGGS`.
+
If you need the program `EGGS`, determine the package that owns it by running `rpm -qf \`which EGGS\``. Keep dependencies to a minimum. For example, use `sed` instead of `perl` if you do not need Perl, but note that some applications permanently disable functions if the associated dependency is not present; in those cases you might need to include the additional packages.
If you need the program `EGGS`, determine the package that owns it by running "`rpm -qf \`which EGGS\``". Keep dependencies to a minimum. For example, use `sed` instead of `perl` if you do not need perl, but note that some applications permanently disable functions if the associated dependency is not present; in those cases you might need to include the additional packages.
.Requires
`Requires`::
Enter a comma-separate list of packages that are required when the program is installed. Note that the `BuildRequires` tag lists what is required to build the binary RPM, while the `Requires` tag lists what is required when installing and running the program; a package may be in one list or in both.
.%description
`%description`::
Enter a longer, multi-line description of the program. Use American English. All lines must be 80 characters or less. Blank lines indicate a new paragraph.
+
Some graphical user interface installation programs reformat paragraphs; lines that start with whitespace might be treated as preformatted text and displayed as is, normally with a fixed-width font.
Some graphical user interface installation programs reformat paragraphs; lines that start with whitespace might be treated as preformatted text and displayed as is, normally with a fixed-width font. See
https://docs-old.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch09s03.html[RPM
Guide].
`%prep`::
Add script commands to "prepare" the program. For example, to extract the program, so that it is ready for building. Typically this is just `%autosetup`; a common variation is `%autosetup -n NAME` if the source file unpacks into `NAME`.
.%prep
Add script commands to "prepare" the program. For example, to extract the program, so that it is ready for building. Typically this is just "`%autosetup`"; a common variation is "`%autosetup -n NAME`" if the
source file unpacks into `NAME`.
`%build`::
Add script commands to compile the program and get it ready for installing. The program must come with instructions on how to do this.
.%build
Add script commands to compile the program and get it ready for installing. The program must come with instructions on how to do this.
.%install
`%install`::
Add script commands to "install" the program. The commands must copy the files from the `BUILD` directory `%{_builddir}` into the buildroot directory, `%{buildroot}`.
.%check
`%check`::
Add script commands to "test" the program. This is run after the `%install` procedure, so place it there if you have this section. Often it contains `make test` or `make check`. This is separated from `%build` so that people can skip the self-test if they desire.
.%clean
Note that this section is now redundant in Fedora and is only necessary for EPEL.
Typically this contains only the following command:
`%clean`::
Note that this section is now redundant in Fedora and is only necessary for EPEL. Typically this contains only the following command: `rm -rf %{buildroot}`.
`rm -rf %{buildroot}`
.%files
`%files`::
Add the list of files to be installed.
.%changelog
Add changes in the package. Use the format example above.
Do not put software's change log here. This change log is only for the RPM.
.ExcludeArch
If the package does not successfully compile, build or work on a particular architecture, list those architectures under this
tag.
`%changelog`::
Add changes in the package. Use the format example above. Do not put software's change log here. This change log is only for the RPM.
`ExcludeArch`::
If the package does not successfully compile, build or work on a particular architecture, list those architectures under this tag.
RPM also supports the creation of several packages called subpackages from a single `.spec` file, such as `name-libs` and `name-devel` packages.
@ -114,10 +99,8 @@ Do *not* create a "relocatable" package; they do not add value in Fedora and mak
.Inserting comments
Insert comments with a leading "`#`" character, and beware of macros (beginning with `%`) that are potentially multi-line, as they are expanded first.
When commenting out a line, double the percent signs (`%%`) of the macros appearing after the "`#`".
Also avoid inline comments on the same line as script commands.
* Insert comments with a leading `#` character, and beware of macros (beginning with `%`) that are potentially multi-line, as they are expanded first.
* When commenting out a line, double the percent signs (`%%`) of the macros appearing after the `#`.
* Avoid inline comments on the same line as script commands.

View file

@ -1,5 +1,5 @@
[[creating_rpm_package]]
== Creating an RPM package
= Creating an RPM package
.Overview
@ -11,7 +11,7 @@ To create an RPM package, you must complete the following steps:
. To create a directory, add a package, and within the package, create a simple program, enter the following commands:
+
-----------
----
mkdir -p ~/packaging-work/howdy
cd ~/packaging-work/howdy
cat << EOF > howdy
@ -19,24 +19,21 @@ cat << EOF > howdy
echo "Howdy, partner!"
EOF
chmod 644 howdy
-----------
----
+
[NOTE]
The directory `packaging-work`, the package `howdy`, and program `howdy` names are for example purposes. Edit these names to suit your project.
You can use any location you want but the directory name for the package should match the name of the package.
NOTE: The directory `packaging-work`, the package `howdy`, and program `howdy` names are for example purposes. Edit these names to suit your project. You can use any location you want but the directory name for the package should match the name of the package.
+
. To verify that everything built correctly, enter the following command:
+
-------
----
$ bash ./howdy
-------
----
+
. Create a new file `howdy.spec` and open `howdy.spec` in your text editor. Populate the `howdy.spec` file using the following example as a guide but change anything you require:
+
[NOTE]
When you create the file, use spaces and do not use tabs to align the text.
NOTE: Then you create the file, use spaces and do not use tabs to align the text.
+
---------
----
....
Name: howdy
Version: 1
@ -55,51 +52,48 @@ A simple program to greet the user, Texas style.
%changelog
....
---------
----
+
. To instruct the package how to install the program, add thie following information to the `%install` section of the `.spec` file. Add the information to the line that follows `%install`:
+
--------
----
mkdir -p %{buildroot}/%{_bindir}
install -p -m 755 %{SOURCE0} %{buildroot}/%{_bindir}
--------
----
+
[NOTE]
In this example, we use the following three macros: `%{buildroot}`, `%{_bindir}`, and `%{SOURCE0}`. This method ignores the origin of the files and directories and focuses on the destination of the files. Without `%{buildroot}` the files might install directly onto your development machine. This is not recommended, especially if you run as root. For more information on macros and `.spec` file entries, see xref:con_rpm_spec_file_overview[].
NOTE: In this example, we use the following three macros: `%{buildroot}`, `%{_bindir}`, and `%{SOURCE0}`. This method ignores the origin of the files and directories and focuses on the destination of the files. Without `%{buildroot}` the files might install directly onto your development machine. This is not recommended, especially if you run as root. For more information on macros and `.spec` file entries, see xref:con_rpm_spec_file_overview[].
+
. To tell RPM about the file, enter the following information to the `%files` section:
+
-------
----
%{_bindir}/howdy
-------
----
+
[NOTE]
In general, the `%files` section is about files you have installed into the buildroot. You do not use the `%{buildroot}` macro when listing
files there.
NOTE: In general, the `%files` section is about files you have installed into the buildroot. You do not use the `%{buildroot}` macro when listing files there.
+
. Save your edits and to run a local build, enter the following command:
+
-----
----
$ fedpkg --release f27 local
-----
----
This updates the two RPMs.
.Adding no architecture dependencies
In this example, the package is a shell script and there is no requirement for the package to build separately on every architecture that Fedora supports.
In this example, the package is a shell script, and there is no requirement for the package to build separately on every architecture that Fedora supports.
. To specify that this package independent of architectures, open the file in your text editor and add the following information after the `Source0:` line:
. To specify that this package is independent of architectures, open the file in your text editor and add the following information after the `Source0:` line:
+
---------
----
BuildArch: noarch
---------
----
+
. Delete the existing `.rpm` files in this directory and run another local build:
+
-----
----
$ fedpkg --release f27 local
-----
----
.Result
@ -120,20 +114,18 @@ At this stage, there are four or more errors because of the lack of `%prep`, `%b
To view the list of dependencies, enter the following command:
-----
rpm -qp --requires howdy-1-1.fc``.noarch.rpm
-----
----
rpm -qp --requires howdy-1-1.fc27.noarch.rpm
----
RPM adds some internal `rpmlib` dependencies, and one in `/bin/bash` which matches up with the first line of the howdy program.
To view a list of what the RPM provides, enter the following commnad:
-----
rpm -qp --provides howdy-1-1.fc``.noarch.rpm
-----
----
rpm -qp --provides howdy-1-1.fc27.noarch.rpm
----
This command is more important when your RPM package gains complexity and has dependencies.
For more information about building a more complete and complex RPM package, see https://fedoraproject.org/wiki/How_to_create_a_GNU_Hello_RPM_package[How to create a GNU Hello RPM package].

View file

@ -1,43 +1,38 @@
[[preparing-your-system]]
== Preparing your system to create RPM packages
[[preparing-your-system-to-create-rpm-packages]]
= Preparing your system to create RPM packages
Before you create RPM packages on Fedora, you must install packaging tools and set up any accounts that you want to use.
For general information about preparing your environment, understanding source code, building and patching software, see the https://rpm-packaging-guide.github.io/#preparing-software-for-packaging[Preparing Software for Packaging] section in the RPM packaging guide.
For general information about preparing your environment, understanding source code, building and patching software, see the https://rpm-packaging-guide.github.io/#preparing-software-for-packaging[Preparing Software for Packaging] section in the RPM packaging guide.
This installs the utilities that you require to work with and build packages in the same manner as official Fedora packages, including the tool that the package reviewers use to check package quality.
To prepare your build environment to create RPM packages, complete the following steps:
To prepare your build environment to create RPM packages, complete the following steps:
[NOTE]
You must run the following two commands as the root user.
NOTE: You must run the following two commands as the root user.
. To install the `fedora-packager` and `fedora-review` tools, enter the following command:
. Install the _fedora-packager_ and _fedora-review_ tools:
+
------------
# dnf install fedora-packager fedora-review`
------------
+
. To add yourself to the mock group, run the following command:
. Add yourself to the *mock* group:
+
-----------
# usermod -a -G mock yourusername
-----------
+
. Change from the root user to your user name and enter the `newgrp` command or log in and out for this change to take effect:
. Change from the *root* user to your user name and enter the `newgrp` command or log in and out for this change to take effect:
+
-------------
$ newgrp
-------------
+
. Run the `id` command to verify that the "mock" group appears in your group list, enter the following command:
. Run the `id` command to verify that the *mock* group appears in your group list:
+
----------------
$ id
----------------
+
[NOTE]
You can also create a separate user and use it for doing RPM development. Ensure that the user is part of the "mock"
group and enters the `fedora-packager-setup` command.
NOTE: You can also create a separate user and use it for doing RPM development. Ensure that the user is part of the *mock* group and enters the `fedora-packager-setup` command.