http://www.perlmonks.org?node_id=281966


in reply to Forks.pm dilemma

Perhaps you could determine the version of perl during the makefile building process, set a proper variable, and then run the XS code through some kind of preprocessor? I'm not sure how ExtUtils::MM does things, so I can't comment on the difficulty. Considering all the work that DBD::Oracle does when you do perl Makefile.PL, it must be possible.
PERL_VER = `perl -e 'print $['` preprocess: @cpp -DPERL_VAR=${PERL_VAR} forks.xs forks.i @mv forks.i forks.xs
In forks.xs, use happy fun #ifdefs to partition the code. What do you think?

Replies are listed 'Best First'.
Re: Re: Forks.pm dilemma
by liz (Monsignor) on Aug 07, 2003 at 18:11 UTC
    PERL_VER = `perl -e 'print $['`

    I assume you mean:

    PERL_VER = `$^X -e 'print $]'`
    as you cannot be sure the Makefile.PL is called by "perl". And note it should be $] rather than $[

    Actually, if I would have to resort to that, it would probably be easier to not define a macro for 5.6.x, and define a macro with the the PROTOTYPE: string for all other versions.

    Liz

    Update:
    While investigating something about $[, I realized there was an error in this node. So I changed $[ to $] where appropriate and added a comment.

      That's exactly what I meant ;) I wonder if the xsubpp maintainer (is there one?) can be convinced to allow a pre-processing option, similar to 'perl -P'.
        Here is a patch which adds preliminary pre-processor support to xsubpp. There's a few caveats. #line will now be incorrect, since the #includes now occur BEFORE xsubpp gets to them (I wonder if there's a way to disable those directives). As soon as I get better testing done, I'll send this in to whoever is supposed to see it. To invoke, use xsubpp -preprocess blah
        *** xsubpp.old Fri Aug 8 13:18:20 2003 --- xsubpp Fri Aug 8 13:13:23 2003 *************** *** 164,169 **** --- 164,170 ---- $process_inout = 1, next SWITCH if $flag eq 'inout'; $process_argtypes = 0, next SWITCH if $flag eq 'noargtype +s'; $process_argtypes = 1, next SWITCH if $flag eq 'argtypes' +; + $preprocess = 1, next SWITCH if $flag eq 'preprocess'; (print "xsubpp version $XSUBPP_version\n"), exit if $flag eq 'v'; die $usage; *************** *** 883,889 **** $text; } ! open($FH, $filename) or die "cannot open $filename: $!\n"; # Identify the version of xsubpp used print <<EOM ; --- 884,895 ---- $text; } ! if ( $preprocess ) { ! open($FH, "$Config{cpp} $filename |") ! or die "cannot open $Config{cpp} $filename: $!\n"; ! } else { ! open($FH, $filename) or die "cannot open $filename: $!\n"; ! }