rpm macro magic help

Michael Schwendt mschwendt at gmail.com
Fri Nov 8 12:47:08 UTC 2013


On Thu, 07 Nov 2013 14:10:19 +0100, Sandro Mani wrote:

> > Well, a Shell Function would be more readable, for example. It would
> > accept normal arguments to fill in variables -- instead of global RPM
> > macros, which are substituted in the entire spec file.
> Uhm, how can one this be done? Shell variables are substituted after 
> macro expansion, so i.e.

With the benefit that the function is more readable and more comprehensible
(especially if adding comments) than a global RPM macro. In a Shell function
you could evaluate the arguments and create conditional sections, whereas
in the RPM macro that would get even less readable.

The linked spec is an entertaining exercise, but also an example of
macro-madness. Several values (e.g. paths) are expanded multiple times
instead of defining them once at the beginning and reusing them later. And
the macro is not even fully reusable yet due to hardcoded library file
names.

> %define do_install() \
> (cd build_win%{1}_%{2}; \
> %{expand:%%{mingw%{1}_make}} INSTALL_ROOT=%{buildroot} install; \
> )\
> mkdir -p %{buildroot}%{expand:%%{mingw%{1}_bindir}}; \
> mv %{buildroot}%{expand:%%{mingw%{1}_libdir}}/quazip-%{2}-?.dll %{buildroot}%{> expand:%%{mingw%{1}_bindir}}; \
> mv %{buildroot}%{expand:%%{mingw%{1}_libdir}}/libquazip-%{2}-?.a %{buildroot}%> {expand:%%{mingw%{1}_libdir}}/libquazip-%{2}.dll.a; \
> (cd build_win%{1}_%{2}_static; \
> %{expand:%%{mingw%{1}_make}} INSTALL_ROOT=%{buildroot} install; \
> )\
> mv %{buildroot}%{expand:%%{mingw%{1}_libdir}}/libquazip-%{2}-.a %{buildroot}%{> expand:%%{mingw%{1}_libdir}}/libquazip-%{2}.a; \
> mv %{buildroot}%{expand:%%{mingw%{1}_includedir}}/%{pkgname} %{buildroot}%{exp> and:%%{mingw%{1}_includedir}}/%{pkgname}-%{2}; \
> mkdir -p %{buildroot}%{expand:%%{mingw%{1}_libdir}}/pkgconfig; \
> cat > %{buildroot}%{expand:%%{mingw%{1}_libdir}}/pkgconfig/%{pkgname}-%{2}.pc > <<EOF\
> prefix=%{expand:%%{mingw%{1}_prefix}}\
> exec_prefix=%{expand:%%{mingw%{1}_prefix}}\
> libdir=%{expand:%%{mingw%{1}_libdir}}\
> includedir=%{expand:%%{mingw%{1}_includedir}}/%{pkgname}-%{2}\
> \
> Name: %{pkgname}\
> Description: Qt/C++ wrapper for the minizip library\
> Version: %{version}\
> \
> Requires:\
> Libs: -L\\${libdir} -lquazip\
> Cflags: -I\\${includedir}\
> \
> Requires.private: libzip\
> EOF\
> %{nil}


> function do_build {
> arch=$1
> qt_version=$2
> %{mingw${arch}_qmake_${qt_version}}
> }
> 
> would hardly work? Or are you suggesting passing the entire macros as 
> arguments? I.e.
> 
> function do_build {
> qmake=$1
> make=$2
> ${qmake} <args>
> ${make} %{?_smp_mflags}}
> [...]
> do_build "%{mingw32_qmake_qt4}" "%{mingw32_make}"

Yes, something like that is *much* more readable IMO, because it becomes
clear which commands will be used, and since most of the code is Shell
based, it becomes easier to insert guards and/or debugging help.


More information about the devel mailing list