Tuesday 10 July 2007

More "RPM argh" or how to use %includes properly

It turns out that if you want to use includes in your .spec file and want the files to be included in the .src.rpm you have to declare those scripts as supplemental sources.

So instead of:
Name: foo
Version: x.y
Release: z
Summary: foo package
Group: Applications/System
Source: foo.tar.gz
Packager: Eddy Petrisor
BuildArch: noarch
BuildRoot: $RPM_BUILD_ROOT
....


You have to have:

Name: foo
Version: x.y
Release: z
Summary: foo package
Group: Applications/System
Source: foo.tar.gz
Source101: foo.pre.sh
Source102: foo.post.sh
Source103: foo.preun.sh
Source104: foo.postun.sh
Source105: foo.changelog
Packager: Eddy Petrisor
BuildArch: noarch
BuildRoot: $RPM_BUILD_ROOT
....

In case you want to have the scripts separated in different files and you use them all.

Note: the number in the "SourceXXX" is arbitrary but must be unique.

But mentioning the files as being Source... means you have to write:


%post
%include ../SOURCES/foo.post.sh

%preun
%include ../SOURCES/foo.preun.sh

%postun
%include ../SOURCES/foo.postun.sh


Instead of:


%post
%include foo.post.sh

%preun
%include foo.preun.sh

%postun
%include foo.postun.sh


Which should have been more reasonable...

RPM, please die... or grow some 21st century features... or some sense!!!


Update: Thanks to a few people, I was pointed out I am still not thinking in terms or RPM.
The proper way of writing the include without them looking odd is something like:

%post
%include %{SOURCE102}

4 comments:

Anonymous said...

Why would you want to use include files? I have never seen an rpm use include files. Stop using rpm as if you're creating a deb package.

eddyp said...

Why would you want to use include files? I have never seen an rpm use include files. Stop using rpm as if you're creating a deb package.

Because:
1. I keep in sync rpms, debs, ebuilds and more
2. is possible
3. is useful to split the spec in functional units, instead of having a huge blob
4. the mix of macros and section names (did you notice that sections are specified in the same way macros are?) is already too confusing and splitting maintainer scripts out of the spec makes the later more readable

Anonymous said...

What you really want is:

%post
%include %{SOURCE102}

But in general, don't use scriptlets. If you need them you've probably done something wrong.

Unknown said...

> BuildRoot: $RPM_BUILD_ROOT

That is very strange. BuildRoot should be setup to a temporary path, for example:
BuildRoot: %{_tmppath}/%{name}-root