I think ExtUtils::CBuilder is useful for detecting the presence of a
compiler. It has a "have_compiler" method that tells you whether a
compiler is present (by actually trying to compile a C file). For more
advanced uses, something like the aforementioned Devel::CheckLib will
probably be of great help.

What I've done (so that users have a choice) is provide alternate
implementations using Pure Perl and XS, and then have the Perl version
load the XS one if it's available (using eval { require ... })

It's good because
a) Lots of modules already do this
b) It means updates to one (say, fixing a bug in the Perl version)
doesn't require re-releasing of both
c) It means if someone has a C builder present but wants to use the
Perl version anyway (for whatever reason), they can do so.

You can look into Math::Random::ISAAC (pure perl) and
Math::Random::ISAAC::XS for these. The code is rather small.

On the other hand lots of other packages (version.pm for example) do
the whole Perl/XS selection t build-time. You may want to go that
route, too, and there are legitimate reasons for that choice.

On Tue, Oct 13, 2009 at 2:13 PM, Bill Ward <b...@wards.net> wrote:
> The Template Toolkit handles this with a command line option to Makefile.PL
> where you can build the toolkit with compiled code if the compiler is
> available.  I don't think it has automatic detection as well, but it might.
> In any case you might want to consult with the Template Toolkit authors.
> Their mailing list is:
> http://mail.template-toolkit.org/mailman/listinfo/templates
>
> If you come up with a better solution, Template Toolkit might want to use it
> as well.
>
> On Tue, Oct 13, 2009 at 3:17 AM, O. STeffen BEYer <ost...@gmail.com> wrote:
>>
>> Dear Perl module authors,
>>
>> 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!
>>
>> Best regards,
>>
>> Steffen Beyer
>>
>> http://www.engelschall.com/u/sb/download/
>>
>> http://search.cpan.org/author/STBEY
>
>
>
> --
> Check out my LEGO blog at http://www.brickpile.com/
> View my photos at http://flickr.com/photos/billward/
> Follow me at http://twitter.com/williamward
>

Reply via email to