WindowsでEncode::Detectを入れるためのMakefile.PL

を作った.Win32にEncode::Detectを入れる - Charsbar::Noteを参考にして,ちょっとだけ構成変えつつこれを自動でやるようにした.Encode-Detect-0.01のtarballを展開して,以下のソースをMakefile.PLとして置いてやれば,あとはおきまりの perl Makefile.PL から nmake install で.

自分の環境ではこれでうまくいったので,Detector.xs の extern "C" は外してません.

#!perl

use strict;
use warnings;
use ExtUtils::MakeMaker;
use File::Copy::Recursive qw(fmove);
use File::Slurp qw(slurp write_file);

my @DELETE = qw(Build.PL MANIFEST);

my %MOVE = (
  'Detect.pm'   => 'lib/Encode/Detect.pm',
  'Detector.pm' => 'lib/Encode/Detect/Detector.pm',
  'Detector.xs' => 'src/Detector.xs',
  'typemap'     => 'src/typemap',
);

# delete
unlink $_ for grep { -e } @DELETE;

# move
while (my ($source, $target) = each %MOVE) {
  fmove $source => $target if -e $source and not -e $target;
}

# write src/Makefile.PL
write_file 'src/Makefile.PL', slurp \*DATA;

# write Makefile
WriteMakefile(
  NAME         => 'Encode::Detect',
  VERSION_FROM => 'lib/Encode/Detect.pm',
  DIR          => ['src'],
  PREREQ_PM    => {
    'Test::More' => 0,
    'Data::Dump' => 0,
  },
);

__END__

use ExtUtils::MakeMaker;

WriteMakefile(
  NAME         => 'Encode::Detect::Detector',
  VERSION_FROM => '../lib/Encode/Detect/Detector.pm',
  INC          => '-I../include',
  XS           => { 'Detector.xs' => 'Detector.cpp', },
  OBJECT       => '$(O_FILES)',
);

sub MY::postamble {
  return q!.xs.cpp:
	$(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $(XSUBPP_EXTRA_ARGS) $*.xs > $*.xsc && $(MV) $*.xsc $*.cpp!;
}