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