openSUSE:Build system recipes

Jump to: navigation, search

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}`.

%make_install is a macro available starting rpm-4.10. It is equivalent to `make install DESTDIR="%{?buildroot}"`.

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_install -C obj

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"
%cmake_build

%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
...

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

Legacy Setuptools style:

BuildRequires: fdupes
BuildRequires: python-rpm-macros
BuildRequires: %{python_module setuptools}
%python_subpackages

%build
%python_build

%install
%python_install
%python_expand %fdupes %{buildroot}%{python_sitelib}
%check
%pyunittest -v

%files %python_files
%{python_sitelib}/name
%{python_sitelib}/name-%{version}*-info
/other/files/not/conflicting-for-all-supported-flavors-e.g.-distinguished-by-%{python_bin-suffix}

PEP517 style:

BuildRequires: fdupes
BuildRequires: python-rpm-macros
BuildRequires: %{python_module pip}
BuildRequires: %{python_module wheel}
%python_subpackages

%build
%pyproject_wheel

%install
%pyproject_install
%python_expand %fdupes %{buildroot}%{python_sitelib}
%check
%pyunittest -v

%files %python_files
%{python_sitelib}/name
%{python_sitelib}/name-%{version}*-info
/other/files/not/conflicting-for-all-supported-flavors-e.g.-distinguished-by-%{python_bin-suffix}

qmake

The no-frills boilerplate:

%build
qmake-qt5 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"

qmake can be found in the package libqt5-qtbase-devel.

For everything else

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