19

I have a .spec file that relies on a variable called _topdir.

Right now when you checkout the SRPM source from git, you have to go and change where _topdir is pointing to to get the rpmbuild to function correctly.

# We need the following line so that RPM can find the BUILD and SOURCES and RPMS dirs.
%define _topdir /root/projects/my-project/my-project-srpm/

How do you specify that _topdir should be relative to the location of the .spec file so that _topdir isn't hard coded?

  • That looks like a scary spec file. For starters, it looks like it is being built by root which is asking for trouble. What does the structure of the project look like? Better yet, is this a public git repo so? – linuts Jun 13 '11 at 12:20
  • that line has to be edited to point to wherever I checked it out from git, how do I make it where I don't have to edit that line every time I check it out to a different place from version control –  Jun 13 '11 at 15:02
  • What does the structure of the project look like? – linuts Jun 13 '11 at 16:53
  • 1
    Just to add - the answers that use 'pwd' don't satisfy the OPs requirement as stated - there is no guarentee that the environment pwd is the location of the spec file - that is adding an assumption on how the spec file is being used. ...back to google... – simon.watts Mar 02 '16 at 11:37

3 Answers3

16

specify your topdir on the command line like so ...

rpmbuild --define "_topdir \`pwd\`" ...
SingleNegationElimination
  • 151,563
  • 33
  • 264
  • 304
Red Cricket
  • 9,762
  • 21
  • 81
  • 166
  • where is the --define argument specified? I couldn't find it in the man pages or even just googling. – caspian311 Jul 03 '14 at 15:26
  • @caspian311 hmm. looks like the `--define` option got removed. Maybe one could use the `--root` instead. Take a look at http://www.rpm.org/max-rpm-snapshot/rpmbuild.8.html – Red Cricket Jul 14 '14 at 06:03
12

You can define the _topdir variable in your spec file (e.g., at the top)

%define _topdir %(echo $PWD)/
dirkl
  • 131
  • 1
  • 3
  • 1
    the answers that use 'pwd' don't satisfy the OPs requirement as stated - there is no guarentee that the environment pwd is the location of the spec file –  Mar 23 '16 at 21:26
-3

In your ~/.rpmmacros file, do this:

%_topdir      %(echo $PWD)/subdir

I'm unsure if you can do this inside the spec file itself, I don't see why not, but I'm unsure how to notate it.

Corey Henderson
  • 7,239
  • 1
  • 39
  • 43
  • this answer just moves what file I have to edit depending on where I check out the code. I don't want to have to edit a file to point to ever different place I checkout the source rpm to be built –  Jun 24 '11 at 15:12