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.

Abstract

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.

automake

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

%build
%configure
%make_build
%install
%make_install

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]:

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

%install
make -C obj install DESTDIR="%buildroot"

autoconf

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.

cmake

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:

%build
%cmake \
        -DSOME_SPECIAL_VARIABLE="SOME_VALUE"
%make_jobs

%install
%cmake_install

%check
%ctest

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

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

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:

%build
mkdir build
cd build
cmake .. \
        -DCMAKE_INSTALL_PREFIX="%_prefix" \
        -DCMAKE_INSTALL_LIBEXEC="%_libexecdir" \
        -DCMAKE_C_FLAGS:STRING="%optflags" \
        -DCMAKE_CXX_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_BUILD_WITH_INSTALL_RPATH(:BOOL)="yes|no"
-DCMAKE_BUILD_TYPE="Release|RelWithDebugInfo"
-DCMAKE_CONF_PATH(:PATH)="%_sysconfdir"
-DCMAKE_C_FLAGS:STRING="%optflags"
-DCMAKE_C_FLAGS_RELEASE:STRING="%optflags"
-DCMAKE_CXX_FLAGS:STRING="%optflags"
-DCMAKE_CXX_FLAGS_RELEASE:STRING="%optflags"
-DCMAKE_DATA_PATH(:PATH)="%_datadir"
-DCMAKE_DOC_PATH(:PATH)="%_docdir"
-DCMAKE_FIND_ROOT_PATH="/%{?_sysroot}"
-DCMAKE_INSTALL_DO_STRIP=0
-DCMAKE_INSTALL_LIBDIR="%_lib"
-DCMAKE_INSTALL_LIBEXECDIR(:PATH)="%_prefix"
-DCMAKE_INSTALL_PREFIX(:PATH)="%_prefix"
-DCMAKE_LD_FLAGS(:STRING)="-Wl,-z -Wl,defs"
-DCMAKE_LOCALE_PATH(:PATH)="%_datadir/locale"
-DCMAKE_SKIP_RPATH(:BOOL)=YES
-DCMAKE_STRIP(:FILEPATH)="/bin/true"
-DCMAKE_VERBOSE_MAKEFILE(:BOOL)="true"
-DNO_STRIP=1

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

%build
python setup.py build

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

%files
%defattr(-,root,root)
%python_sitearch/name*
%python_sitelib/name*
/other/files

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.

qmake

The no-frills boilerplate:

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

%install
make install INSTALL_ROOT="%buildroot";

For everything else

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