Short answer, rpmbuild does not directly allow this to be done, and even if it were possible, it wouldn't really buy you much as far as reduction of the build time is concerned. The %build
section in the rpm spec file does not know anything about subpackages, so it will build everything anyway. Subpackages only come into play (beyond the metadata such as Requires, Provides, etc) in the %files
section, where rpmbuild is to know which subpackage should ship a file already appropriately built and installed in the %buildroot
. So essentially you might as well build the entire set of packages from the SRPM and delete the packages you do not need.
If your issue is that you would like to shorten the build time, what you could to is first introduce support in the build scripts of the software package you are compiling to only selectively build a subset of the package (i.e. make library
, make documentation
, etc). Then, you can enclose certain sections of your spec file with conditional macros [1], and then define those macros from the command line:
rpmbuild -ba --define '_build_library' somespecfile.spec
So then for instance something like this in the specfile should work:
[...]
%if 0%{?_build_library:1}
Package libs
Summary: Libraries for %{name}
%description libs
Libraries for %{name}
%endif
%if 0%{?_build_docs:1}
Package docs
Summary: Documentation for %{name}
%description docs
Documentation for %{name}
%endif
[...]
%build
%if 0%{?_build_library:1}
make libs
%endif
if 0%{?_build_docs:1}
make docs
%endif
%install
%if 0%{?_build_library:1}
%make_install libs
%endif
if 0%{?_build_docs:1}
%make_install docs
%endif
%if 0%{?_build_library:1}
%files libs
%{_libdir}/*.so*
%endif
if 0%{?_build_docs:1}
%files docs
%doc doc/html
%endif
Needless to say this is not terribly elegant.
[1] http://backreference.org/2011/09/17/some-tips-on-rpm-conditional-macros/
%files
section for the main package. – Wills