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 TC |
9 | use lib "inc"; |
10 | use Devel::CheckLib; | |
574c4fe0 TC |
11 | |
12 | my @incpaths; # places to look for headers | |
13 | my @libpaths; # places to look for libraries | |
14 | ||
15 | GetOptions("incpath=s", \@incpaths, | |
16 | "libpath=s" => \@libpaths); | |
0ddb7051 TC |
17 | |
18 | my @objs = qw/Screenshot.o/; | |
19 | my @cflags; | |
20 | my @lflags; | |
bc99c241 | 21 | my @lddlflags; |
8a7d6890 TC |
22 | my %seen_incdir; |
23 | my %seen_libdir; | |
0ddb7051 | 24 | my $X11_lib = $^O eq 'cygwin' ? 'X11.dll' : 'X11'; |
574c4fe0 TC |
25 | if (find_header("X11/Xlib.h", "X11 header") |
26 | and find_lib($X11_lib, "X11 library")) { | |
0ddb7051 TC |
27 | push @objs, 'scx11.o'; |
28 | push @cflags, '-DSS_X11'; | |
29 | push @lflags, '-l'.$X11_lib; | |
30 | print "Found X11\n"; | |
31 | } | |
574c4fe0 | 32 | if (find_header('windows.h', "Win32 header") |
47f35d89 TC |
33 | && find_lib('gdi32', "Win32 library") |
34 | || check_lib(header => "windows.h", | |
35 | lib => "gdi32", | |
36 | title => "Win32")) { | |
6f00ec2f | 37 | push @objs, 'scwin32.o', 'svwin32.o'; |
0ddb7051 TC |
38 | push @cflags, '-DSS_WIN32'; |
39 | if ($^O eq 'cygwin') { | |
40 | push @lflags, '-L/usr/lib/w32api', '-lgdi32'; | |
41 | } | |
42 | print "Found Win32\n"; | |
43 | } | |
44 | ||
759271f8 | 45 | if ($^O eq "darwin" and my ($rel) = `uname -r` =~ /^([0-9]+)/) { |
0cc0b6d7 | 46 | # this test is overly simple |
759271f8 TC |
47 | if ($rel < 11) { |
48 | push @objs, "scdarwin.o"; | |
49 | push @cflags, "-DSS_DARWIN"; | |
50 | push @lddlflags, qw/-framework OpenGL -framework Cocoa/; | |
51 | print "Found OS X (<11)\n"; | |
52 | } | |
53 | else { | |
54 | push @objs, "scdarwin2.o"; | |
55 | push @cflags, "-DSS_DARWIN"; | |
56 | push @lddlflags, qw/-framework Cocoa/; | |
57 | print "Found OS X (>=11)\n"; | |
58 | } | |
bc99c241 TC |
59 | } |
60 | ||
0ddb7051 | 61 | unless (@objs > 1) { |
574c4fe0 | 62 | die <<DEAD; |
7f198d6e | 63 | OS unsupported: Headers or libraries not found for a supported GUI |
574c4fe0 | 64 | |
7f198d6e | 65 | Sorry, I can't find headers or libraries for a supported GUI |
574c4fe0 TC |
66 | You need to install development headers and libraries for your GUI |
67 | For Win32: Platform SDK or a substitute | |
68 | For X11: X11 headers and libraries, eg. the libX11-dev package on Debian | |
bc99c241 | 69 | For OS X: Install Xcode |
574c4fe0 TC |
70 | |
71 | DEAD | |
0ddb7051 TC |
72 | } |
73 | ||
74 | my %opts = | |
75 | ( | |
76 | NAME => 'Imager::Screenshot', | |
77 | VERSION_FROM => 'Screenshot.pm', | |
78 | OBJECT => "@objs", | |
79 | PREREQ_PM => { | |
e5b9e4b8 | 80 | 'Imager' => 0.88, |
0ddb7051 TC |
81 | }, |
82 | INC => Imager::ExtUtils->includes, | |
83 | TYPEMAPS => [ Imager::ExtUtils->typemap ], | |
84 | ); | |
85 | ||
86 | $opts{LIBS} = "@lflags" if @lflags; | |
87 | $opts{INC} .= " @cflags" if @cflags; | |
88 | ||
bc99c241 TC |
89 | if (@lddlflags) { |
90 | $opts{LDDLFLAGS} = $Config{lddlflags} . " @lddlflags"; | |
91 | } | |
92 | ||
0cc0b6d7 | 93 | # avoid "... isn't numeric in numeric gt ..." warnings for dev versions |
37819a40 TC |
94 | my $eu_mm_version = eval $ExtUtils::MakeMaker::VERSION; |
95 | if ($eu_mm_version > 6.06) { | |
0ddb7051 TC |
96 | $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>'; |
97 | $opts{ABSTRACT} = 'Screen/Window capture to Imager images'; | |
98 | } | |
99 | ||
37819a40 TC |
100 | # LICENSE was introduced in 6.30_01, but Debian etch includes |
101 | # (as of 2007/01/12) an ExtUtils::MakeMaker versioned 6.30_01 without | |
102 | # LICENSE support | |
54f11a66 | 103 | # EXTRA_META was also introduced in 6.30_01 |
37819a40 | 104 | if ($eu_mm_version > 6.3001) { |
770c534e | 105 | $opts{LICENSE} = 'perl'; |
8cb7800a TC |
106 | } |
107 | if ($eu_mm_version >= 6.46) { | |
108 | $opts{META_MERGE} = | |
109 | { | |
110 | configure_requires => | |
111 | { | |
e5b9e4b8 | 112 | Imager => "0.88" |
8cb7800a TC |
113 | }, |
114 | build_requires => | |
115 | { | |
e5b9e4b8 | 116 | Imager => "0.88", |
8cb7800a | 117 | "Test::More" => "0.47", |
9f31212c TC |
118 | }, |
119 | dynamic_config => 1, | |
120 | resources => | |
121 | { | |
122 | homepage => "http://imager.perl.org/", | |
123 | repository => "git://git.imager.perl.org/imager-screenshot.git", | |
124 | bugtracker => "http://rt.cpan.org/NoAuth/Bugs.html?Dist=Imager-Screenshot", | |
125 | }, | |
8cb7800a | 126 | }; |
770c534e TC |
127 | } |
128 | ||
0ddb7051 TC |
129 | WriteMakefile(%opts); |
130 | ||
131 | my @incs; | |
132 | sub header_search_path { | |
133 | @incs and return @incs; | |
134 | ||
574c4fe0 TC |
135 | push @incs, map {; split /\Q$Config{path_sep}/ } @incpaths; |
136 | push @incs, split /\Q$Config{path_sep}/, $ENV{IM_INCPATH} | |
137 | if defined $ENV{IM_INCPATH}; | |
8a7d6890 | 138 | push @incs, '/usr/include', '/usr/X11R6/include' |
0ddb7051 TC |
139 | unless $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/; |
140 | push @incs, split /\Q$Config{path_sep}/, $ENV{INCLUDE} | |
141 | if $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/ and $ENV{INCLUDE}; | |
142 | push @incs, split ' ', $Config{locincpth} | |
143 | if $Config{locincpth}; | |
144 | push @incs, split /\Q$Config{path_sep}/, $Config{incpath} | |
145 | if $Config{incpath}; | |
146 | push @incs, '/usr/include/w32api', '/usr/X11R6/include' | |
147 | if $^O eq 'cygwin'; | |
148 | ||
149 | @incs = grep -d, @incs; | |
150 | ||
151 | @incs; | |
152 | } | |
153 | ||
154 | my @libs; | |
155 | sub library_search_path { | |
156 | @libs and return @libs; | |
157 | ||
574c4fe0 TC |
158 | push @libs, map {; split /\Q$Config{path_sep}/ } @libpaths; |
159 | push @incs, split /\Q$Config{path_sep}/, $ENV{IM_LIBPATH} | |
160 | if defined $ENV{IM_LIBPATH}; | |
8aca6763 | 161 | push @libs, '/usr/lib', '/usr/X11R6/lib' |
0ddb7051 TC |
162 | unless $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/; |
163 | push @libs, split /\Q$Config{path_sep}/, $ENV{LIB} | |
164 | if $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/ and $ENV{LIB}; | |
165 | push @libs, split ' ', $Config{loclibpth} | |
166 | if $Config{loclibpth}; | |
167 | push @libs, split /\Q$Config{path_sep}/, $Config{libpth} | |
168 | if $Config{libpth}; | |
169 | push @libs, '/usr/lib/w32api', '/usr/X11R6/lib' | |
170 | if $^O eq 'cygwin'; | |
171 | ||
172 | @libs = grep -d, @libs; | |
173 | ||
174 | @libs; | |
175 | } | |
176 | ||
0ddb7051 TC |
177 | sub _find_file { |
178 | my ($name, @where) = @_; | |
179 | ||
180 | grep -f File::Spec->catfile($_, $name), @where; | |
181 | } | |
182 | ||
f3391324 TC |
183 | sub _quote_spaces { |
184 | my $path = shift; | |
185 | ||
186 | if ($path =~ / /) { | |
187 | return qq("$path"); | |
188 | } | |
189 | ||
190 | return $path; | |
191 | } | |
192 | ||
0ddb7051 | 193 | sub find_header { |
574c4fe0 | 194 | my ($name, $description) = @_; |
8a7d6890 TC |
195 | my @found = _find_file($_[0], header_search_path()); |
196 | ||
197 | if (@found) { | |
f3391324 | 198 | push @cflags, _quote_spaces("-I$_") for grep !$seen_incdir{$_}, @found; |
574c4fe0 TC |
199 | @seen_incdir{@found} = (1) x @found; |
200 | } | |
201 | else { | |
202 | print STDERR "Could not find $name ($description)\n"; | |
8a7d6890 TC |
203 | } |
204 | ||
205 | @found; | |
0ddb7051 TC |
206 | } |
207 | ||
208 | sub find_lib { | |
574c4fe0 | 209 | my ($name, $description) = shift; |
0ddb7051 | 210 | my @found; |
574c4fe0 | 211 | my $libname; |
0ddb7051 | 212 | if ($^O eq 'MSWin32' && $Config{_a} eq '.lib') { |
574c4fe0 | 213 | $libname = $name . $Config{_a}; |
91eba490 | 214 | @found = _find_file($libname, library_search_path()); |
0ddb7051 TC |
215 | } |
216 | else { | |
574c4fe0 | 217 | $libname = "lib" . $name . $Config{_a}; |
91eba490 TC |
218 | @found = _find_file($libname, library_search_path()); |
219 | if (!@found && $Config{so}) { | |
220 | $libname = "lib" . $name . "." . $Config{so}; | |
221 | @found = _find_file($libname, library_search_path()); | |
222 | } | |
0ddb7051 TC |
223 | } |
224 | if (@found) { | |
8b4e133f | 225 | push @lflags, _quote_spaces("-L$_") for grep !$seen_libdir{$_}, @found; |
8a7d6890 | 226 | @seen_libdir{@found} = (1) x @found; |
0ddb7051 | 227 | } |
574c4fe0 TC |
228 | else { |
229 | print STDERR "Could not find $libname ($description)\n"; | |
230 | } | |
231 | ||
0ddb7051 TC |
232 | @found; |
233 | } | |
47f35d89 | 234 |