Rpmbuild question.

Tim Mooney Tim.Mooney at ndsu.edu
Fri May 4 18:27:47 UTC 2012

In regard to: Rpmbuild question., Jim Lynch said (at 11:32am on May 4, 2012):

> Here's the %files section of the spec file:
> %files
> %defattr(-,root,root)
> /usr/local/bin/logpoll
> /etc/cron.daily/logpoll_cron
> /etc/cron.d/logpoll_cmd
> When I do a rpmbuild -bb logpoll.spec
> I get a bunch of messages, "file not found"  that reference (for example)
> rpmbuild -bb logpoll.spec
> Processing files: logpoll-1-62.x86_64
> error: File not found: 
> /home/jim/rpmbuild/BUILDROOT/logpoll-1-62.x86_64/usr/local/bin/logpoll
> error: File not found: 
> /home/jim/rpmbuild/BUILDROOT/logpoll-1-62.x86_64/etc/cron.daily/logpoll_cron
> error: File not found: 
> /home/jim/rpmbuild/BUILDROOT/logpoll-1-62.x86_64/etc/cron.d/logpoll_cmd
> I'm guessing something in the configuration changed.  I tried rpmbuild 
> --buildroot=/ -bb logpoll.spec
> and
> rpmbuild --buildroot='' -bb logpoll.spec
> But it complained that the buildroot can't be /.

Yeah, don't do that.  With some specs it would be extremely dangerous,
especially if you build packages as root (don't do *that*, either).

I'm all for having software that works the way we want it to work, but
in this case RPM really is encouraging good habits from packagers.

In other words, don't fight it.

What you want to do is update your %install section, so that rather than
install your files into the real, final destination, you instead install
those files into the buildroot, for packaging.

How you do that depends on what you're packaging.

- If you're packaging some piece of opensource software that is configured
   and built via GNU autotools, then the Makefile *likely* supports
   setting DESTDIR at install time.  In other words, nothing changes in
   your %build (you run configure, make, and make check normally), but
   your %install changes from

 	make install


 	make install DESTDIR=$RPM_BUILD_ROOT

   Sometimes packages don't work *quite* right with DESTDIR installs,
   perhaps they need you to pre-create the install hierarchy (.e.g.
   /usr/local/bin, /etc/cron.d, etc. *under* your setting for buildroot)
   or they have a custom "install-data" rule that hasn't been written to
   support DESTDIR.  These are usually pretty easy to fix or work around.

- If you're packaging your own software and it uses a Makefile with
   an "install" target, you just need to modify your Makefile so that
   somewhere in the file you have


   (i.e. DESTDIR is blank/undefined most of the time) and then you need
   to modify the install target so that each destination directory listed
   in the install target is prefixed with $(DESTDIR).  In other words

 	install: foo bar baz.conf
 		cp -p src/foo /usr/local/bin/foo
 		cp -p data/bar /usr/local/share/bar
 		cp -p etc/baz.conf /etc/foo/baz.conf


 	install: foo bar baz.conf
 		cp -p src/foo $(DESTDIR)/usr/local/bin/foo
 		cp -p data/bar $(DESTDIR)/usr/local/share/bar
 		cp -p etc/baz.conf $(DESTDIR)/etc/foo/baz.conf

   Better yet, you fix your install target so that it also depends on
   all of the destination directories being present (and a target creates
   them if they're not).

- If your %install just uses cp or install directly (no Makefile), then
   just modify the commands so that each destination directory is prefixed
   with $RPM_BUILD_ROOT.

With most packages, it's relatively straightforward to get them to install
using a buildroot.  The trickiest situation I typically run into is with
libtool libraries that I'm packaging where the same ABI version is
*already* installed on the system.  Everything else is easy to work

Good luck,

Tim Mooney                                             Tim.Mooney at ndsu.edu
Enterprise Computing & Infrastructure                  701-231-1076 (Voice)
Room 242-J6, IACC Building                             701-231-8541 (Fax)
North Dakota State University, Fargo, ND 58105-5164

More information about the Rpm-list mailing list