3 use ExtUtils::MakeMaker;
12 my @incpaths; # places to look for headers
13 my @libpaths; # places to look for libraries
15 GetOptions("incpath=s", \@incpaths,
16 "libpath=s" => \@libpaths);
18 my @objs = qw/Screenshot.o/;
24 my $X11_lib = $^O eq 'cygwin' ? 'X11.dll' : 'X11';
25 if (find_header("X11/Xlib.h", "X11 header")
26 and find_lib($X11_lib, "X11 library")) {
27 push @objs, 'scx11.o';
28 push @cflags, '-DSS_X11';
29 push @lflags, '-l'.$X11_lib;
32 if (find_header('windows.h', "Win32 header")
33 && find_lib('gdi32', "Win32 library")
34 || check_lib(header => "windows.h",
37 push @objs, 'scwin32.o';
38 push @cflags, '-DSS_WIN32';
39 if ($^O eq 'cygwin') {
40 push @lflags, '-L/usr/lib/w32api', '-lgdi32';
42 print "Found Win32\n";
45 if ($^O eq "darwin") {
46 push @objs, "scdarwin.o";
47 push @cflags, "-DSS_DARWIN";
48 push @lddlflags, qw/-framework OpenGL -framework Cocoa/;
54 OS unsupported: Headers or libraries not found for a supported GUI
56 Sorry, I can't find headers or libraries for a supported GUI
57 You need to install development headers and libraries for your GUI
58 For Win32: Platform SDK or a substitute
59 For X11: X11 headers and libraries, eg. the libX11-dev package on Debian
60 For OS X: Install Xcode
67 NAME => 'Imager::Screenshot',
68 VERSION_FROM => 'Screenshot.pm',
73 INC => Imager::ExtUtils->includes,
74 TYPEMAPS => [ Imager::ExtUtils->typemap ],
77 $opts{LIBS} = "@lflags" if @lflags;
78 $opts{INC} .= " @cflags" if @cflags;
81 $opts{LDDLFLAGS} = $Config{lddlflags} . " @lddlflags";
84 # avoid "... isn't numberic in numeric gt ..." warnings for dev versions
85 my $eu_mm_version = eval $ExtUtils::MakeMaker::VERSION;
86 if ($eu_mm_version > 6.06) {
87 $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>';
88 $opts{ABSTRACT} = 'Screen/Window capture to Imager images';
91 # LICENSE was introduced in 6.30_01, but Debian etch includes
92 # (as of 2007/01/12) an ExtUtils::MakeMaker versioned 6.30_01 without
94 # EXTRA_META was also introduced in 6.30_01
95 if ($eu_mm_version > 6.3001) {
96 $opts{LICENSE} = 'perl';
98 if ($eu_mm_version >= 6.46) {
101 configure_requires =>
108 "Test::More" => "0.47",
113 WriteMakefile(%opts);
116 sub header_search_path {
117 @incs and return @incs;
119 push @incs, map {; split /\Q$Config{path_sep}/ } @incpaths;
120 push @incs, split /\Q$Config{path_sep}/, $ENV{IM_INCPATH}
121 if defined $ENV{IM_INCPATH};
122 push @incs, '/usr/include', '/usr/X11R6/include'
123 unless $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/;
124 push @incs, split /\Q$Config{path_sep}/, $ENV{INCLUDE}
125 if $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/ and $ENV{INCLUDE};
126 push @incs, split ' ', $Config{locincpth}
127 if $Config{locincpth};
128 push @incs, split /\Q$Config{path_sep}/, $Config{incpath}
130 push @incs, '/usr/include/w32api', '/usr/X11R6/include'
133 @incs = grep -d, @incs;
139 sub library_search_path {
140 @libs and return @libs;
142 push @libs, map {; split /\Q$Config{path_sep}/ } @libpaths;
143 push @incs, split /\Q$Config{path_sep}/, $ENV{IM_LIBPATH}
144 if defined $ENV{IM_LIBPATH};
145 push @libs, '/usr/lib', '/usr/X11R6/lib'
146 unless $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/;
147 push @libs, split /\Q$Config{path_sep}/, $ENV{LIB}
148 if $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/ and $ENV{LIB};
149 push @libs, split ' ', $Config{loclibpth}
150 if $Config{loclibpth};
151 push @libs, split /\Q$Config{path_sep}/, $Config{libpth}
153 push @libs, '/usr/lib/w32api', '/usr/X11R6/lib'
156 @libs = grep -d, @libs;
162 my ($name, @where) = @_;
164 grep -f File::Spec->catfile($_, $name), @where;
168 my ($name, $description) = @_;
169 my @found = _find_file($_[0], header_search_path());
172 push @cflags, "-I$_" for grep !$seen_incdir{$_}, @found;
173 @seen_incdir{@found} = (1) x @found;
176 print STDERR "Could not find $name ($description)\n";
183 my ($name, $description) = shift;
186 if ($^O eq 'MSWin32' && $Config{_a} eq '.lib') {
187 $libname = $name . $Config{_a};
188 @found = _find_file($libname, library_search_path());
191 $libname = "lib" . $name . $Config{_a};
192 @found = _find_file($libname, library_search_path());
193 if (!@found && $Config{so}) {
194 $libname = "lib" . $name . "." . $Config{so};
195 @found = _find_file($libname, library_search_path());
199 push @lflags, "-L$_" for grep !$seen_libdir{$_}, @found;
200 @seen_libdir{@found} = (1) x @found;
203 print STDERR "Could not find $libname ($description)\n";
209 # wrapper around assert lib that doesn't exit and doesn't die
213 my $title = delete $opts{title};
214 $title and print "Looking even harder for $title\n";
216 return eval { assert_lib(%opts); 1 };