I'm trying to package an RPM of a systemd service written in C and managed by autoconf and autotools. When I attempt to package an RPM using the sudo make rpm
command as instructed in the project's README.md, the command errors out with:
cp: cannot create regular file '/root/rpmbuild/SOURCES': No such file or directory
How can I configure the make
target to look in $HOME/rpmbuild/SOURCES
(where rpmbuild actualy is) instead of in the root home directory?
Following What actually is $RPM_BUILD_ROOT?, I've checked ~/.rpmmacros
and it indeed includes the line
%_topdir %(echo $HOME)/rpmbuild
So I'm not sure what I'm doing wrong.
For context I run ./bootstrap
, ./configure
, sudo make
, and sudo make install
before attempting sudo make rpm
.
This ...
cp: cannot create regular file '/root/rpmbuild/SOURCES': No such file or directory
... indicates that user root does not have an RPM-building environment set up. That's ok in itself, because you shouldn't build RPMs as root, just as you shouldn't build programs as root.
But if you want to build this RPM as yourself then you will need an RPM build environment of your own. RedHat has some decent documentation on the basics. You probably don't need to go through all that, but fairly early on it documents the RPM build environment you will need in your home directory, starting at ~/rpmbuild
. If you have or care to install rpmdev-setuptree
(from rpmdevtools) then you can use it to set up an appropriate environment, but I usually just create the needed directories by hand.
I anticipate that you will get further by setting up an RPM build environment for yourself, then running make rpm
as yourself. Or if you insist on unwisely building as root, then by first setting up an RPM build environment for root.
How can I configure the
make
target to look in/home/rpmbuild/SOURCES
(where rpmbuild actualy is) instead of in the root directory?
/home/rpmbuild
should be the home directory of a user named 'rpmbuild'. In principle, you could build as such a user instead of as yourself, but that might not help with your immediate problem, depending on user 'rpmbuild's own RPM-building configuration.
I've checked ~/.rpmmacros and it indeed includes the line
%_topdir %(echo $HOME)/rpmbuild
So I'm not sure what I'm doing wrong.
If you are running the build as root (as you do if you use sudo
) then it will be root's rpmbuild configuration that is effective, not your own. Note, however, that if your own rpmbuild configuration points the _topdir
to /home/rpmbuild
then that's what rpmbuild
will try to use when you run it as yourself. Don't do that. Set up your own RPM building environment, inside your home directory. If you use the default name then you probably don't need an .rpmmacros
file at all.