Commit | Line | Data |
---|---|---|
0ddb7051 TC |
1 | #!perl -w |
2 | use strict; | |
3 | use ExtUtils::MakeMaker; | |
e5b9e4b8 | 4 | use Imager 0.88; |
0ddb7051 TC |
5 | use Imager::ExtUtils; |
6 | use Config; | |
7 | use File::Spec; | |
574c4fe0 | 8 | use Getopt::Long; |
47f35d89 | 9 | use lib "inc"; |
563b1064 | 10 | use Imager::Probe; |
574c4fe0 TC |
11 | |
12 | my @incpaths; # places to look for headers | |
13 | my @libpaths; # places to look for libraries | |
563b1064 | 14 | my $verbose; |
574c4fe0 TC |
15 | |
16 | GetOptions("incpath=s", \@incpaths, | |
563b1064 TC |
17 | "libpath=s" => \@libpaths, |
18 | "v|verbose" => \$verbose); | |
0ddb7051 TC |
19 | |
20 | my @objs = qw/Screenshot.o/; | |
21 | my @cflags; | |
22 | my @lflags; | |
bc99c241 | 23 | my @lddlflags; |
8a7d6890 TC |
24 | my %seen_incdir; |
25 | my %seen_libdir; | |
563b1064 TC |
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) { | |
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 |
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) { | |
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 | 72 | if ($^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 | 88 | unless (@objs > 1) { |
574c4fe0 | 89 | die <<DEAD; |
7f198d6e | 90 | OS unsupported: Headers or libraries not found for a supported GUI |
574c4fe0 | 91 | |
7f198d6e | 92 | Sorry, I can't find headers or libraries for a supported GUI |
574c4fe0 TC |
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 | |
bc99c241 | 96 | For OS X: Install Xcode |
574c4fe0 TC |
97 | |
98 | DEAD | |
0ddb7051 TC |
99 | } |
100 | ||
101 | my %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 |
118 | if (@lddlflags) { |
119 | $opts{LDDLFLAGS} = $Config{lddlflags} . " @lddlflags"; | |
120 | } | |
121 | ||
0cc0b6d7 | 122 | # avoid "... isn't numeric in numeric gt ..." warnings for dev versions |
37819a40 TC |
123 | my $eu_mm_version = eval $ExtUtils::MakeMaker::VERSION; |
124 | if ($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 | 133 | if ($eu_mm_version > 6.3001) { |
770c534e | 134 | $opts{LICENSE} = 'perl'; |
8cb7800a TC |
135 | } |
136 | if ($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 |
159 | WriteMakefile(%opts); |
160 | ||
563b1064 TC |
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 | |
0ddb7051 | 169 | } |