Building RPMs using mock
Generating the source RPM
Using rpmbuild to build the src.rpm
The source RPM must be generated on an EL5 machine, because EL5 and older systems have a version of RPM that doesn't understand the new SHA1 checksum.
Get the sources from the official software distribution:
wget http://software.nikhef.nl/security/component/component-version.tar.gz
Get the SPEC file:
wget http://ndpfsvn.nikhef.nl/ro/mwsec/packaging/fedora/trunk/component.spec
Build the source RPM:
rpmbuild --define "_tmppath /tmp" --define "_sourcedir ." --define "_srcrpmdir ." --nodeps -bs component.spec
This will leave the source RPM in the current directory. This needs to be transferred to the mock build machine.
Using mock to build the src.rpm
Alternatively one can use mock (see also Generating the binary and source RPMs):
mock -r epel-5-x86_64 --spec=component.spec --sources=. --resultdir=mock/result --buildsrpm
This will leave the source RPM in mock/result.
Generating the binary (and source) RPMs
Using mock to build both RPMs
Copy the source RPM to a relatively new mock build machine, e.g. CentOS 6, Fedora Core 14 or higher or Ubuntu :-).
The configuration to be used should be tuned to include the stable mwsec repository at http://software.nikhef.nl/dist/redhat/el5/mwsec/, see mwsec mock setup for details.
Now run mock:
mock --clean -D 'dist .el5' -r mwsec-el5-x86_64 --configdir=mock/config --resultdir=mock/result/64 --rebuild component.src.rpm mock --clean -D 'dist .el5' -r mwsec-el5-i386 --configdir=mock/config --resultdir=mock/result/32 --rebuild component.src.rpm
This creates source and binary RPMS in mock/result/{32,64} using the configuration setup from mock/config/ NOTE: the explicit setting of the %dist macro is needed to prevent it from becoming the new Centos standard .el5.centos.
On fc14.testbed these configs are installed in the standard directory, and the --configdir option should be left out. In addition, on this machine, two configs which also enable the mwsec testing repo have been installed: mwsec_testing-el5-x86_64 and mwsec_testing-el5-i386. These should only be used for either testing purposes or in rare circumstances when multiple packages need updating at the same time.
Using rpmbuild to build the binary RPMs
The above procedure produces 'official' RPMS, in a reproducible way from a clean build environment. However, it is possible to generate RPM packages manually with a simple recipe.
This procedure should work on a machine that matches the build target, i.e. CentOS 5 x86_64 or i386.
- Create a file called
.rpmmacros
with the following content:
%_topdir /home/username/rpmbuild %_tmppath /home/username/rpmbuild/tmp
- Create a directory
rpmbuild
in your home directory, with the following subdirectories:
BUILD -> /tmp/username/rpmbuild/BUILD RPMS SOURCES SPECS SRPMS tmp -> /tmp/username/rpmbuild/tmp
- create the tempdirs if necessary
mkdir -p /tmp/`id -un`/rpmbuild/{tmp,BUILD}
- Check out the SPEC directory
- test the build dependencies by running
rpmbuild specfile
- Install build dependencies as necessary
- Run
rpmbuild -ba specfile
to generate binary and source RPMs.