6

Is it possible to have a separate %install section for a subpackage in a spec file?

For example, files can be specified for the main package as

%files

and for the subpackage like this:

%files mysubpackage

however, I have only seen one

%install

section, and I get an error if I do

%install mysubpackage
user12066
  • 613
  • 6
  • 23
  • Remember - `%install` is at RPM *build time*. The scriptlets are executed at *install time*, *e.g.* `%post`. Those allow subpackages. – Aaron D. Marasco Sep 22 '17 at 01:25

1 Answers1

8

no, you cannot have, and you don't need a separate %install section.

Let's suppose a typical example: you compile a program and want to create two packages; library.rpm and library-devel.rpm (with the headers). Then you'll have a spec file something like this:

Name: library
# probably some other fields...

%description
describre library

%package devel
Summary: headers for library

%description devel
describe library-devel package

%prep
# some common prep code for both packages; eg
%setup -q

%build
make (or whatever to build your program)

%install
# install files for both rpm packages; library AND headers
mkdir -p ${RPM_BUILD_ROOT}/%_libdir/
mkdir -p ${RPM_BUILD_ROOT}/usr/include/

cp library.so* ${RPM_BUILD_ROOT}/%_libdir/
cp include/*.h* ${RPM_BUILD_ROOT}/usr/include/

%files
%defattr(-,root,root)
%_libdir/*.so.*

%files devel
%defattr(-,root,root)
%_libdir/*.so # yes; if you use version numbers; the versioned .so go in the normal package; the one without version number in the devel package
/usr/include/*

further reading: RPM packaging guide

Chris Maes
  • 35,025
  • 12
  • 111
  • 136
  • Erm I'm a bit confused, how does this work? Does the install section somehow automagicaly pick the right rpm for each command? They can be installed separately right, what's up with that? – Pyjong Jan 28 '20 at 15:11
  • 1
    in `%install` you install all files for all (sub)packages, you make the separation in the `%files` sections which are different for each (sub)package. – Chris Maes Jan 28 '20 at 15:21
  • Ahhh, ok my misconception was that I thought the commands in the install section are packed in the rpms as well. Ermm, but then once you have the rpms built. How do they know where to install what? – Pyjong Jan 28 '20 at 15:26
  • Actually that's really helpful. Thanks! – Pyjong Jan 28 '20 at 15:39