Skip to content

Create an rpm package

Parley Martins edited this page Dec 15, 2017 · 3 revisions

This article gives some basic instructions on how to create an rpm package.

To start building the package one should use rpmdev-setuptree. This command creates a folder structure in the user's home folder (~) that will store the contents of the package as well as the final binaries.

The directory SPECS contains the .spec files that will tell rpm how to handle the package. They carry all the information about what is inside and where it should be installed, for example. These files have the following structure (you can check the full file here):

Name: %%PACKAGE_NAME%%
Version: %%VERSION_MAJOR%%.%%VERSION_MINOR%%
Release: %%VERSION_RELEASE%%%{?dist}
Summary: %%GAME_DESCRIPTION%%

Group: Amusements/Games
License: GPLv3
URL: https://github.com/fgagamedev/multiplatform-sdl2-project-template
Source0: %{name}.tar.gz

BuildRoot: %{_tmppath}/%{name}-root
AutoReq: no
  1. The first part of the file gives some information about the package, its license and maintainer.
%prep
%setup -q
  1. The prep section calls the setup macro. This section is responsible for preparing the package and gather everything needed to build. If the developer wants to change it, there are more details on this here, here, or here, for example.
%build
./scripts/build.sh release
  1. The build section executes steps to build the package. It also may call a script to achieve that task.
%install
mkdir -p %{buildroot}/var/games/%%PACKAGE_NAME%%/lib
cp src/%%PACKAGE_NAME%%_release %{buildroot}/var/games/%%PACKAGE_NAME%%/%%PACKAGE_NAME%%
...
  1. Install section does everything needed to copy the package files to their expected location. It's also responsible for creating the new required directories.
%post
/sbin/ldconfig
ln -s /usr/games/%%PACKAGE_NAME%% /usr/bin/

%postun
/sbin/ldconfig
rm /usr/bin/%%PACKAGE_NAME%%
  1. These sections are responsible for processing things after they are installed or uninstalled.
%files
%defattr(644,root,root)
%attr(755,root,root) /usr/games/%%PACKAGE_NAME%%
%attr(755,root,root) /var/games/%%PACKAGE_NAME%%/%%PACKAGE_NAME%%
%attr(755,root,root) /var/games/%%PACKAGE_NAME%%
%attr(755,root,root) /var/games/%%PACKAGE_NAME%%/resources
%attr(755,root,root) /var/games/%%PACKAGE_NAME%%/lib
%doc %{_mandir}/man6/%%PACKAGE_NAME%%.6.gz

%changelog
* Fri Jul 21 2017 Edson Alves <edsomjr@gmail.com>  - 0.0-1%{?dist}
- Fixing several rpmlintian errors and warnings
  1. The last sections set permissions on the files and give the modifications added to the package.

After the spec file is created, the contents of the package should be compressed and stored in the SOURCES directory (inside the structure created by the first command).

rpmbuild should be called from the SPECS folder. It will create the binaries and store them in the RPMS folder.

Fedora and IBM provide more complete and in-depth files on how to create packages and their documentation should be checked.

Clone this wiki locally