How do you make _topdir relative to the location of the .spec file when building an RPM?
Asked Answered
E

3

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?

Eldredge answered 8/6, 2011 at 22:2 Comment(4)
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?Fluoresce
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 controlEldredge
What does the structure of the project look like?Fluoresce
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...Trunnion
A
16

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

rpmbuild --define "_topdir \`pwd\`" ...
Angelia answered 3/9, 2011 at 4:46 Comment(2)
where is the --define argument specified? I couldn't find it in the man pages or even just googling.Radiancy
@Radiancy hmm. looks like the --define option got removed. Maybe one could use the --root instead. Take a look at rpm.org/max-rpm-snapshot/rpmbuild.8.htmlAngelia
K
12

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

%define _topdir %(echo $PWD)/
Krefeld answered 23/11, 2011 at 13:57 Comment(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 fileEldredge
F
-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.

Fou answered 23/6, 2011 at 22:7 Comment(1)
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 builtEldredge

© 2022 - 2024 — McMap. All rights reserved.