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
|
package inc::MyMakeMaker;
# ABSTRACT: build a Makefile.PL that uses ExtUtils::MakeMaker
use Moose;
use namespace::autoclean;
extends 'Dist::Zilla::Plugin::DROLSKY::MakeMaker';
# We need to override this because we remove the DROLSKY::MakeMaker plugin
# from our config, and that's where this value is passed from our bundle.
has '+has_xs' => (
default => 1,
);
override _build_WriteMakefile_args => sub {
my $self = shift;
my $args = super();
$args->{PM} = {
'lib/File/LibMagic.pm' => '$(INST_LIB)/File/LibMagic.pm',
'lib/File/LibMagic/Constants.pm' =>
'$(INST_LIB)/File/LibMagic/Constants.pm',
};
$args->{LIBS} = '-lmagic';
delete $args->{VERSION};
$args->{VERSION_FROM} = 'lib/File/LibMagic.pm';
return $args;
};
override _build_WriteMakefile_dump => sub {
my $self = shift;
my $dump = super();
$dump .= <<'EOF';
$WriteMakefileArgs{DEFINE} = ( $WriteMakefileArgs{DEFINE} || q{} ) . _defines();
$WriteMakefileArgs{INC} = join q{ }, _includes();
$WriteMakefileArgs{LIBS} = join q{ }, _libs(), $WriteMakefileArgs{LIBS};
EOF
return $dump;
};
override _build_MakeFile_PL_template => sub {
return super() . do { local $/ = undef; <DATA> };
};
__PACKAGE__->meta->make_immutable;
1;
__DATA__
use Config::AutoConf;
use Getopt::Long;
my @libs;
my @includes;
sub _libs { return map { '-L' . $_ } @libs }
sub _includes { return map { '-I' . $_ } @includes }
sub _defines {
GetOptions(
'lib:s@' => \@libs,
'include:s@' => \@includes,
);
my $ac = Config::AutoConf->new(
extra_link_flags => [ _libs() ],
extra_include_dirs => \@includes,
);
_check_libmagic($ac);
my @defs;
push @defs, '-DHAVE_MAGIC_VERSION'
if $ac->check_lib( 'magic', 'magic_version' );
push @defs, '-DHAVE_MAGIC_SETPARAM'
if $ac->check_lib( 'magic', 'magic_setparam' );
push @defs, '-DHAVE_MAGIC_GETPARAM'
if $ac->check_lib( 'magic', 'magic_getparam' );
return q{} unless @defs;
return q{ } . join q{ }, @defs;
}
sub _check_libmagic {
my $ac = shift;
return
if $ac->check_header('magic.h')
&& $ac->check_lib( 'magic', 'magic_open' );
warn <<'EOF';
This module requires the libmagic.so library and magic.h header. See
INSTALL.md for more details on installing these.
EOF
exit 1;
}
|