Useful rpmbuild macros

Posted in Linux , tweaks

package-125x125

Utilizing macros can make life easier when you’re dealing with building on, and for, multiple platforms. Why bother with hard-coding full paths to system utilities when you can simply refer to them by their macro name?

These can also be useful for avoiding things like rpm check-files errors, installed (but unpackaged) file(s) found, and debuginfo related stuff.

If you find these macros are not available in your version of rpmbuild, you can explicitly define them yourself. Most systems will have (most of) these preconfigured for you in /usr/lib/rpm or a similar path.

filesystem macros

%__awk          gawk
%__bzip2        /usr/bin/bzip2
%__cat          /bin/cat
%__chgrp        /bin/chgrp
%__chmod        /bin/chmod
%__chown        /bin/chown
%__cp           /bin/cp
%__cpio         /bin/cpio
%__file         /usr/bin/file
%__gpg          /usr/bin/gpg
%__grep         /bin/grep
%__gzip         /usr/bin/gzip
%__id           /usr/bin/id
%__install      /usr/bin/install
%__ln_s         ln -s
%__lzma         /usr/bin/lzma
%__xz           /usr/bin/xz
%__make         /usr/bin/make
%__mkdir        /bin/mkdir
%__mkdir_p      /bin/mkdir -p
%__mv           /bin/mv
%__patch        /usr/bin/patch
%__perl         /usr/bin/perl
%__pgp          /usr/bin/pgp
%__python       /usr/bin/python
%__rm           /bin/rm
%__rsh          /usr/bin/rsh
%__sed          /bin/sed
%__ssh          /usr/bin/ssh
%__tar          /bin/tar
%__unzip        /usr/bin/unzip

Build system path macros

%__ar           ar
%__as           as
%__cc           gcc
%__cpp          gcc -E
%__cxx          g++
%__ld           /usr/bin/ld
%__nm           /usr/bin/nm
%__objcopy      /usr/bin/objcopy
%__objdump      /usr/bin/objdump
%__ranlib       ranlib
%__remsh        %{__rsh}
%__strip        /usr/bin/strip

Avoid failures if tools are not installed when rpm is built

%__libtoolize       libtoolize
%__aclocal      aclocal
%__autoheader       autoheader
%__automake     automake
%__autoconf     autoconf

Other

# The directory where rpm's configuration and scripts live
%_rpmconfigdir      %{getconfdir}

# The directory where sources/patches will be unpacked and built.
%_builddir      %{_topdir}/BUILD

# The interpreter used for build scriptlets.
%_buildshell        /bin/sh

# The path to the bzip2 executable (legacy, use %{__bzip2} instead).
%_bzip2bin      %{__bzip2}

The location of the rpm database file(s).
%_dbpath        %{_var}/lib/rpm

# The location of the rpm database file(s) after "rpm --rebuilddb".
%_dbpath_rebuild    %{_dbpath}

# The path to the gzip executable (legacy, use %{__gzip} instead).
%_gzipbin       %{__gzip}

# The number of changelog entries kept when installing (unused in rpm-4.0.1 and later).
%_instchangelog     5

# The path to the pgp executable (legacy, use %{__pgp} instead).
%_pgpbin        %{__pgp}

# The directory where newly built binary packages will be written.
%_rpmdir        %{_topdir}/RPMS

# A template used to generate the output binary package file name (legacy).
%_rpmfilename       %{_build_name_fmt}

# The default signature type.
%_signature     gpg

# The directory where sources/patches from a source package will be installed.
%_sourcedir     %{_topdir}/SOURCES

# The directory where the spec file from a source package will be installed.
%_specdir       %{_topdir}/SPECS

# The directory where newly built source packages will be written.
%_srcrpmdir     %{_topdir}/SRPMS

# The directory where buildroots will be created.
%_buildrootdir      %{_topdir}/BUILDROOT

# Build root path, where %install installs the package during build.
%buildroot      %{_buildrootdir}/%{name}-%{version}-%{release}.%{_arch}

# Directory where temporaray files can be created.
%_tmppath       %{_var}/tmp

# Path to top of build area.
%_topdir        %{getenv:HOME}/rpmbuild

# The path to the unzip executable (legacy, use %{__unzip} instead).
%_unzipbin      %{__unzip}

# A macro that expands to nothing.
%nil            %{!?nil}

If you need to override a system’s currently configured macros, rather than edit the etc config settings, you can override a macro or define your own from scratch in ~/.rpmmacros

Posted by admica   @   3 December 2010

Related Posts

1 Comments

Comments
Mar 9, 2011
2:59 am
#1 McMoo :

Just the cheat-sheet I was looking for. Thanks!

Leave a Comment

Name

Email

Website

*

Previous Post
«
Next Post
»
Powered by Wordpress   |   Lunated designed by ZenVerse

Valid XHTML 1.0 Transitional