From Fedora Project Wiki

Rename this page to something more readable.

Give a basic introduction to macros without supplying documentation. Try to briefly indicate what macros are and should be used for.

Move relevant sections from the main guidelines here if appropriate.

Note that this page is not intended to be exhaustive or to provide documentation beyond the macros used in the guidelines and suggested for use by the guideline that recommends the use of macros for directories. Warn against capricious use of macros; the mere existence of a macro in the RPM configuration does not mean that it should be used.

Mention rpm --eval and --showrc.


Selected RPM Macros

Here are the definitions for some macros as they are defined on Fedora 13 (rpm-4.8.0-14.fc13). For definitions of more macros, examine the output of "rpm --showrc". To see the expanded definition of a macro use the command rpm --eval "%{macro}". Note that neither command will take into account macros defined inside specfiles, but both will take into account macros defined in your ~/.rpmmacros file and macros defined on the command line.

Keep in mind that some of these macros may evaluate differently on older Fedora or EPEL releases.

Note that all macros are shown here with the enclosing brackets for clarity but it is not required that they be used except, of course, where required by RPM.

Macros for Paths

Several macros are used to represent paths. Use of these is not mandatory except for %{_libdir} (because it has a different value for different architectures), but using them allows those locations to be redefined by other macros, which can be useful in some situations such as generation of Flatpaks or creating parallel-installable packages.

%{_sysconfdir}        /etc
%{_prefix}            /usr
%{_exec_prefix}       %{_prefix}
%{_bindir}            %{_exec_prefix}/bin
%{_libdir}            %{_exec_prefix}/%{_lib}
%{_libexecdir}        %{_exec_prefix}/libexec
%{_sbindir}           %{_exec_prefix}/sbin
%{_sharedstatedir}    /var/lib
%{_datadir}           %{_prefix}/share

%{_includedir}        %{_prefix}/include
%{_infodir}           /usr/share/info
%{_mandir}            /usr/share/man
%{_var}     /var

Other macros and variables for paths

These macros should be used for paths that are not covered by the macros mimicking autoconf variables. The %{buildroot} macro or the $RPM_BUILD_ROOT variable is the directory that should be assumed to be the root file system when installing files. It is used as the value for the DESTDIR variable.

%{_var}               /var
%{_tmppath}           %{_var}/tmp
%{_usr}               /usr
%{_usrsrc}            %{_usr}/src
%{_lib}               lib (lib64 on 64bit multilib systems)
%{_docdir}            %{_datadir}/doc
%{buildroot}          %{_buildrootdir}/%{name}-%{version}-%{release}.%{_arch}
$RPM_BUILD_ROOT       %{buildroot}

Build flags macros and variables

These macros should be used as flags for the compiler or linker. Note that the values for the macros below reflect the settings on Fedora 13 (i686) with redhat-rpm-config installed.

%{__global_cflags}   -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4
%{optflags}          %{__global_cflags} -m32 -march=i686 -mtune=atom -fasynchronous-unwind-tables
$RPM_OPT_FLAGS       %{optflags}