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