0.009 release
[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;
8a7d6890
TC
21my %seen_incdir;
22my %seen_libdir;
0ddb7051 23my $X11_lib = $^O eq 'cygwin' ? 'X11.dll' : 'X11';
574c4fe0
TC
24if (find_header("X11/Xlib.h", "X11 header")
25 and find_lib($X11_lib, "X11 library")) {
0ddb7051
TC
26 push @objs, 'scx11.o';
27 push @cflags, '-DSS_X11';
28 push @lflags, '-l'.$X11_lib;
29 print "Found X11\n";
30}
574c4fe0 31if (find_header('windows.h', "Win32 header")
47f35d89
TC
32 && find_lib('gdi32', "Win32 library")
33 || check_lib(header => "windows.h",
34 lib => "gdi32",
35 title => "Win32")) {
0ddb7051
TC
36 push @objs, 'scwin32.o';
37 push @cflags, '-DSS_WIN32';
38 if ($^O eq 'cygwin') {
39 push @lflags, '-L/usr/lib/w32api', '-lgdi32';
40 }
41 print "Found Win32\n";
42}
43
44unless (@objs > 1) {
574c4fe0 45 die <<DEAD;
7f198d6e 46OS unsupported: Headers or libraries not found for a supported GUI
574c4fe0 47
7f198d6e 48Sorry, I can't find headers or libraries for a supported GUI
574c4fe0
TC
49You need to install development headers and libraries for your GUI
50For Win32: Platform SDK or a substitute
51For X11: X11 headers and libraries, eg. the libX11-dev package on Debian
52
53DEAD
0ddb7051
TC
54}
55
56my %opts =
57 (
58 NAME => 'Imager::Screenshot',
59 VERSION_FROM => 'Screenshot.pm',
60 OBJECT => "@objs",
61 PREREQ_PM => {
62 'Imager' => 0.54,
63 },
64 INC => Imager::ExtUtils->includes,
65 TYPEMAPS => [ Imager::ExtUtils->typemap ],
66 );
67
68$opts{LIBS} = "@lflags" if @lflags;
69$opts{INC} .= " @cflags" if @cflags;
70
37819a40
TC
71# avoid "... isn't numberic in numeric gt ..." warnings for dev versions
72my $eu_mm_version = eval $ExtUtils::MakeMaker::VERSION;
73if ($eu_mm_version > 6.06) {
0ddb7051
TC
74 $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>';
75 $opts{ABSTRACT} = 'Screen/Window capture to Imager images';
76}
77
37819a40
TC
78# LICENSE was introduced in 6.30_01, but Debian etch includes
79# (as of 2007/01/12) an ExtUtils::MakeMaker versioned 6.30_01 without
80# LICENSE support
54f11a66 81# EXTRA_META was also introduced in 6.30_01
37819a40 82if ($eu_mm_version > 6.3001) {
770c534e 83 $opts{LICENSE} = 'perl';
8cb7800a
TC
84}
85if ($eu_mm_version >= 6.46) {
86 $opts{META_MERGE} =
87 {
88 configure_requires =>
89 {
90 Imager => "0.54"
91 },
92 build_requires =>
93 {
94 Imager => "0.54",
95 "Test::More" => "0.47",
96 }
97 };
770c534e
TC
98}
99
0ddb7051
TC
100WriteMakefile(%opts);
101
102my @incs;
103sub header_search_path {
104 @incs and return @incs;
105
574c4fe0
TC
106 push @incs, map {; split /\Q$Config{path_sep}/ } @incpaths;
107 push @incs, split /\Q$Config{path_sep}/, $ENV{IM_INCPATH}
108 if defined $ENV{IM_INCPATH};
8a7d6890 109 push @incs, '/usr/include', '/usr/X11R6/include'
0ddb7051
TC
110 unless $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/;
111 push @incs, split /\Q$Config{path_sep}/, $ENV{INCLUDE}
112 if $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/ and $ENV{INCLUDE};
113 push @incs, split ' ', $Config{locincpth}
114 if $Config{locincpth};
115 push @incs, split /\Q$Config{path_sep}/, $Config{incpath}
116 if $Config{incpath};
117 push @incs, '/usr/include/w32api', '/usr/X11R6/include'
118 if $^O eq 'cygwin';
119
120 @incs = grep -d, @incs;
121
122 @incs;
123}
124
125my @libs;
126sub library_search_path {
127 @libs and return @libs;
128
574c4fe0
TC
129 push @libs, map {; split /\Q$Config{path_sep}/ } @libpaths;
130 push @incs, split /\Q$Config{path_sep}/, $ENV{IM_LIBPATH}
131 if defined $ENV{IM_LIBPATH};
8aca6763 132 push @libs, '/usr/lib', '/usr/X11R6/lib'
0ddb7051
TC
133 unless $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/;
134 push @libs, split /\Q$Config{path_sep}/, $ENV{LIB}
135 if $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/ and $ENV{LIB};
136 push @libs, split ' ', $Config{loclibpth}
137 if $Config{loclibpth};
138 push @libs, split /\Q$Config{path_sep}/, $Config{libpth}
139 if $Config{libpth};
140 push @libs, '/usr/lib/w32api', '/usr/X11R6/lib'
141 if $^O eq 'cygwin';
142
143 @libs = grep -d, @libs;
144
145 @libs;
146}
147
0ddb7051
TC
148sub _find_file {
149 my ($name, @where) = @_;
150
151 grep -f File::Spec->catfile($_, $name), @where;
152}
153
154sub find_header {
574c4fe0 155 my ($name, $description) = @_;
8a7d6890
TC
156 my @found = _find_file($_[0], header_search_path());
157
158 if (@found) {
574c4fe0
TC
159 push @cflags, "-I$_" for grep !$seen_incdir{$_}, @found;
160 @seen_incdir{@found} = (1) x @found;
161 }
162 else {
163 print STDERR "Could not find $name ($description)\n";
8a7d6890
TC
164 }
165
166 @found;
0ddb7051
TC
167}
168
169sub find_lib {
574c4fe0 170 my ($name, $description) = shift;
0ddb7051 171 my @found;
574c4fe0 172 my $libname;
0ddb7051 173 if ($^O eq 'MSWin32' && $Config{_a} eq '.lib') {
574c4fe0 174 $libname = $name . $Config{_a};
91eba490 175 @found = _find_file($libname, library_search_path());
0ddb7051
TC
176 }
177 else {
574c4fe0 178 $libname = "lib" . $name . $Config{_a};
91eba490
TC
179 @found = _find_file($libname, library_search_path());
180 if (!@found && $Config{so}) {
181 $libname = "lib" . $name . "." . $Config{so};
182 @found = _find_file($libname, library_search_path());
183 }
0ddb7051
TC
184 }
185 if (@found) {
8a7d6890
TC
186 push @lflags, "-L$_" for grep !$seen_libdir{$_}, @found;
187 @seen_libdir{@found} = (1) x @found;
0ddb7051 188 }
574c4fe0
TC
189 else {
190 print STDERR "Could not find $libname ($description)\n";
191 }
192
0ddb7051
TC
193 @found;
194}
47f35d89
TC
195
196# wrapper around assert lib that doesn't exit and doesn't die
197sub check_lib {
198 my (%opts) = @_;
199
200 my $title = delete $opts{title};
201 $title and print "Looking even harder for $title\n";
202
203 return eval { assert_lib(%opts); 1 };
204}