[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: Defining a macro if it is NOT yet defined
- From: Jeff Johnson <jbj JBJ ORG>
- To: rpm-list redhat com
- Subject: Re: Defining a macro if it is NOT yet defined
- Date: Sun, 27 Jan 2002 13:29:38 -0500
On Sun, Jan 27, 2002 at 07:05:05PM +0100, Alexander Skwar wrote:
> Hello.
>
> I'm trying to hack together a SPEC file which should build identically
> on RedHat, Mandrake and Debian machines. However, for the Mandrake
> build, I'd like to use some predefined macros (like %{update_menus}).
> Now, since I'd put %{update_menus} in the %post scriptlet, I want to
> have a "real" value there, and not just %{update_menus}, so that when a
> Mandrake user installs this package which is built on a Debian PC (where
> %update_menus is not defined) he'll still get the "real" value of
> %%update_menus.
>
> What I'm looking for is a way to %define a macro, if it's not yet
> defined. So something likd ifndef would be of good use here.
>
> I'm currently trying something like:
>
> %if %(echo %{?update_menus:1})
> # do nothing - update_menus is already defined
> %else
> %define update_menus some value here
> %endif
>
> But that's not working :( If %update_menus is already defined, the TRUE
> part is executed (which contains nothing but the comment). However, if
> update_menus is not defined, I'll get this error message:
>
> error: /home/askwar/rpm/SPECS/test.spec:41: parseExpressionBoolean returns -1
>
> Is there a way to do this?
>
> ---- a little later... ----
>
> Ah! I figured it out. I now have:
>
> %if !%(test "%{?update_menus:1}" = 1 && echo 1 || echo 0)
> %define update_menus some value
> %endif
>
> However, that's a little "clumsy". Is there a shorter way to do this?
IIRC this is gonna break (at least with some versions of rpm, I forget).
Remember macros have absolutely no context, so %define is recognized in
comments, in strings, on the false branch of %if conditions, *everywhere*.
However, you can test for existence, and then, if not defined, set a default
thusly
%{!?update_menus: %define update_menus some_value}
73 de Jeff
--
Jeff Johnson ARS N3NPQ
jbj@jbj.org (jbj@redhat.com)
Chapel Hill, NC
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
[]