Commit | Line | Data |
---|---|---|
718b8c97 TC |
1 | #!perl -w |
2 | use strict; | |
d24404be | 3 | use ExtUtils::MakeMaker; |
718b8c97 TC |
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; | |
d97c8dbd | 16 | our %IMAGER_LIBS; |
718b8c97 | 17 | |
718b8c97 TC |
18 | my %opts = |
19 | ( | |
20 | NAME => 'Imager::Font::W32', | |
21 | VERSION_FROM => 'W32.pm', | |
22 | OBJECT => 'W32.o win32.o', | |
3edd17c9 | 23 | clean => { FILES => 'testout' }, |
718b8c97 TC |
24 | ); |
25 | ||
572d5255 TC |
26 | if (eval { ExtUtils::MakeMaker->VERSION('6.46'); 1 }) { |
27 | $opts{LICENSE} = "perl_5"; | |
28 | $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>'; | |
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://git.imager.perl.org/imager.git", | |
44 | web => "http://git.imager.perl.org/imager.git", | |
45 | }, | |
46 | bugtracker => | |
47 | { | |
48 | web => "http://rt.cpan.org/NoAuth/Bugs.html?Dist=Imager", | |
49 | mailto => 'bug-Imager@rt.cpan.org', | |
50 | }, | |
51 | }, | |
52 | }; | |
53 | } | |
54 | ||
718b8c97 TC |
55 | my @inc; |
56 | if ($BUILDING_IMAGER) { | |
57 | push @inc, "-I.."; | |
58 | unshift @INC, "../lib"; | |
59 | } | |
60 | else { | |
61 | unshift @INC, "inc"; | |
62 | print "Win32: building independently\n"; | |
63 | require Imager::ExtUtils; | |
64 | push @inc, Imager::ExtUtils->includes; | |
65 | $opts{TYPEMAPS} = [ Imager::ExtUtils->typemap ]; | |
66 | ||
67 | # Imager required configure through use | |
5eac8456 | 68 | my @Imager_req = ( Imager => "0.95" ); |
572d5255 TC |
69 | if (eval { ExtUtils::MakeMaker->VERSION('6.46'); 1 }) { |
70 | $opts{META_MERGE}{prereqs} = | |
718b8c97 | 71 | { |
572d5255 TC |
72 | configure => |
73 | { | |
74 | requires => | |
75 | { | |
76 | @Imager_req, | |
77 | }, | |
78 | }, | |
79 | build => | |
718b8c97 | 80 | { |
572d5255 TC |
81 | requires => |
82 | { | |
83 | @Imager_req, | |
84 | "Test::More" => "0.47", | |
85 | } | |
718b8c97 | 86 | }, |
572d5255 | 87 | runtime => |
718b8c97 | 88 | { |
572d5255 TC |
89 | requires => |
90 | { | |
91 | @Imager_req, | |
92 | } | |
718b8c97 | 93 | }, |
572d5255 | 94 | test => |
718b8c97 | 95 | { |
572d5255 TC |
96 | requires => |
97 | { | |
98 | "Test::More" => "0.47", | |
99 | } | |
718b8c97 TC |
100 | }, |
101 | }; | |
102 | $opts{PREREQ_PM} = | |
103 | { | |
104 | @Imager_req, | |
a5919365 | 105 | XSLoader => 0, |
718b8c97 TC |
106 | }; |
107 | } | |
108 | } | |
109 | ||
110 | require Imager::Probe; | |
111 | ||
112 | my %probe = | |
113 | ( | |
114 | name => "Win32", | |
115 | inccheck => sub { -e File::Spec->catfile($_[0], "windows.h") }, | |
116 | libbase => "gdi32", | |
117 | testcode => _win32_test_code(), | |
118 | testcodeheaders => [ "stdio.h", "string.h", "windows.h" ], | |
0c3c1180 TC |
119 | incpath => \@incpaths, |
120 | libpath => \@libpaths, | |
0987aae1 | 121 | verbose => $verbose, |
718b8c97 TC |
122 | ); |
123 | ||
124 | my $probe_res = Imager::Probe->probe(\%probe); | |
125 | if ($probe_res) { | |
d97c8dbd TC |
126 | $IMAGER_LIBS{Win32} = 1; |
127 | ||
718b8c97 TC |
128 | push @inc, $probe_res->{INC}; |
129 | $opts{LIBS} = $probe_res->{LIBS}; | |
03e49392 | 130 | $opts{DEFINE} = $probe_res->{DEFINE}; |
718b8c97 TC |
131 | $opts{INC} = "@inc"; |
132 | ||
718b8c97 TC |
133 | WriteMakefile(%opts); |
134 | } | |
135 | else { | |
d97c8dbd TC |
136 | $IMAGER_LIBS{Win32} = 0; |
137 | ||
718b8c97 | 138 | if ($BUILDING_IMAGER) { |
d24404be | 139 | ExtUtils::MakeMaker::WriteEmptyMakefile(%opts); |
718b8c97 TC |
140 | } |
141 | else { | |
142 | # fail in good way | |
143 | die "OS unsupported: Win32 libraries or headers not found\n"; | |
144 | } | |
145 | } | |
146 | ||
147 | sub _win32_test_code { | |
148 | return <<'CODE'; | |
149 | HDC dc = GetDC(NULL); | |
150 | HDC bmpDc = CreateCompatibleDC(dc); | |
151 | DeleteDC(bmpDc); | |
152 | ReleaseDC(NULL, dc); | |
153 | return 0; | |
154 | CODE | |
155 | } |