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.

Contents

Abstract

This page provides a cheat sheet of sorts for what code you need in .spec files to get a common software package built when there is no convenience macro for the — sometimes needlessy divergent — syntaxes of different build systems that software happens to use.

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

automake

For automake, there already exists a macro provided by rpm, %configure. The %configure macro will set CFLAGS, CXXFLAGS, FFLAGS to %optflags if they have not already been defined. This is also why it is generally pointless to call `./configure`, since %configure will not override your own flags.

%build
%configure
make %{?_smp_mflags};

%install
make install DESTDIR="%buildroot";

%make_install exists as a hardly shorter shortcut, but this is not available in older versions of the RPM package manager (such as the one in SLES_11). %makeinstall (without underscore) exists as an alternative, but it actually breaks the installation with certain subpar software that uses autotools in a strange or outright wrong way. The shown full command `make install DESTDIR="%buildroot"` is just right.

If you need your own flags, specify them like this:

%build
export CPPFLAGS="-Dthis -Ihere"; # preprocessor flags
export CFLAGS="%optflags -Wnested-extern"; # only C
export CXXFLAGS="%optflags -fno-rtti"; # only C++ flags
%configure
...

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

The basic part

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

More flags may be needed:

-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

It seems not all CMakeLists.txt honor all CMAKE variables. That only contributes to the hardships of using cmake on a distro packaging level. cmake bug: not specifying the :TYPE can lead to the argument being ignored or so. (And you wonder why automake still remains popular.)

qmake

The no-frills boilerplate:

%build
qmake QMAKE_CFLAGS+="%optflags" QMAKE_CXXFLAGS+="%optflags" QMAKE_STRIP="/bin/true";
make %{?_smp_mflags};

%install
make install INSTALL_ROOT="%buildroot";

For everything else

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