]> git.imager.perl.org - imager-screenshot.git/blame - Makefile.PL
older Tk doesn't supply the windowing system method
[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;
11my $X11_lib = $^O eq 'cygwin' ? 'X11.dll' : 'X11';
12if (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}
18if (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
27unless (@objs > 1) {
28 die "Sorry, I can't find headers or libraries for a supported GUI\n"
29}
30
31my %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
46if ($ExtUtils::MakeMaker::VERSION > 6.06) {
47 $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>';
48 $opts{ABSTRACT} = 'Screen/Window capture to Imager images';
49}
50
51WriteMakefile(%opts);
52
53my @incs;
54sub header_search_path {
55 @incs and return @incs;
56
57 push @incs, '/usr/include'
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
73my @libs;
74sub library_search_path {
75 @libs and return @libs;
76
77 push @libs, '/usr/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
94sub _find_file {
95 my ($name, @where) = @_;
96
97 grep -f File::Spec->catfile($_, $name), @where;
98}
99
100sub find_header {
101 _find_file($_[0], header_search_path());
102}
103
104sub 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}