]> git.imager.perl.org - imager-screenshot.git/blob - Makefile.PL
screenshotting a remote display under X is slow, make sure the user knows
[imager-screenshot.git] / Makefile.PL
1 #!perl -w
2 use strict;
3 use ExtUtils::MakeMaker;
4 use Imager::ExtUtils;
5 use Config;
6 use File::Spec;
7
8 my @objs = qw/Screenshot.o/;
9 my @cflags;
10 my @lflags;
11 my $X11_lib = $^O eq 'cygwin' ? 'X11.dll' : 'X11';
12 if (find_header("X11/Xlib.h") and find_lib($X11_lib)) {
13   push @objs, 'scx11.o';
14   push @cflags, '-DSS_X11';
15   push @lflags, '-l'.$X11_lib;
16   print "Found X11\n";
17 }
18 if (find_header('windows.h') and find_lib('gdi32')) {
19   push @objs, 'scwin32.o';
20   push @cflags, '-DSS_WIN32';
21   if ($^O eq 'cygwin') {
22     push @lflags, '-L/usr/lib/w32api', '-lgdi32';
23   }
24   print "Found Win32\n";
25 }
26
27 unless (@objs > 1) {
28   die "Sorry, I can't find headers or libraries for a supported GUI\n"
29 }
30
31 my %opts = 
32   (
33    NAME => 'Imager::Screenshot',
34    VERSION_FROM => 'Screenshot.pm',
35    OBJECT => "@objs",
36    PREREQ_PM => {
37                  'Imager'    => 0.54,
38                 },
39    INC => Imager::ExtUtils->includes,
40    TYPEMAPS => [ Imager::ExtUtils->typemap ],
41   );
42
43 $opts{LIBS} = "@lflags" if @lflags;
44 $opts{INC} .= " @cflags" if @cflags;
45
46 if ($ExtUtils::MakeMaker::VERSION > 6.06) {
47   $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>';
48   $opts{ABSTRACT} = 'Screen/Window capture to Imager images';
49 }
50
51 WriteMakefile(%opts);
52
53 my @incs;
54 sub header_search_path {
55   @incs and return @incs;
56
57   push @incs, '/usr/include', '/usr/X11R6'
58     unless $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/;
59   push @incs, split /\Q$Config{path_sep}/, $ENV{INCLUDE}
60     if $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/ and $ENV{INCLUDE};
61   push @incs, split ' ', $Config{locincpth}
62     if $Config{locincpth};
63   push @incs, split /\Q$Config{path_sep}/, $Config{incpath}
64     if $Config{incpath};
65   push @incs, '/usr/include/w32api', '/usr/X11R6/include'
66     if $^O eq 'cygwin';
67
68   @incs = grep -d, @incs;
69
70   @incs;
71 }
72
73 my @libs;
74 sub library_search_path {
75   @libs and return @libs;
76
77   push @libs, '/usr/lib', '/usr/X11R6/lib'
78     unless $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/;
79   push @libs, split /\Q$Config{path_sep}/, $ENV{LIB}
80     if $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/ and $ENV{LIB};
81   push @libs, split ' ', $Config{loclibpth}
82     if $Config{loclibpth};
83   push @libs, split /\Q$Config{path_sep}/, $Config{libpth}
84     if $Config{libpth};
85   push @libs, '/usr/lib/w32api', '/usr/X11R6/lib'
86     if $^O eq 'cygwin';
87
88   @libs = grep -d, @libs;
89
90   @libs;
91 }
92
93
94 sub _find_file {
95   my ($name, @where) = @_;
96
97   grep -f File::Spec->catfile($_, $name), @where;
98 }
99
100 sub find_header {
101   _find_file($_[0], header_search_path());
102 }
103
104 sub find_lib {
105   my $name = shift;
106   my @found;
107   if ($^O eq 'MSWin32' && $Config{_a} eq '.lib') {
108     @found = _find_file($name . $Config{_a}, library_search_path());
109   }
110   else {
111     @found = _find_file("lib" . $name . $Config{_a}, library_search_path());
112   }
113   if (@found) {
114     push @lflags, "-L$_" for @found;
115   }
116   @found;
117 }