The spec file is present inside the source directory. The specfile build section looks like

cd ~/path/sources

If the spec file path can be detected then the hardcoding of the ~/path/sources can be avoided. How to get the spec file path.

2 Answers 2

%{_specdir} /${name}.spec 

will do the job. See this Fedora Wiki Page for more information.

  • Please consider expanding more on your answers which paraphrase links rather than just putting a link.
    – HalosGhost
    Aug 31, 2016 at 16:07
  • 1
    Note that the %{_specdir} macro will redirect to %{_topdir}/SPECS/, which by default is ~/rpmbuild/SPECS/. Not sure if that is what the OP was looking for.
    – Abby
    Feb 2, 2019 at 14:02

The path is often derived from the process itself. If you look at the output of the build process, you'll see it CDing into various directories as it prepares for another phase of the process.

Simply, if you change the absolute paths to a relative path (and your source files should all be in the payload of your SRPM or moved into a source tree before building if this is a new build) then much of these problems will happily go away.

Also, using an echo in the %prep section, look at stupid pet tricks like

%prep echo %(dirname %{Source0}) echo %(basename %{S:1})

When you are absolutely sure you definitely need to do such horror, that kind of mess will come in handy. Keep it as a rarity if you can.

Someone better than me: If you see this post, remind me how to make it ONLY resolve that %() once, and not every time it needs it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.