2010-03-26

RPM atomated building

If your are providing sources or binaries of your software as RPMs you should be aware of a smart way of automating RPM creation.
To create RPM building environment:

  1. create ~/.rpmmacros with the following content:

    %_topdir .../rpm #Arbitrary
    %_tmppath /tmp/rpm #Optional

    Three dots here denote your favorite RPM building directory infrastructure root. (/home/username will do)
  2. use the following script:

    #!/bin/sh
    for d in _topdir _sourcedir _rpmdir _srcrpmdir _specdir _builddir _tmppath; do
    mkdir -p `rpm --eval %{$d}`
    done


In your RPM generation script use constructions like

# Doesn't override previously set value. See Parameter Expansion
SOURCES=${SOURCES:-`rpm --eval %{_sourcedir}`}
#Assumes your sources are in $PROJECTS/$PROJECT directory
tar --wildcards --exclude \*\.svn\* --exclude \*\~ \ -C "$PROJECTS" -zcf "$SOURCES/$PROJECT.tar.gz" $PROJECT
rpmbuild -ba "$PROJECTS/$PROJECT/$PROJECT.spec"


Following this recommendation you will never need to force your packagers to use a harcoded SOURCES folder or to do configuration of your package with their RPM settings.

Again, thanks to comrade Buzykaev, for his tar command idea