So, I am somewhat puzzled by the rpmbuild process. I'm now maintaining a slew of scripts previously created and while most work, there are enough differences between them that finding a consistent approach is just not happening.

  • Some individually copy files (very tedious) to a temp location prior to packaging.

  • Some use the original author's spec file, we're just modifying configs or code.

  • Some are home-rolled, but were apparently created with the same level of understanding as I!

Specifically, I would love to just have the make; make install approach, but, while make builds the software just fine, make install actually installs it on my system.

What I would like to do, is use make install, but have it placed in a working directory for the purpose of the packager. I want the software to install on the target machine in /usr/bin etc, but when I run make install, I want it to go to /tempDir/usr/bin -- make sense? Basically, I just want to avoid polluting my system with software I'm packaging; it doesn't seem right that it all gets plugged in. Must be something misconfigured or is this normal?

Exerpts from the spec file I'm working with. Copying source file to /usr/src/redhat/SOURCES and building with rpmbuild -bb <specfilename>.

BuildRoot:      /var/tmp/%{name}-%{version}-root
Source0:        %{name}-%{version}.tar.gz

%setup -q

./configure <config opts>

make install
  • 2
    Not an expert on rpm packing but can't you usually do a ./configure --prefix=%{buildroot} or pass a variable to make so that it puts it in the temp directory instead of your actual root filesystem? If not wouldn't this call for patching the makefile so that you can change the path it installs into? – Bratchley Jan 23 '15 at 16:33
  • 1
    Usually, you don't need to set BuildRoot yourself. See fedoraproject.org/wiki/Packaging:RPMMacros. And in the compile step, what you typically want is to install to %{buildroot} by passing DESTDIR=%{buildroot} to make. – jayhendren Jan 23 '15 at 19:13
  • @jayhendren out of curiosity why to make and not to ./configure? – Bratchley Jan 23 '15 at 19:22
  • 1
    see gnu.org/prep/standards/html_node/DESTDIR.html and sourceware.org/autobook/autobook/autobook_14.html. basically, --prefix determines the final installation directory, DESTDIR determines a staging directory for the installation and not the final installation directory. – jayhendren Jan 23 '15 at 19:29
  • jayhendren hit the nail on the head... DESTDIR did the trick! If you write that up as an answer, I'll accept it. – Jon Jan 26 '15 at 20:56

The files that are to be packaged need to be installed/isolated into a shadow tree.

This is usually done by overriding]DESTDIR like

make DESTDIR=%{buildroot} install

in the %install section.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.