In my organization, we deploy all our software to our production machines using RPM. Our build process (which is automated) involves checking out the source from version control, tarring that source directory up, then running rpmbuild using that source tarball. rpmbuild only uses that tarball to untar the sources to work on them. So, it seem like the whole taring and untaring business is just an unneeded extra step in the build process. Is there was a way to just specify the source directory in the spec file, avoiding those extra steps?
3 Answers
Yes, you can do that. Do not list any Source
s. In the %prep
section do not use the %setup
macro (which untars the source); rather, just check out the source.
Note that you will not be able to build SRPMs if you do this.
-
This does it. I just need to modify the build procedure to check things out to the rpm BUILD directory instead. Thanks!– EddieSep 14, 2011 at 21:41
This question is a bit old, but in case other people find it in search there is a more correct way to do this that does also allow the creation of an SRPM.
In the prep section, instead of using the setup macro, you should instead just type out yourself what you want it to do, namely copying the source directory from SOURCES to BUILD, instead of unpacking an archive. I found that you also then have to add a cd into your source directory in the build and install sections.
Example snippet
%prep
# Don't use the setup macro anymore, replace it with typed-out commands
#%setup -q -n myapp-%{version}
cd %{_topdir}/BUILD
rm -rf myapp-%{version}
cp -rf %{_topdir}/SOURCES/myapp-%{version} .
cd myapp-%{version}
/usr/bin/chmod -Rf a+rX,u+w,g-w,o-w .
%patch1 -p1 -b .cert-config
%patch2
%build
cd myapp-%{version}
%install
cd myapp-%{version}
-
1Should
%{_topdir}/SOURCES
be%{_sourcedir}
? And%{_topdir}/BUILD
could be%{buildroot}
? (As an aside, for similar-but-different situations where you're trying to add extra files to override those extracted from%setup
, the Fedora docs recommend using%{SOURCE2}
etc - fedoraproject.org/wiki/Packaging:RPM_Source_Dir)– IBBoardMay 18, 2019 at 14:43 -
the -n part after %setup was what I needed: The untar'ed subdir differed from the raw version number so I needed
%setup -n %{name}-v%{version}
because of the "v"– KJ7LNWMar 20, 2022 at 3:07 -
%{_fixperms}
should be used: github.com/rpm-software-management/rpm/blob/…– Et7f3XIVApr 27, 2023 at 23:37
12 years late to the party, but maybe this will help someone. You can just redefine the _sourcedir macro on the command line with rpmbuild. For example:
rpmbuild --define "_sourcedir $(pwd)/SOURCES" -ba SPECS/my-app.spec
This allows you to build all expected RPMs and SRPMs with the expected structure from basically anywhere without having to tar and untar.