Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can an RPM spec file "include" other files?

Is there a kind of "include" directive in RPM spec? I couldn't find an answer by googling.

Motivation: I have a RPM spec template which the build process modifies with the version, revision and other build-specific data. This is done by sed currently. I think it would be cleaner if the spec would #include a build-specific definitions file, which would be generated by the build process, so I don't need to search and replace in the spec.

If there is no include, is there an idiomatic way to do this (quite common, I believe) task?

like image 296
davka Avatar asked May 26 '11 09:05

davka


People also ask

What is spec file in RPM?

What is a SPEC File? A SPEC file can be thought of as the "recipe" that the rpmbuild utility uses to actually build an RPM. It tells the build system what to do by defining instructions in a series of sections. The sections are defined in the Preamble and the Body.

What is a spec file?

Spec files are plain-text files that are used to construct spec strings. They consist of a sequence of directives separated by blank lines. The type of directive is determined by the first non-whitespace character on the line, which can be one of the following: % command.

What kind of file is required in order to build an RPM?

In order to build RPMs, you will need source code, which usually means a compressed tar file that also includes the SPEC file. The SPEC file typically contains instructions on how to build RPM, what files are part of package and where it should be installed.

What is in an RPM package?

An RPM package typically contains binary executables, along with relevant configuration files and documentation. The rpm program is a powerful package manager, which can be used to install, query, verify, update, erase and build software packages in the RPM format.


3 Answers

Sufficiently recent versions of rpmbuild certainly do support %include:

%include common.inc

Unfortunately, they aren't very smart about it -- there is no known set of directories, in which it will look for the requested files, for example. But it is there and variables are expanded, for example:

%include %{_topdir}/Common/common.inc
like image 65
Міша Avatar answered Oct 04 '22 04:10

Міша


RPM does not support includes.

I have solved similar problems with either m4 macro processor or by just concatenating parts of spec (when the "include" was at the beginning).

If you only need to pass a few variables at build time, and not include several lines from another file, you can run

rpmbuild --define 'myvar SOMEVALUE' -bb myspec.spec

and you can use %myvar in the spec.

like image 34
m1tk4 Avatar answered Oct 04 '22 04:10

m1tk4


I faced this same issue recently. I wanted to define multiple sub-packages that were similar, but each varied just slightly (they were language-specific RPMs). I didn't want to repeat the same boiler-plate stuff for each sub-package.

Here's a generic version of what I did:

%define foo_spec() %{expand:%(cat '%{myloc}/main-foo.spec')}
%{foo_spec bar}
%{foo_spec baz}
%{foo_spec qux}

The use of %{expand} ensures that %(cat) is only executed a single time, when the macro is defined. The content of the main-foo.spec file is then three times, and each time %1 in the main-foo.spec file expands to each of bar, baz and qux, in turn, allowing me to treat it as a template. You could easily expand this to more than one parameter, if you have the need (I did not).

like image 20
Bob Bell Avatar answered Oct 04 '22 04:10

Bob Bell