How to create binary only RPM packages
The RPM Packet Manager is a frequently used tool for software configuration management on UNIX based systems, especially Linux based systems. In contrast to Windows based installers and also to the DEBIAN packaging system, the RPM Packet Manager is intended to be used to create source- and binary distributions of packages being available as source code. Typical application includes
- get a software system as source code
- apply changes as patches for a particular environment
- compile everything together
- create a binary and source code distribution from it to supply it to the particular community
If you want to create a binary distribution of some executables an configuration files only, the standard RPM way requires some effort.
In this article we describe how to create a binary-only dstribution with little effort.
Getting started - create and install binaries
On UNIX we are using "make" to compile and install our software. To build RPM distributions we retain this practive. Therefore our makefiles for UNIX include a install section, e.g.:
install -m 755 $(SYSNAME)/$(CFG)/$(BINARY) /opt/target/bin/$(BINARY)
install -m 755 $(SHARED_LIB) /opt/target/bin/$(SHARED_LIB)
install -m 644 $(CONFIG_FILE) /opt/target/etc/$(CONFIG_FILE)
After you are ready with compilation you should install the software ("make install"). "rpmbuild" will create the binary package from these files.
Next step - create the envrionment
There is one important rule the reader should take in mind always - never run "rpmbuild" as root. This might end up in an empty root directory sooner as the reader might expect. Therefore the first configuration step to use "rpmbuild" should always be to create a suitable environment in normal user space. We are using the "sandbox" folder in our "Projects" tree for this prupose:
mkdir -p Projects/sandbox
cd Projects/sandbox
mkdir SPECS
mkdir SOURCES
mkdir BUILD
mkdir RPMS
mkdir SRPMS
Afterwards we create the file ".rpmmacros" in our home directory:
vi .rpmmacros
After the editor launced, please enter the following text according to local environment constraints:
%_builddir %{_topdir}/BUILD
%_rpmdir %{_topdir}/RPMS
%_sourcedir %{_topdir}/SOURCES
%_specdir %{_topdir}/SPECS
%_srcrpmdir %{_topdir}/SRPMS
Basically you are through. What stil is missing, is ".spec" file.
Pre-final - the spec file
"rpmbuild" needs a ".spec" file to build a ".rpm" file. Create such a spec file in your project directory (where the makefile is residing). A minimal example is given below:
Name: name-of-the-package
Version: 1.2.3.4
Release: 1
Copyright: Copyright info
Group: Applications/System
%description
Brief description of software package.
%prep
%build
%install
%clean
%files
%defattr(-,root,root)
%doc
/opt/target/bin/programfile
/opt/target/bin/libshared.so
/opt/target/etc/config.cfg
%changelog
Please adapt the contents of thís file to your particular needs, especially the filenames section (starting with "/opt/target").
Final - get the binary RPM
After the ".spec" file was created (let's assume it was named "specfile.spec") "rpmbuild" can be used to create binary distribution:
Afterwards you should find the binary RPM package in the particular architecture folder in "%_rpmdir"
