Reputation: 1476
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?
Upvotes: 2
Views: 10719
Reputation: 118300
The other answer already explained the problem with the %setup -c command, and the general principles of building RPMs.
I'll add the following, which may help you understand how the RPM build script should work:
%install
rm -rf $RPM_BUILD_ROOT
#make install DESTDIR=$RPM_BUILD_ROOT
The above snippet, from the skeleton spec file, gives you a big clue. What you should be doing here is creating an installation image under $RPM_BUILD_ROOT.
So, if you want to, for example, install files in /opt/test, you'd probably want to do something like:
%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/opt/test/bin
cp <something> $RPM_BUILD_ROOT/opt/test/bin/something
The RPM build script is supposed to create what essentially is an installation image under $RPM_BUILD_ROOT. rpm then packages it up, and produces the binary installable rpm file that installs the contents of $RPM_BUILD_ROOT.
You will also need to have a %files section that lists all the individual files that get installed, as a sanity check. rpm will package only the files listed there in $RPM_BUILD_ROOT.
So, your general guidelines are:
In the setup section, extract your tarball into the current working directory. rpm creates a scratch directory for the build. %setup, by default, will unpack the files in there.
In the install section, copy what you want from the current working directory to $RPM_BUILD_ROOT. This becomes the installation image.
Upvotes: 2
Reputation: 80921
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.
Upvotes: 2