Search code examples
centosredhatrpmbuildrpm-spec

rpmbuild no such file or directory


I'm just learning making rpm packages for some custom builds of software that gets compiled from source (some legacy stuff needs this, so I'm trying to learn, as some packages can't use the latest versions), but hitting an error (I'm doing this in Vagrant, and also as root, but typically I'm trying not to use root as I'm aware it has potential for damage, its just this example seems to need some root changes).

sudo rpmbuild -ba testspec.spec --define "_topdir /tmp/"

So far it looks to be using the directory I expected, /tmp/rpmbuild

make[2]: Entering directory `/tmp/rpmbuild/BUILD/exim-4.80.1/build-Linux-x86_64/pdkim'
make[2]: `pdkim.a' is up to date.
make[2]: Leaving directory `/tmp/rpmbu

But then I see these errors...

/usr/lib/rpm/brp-compress: line 8: cd: /tmp/BUILDROOT/custom-exim-4.80.1-1.x86_64: No such file or directory
+ /usr/lib/rpm/brp-strip
find: `/tmp/BUILDROOT/custom-exim-4.80.1-1.x86_64': No such file or directory
+ /usr/lib/rpm/brp-strip-static-archive
find: `/tmp/BUILDROOT/custom-exim-4.80.1-1.x86_64': No such file or directory
+ /usr/lib/rpm/brp-strip-comment-note

So it now seems to be looking in /tmp/BUILDROOT

I'm new to rpmbuild, and don't quite understand some of the process.

My test spec file is at...


%define myversion       exim-4.80.1
##%define mybase                %{getenv:HOME}
%define mybase          /tmp

%define _topdir         %{mybase}/rpmbuild
%define _tmppath        %{mybase}/rpmbuild/tmp
%define name            custom-exim
%define release         1
%define version         4.80.1
%define buildroot       %{_topdir}/%{name}-%{version}-root


BuildRoot:      %{buildroot}
Summary:        %{name}
Name:           %{name}
Version:        %{version}
Release:        %{release}
Source0:        ftp://exim.noris.de/exim/exim4/old/exim-4.80.1.tar.gz

License:        GPLv1+
Group:          Language
AutoReq:        no
AutoProv:       no
Requires:       db4-devel pcre-devel libdb-devel libXt-devel libXaw-devel

%description
Custom Exim Build

%prep

#Do the following manually before building rpm
#mkdir -p /tmp/rpmbuild/BUILD /tmp/rpmbuild/SPECS /tmp/rpmbuild/SOURCES /tmp/rpmbuild/BUILDROOT /tmp/rpmbuild/RPMS /tmp/rpmbuild/SRPMS
#wget ftp://exim.noris.de/exim/exim4/old/exim-4.80.1.tar.gz -O /tmp/rpmbuild/SOURCES/exim-4.80.1.tar.gz


%setup -q -n %{myversion}
grep exim /etc/passwd ||  useradd -c "Exim" -d /var/spool/exim -m -s /bin/bash exim

%build

# exim needs to config changes before compiling, may do these first and repackage

cp %{mybase}/rpmbuild/BUILD/%{myversion}/src/EDITME %{mybase}/rpmbuild/BUILD/%{myversion}/Local/Makefile
cp %{mybase}/rpmbuild/BUILD/%{myversion}/exim_monitor/EDITME %{mybase}/rpmbuild/BUILD/%{myversion}/Local/eximon.conf

sed -i -e 's/EXIM_USER=$/EXIM_USER=exim/g' "%{mybase}/rpmbuild/BUILD/%{myversion}/Local/Makefile"
sed -i -e 's/LOOKUP_DNSDB=yes/#LOOKUP_DNSDB=yes/g' "%{mybase}/rpmbuild/BUILD/%{myversion}/Local/Makefile"

make

%install

rm -rf $RPM_BUILD_ROOT
#%{__mkdir_p} '%{buildroot}%{_sbindir}'
make install

%clean
rm -rf $RPM_BUILD_ROOT

%post

%postun

%files

Why is it using /tmp/BUILDROOT literally, instead of /tmp/rpmbuild, and are there other obvious things I'm doing wrong ? I've looked at a lot of other tutorials on rpmbuild, but aren't very clear on best practices or what happens during each phase.


Solution

  • Since the buildroot parm is not passed to rpmbuild, the default path is being used by your spec file:

    BuildRoot:      %{buildroot}
    

    Try adding the buildroot parm... Add buildroot /tmp/rpmbuild to --define

    Or if using a makefile:

    BUILD_TMP=/tmp/rpmbuild
    TOP_DIR=/tmp
    
    rpmbuild -bb 
      --buildroot $(BUILD_TMP)
      --topdir $(TOP_DIR)
      $(SPEC_DIR)/testspec.spec