----- Original Message ----- 
From: "muppet" <[EMAIL PROTECTED]>
To: "Sisyphus" <[EMAIL PROTECTED]>
Cc: "xs" <perl-xs@perl.org>
Sent: Sunday, November 26, 2006 1:05 PM
Subject: Re: Determining OS type and perl version


>
> On Nov 25, 2006, at 7:26 PM, Sisyphus wrote:
>
> > Hi,
> > Where do I find the definitions (assuming such exist) that I can
> > use to
> > determine from within an XSub:
> >
> > 1) The operating system in use (specifically, whether it's Cygwin);
> > 2) The version of perl (specifically, whether it's >= 5.6.1);
> >
> > In the past I've used the values of $] and $^O to DEFINE my own
> > symbols in
> > the Makefile.PL - which works fine, but is a little silly if the
> > info the
> > XSub needs is already available.
>
> You can use those variables in XS the same as in perl code.

Sorry - I didn't specify it, but I was wanting to do it with the
pre-processor:

SV * foo(Sv * arg) {
#ifdef USING_CYGWIN
// do stuff
#else
// do other stuff
#endif
}

SV * bar(Sv * arg) {
#ifdef PERL561_OR_LATER
// do it one way
#else
// do it another way
#endif
}

.
.
.
>
> But the perlvar manpage warns against using $^O on windows...
>

The main concern there seems to be that $^O doesn't distinguish between the
various Windows versions (95, 98, XP, etc.).
That's rarely an issue - and Win32.pm has a function to deal with that issue
when it *does* arise.

>
> Dunno if that's relevant for using Cygwin.
>

I think $^O would be suitable for my purposes wrt Cygwin - but, rather than
do it with a callback, I'd probably just put something like the following in
the WriteMakefile() section of the Makefile.PL:

DEFINE => $^O =~ /cygwin/i ? '-DUSING_CYGWIN' : '',

And I'm quite happy to do it that way - it's just I expected there would be
an #ifdef already in place that I ought to instead be using.
Not so ?

Cheers,
Rob

Reply via email to