mirror of
https://pagure.io/fedora-docs/quick-docs.git
synced 2024-12-01 07:39:48 +00:00
131 lines
4.3 KiB
Text
131 lines
4.3 KiB
Text
[[creating_rpm_package]]
|
||
= Creating an RPM package
|
||
|
||
.Overview
|
||
|
||
To create an RPM package, you must complete the following steps:
|
||
|
||
. Create a directory to store the package. Within the package directory, create a `.spec` file.
|
||
. In the `.spec` file, add information about your software, instructions for unpacking it, building it, and installing it, as well as a list of files that are in the package.
|
||
. Run the `fedpkg` command with the appropriate options to build your package.
|
||
|
||
. 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
|
||
#!/bin/bash
|
||
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.
|
||
+
|
||
. 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: Then you create the file, use spaces and do not use tabs to align the text.
|
||
+
|
||
----
|
||
....
|
||
Name: howdy
|
||
Version: 1
|
||
Release: 1%{?dist}
|
||
Summary: Say hello, Texas style
|
||
|
||
License: Public Domain
|
||
Source0: howdy
|
||
|
||
%description
|
||
A simple program to greet the user, Texas style.
|
||
|
||
%install
|
||
|
||
%files
|
||
|
||
%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[].
|
||
+
|
||
. 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.
|
||
+
|
||
. 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.
|
||
|
||
. 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
|
||
|
||
After you complete the procedure, ensure that you have the following two files:
|
||
|
||
. One source file that contains the latest source.
|
||
. One binary file with the `.noarch.rpm`.
|
||
|
||
.What to do next
|
||
|
||
Validate your RPM package with RPM lint, using the following command:
|
||
|
||
----
|
||
fedpkg --release f27 lint
|
||
----
|
||
|
||
At this stage, there are four or more errors because of the lack of `%prep`, `%build` sections, and `URL` tag.
|
||
|
||
To view the list of dependencies, enter the following command:
|
||
|
||
----
|
||
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.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].
|