0.014 release
[imager-screenshot.git] / Makefile.PL
CommitLineData
0ddb7051
TC
1#!perl -w
2use strict;
3use ExtUtils::MakeMaker;
e5b9e4b8 4use Imager 0.88;
0ddb7051
TC
5use Imager::ExtUtils;
6use Config;
7use File::Spec;
574c4fe0 8use Getopt::Long;
47f35d89 9use lib "inc";
563b1064 10use Imager::Probe;
574c4fe0
TC
11
12my @incpaths; # places to look for headers
13my @libpaths; # places to look for libraries
563b1064 14my $verbose;
574c4fe0
TC
15
16GetOptions("incpath=s", \@incpaths,
563b1064
TC
17 "libpath=s" => \@libpaths,
18 "v|verbose" => \$verbose);
0ddb7051
TC
19
20my @objs = qw/Screenshot.o/;
21my @cflags;
22my @lflags;
bc99c241 23my @lddlflags;
8a7d6890
TC
24my %seen_incdir;
25my %seen_libdir;
563b1064
TC
26my @inc = Imager::ExtUtils->includes;
27my %x11_probe =
28 (
29 name => "X11",
30 libbase => "X11",
31 inccheck => sub { -e File::Spec->catfile($_[0], "X11/Xlib.h") },
32 verbose => $verbose,
33 libpath => [ @libpaths, "/usr/X11R6/lib", "/usr/X11/lib" ],
34 incpath => [ @incpaths, "/usr/X11R6/include", "/usr/X11/include" ],
35 );
36$x11_probe{alternatives} =
37 [
38 {
39 altname => "Cygwin",
40 libbase => "X11.dll",
41 },
42 ] if $^O eq "cygwin";
43my $x11_result = Imager::Probe->probe(\%x11_probe);
44if ($x11_result) {
0ddb7051 45 push @objs, 'scx11.o';
563b1064
TC
46 push @cflags, '-DSS_X11', $x11_result->{DEFINE};
47 push @lflags, $x11_result->{LIBS};
48 push @inc, $x11_result->{INC};
0ddb7051
TC
49 print "Found X11\n";
50}
563b1064
TC
51my %win32_probe =
52 (
53 name => "Win32",
54 inccheck => sub { -e File::Spec->catfile($_[0], "windows.h") },
55 libbase => "gdi32",
56 testcode => _win32_test_code(),
57 testcodeheaders => [ "stdio.h", "string.h", "windows.h" ],
58 incpath => \@incpaths,
59 libpath => \@libpaths,
60 verbose => $verbose,
61 );
62my $win32_result = Imager::Probe->probe(\%win32_probe);
63if ($win32_result) {
6f00ec2f 64 push @objs, 'scwin32.o', 'svwin32.o';
563b1064 65 push @cflags, '-DSS_WIN32', $win32_result->{DEFINE};
0ddb7051
TC
66 if ($^O eq 'cygwin') {
67 push @lflags, '-L/usr/lib/w32api', '-lgdi32';
68 }
69 print "Found Win32\n";
70}
71
759271f8 72if ($^O eq "darwin" and my ($rel) = `uname -r` =~ /^([0-9]+)/) {
0cc0b6d7 73 # this test is overly simple
759271f8
TC
74 if ($rel < 11) {
75 push @objs, "scdarwin.o";
76 push @cflags, "-DSS_DARWIN";
77 push @lddlflags, qw/-framework OpenGL -framework Cocoa/;
78 print "Found OS X (<11)\n";
79 }
80 else {
81 push @objs, "scdarwin2.o";
82 push @cflags, "-DSS_DARWIN";
83 push @lddlflags, qw/-framework Cocoa/;
84 print "Found OS X (>=11)\n";
85 }
bc99c241
TC
86}
87
0ddb7051 88unless (@objs > 1) {
574c4fe0 89 die <<DEAD;
7f198d6e 90OS unsupported: Headers or libraries not found for a supported GUI
574c4fe0 91
7f198d6e 92Sorry, I can't find headers or libraries for a supported GUI
574c4fe0
TC
93You need to install development headers and libraries for your GUI
94For Win32: Platform SDK or a substitute
95For X11: X11 headers and libraries, eg. the libX11-dev package on Debian
bc99c241 96For OS X: Install Xcode
574c4fe0
TC
97
98DEAD
0ddb7051
TC
99}
100
101my %opts =
102 (
103 NAME => 'Imager::Screenshot',
104 VERSION_FROM => 'Screenshot.pm',
105 OBJECT => "@objs",
106 PREREQ_PM => {
e5b9e4b8 107 'Imager' => 0.88,
563b1064 108 'Imager::Probe' => 0,
e5b8f93d 109 'XSLoader' => 0,
0ddb7051 110 },
563b1064 111 INC => "@inc",
0ddb7051
TC
112 TYPEMAPS => [ Imager::ExtUtils->typemap ],
113 );
114
115$opts{LIBS} = "@lflags" if @lflags;
116$opts{INC} .= " @cflags" if @cflags;
117
bc99c241
TC
118if (@lddlflags) {
119 $opts{LDDLFLAGS} = $Config{lddlflags} . " @lddlflags";
120}
121
0cc0b6d7 122# avoid "... isn't numeric in numeric gt ..." warnings for dev versions
37819a40
TC
123my $eu_mm_version = eval $ExtUtils::MakeMaker::VERSION;
124if ($eu_mm_version > 6.06) {
0ddb7051
TC
125 $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>';
126 $opts{ABSTRACT} = 'Screen/Window capture to Imager images';
127}
128
37819a40
TC
129# LICENSE was introduced in 6.30_01, but Debian etch includes
130# (as of 2007/01/12) an ExtUtils::MakeMaker versioned 6.30_01 without
131# LICENSE support
54f11a66 132# EXTRA_META was also introduced in 6.30_01
37819a40 133if ($eu_mm_version > 6.3001) {
770c534e 134 $opts{LICENSE} = 'perl';
8cb7800a
TC
135}
136if ($eu_mm_version >= 6.46) {
137 $opts{META_MERGE} =
138 {
139 configure_requires =>
140 {
563b1064
TC
141 Imager => "0.88",
142 'Imager::Probe' => 0,
8cb7800a
TC
143 },
144 build_requires =>
145 {
e5b9e4b8 146 Imager => "0.88",
8cb7800a 147 "Test::More" => "0.47",
9f31212c
TC
148 },
149 dynamic_config => 1,
150 resources =>
151 {
152 homepage => "http://imager.perl.org/",
153 repository => "git://git.imager.perl.org/imager-screenshot.git",
154 bugtracker => "http://rt.cpan.org/NoAuth/Bugs.html?Dist=Imager-Screenshot",
155 },
8cb7800a 156 };
770c534e
TC
157}
158
0ddb7051
TC
159WriteMakefile(%opts);
160
563b1064
TC
161sub _win32_test_code {
162 return <<'CODE';
163HDC dc = GetDC(NULL);
164HDC bmpDc = CreateCompatibleDC(dc);
165DeleteDC(bmpDc);
166ReleaseDC(NULL, dc);
167return 0;
168CODE
0ddb7051 169}