/usr/share/perl5/Devel/CheckCompiler.pm is in libdevel-checkcompiler-perl 0.05-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | package Devel::CheckCompiler;
use strict;
use warnings;
use 5.008001;
our $VERSION = '0.05';
use parent qw/Exporter/;
our @EXPORT = qw/check_c99 check_c99_or_exit check_compile/;
use ExtUtils::CBuilder;
my $C99_SOURCE = <<'C99';
// include a C99 header
#include <stdbool.h>
inline // a C99 keyword with C99 style comments
int test_c99() {
int i = 0;
i++;
int j = i - 1; // another C99 feature: declaration after statement
return j;
}
C99
sub check_c99 {
check_compile($C99_SOURCE);
}
sub check_c99_or_exit {
check_compile($C99_SOURCE) or do {
warn "Your system is not support C99(OS unsupported)\n";
exit 0;
};
}
sub check_compile {
my ($src, %opt) = @_;
my $cbuilder = ExtUtils::CBuilder->new(quiet => 1);
return 0 unless $cbuilder->have_compiler;
require File::Temp;
my $tmpfile = File::Temp->new(SUFFIX => '.c');
$tmpfile->print($src);
$tmpfile->close();
my $objname = eval {
$cbuilder->compile(source => $tmpfile->filename);
};
if ($objname) {
my $ret = 1;
if ($opt{executable}) {
my $execfile = eval {
$cbuilder->link_executable(objects => $objname,
extra_linker_flags => $opt{extra_linker_flags});
};
if ($execfile) {
unlink $execfile or warn "Cannot unlink $execfile (ignored): $!";
} else {
$ret = 0;
}
}
unlink $objname or warn "Cannot unlink $objname (ignored): $!";
return $ret;
} else {
return 0;
}
}
1;
__END__
=encoding utf8
=head1 NAME
Devel::CheckCompiler - Check the compiler's availability
=head1 SYNOPSIS
use Devel::CheckCompiler;
check_c99_or_exit();
=head1 DESCRIPTION
Devel::CheckCompiler is checker for compiler's availability.
=head1 FUNCTIONS
=over 4
=item C<check_c99()>
Returns true if the current system has a working C99 compiler, false otherwise.
=item C<check_c99_or_exit()>
Check the current system has a working C99 compiler, if it's not available, exit by 0.
=item C<check_compile($src: Str, %options)>
Compile C<$src> as C code. Return 1 if it's available, 0 otherwise.
Possible options are:
=over
=item executable :Bool = false
Check to see if generating executable is possible if this parameter is true.
=item extra_linker_flags : Str | ArrayRef[Str]
Any additional flags you wish to pass to the linker. This option is used
only when C<executable> option specified.
=back
=back
=head1 AUTHOR
Tokuhiro Matsuno E<lt>tokuhirom AAJKLFJEF@ GMAIL COME<gt>
=head1 SEE ALSO
L<ExtUtils::CBuilder>
=head1 LICENSE
Copyright (C) Tokuhiro Matsuno
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
|