| 1 |
#!perl -w |
| 2 |
use strict; |
| 3 |
use ExtUtils::MakeMaker; |
| 4 |
use Getopt::Long; |
| 5 |
use Config; |
| 6 |
|
| 7 |
my $verbose = $ENV{IM_VERBOSE}; |
| 8 |
my @libpaths; |
| 9 |
my @incpaths; |
| 10 |
|
| 11 |
GetOptions("incpath=s", \@incpaths, |
| 12 |
"libpath=s" => \@libpaths, |
| 13 |
"verbose|v" => \$verbose); |
| 14 |
|
| 15 |
our $BUILDING_IMAGER; |
| 16 |
our %IMAGER_LIBS; |
| 17 |
|
| 18 |
my %opts = |
| 19 |
( |
| 20 |
NAME => 'Imager::Font::W32', |
| 21 |
VERSION_FROM => 'W32.pm', |
| 22 |
OBJECT => 'W32.o win32.o', |
| 23 |
clean => { FILES => 'testout' }, |
| 24 |
); |
| 25 |
|
| 26 |
if (eval { ExtUtils::MakeMaker->VERSION('6.46'); 1 }) { |
| 27 |
$opts{LICENSE} = "perl_5"; |
| 28 |
$opts{AUTHOR} = 'Tony Cook <[email protected]>'; |
| 29 |
$opts{ABSTRACT} = 'Win32 font driver for Imager'; |
| 30 |
$opts{META_MERGE} = |
| 31 |
{ |
| 32 |
'meta-spec' => |
| 33 |
{ |
| 34 |
version => "2", |
| 35 |
url => "https://metacpan.org/pod/CPAN::Meta::Spec", |
| 36 |
}, |
| 37 |
resources => |
| 38 |
{ |
| 39 |
homepage => "http://imager.perl.org/", |
| 40 |
repository => |
| 41 |
{ |
| 42 |
type => "git", |
| 43 |
url => "git://github.com/tonycoz/imager.git", |
| 44 |
web => "https://github.com/tonycoz/imager.git", |
| 45 |
}, |
| 46 |
bugtracker => |
| 47 |
{ |
| 48 |
web => "https://github.com/tonycoz/imager/issues", |
| 49 |
}, |
| 50 |
}, |
| 51 |
}; |
| 52 |
} |
| 53 |
|
| 54 |
my @inc; |
| 55 |
if ($BUILDING_IMAGER) { |
| 56 |
push @inc, "-I.."; |
| 57 |
unshift @INC, "../lib"; |
| 58 |
} |
| 59 |
else { |
| 60 |
unshift @INC, "inc"; |
| 61 |
print "Win32: building independently\n"; |
| 62 |
require Imager::ExtUtils; |
| 63 |
push @inc, Imager::ExtUtils->includes; |
| 64 |
$opts{TYPEMAPS} = [ Imager::ExtUtils->typemap ]; |
| 65 |
|
| 66 |
# Imager required configure through use |
| 67 |
my @Imager_req = ( Imager => "0.95" ); |
| 68 |
if (eval { ExtUtils::MakeMaker->VERSION('6.46'); 1 }) { |
| 69 |
$opts{META_MERGE}{prereqs} = |
| 70 |
{ |
| 71 |
configure => |
| 72 |
{ |
| 73 |
requires => |
| 74 |
{ |
| 75 |
@Imager_req, |
| 76 |
}, |
| 77 |
}, |
| 78 |
build => |
| 79 |
{ |
| 80 |
requires => |
| 81 |
{ |
| 82 |
@Imager_req, |
| 83 |
"Test::More" => "0.47", |
| 84 |
} |
| 85 |
}, |
| 86 |
runtime => |
| 87 |
{ |
| 88 |
requires => |
| 89 |
{ |
| 90 |
@Imager_req, |
| 91 |
} |
| 92 |
}, |
| 93 |
test => |
| 94 |
{ |
| 95 |
requires => |
| 96 |
{ |
| 97 |
"Test::More" => "0.47", |
| 98 |
} |
| 99 |
}, |
| 100 |
}; |
| 101 |
$opts{PREREQ_PM} = |
| 102 |
{ |
| 103 |
@Imager_req, |
| 104 |
XSLoader => 0, |
| 105 |
}; |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
require Imager::Probe; |
| 110 |
|
| 111 |
my %probe = |
| 112 |
( |
| 113 |
name => "Win32", |
| 114 |
inccheck => sub { -e File::Spec->catfile($_[0], "windows.h") }, |
| 115 |
libbase => "gdi32", |
| 116 |
testcode => _win32_test_code(), |
| 117 |
testcodeheaders => [ "stdio.h", "string.h", "windows.h" ], |
| 118 |
incpath => \@incpaths, |
| 119 |
libpath => \@libpaths, |
| 120 |
verbose => $verbose, |
| 121 |
); |
| 122 |
|
| 123 |
my $probe_res = Imager::Probe->probe(\%probe); |
| 124 |
if ($probe_res) { |
| 125 |
$IMAGER_LIBS{Win32} = 1; |
| 126 |
|
| 127 |
push @inc, $probe_res->{INC}; |
| 128 |
$opts{LIBS} = $probe_res->{LIBS}; |
| 129 |
$opts{DEFINE} = $probe_res->{DEFINE}; |
| 130 |
$opts{INC} = "@inc"; |
| 131 |
|
| 132 |
WriteMakefile(%opts); |
| 133 |
} |
| 134 |
else { |
| 135 |
$IMAGER_LIBS{Win32} = 0; |
| 136 |
|
| 137 |
if ($BUILDING_IMAGER) { |
| 138 |
ExtUtils::MakeMaker::WriteEmptyMakefile(%opts); |
| 139 |
} |
| 140 |
else { |
| 141 |
# fail in good way |
| 142 |
die "OS unsupported: Win32 libraries or headers not found\n"; |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
sub _win32_test_code { |
| 147 |
return <<'CODE'; |
| 148 |
HDC dc = GetDC(NULL); |
| 149 |
HDC bmpDc = CreateCompatibleDC(dc); |
| 150 |
DeleteDC(bmpDc); |
| 151 |
ReleaseDC(NULL, dc); |
| 152 |
return 0; |
| 153 |
CODE |
| 154 |
} |