title: Define many macros for rpmbuild at once?
body: <p>I would like to pass many macros into <code>rpmuild</code> without having to type out each macro manually, or even have a long makefile with <code>-D 'foo bar' -D 'foo bar' -D 'foo bar'</code> many times. I want to pass these macros into rpmbuild "all at once".</p>
  
  <p>Let me describe my use case - I have a script called <code>buildid</code> that reports information about a build;</p>
  
  <pre><code>user@host: buildid -k tag
  1.8.0-1444293343
  
  user@host: buildid -k buildhost.platform
  Linux-4.0.7-300.fc22.x86_64-x86_64-with-fedora-22-Twenty_Two
  
  user@host: buildid -k version.formatted.gnu
  1.8.0
  </code></pre>
  
  <p>I use these values in a RPM .spec file like this;</p>
  
  <pre><code>rpmbuild -ba foo.spec -D "tag `buildid -k tag`" -D "buildhost_platform `buildid -k buildhost.platform`" -D "version `buildid -k version.formatted.gnu`"
  </code></pre>
  
  <p>This is the sucky part - a long command line, with lots of typing. Even if I use a Makefile, it's still ugly. </p>
  
  <p>My buildid script is pretty flexible though, and can save these buildid values to a file (.buildid_rpmmacros) or whatever, but better, can just print them out in a nice format like this; </p>
  
  <pre><code>user@host: buildid -f rpmmacros
  %buildhost.hostname myhost.example.com
  %buildhost.platform Linux-4.0.7-300.fc22.x86_64-x86_64-with-fedora-22-Twenty_Two
  %buildhost.release 4.0.7-300.fc22.x86_64
  %buildhost.system Linux
  %buildhost.version #1 SMP Mon Jun 29 22:15:06 UTC 2015
  %git.branch master
  %git.revision 48a30d610cf1ab57dcc6947b2366b6a5e9a1fcc6
  %git.revision.short 48a30d6
  %tag 1.8.0-1444293343
  %timestamp 1444293343
  %version.formatted.gnu 1.8.0
  %version.formatted.short 1.8.0
  %version.formatted.win 1.8.0.0
  %version.major 1
  %version.minor 8
  %version.release 
  %version.revision 0
  </code></pre>
  
  <p>If I could do something like this, it would be ideal;</p>
  
  <pre><code>rpmbuild -ba foo.spec --macros-stdin &lt; `buildid -f rpmmacros`
  </code></pre>
  
  <p>Finally, the macros are project/RPM specific, not global. This means storing them in <code>~/.rpmmacros</code> would not be a viable solution. I can save to a file easily (<code>buildid -nF rpmmacros</code>), but I'm already persisting them to a file in <code>ini</code> format, and just want to output them temporarily in RPM macro format (<code>buildid -f rpmmacro</code>)</p>
  
  <hr>
  
  <p>Shameless plug - if you're interested in the <code>buildid</code> tool; <a href="https://github.com/jamesread/buildid" rel="nofollow">https://github.com/jamesread/buildid</a></p>