Detecting version in a SPEC file

Lamont Peterson lamont at gurulabs.com
Sat Mar 10 18:21:35 UTC 2007


On Saturday 10 March 2007 09:43am, Peter Gordon wrote:
> On Sat, 2007-03-10 at 09:15 -0700, Lamont Peterson wrote:
> > I'm looking for "something_that_gets_version" to use something like this:
> >
> > %define gnupg_version "%something_that_gets_version gnupg"
> > %if "%gnupg_version" = "1.2"
> >    Patch1:     GnuPG-Interface-0.33.test-results-1.2.patch
> >    BuildRequires: gpg = 1.2
> > %else
> >    Patch1:     GnuPG-Interface-0.33.test-results-1.4.patch
> >    BuildRequires: gpg >= %{gnupg_version}
> > %endif
> >
> > I need it to work for all sorts of distros, not just RHEL, FC and not
> > just within buildsystems.
> >
> > Is there such a mechanism available for use in the SPEC file or do I need
> > to execure an external rpm command to query for that on my own?
>
> You could execute an `rpm -q` version query manually:

Yeah, that's basically what I'm trying now (still working on getting one of 
the patches built correctly too).  I was just hoping there was a way internal 
to rpmbuild so I wouldn't have to run an external command, thinking that 
would probably be cleaner.

> %define gnupg_ver_major_minor %(rpm -q gnupg --qf '%{version}' 2>/dev/null
> | cut -d '.' -f 1,2)

Right now, I'm doing:

%define gnupg_version %(rpm -q --queryformat '%{version}' gnupg 2>/dev/null | 
cut -d. -f 1,2)

> (That should all be on one line, in case it gets wrapped by your
> mailer.)

Yup.

> In fact, if your patches are named accordingly, you might be able to use
> that directly in the patch names:
>
> Patch1:	GnuPG-Interface-0.33.test-results.%{gnupg_ver_major_minor}.patch

I like that idea, but in this case, the latest version doesn't need a patch. 
If/when a future release of gnupg changes the output again that make this 
patch necessary, then I'll create another set of entries to deal with the 
current set of files for version 1.4.x, etc.

> Hope that helps.

It does.

However, I'm getting an error trying to run rpmbuild against the spec file:

   $ rpmbuild -ba perl-GnuPG-Interface.spec
   error: syntax error while parsing ==
   error: /home/lamontp/rpmbuild/SPECS/perl-GnuPG-Interface.spec:15: 
parseExpressionBoolean returns -1
   error: Package has no %description: perl-GnuPG-Interface

There is a %description (which works fine without this conditional stuff). 
Lines 15 is:

   %if "%gnupg_version" = "1.2"

I've double checked the exact command being used to define %gnupg_version and 
that is working correctly. This makes me think that I've got a syntax error 
on line 15, but it's such a simple line that I don't see what it could be.  
If I take out line 15 (and corresponding elements), it works just fine, so it 
really seems to be something wrong with the %if.

Any ideas?

BTW:  I've already spoken with the package maintainer for this package (in 
extras) and will be giving him the results of this for EPEL to be able to 
build this package, too.
-- 
Lamont Peterson <lamont at gurulabs.com>
Senior Instructor
Guru Labs, L.C. [ http://www.GuruLabs.com/ ]

NOTE:  All messages from this email address should be digitally signed with my
       0xDC0DD409 GPG key. It is available on the pgp.mit.edu keyserver as
       well as other keyservers that sync with MIT's.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/fedora-devel-list/attachments/20070310/a21c93dc/attachment.sig>


More information about the fedora-devel-list mailing list