in reply to How to know if a CPAN module uses XS

WriteMakefile returns a MM object which has has_link_code and needs_linking. Somehow calling these are your safest bet. If I had to try and do it, I would copy EUMM's WriteMakefile into my script, switch packages, define a new WriteMakefile based off EUMM's but without the flush() at the end, switch packages back to main, , run the makefile.pl with a do(), intercept the returning MM obj in my WriteMakefile, and call needs_linking(). The most complex use of EUMM I've ever seen was in Perl TK, and I did something similar to what I described to you to intercept Tk::MMutil::TkExtMakefile. Note this is not a "static" way of determining whether it needs to be compile, so security issues might be a problem for you.

Another solution would be to generate the makefile, then do backticks on your make tool running in "list commands and do not execute" mode, then parse that looking for your local C compiler.
  • Comment on Re: How to know if a CPAN module uses XS

Replies are listed 'Best First'.
Re^2: How to know if a CPAN module uses XS
by syphilis (Archbishop) on Jun 20, 2012 at 09:14 UTC
    I think the first difficulty (not necessarily a show-stopper) I see with that approach is that it relies on WriteMakefile() being run.
    However, some Makefile.PL's may abort prior to that happening - eg because $] is too low, or because $^O is inappropriate, or because some pre-requisite could not be found.

    Handle that, and you're probably on a winner.
    It may even be that if $] is too low or $^O is inappropriate, then you don't even need to know whether the module needs to be compiled ... and if the Makefile.PL aborts because a pre-requisite C library can't be found, then it should be safe to assume it's a module that needs compiling. But if the Makefile.PL aborts because a pre-requisite perl module could not be found, then all bets are off. (I've a notion that there are some modules that do that, though I can't provide an example.)

    then do backticks on your make tool running in "list commands and do not execute" mode

    And then there's Inline/Inline::C ... run make in "list commands and do not execute" mode when building Inline/Inline::C and you'll see no mention of any compiler. (But perhaps that's the right result anyway ... not sure about that one.)

    And, of course, not every distro has a Makefile.PL - and there's presumably a need to handle them, too. (That's the beauty of having a choice of 2 build systems - instead of solving a problem once, you get the added joy of having to solve it twice :-)

    Cheers,
    Rob