Dear Perl Monks,

what would be the best way to detect whether a working C compiler is available at build time of a module (i.e., in Makefile.PL)?

I would like to install a (faster) XS version of a module if that is the case, and a (slower) pure-Perl implementation if not.

Remember that C compilers are not always available on all systems. Sometimes they cost heavy extra money, or sometimes you have to work with what's there on a customer's or provider's server (where frequently installing a C compiler is not an option due to company policies).

Thank you!

UPDATE:

In the meantime, I've adopted a mixed approach, using an "Inline"-like search of the PATH (as fallback) and the "have_compiler" method (which actually compiles and links a test file) when "ExtUtils::CBuilder" is available.

Look here: http://cpansearch.perl.org/src/STBEY/Date-Calc-6.1/Makefile.PL

After that, I dropped this approach altogether and went for the usual "wrapper" approach - "Date::Calc" is now (v6.2) a wrapper which tries to load "Date::Calc::XS", and failing that, loads "Date::Calc::PP".


In reply to How to best detect availability of C compiler in Makefile.PL? by stbey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.