Using rpmbuild when source tar directory doesn't correspond to name-version

Viewed 2354

I'm trying to build an rpm from source-1.4.3-linux.tgz (that is downloaded so I don't control the name) and the file untars into the directory source-1.4.3-linux. In my source.spec file, I have

Name: source
Version: 1.4.3 

So it is probably quite logical that I am getting an error:

cd: source-1.4.3: No such file or directory.  

I tried tacking -linux onto the version, but rpmbuild wants only a number there. What do I have to do to tell rpmbuild that the source files are untarred into source-1.4.3-linux?

3 Answers

Just use the setup macro.

setup -n %{name}-%{version}.linux

Here is a simple.spec file that would help you understand the issue. Source tarball contains the following:

$ tar tzf simple-0.tar.gz 
simple-0/
simple-0/simple.txt

Spec file:

Summary: Simple SPEC
Name: simple
Version: 0
Release: 1
License: NONE
Group: NONE
URL: NONE
Source0: %{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root


%description
" This is Simple "

%prep
%setup -q

%build

%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/tmp/
install -m 0644 simple.txt %{buildroot}/tmp/simple.txt

%clean
rm -rf $RPM_BUILD_ROOT

%post
echo "In the Post section of Simple"

%files
%defattr(-,root,root,-)
%doc
/tmp/simple.txt


%changelog
* Wed Sep 12 2018  <iamauser@localdomain> - 
- Initial build.

ok I got this working. Maybe a hack but it is working. As per the question my tarball is unconventionally named.

$ tar tzf source-1.4.3-linux-amd64.tar.gz 
source-1.4.3-linux-amd64/
source-1.4.3-linux-amd64/simple.txt

in the specfile %prep section instead of using %setup or %autosetup, I unpacked manually and renamed the untarred directory.

Name:       source
Version:    1.4.3
Release:    0
Source0:    https://example.com/%{name}-%{version}-linux-amd64.tar.bz2

%prep
rm -fr %{name}-%{version}
tar -xjf %{SOURCE0}
mv %{name}-%{version}-linux-amd64 %{name}-%{version}
Related