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