1require 5.004;
2use ExtUtils::MakeMaker;
3
4use Config qw(%Config);
5
6for (@ARGV) {
7  /^-pm/ and $no_xs = 1;
8  /^-xs/ and $no_xs = 0;
9}
10
11sub init {
12  my $hash = $_[1];
13  if ($no_xs) {
14    @{$hash}{XS,C} = ( {}, [] );
15  }
16  $hash;
17}
18
19sub write_makefile {
20  WriteMakefile(
21    NAME         => 'Digest::CRC',
22    VERSION_FROM => 'lib/Digest/CRC.pm', # finds $VERSION
23    PL_FILES     => {},
24    CONFIGURE    => \&init,
25    clean        => {FILES => 'test.c typemap'}
26  );
27}
28
29sub no_cc {
30  $no_xs = 1;
31  print <<"EDQ";
32
33 I cannot determine if you have a C compiler
34 so I will install a perl-only implementation
35
36 You can force installation of the XS version with
37
38    perl Makefile.PL -xs
39
40EDQ
41  write_makefile();
42  exit;
43}
44
45if ($] < 5.006001) {
46  open(TYPEMAP,">typemap");
47  print TYPEMAP <<'EOS';
48NV                      T_NV
49UV                      T_UV
50
51INPUT
52T_NV
53	$var = ($type)SvNV($arg)
54T_UV
55	$var = ($type)SvUV($arg)
56
57OUTPUT
58T_NV
59	sv_setnv($arg, (NV)$var);
60T_UV
61	sv_setuv($arg, (UV)$var);
62
63EOS
64  close(TYPEMAP);
65}
66
67write_makefile();
68
69exit if defined $no_xs;
70
71print "Testing if you have a C compiler\n";
72
73open(F,">test.c") or no_cc();
74print F <<EOF;
75int main() { return 0; }
76EOF
77close(F) or no_cc();
78$make = $Config{make} || 'make';
79system("$make test$Config{obj_ext}") and no_cc();
80
81