title: How to set the build area for rpmbuild per-invocation
body: <p>I'm modifying an automated build, and want to tell <code>rpmbuild</code> to <strong>use a specific build area when invoking it</strong>.</p>
  
  <p>This is similar to an <a href="https://stackoverflow.com/questions/2777737/how-to-set-the-rpmbuild-destination-folder">existing question</a>, but more specific.</p>
  
  <ul>
  <li><p>I don't want to run any of the build commands as the root user; the aim is only to have an RPM, not to install anything into the system.</p></li>
  <li><p>I don't want to <a href="http://www.rpm.org/max-rpm/s1-rpm-anywhere-different-build-area.html" rel="noreferrer">require the user to change their dotfiles</a> (e.g. <code>$HOME/.rpmrc</code>); the build should be self-contained and not affect the user's existing settings.</p></li>
  <li><p>I don't want to hard-code the location into the <code>foo.spec</code> file; that file should be useable as-is if the user wants to build in a different location.</p></li>
  <li><p>The <a href="http://www.rpm.org/max-rpm-snapshot/ch-rpm-b-command.html#S2-RPM-B-COMMAND-BUILDROOT-OPTION" rel="noreferrer"><code>--buildroot</code> option</a> is not what I need; that sets a pseudo-root filesystem for the <code>make</code> part of the build process, but I need to specify the “build area” for the <em>entire</em> RPM build process.</p></li>
  </ul>
  
  <p>What I'm looking for is <strong>a hypothetical <code>--build-area FOODIR</code> option</strong> that can be given to the <code>rpmbuild</code> command, or an equivalent environment variable. It should thus affect just that single invocation of the command and cause it to use a specified user-writable location for its build area.</p>
  
  <p>I've seen references to a <code>_topdir</code> macro that seems to be what I'm talking about, but it doesn't appear to be configurable per invocation.</p>
  
  <p>It would be ideal if <code>rpmbuild</code> could set up its own environment in that location when it needs it, but I don't mind setting up the directories for that per build, since that can be automated as part of the build. The goal is to <strong>have that user-writable location exist only for the duration of the build run</strong>, and then clean up by deleting that entire location once the RPM file is generated.</p>