]> git.imager.perl.org - imager-screenshot.git/blob - Makefile.PL
0.014 release
[imager-screenshot.git] / Makefile.PL
1 #!perl -w
2 use strict;
3 use ExtUtils::MakeMaker;
4 use Imager 0.88;
5 use Imager::ExtUtils;
6 use Config;
7 use File::Spec;
8 use Getopt::Long;
9 use lib "inc";
10 use Imager::Probe;
11
12 my @incpaths; # places to look for headers
13 my @libpaths; # places to look for libraries
14 my $verbose;
15
16 GetOptions("incpath=s", \@incpaths,
17            "libpath=s" => \@libpaths,
18            "v|verbose" => \$verbose);
19
20 my @objs = qw/Screenshot.o/;
21 my @cflags;
22 my @lflags;
23 my @lddlflags;
24 my %seen_incdir;
25 my %seen_libdir;
26 my @inc = Imager::ExtUtils->includes;
27 my %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";
43 my $x11_result = Imager::Probe->probe(\%x11_probe);
44 if ($x11_result) {
45   push @objs, 'scx11.o';
46   push @cflags, '-DSS_X11', $x11_result->{DEFINE};
47   push @lflags, $x11_result->{LIBS};
48   push @inc, $x11_result->{INC};
49   print "Found X11\n";
50 }
51 my %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   );
62 my $win32_result = Imager::Probe->probe(\%win32_probe);
63 if ($win32_result) {
64   push @objs, 'scwin32.o', 'svwin32.o';
65   push @cflags, '-DSS_WIN32', $win32_result->{DEFINE};
66   if ($^O eq 'cygwin') {
67     push @lflags, '-L/usr/lib/w32api', '-lgdi32';
68   }
69   print "Found Win32\n";
70 }
71
72 if ($^O eq "darwin" and my ($rel) = `uname -r` =~ /^([0-9]+)/) {
73   # this test is overly simple
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   }
86 }
87
88 unless (@objs > 1) {
89   die <<DEAD;
90 OS unsupported: Headers or libraries not found for a supported GUI
91
92 Sorry, I can't find headers or libraries for a supported GUI
93 You need to install development headers and libraries for your GUI
94 For Win32: Platform SDK or a substitute
95 For X11: X11 headers and libraries, eg. the libX11-dev package on Debian
96 For OS X: Install Xcode
97
98 DEAD
99 }
100
101 my %opts = 
102   (
103    NAME => 'Imager::Screenshot',
104    VERSION_FROM => 'Screenshot.pm',
105    OBJECT => "@objs",
106    PREREQ_PM => {
107                  'Imager'    => 0.88,
108                  'Imager::Probe' => 0,
109                  'XSLoader'  => 0,
110                 },
111    INC => "@inc",
112    TYPEMAPS => [ Imager::ExtUtils->typemap ],
113   );
114
115 $opts{LIBS} = "@lflags" if @lflags;
116 $opts{INC} .= " @cflags" if @cflags;
117
118 if (@lddlflags) {
119   $opts{LDDLFLAGS} = $Config{lddlflags} . " @lddlflags";
120 }
121
122 # avoid "... isn't numeric in numeric gt ..." warnings for dev versions
123 my $eu_mm_version = eval $ExtUtils::MakeMaker::VERSION;
124 if ($eu_mm_version > 6.06) {
125   $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>';
126   $opts{ABSTRACT} = 'Screen/Window capture to Imager images';
127 }
128
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
132 # EXTRA_META was also introduced in 6.30_01
133 if ($eu_mm_version > 6.3001) {
134   $opts{LICENSE} = 'perl';
135 }
136 if ($eu_mm_version >= 6.46) {
137   $opts{META_MERGE} =
138     {
139      configure_requires => 
140      {
141       Imager => "0.88",
142       'Imager::Probe' => 0,
143      },
144      build_requires => 
145      {
146       Imager => "0.88",
147       "Test::More" => "0.47",
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      },
156     };
157 }
158
159 WriteMakefile(%opts);
160
161 sub _win32_test_code {
162   return <<'CODE';
163 HDC dc = GetDC(NULL);
164 HDC bmpDc = CreateCompatibleDC(dc);
165 DeleteDC(bmpDc);
166 ReleaseDC(NULL, dc);
167 return 0;
168 CODE
169 }