various distribution fixes:
[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
770c534e
TC
51if ($ExtUtils::MakeMaker::VERSION > 6.06) {
52 $opts{LICENSE} = 'perl';
53}
54
0ddb7051
TC
55WriteMakefile(%opts);
56
57my @incs;
58sub header_search_path {
59 @incs and return @incs;
60
8aca6763 61 push @incs, '/usr/include', '/usr/X11R6'
0ddb7051
TC
62 unless $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/;
63 push @incs, split /\Q$Config{path_sep}/, $ENV{INCLUDE}
64 if $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/ and $ENV{INCLUDE};
65 push @incs, split ' ', $Config{locincpth}
66 if $Config{locincpth};
67 push @incs, split /\Q$Config{path_sep}/, $Config{incpath}
68 if $Config{incpath};
69 push @incs, '/usr/include/w32api', '/usr/X11R6/include'
70 if $^O eq 'cygwin';
71
72 @incs = grep -d, @incs;
73
74 @incs;
75}
76
77my @libs;
78sub library_search_path {
79 @libs and return @libs;
80
8aca6763 81 push @libs, '/usr/lib', '/usr/X11R6/lib'
0ddb7051
TC
82 unless $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/;
83 push @libs, split /\Q$Config{path_sep}/, $ENV{LIB}
84 if $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/ and $ENV{LIB};
85 push @libs, split ' ', $Config{loclibpth}
86 if $Config{loclibpth};
87 push @libs, split /\Q$Config{path_sep}/, $Config{libpth}
88 if $Config{libpth};
89 push @libs, '/usr/lib/w32api', '/usr/X11R6/lib'
90 if $^O eq 'cygwin';
91
92 @libs = grep -d, @libs;
93
94 @libs;
95}
96
97
98sub _find_file {
99 my ($name, @where) = @_;
100
101 grep -f File::Spec->catfile($_, $name), @where;
102}
103
104sub find_header {
105 _find_file($_[0], header_search_path());
106}
107
108sub find_lib {
109 my $name = shift;
110 my @found;
111 if ($^O eq 'MSWin32' && $Config{_a} eq '.lib') {
112 @found = _find_file($name . $Config{_a}, library_search_path());
113 }
114 else {
115 @found = _find_file("lib" . $name . $Config{_a}, library_search_path());
116 }
117 if (@found) {
118 push @lflags, "-L$_" for @found;
119 }
120 @found;
121}