2

I am confused about some directories in rpmbuild.

1: buildroot: which should be used to store the files that are supposed to be installed when the binary package is installed by an end-user.

Questions: how to control this directory? What does BuildRoot mean?

 $ cat 3.spec
 ..
 BuildRoot: /opt/abc
 ..
 %prep
 echo %{buildroot}
 echo  $RPM_BUILD_ROOT   

whatever I set the BuildRoot to, I get the result which was defined in /usr/lib/rpm/macros. If I define %buildroot in ~/.rpmmacros, I will get the result from it.

2: How do I control the destination when we install the rpm package? For example: rpm -ivh xxx.rpm, where the files will be installed?

Wilfred Hughes
  • 29,846
  • 15
  • 139
  • 192
zhihuifan
  • 1,093
  • 2
  • 16
  • 30

1 Answers1

7

You create the subdirectories yourself in %install or wherever.

Example: You want to install all your files in /opt/mypkg/ but also want a config file /etc/mypkg.conf. So in the %install section you:

mkdir -p %{buildroot}/opt/mypkg
mkdir -p %{buildroot}/etc

So you are re-creating the tree that you want installed, all with %{buildroot} as the equivalent of the target's /.

Aaron D. Marasco
  • 6,506
  • 3
  • 26
  • 39
  • it works and thank you very much!! the install directory should be same as the directory we installed during %install section except that rpm will replace the %{buildroot} with /, no matter what %{buildroot} is. how about my first question? how to control the value of %{buildroot} in my.spec file? seems the value or BuildRoot is useless? – zhihuifan Apr 19 '13 at 01:44
  • 4
    `rpmbuild --buildroot='/path/to/your/buildroot/'` should work. Sorry, missed that there were two questions. – Aaron D. Marasco Apr 19 '13 at 08:25
  • If you want to control more than just `BuildRoot`, see [this question](http://stackoverflow.com/questions/2971391/how-to-set-the-build-area-for-rpmbuild-per-invocation). – Aaron D. Marasco Apr 19 '13 at 08:26
  • Everything is clear now. appreciated for your help. Thanks! – zhihuifan Apr 22 '13 at 08:03