How to control the rpmbuild buildroot and install directory

zhihuifan picture zhihuifan · Apr 18, 2013 · Viewed 30.5k times · Source

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?

Answer

Aaron D. Marasco picture Aaron D. Marasco · Apr 18, 2013

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 /.