Re: Create two different rpms in the same spec file

Jos Vos <[email protected]> Sun, 20 Jan 2008 11:10:34 +0100
Newsgroups gmane.linux.redhat.rpm.general
Message-ID <[email protected]>
On Thu, Jan 17, 2008 at 02:45:55PM +0200, Doron Shoham wrote:

> I want to create two different rpms (one for redhat and the other for suse) in the same spec file.
> I have a file that is needed be in the same path (/etc/init) for both distros,
> The file's name is the same but its content is not the same for the two distros.
> How can I do it?
> Can %install can get "-n" as a parameter?

Why do you think of "-n"?  Will the resulting package have different
names on RH and SUSE?

Anyway, it's simple when you use the %if / %endif constructions.
Note that it's a matter of taste if you really want this.  In my
personal opinion, maintaining one spec file for multiple distros
often (with more complex packages) results in unnecessary complex
spec files.

Simplified example:


%if %(test -f /etc/redhat-release && echo 1 || echo 0)
%define target redhat
%endif

%if %(test -f ... && echo 1 || echo 0)
%define target suse
%endif

...

%install

%if %[target} == %{redhat}
cp %{SOURCE1} %{buildroot}/etc/rc.d/init.d/foo.init
%endif

%if %[target} == %{suse}
cp %{SOURCE2} %{buildroot}/etc/init.d/foo.init
%endif

...

%files

%if %[target} == %{redhat}
/etc/rc.d/init.d/foo.init
%endif
%if %[target} == %{suse}
/etc/init.d/foo.init
%endif


Note that this example is not complete and/or robust, of course.

-- 
--    Jos Vos <[email protected]>
--    X/OS Experts in Open Systems BV   |   Phone: +31 20 6938364
--    Amsterdam, The Netherlands        |     Fax: +31 20 6948204