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/;
23 my $X11_lib = $^O eq 'cygwin' ? 'X11.dll' : 'X11';
24 if (find_header("X11/Xlib.h", "X11 header")
25 and find_lib($X11_lib, "X11 library")) {
26 push @objs, 'scx11.o';
27 push @cflags, '-DSS_X11';
28 push @lflags, '-l'.$X11_lib;
31 if (find_header('windows.h', "Win32 header")
32 && find_lib('gdi32', "Win32 library")
33 || check_lib(header => "windows.h",
36 push @objs, 'scwin32.o';
37 push @cflags, '-DSS_WIN32';
38 if ($^O eq 'cygwin') {
39 push @lflags, '-L/usr/lib/w32api', '-lgdi32';
41 print "Found Win32\n";
46 OS unsupported: Headers or libraries not found for a supported GUI
48 Sorry, I can't find headers or libraries for a supported GUI
49 You need to install development headers and libraries for your GUI
50 For Win32: Platform SDK or a substitute
51 For X11: X11 headers and libraries, eg. the libX11-dev package on Debian
58 NAME => 'Imager::Screenshot',
59 VERSION_FROM => 'Screenshot.pm',
64 INC => Imager::ExtUtils->includes,
65 TYPEMAPS => [ Imager::ExtUtils->typemap ],
68 $opts{LIBS} = "@lflags" if @lflags;
69 $opts{INC} .= " @cflags" if @cflags;
71 # avoid "... isn't numberic in numeric gt ..." warnings for dev versions
72 my $eu_mm_version = eval $ExtUtils::MakeMaker::VERSION;
73 if ($eu_mm_version > 6.06) {
74 $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>';
75 $opts{ABSTRACT} = 'Screen/Window capture to Imager images';
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
81 # EXTRA_META was also introduced in 6.30_01
82 if ($eu_mm_version > 6.3001) {
83 $opts{LICENSE} = 'perl';
85 if ($eu_mm_version >= 6.46) {
95 "Test::More" => "0.47",
100 WriteMakefile(%opts);
103 sub header_search_path {
104 @incs and return @incs;
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};
109 push @incs, '/usr/include', '/usr/X11R6/include'
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}
117 push @incs, '/usr/include/w32api', '/usr/X11R6/include'
120 @incs = grep -d, @incs;
126 sub library_search_path {
127 @libs and return @libs;
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};
132 push @libs, '/usr/lib', '/usr/X11R6/lib'
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}
140 push @libs, '/usr/lib/w32api', '/usr/X11R6/lib'
143 @libs = grep -d, @libs;
149 my ($name, @where) = @_;
151 grep -f File::Spec->catfile($_, $name), @where;
155 my ($name, $description) = @_;
156 my @found = _find_file($_[0], header_search_path());
159 push @cflags, "-I$_" for grep !$seen_incdir{$_}, @found;
160 @seen_incdir{@found} = (1) x @found;
163 print STDERR "Could not find $name ($description)\n";
170 my ($name, $description) = shift;
173 if ($^O eq 'MSWin32' && $Config{_a} eq '.lib') {
174 $libname = $name . $Config{_a};
175 @found = _find_file($libname, library_search_path());
178 $libname = "lib" . $name . $Config{_a};
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());
186 push @lflags, "-L$_" for grep !$seen_libdir{$_}, @found;
187 @seen_libdir{@found} = (1) x @found;
190 print STDERR "Could not find $libname ($description)\n";
196 # wrapper around assert lib that doesn't exit and doesn't die
200 my $title = delete $opts{title};
201 $title and print "Looking even harder for $title\n";
203 return eval { assert_lib(%opts); 1 };