Home Wiki > openSUSE:Build system recipes
Sign up | Login

openSUSE:Build system recipes

tagline: From openSUSE

Whatever is about packaging should go to this category.


This page provides a cheat sheet of sorts for what code you need in .spec files to get a common software package with a particular build system built in a standardized fashion.

Build system in this context refers to the tools creating Makefiles and/or calling the compilers, not the Open Build Service system.

N.B.: Here is also some background statistics on build system preference for software in openSUSE.


RPM ships a number of convenience macros directly. The base recipe is:


The %configure macro will set CFLAGS, CXXFLAGS, FFLAGS to %optflags if they have not been previously set. To add in your own flags, put on a line before %configure:

export CPPFLAGS="-Dpreprocessor_options -Ihere"
export CFLAGS="%optflags -fwhatever"
export CXXFLAGS="%optflags -fwhateverplusplus"

(There is generally no need to switch to `./configure`!)

%make_build is a macro that is available starting rpm-4.12. It is equivalent to `make %{?_smp_mflags}`, and you should use the expansion directly if you are dealing with versions of rpm older than 4.12 (which is the case for almost everything right now).

%make_install is a macro available starting rpm-4.10. It is equivalent to `make install DESTDIR="%{?buildroot}"`, and, similarly, use the expansion directly if you are dealing with rpm older than 4.10 (which is the case for SLE_11).

Avoid using %makeinstall (note: no underscore). That macro increases chances that badly-written software fails at installation. (For details, see [1].)

You can also use a separate build directory, for fun and profit (and finding software that fails to cope with it) [also not available on SLE11]:

%define _configure ../configure
mkdir obj
pushd obj/

make -C obj install DESTDIR="%buildroot"


Using autoconf without automake in upstream software often has a lot of unexpected nasty surprises when hand-crafted Makefiles are used — most common errors are that variable assignment is not respected (e.g. setting CFLAGS killing important flags that render the product not compilable), and failure to pass flags to commands (e.g. not passing CPPFLAGS when invoking the CC command).

This may not apply, or only apply somewhat, or not apply, when Makefiles are autogenerated by another software (e.g. `scons autotools`). In any case, autoconf without automake is highly susceptible to bugs, hence no single recipe can cover significant ground. If the Makefiles reasonably behave like automake, see the automake section above.


Starting with openSUSE-13.1[2], the distribution provides a %cmake macro, sourced from /etc/rpm/macros.cmake (BuildRequires: cmake) that should set up the basic values for your need so the basic part should look like this:

%cmake \



You can also override few variables to get behaviour you want from cmake:

# build in someotherfolder rather than in build directory
%define __builddir someotherfolder
# use ninja instead of make
%define __builder ninja

If you are trying to package for openSUSE < 13.1, you can choose to either create a package link (osc linkpac), or write the cmake line by hand:

mkdir build
cd build
cmake .. \
        -DCMAKE_INSTALL_PREFIX="%_prefix" \
        -DCMAKE_INSTALL_LIBEXEC="%_libexecdir" \
        -DCMAKE_C_FLAGS:STRING="%optflags" \

Unfortunately, CMakeLists.txt files allow for many freedoms, so much that some software may just ignore some parameters. If that happens, perhaps some of the following extra flags may also need to be specified:

-DCMAKE_LD_FLAGS(:STRING)="-Wl,-z -Wl,defs"

There is also a cmake bug: Not specifying the :TYPE portion can lead to the portion after the '=' being ignored at times.

python (setup.py)

See also: openSUSE:Packaging Python

python setup.py build

python setup.py install --root="%buildroot" --prefix="%_prefix"


There used to be a --record-rpm switch, but this was specific to openSUSE and its use is discouraged in favor of just listing the files from %python_sitearch of %python_sitelib in the %files section directly.


The no-frills boilerplate:

qmake QMAKE_CFLAGS+="%optflags" QMAKE_CXXFLAGS+="%optflags" QMAKE_STRIP="/bin/true";
%make_build / make %{?_smp_mflags} as with automake (see above)

make install INSTALL_ROOT="%buildroot";

For everything else

See for when there is a macro or other dedicated instructions (Perl, Python, ...)