How to control the rpmbuild buildroot and install directory

32,249

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

Share:
32,249
zhihuifan
Author by

zhihuifan

Updated on November 14, 2020

Comments

  • zhihuifan
    zhihuifan over 3 years

    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?

  • zhihuifan
    zhihuifan about 11 years
    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?
  • Aaron D. Marasco
    Aaron D. Marasco about 11 years
    rpmbuild --buildroot='/path/to/your/buildroot/' should work. Sorry, missed that there were two questions.
  • Aaron D. Marasco
    Aaron D. Marasco about 11 years
    If you want to control more than just BuildRoot, see this question.
  • zhihuifan
    zhihuifan about 11 years
    Everything is clear now. appreciated for your help. Thanks!