$RPM_BUILD_ROOT
(or the equivalent %{buildroot}
SPEC file macro) always holds the directory under which RPM will look for any files to package. The RPM scripts (e.g. the script that compresses the manual pages) will also use that value to know where to look for the files that were just installed. Normally, this value will be non-empty and contain a location away from the system directories – usually somewhere under /tmp
or /var/tmp
.
The author of the SPEC file is expected to make sure that make install
(or whatever installer the software in question is using) will place any files under $RPM_BUILD_ROOT
, with the same hierarchy that should be used when the software is finally installed. E.g. to have RPM install ls
in /bin/ls
, the %install
SPEC file section should make sure that ls
is placed in $RPM_BUILD_ROOT/bin/ls
.
The author of the SPEC file is also expected to use the BuildRoot:
tag to specify a proper location. Alternatively, the build system could have an rpmrc
RPM configuration file with a proper entry. In any case the build root should be set, so that:
-
Normal users will be able to build the source package.
-
Should the superuser ever build the source package, the build process will not clobber any system files, unless the superuser installs the resulting binary package. And yes, there may be a good reason to build some packages as
root
– for example, running the fullglibc
testsuite requiresroot
privileges for some tests.
That said, RPM can and will build a package with an empty build root variable. In that case both the build install and the final destination locations will coincide. A potential call to e.g. make install
will use the default locations, thus clobbering the system files under e.g. /usr/lib
if run with sufficient privileges. Additionally, having /usr/bin/*
in your %files
section will happily pull the whole contents of the build host /usr/bin/
directory into your binary package.
Bottom line:
-
Never use an empty build root.
-
Do not build packages as
root
unless there is absolutely no other way.