On RHEL
sudo yum install rpmdevtools rpmbuild rpmlint mock
On Fedora
sudo dnf install rpmdevtools rpmbuild rpmlint mock
Or alternatively/additionally you can just install fedora-packager (on RHEL it requires EPEL repositories)
The first thing to do is create the directory structure needed in your home directory.
rpmdev-setuptree
The next thing is to get your user account added to the local mock group.
sudo usermod -a -G mock $USER
Or more likely, email this request to linux@support.sns.gov! :-(
Now initialise the mock environment for the desired config (You only need to do this once for each environment)
mock -r epel-7-x86_64 --init
mock -r fedora-24-x86_64
The first place to look is the Fedora repository. If it has been built for Fedora, there's a good chance it 'might' work on RHEL. For ease of building, the best place to look is the repositories for the Fedora version that the version of RHEL you are using is based off. For RHEL 7 that is Fedora 19 & 20 and if you are still unlucky enough to be dealing with RHEL6, that was based off Fedora 12 & 13.
For example the links for Fedora 20 are:
- Release versions: http://archive.fedoraproject.org/pub/archive/fedora/linux/releases/20/Everything/source/SRPMS/
- Updates: http://archive.fedoraproject.org/pub/archive/fedora/linux/updates/20/SRPMS/
If you need a newer version it is worth checking the latest development tree (Rawhide):
https://dl.fedoraproject.org/pub/fedora/linux/development/rawhide/Everything/source/tree/Packages/
If you find the *.src.rpm that you need then a good first check to see if it works is to try just rebuilding the package on the current system
rpmbuild --rebuild the-fedora-package.src.rpm
If this works - rejoice and then do a proper clean build either using mock or COPR.
If not, then you need to start looking through the output log to find the error. If there is something you need to edit in the .spec file then you can install the SRPM into your home directory (NOTE: the lack of sudo on this command)
rpm -ivh the-fedora-package.src.rpm
then edit away!
vim ~/rpmbuild/SPECS/the-fedora-package.spec
First thing is to be in the correct directory
cd ~/rpmbuild/SPEC
There is a utitlity contained in the rpmdevtools package that will create a blank .spec file based on a template. It will try and guess what template to use based on your package, but it's probably best to tell it. You can see a list of the available templates by ls /etc/rpmdevtools/spectemplate*.spec
rpmdev-newspec periodictable.spec -t python
One caveat is that this tool does not always produce a file that is easy to understand or contain all the things you need.
Using Autotools (i.e. ./configure,make,make install)
https://github.com/stuartcampbell/rpm-packages/blob/master/rofi/rofi.spec
Using CMake:
https://github.com/stuartcampbell/rpm-packages/blob/master/nexus/nexus.spec
Using Python setuptools
https://github.com/stuartcampbell/rpm-packages/blob/master/sphinx-theme-bootstrap/sphinx-theme-bootstrap.spec
The basic command for building a SPEC locally is
rpmbuild -ba sphinx-theme-bootstrap.spec
The first thing you will run into is that you don't actually have the source files locally!
spectool -g -R sphinx-theme-bootstrap.spec
This will download the required files into your ~/rpmbuild/SOURCES/ directory. If you already have the sources locally then you can just copy them into this directory.
First let's make the SRPM package to compile
rpmbuild -bs mypackage.spec
Let's try building in a clean environment
mock -r epel-7-x86_64 ~/rpmbuild/SRPMS/mypackage-0.1.src.rpm
If something is missing from the environment...
mock -r epel-7-x86_64 --no-clean --install python-setuptools
Rebuild again (not the --no-clean)
mock -r epel-7-x86_64 --no-clean ~/rpmbuild/SRPMS/mypackage-0.1.src.rpm
Enjoy the results of your work!
ls /var/lib/mock/epel-7-x86_64/result
rpmlint mypackage.src.rpm
COPR is basically a web frontend to mock and allows you to build on multiple configurations and will host the resulting repository for you.
Mantid COPR:
https://copr.fedorainfracloud.org/coprs/mantid/mantid/
Some of Stuart's repos:
https://copr.fedorainfracloud.org/coprs/sic/backports/
https://copr.fedorainfracloud.org/coprs/sic/science/
List the dependencies of a package (in the example mantid)
sudo yum deplist mantid
What files does a package contain ?
rpm -qlp mypackage.rpm
https://fedoraproject.org/wiki/Packaging:RPMMacros
https://fedoraproject.org/wiki/Packaging:Guidelines
https://fedoraproject.org/wiki/How_to_create_an_RPM_package