Set target directory in RPM spec file

user1285928 picture user1285928 · Dec 27, 2014 · Viewed 8.7k times · Source

I have a very simple tar.gz file wih Java files which I want to install using RPM package. I created this spec file:

Name:           test
Version:        1.0
Release:        1%{?dist}
Summary:        test installation script

Group:          Utilities
License:        GPL
URL:            http://oracle-base.com/articles/linux/linux-build-simple-rpm-packages.php
Source0:        test-1.0.tar.gz
BuildArch:      x86_64
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

#BuildRequires:  
#Requires:       

%description
test installation script

%prep
%setup -c /opt/test


%build
#%%configure
#make %{?_smp_mflags}


%install
rm -rf $RPM_BUILD_ROOT
#make install DESTDIR=$RPM_BUILD_ROOT

#install -d $RPM_BUILD_ROOT/opt/agent


%clean
rm -rf $RPM_BUILD_ROOT


%files
%defattr(-,root,root,-)
%doc

%changelog

It's not very clear how I can configure the target directory where the target files should be extracted. Can you tell me what I'm missing?

Answer

Etan Reisner picture Etan Reisner · Dec 28, 2014

The build process of an RPM package should operate entirely within the build directories and should not touch the host system in any way.

So %setup -c /opt/test is incorrect as is creates a directory in the host system. Instead you should likely simply use %setup -q and let the default macro extract your source tarball in the default build directory. (If your tarball does not contain a toplevel directory, that is it is a "tar-bomb", then you can use the -c flag with a relative path to create as the toplevel directory in the current directory.

If you don't have any sources to build then you don't need a %build section at all.

The %install section is intended to copy files from the local build directory to the final directory under the buildroot. So (as in that linked guide) it should copy files to $RPM_BUILD_ROOT/opt/test or whatever other path under $RPM_BUILD_ROOT is appropriate.

Those paths (without the $RPM_BUILD_ROOT prefix) are then what need to get listed in the %files section.

The Fedora project has some documentation on building RPMs that will likely be useful to you. The Maximum RPM book, while very old and somewhat out-of-date, is still a good source of information as well.