switch from EXTRA_META to META_MERGE
[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;
574c4fe0
TC
8use Getopt::Long;
9
10my @incpaths; # places to look for headers
11my @libpaths; # places to look for libraries
12
13GetOptions("incpath=s", \@incpaths,
14 "libpath=s" => \@libpaths);
0ddb7051
TC
15
16my @objs = qw/Screenshot.o/;
17my @cflags;
18my @lflags;
8a7d6890
TC
19my %seen_incdir;
20my %seen_libdir;
0ddb7051 21my $X11_lib = $^O eq 'cygwin' ? 'X11.dll' : 'X11';
574c4fe0
TC
22if (find_header("X11/Xlib.h", "X11 header")
23 and find_lib($X11_lib, "X11 library")) {
0ddb7051
TC
24 push @objs, 'scx11.o';
25 push @cflags, '-DSS_X11';
26 push @lflags, '-l'.$X11_lib;
27 print "Found X11\n";
28}
574c4fe0
TC
29if (find_header('windows.h', "Win32 header")
30 and find_lib('gdi32', "Win32 library")) {
0ddb7051
TC
31 push @objs, 'scwin32.o';
32 push @cflags, '-DSS_WIN32';
33 if ($^O eq 'cygwin') {
34 push @lflags, '-L/usr/lib/w32api', '-lgdi32';
35 }
36 print "Found Win32\n";
37}
38
39unless (@objs > 1) {
574c4fe0 40 die <<DEAD;
7f198d6e 41OS unsupported: Headers or libraries not found for a supported GUI
574c4fe0 42
7f198d6e 43Sorry, I can't find headers or libraries for a supported GUI
574c4fe0
TC
44You need to install development headers and libraries for your GUI
45For Win32: Platform SDK or a substitute
46For X11: X11 headers and libraries, eg. the libX11-dev package on Debian
47
48DEAD
0ddb7051
TC
49}
50
51my %opts =
52 (
53 NAME => 'Imager::Screenshot',
54 VERSION_FROM => 'Screenshot.pm',
55 OBJECT => "@objs",
56 PREREQ_PM => {
57 'Imager' => 0.54,
58 },
59 INC => Imager::ExtUtils->includes,
60 TYPEMAPS => [ Imager::ExtUtils->typemap ],
61 );
62
63$opts{LIBS} = "@lflags" if @lflags;
64$opts{INC} .= " @cflags" if @cflags;
65
37819a40
TC
66# avoid "... isn't numberic in numeric gt ..." warnings for dev versions
67my $eu_mm_version = eval $ExtUtils::MakeMaker::VERSION;
68if ($eu_mm_version > 6.06) {
0ddb7051
TC
69 $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>';
70 $opts{ABSTRACT} = 'Screen/Window capture to Imager images';
71}
72
37819a40
TC
73# LICENSE was introduced in 6.30_01, but Debian etch includes
74# (as of 2007/01/12) an ExtUtils::MakeMaker versioned 6.30_01 without
75# LICENSE support
54f11a66 76# EXTRA_META was also introduced in 6.30_01
37819a40 77if ($eu_mm_version > 6.3001) {
770c534e 78 $opts{LICENSE} = 'perl';
8cb7800a
TC
79}
80if ($eu_mm_version >= 6.46) {
81 $opts{META_MERGE} =
82 {
83 configure_requires =>
84 {
85 Imager => "0.54"
86 },
87 build_requires =>
88 {
89 Imager => "0.54",
90 "Test::More" => "0.47",
91 }
92 };
770c534e
TC
93}
94
0ddb7051
TC
95WriteMakefile(%opts);
96
97my @incs;
98sub header_search_path {
99 @incs and return @incs;
100
574c4fe0
TC
101 push @incs, map {; split /\Q$Config{path_sep}/ } @incpaths;
102 push @incs, split /\Q$Config{path_sep}/, $ENV{IM_INCPATH}
103 if defined $ENV{IM_INCPATH};
8a7d6890 104 push @incs, '/usr/include', '/usr/X11R6/include'
0ddb7051
TC
105 unless $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/;
106 push @incs, split /\Q$Config{path_sep}/, $ENV{INCLUDE}
107 if $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/ and $ENV{INCLUDE};
108 push @incs, split ' ', $Config{locincpth}
109 if $Config{locincpth};
110 push @incs, split /\Q$Config{path_sep}/, $Config{incpath}
111 if $Config{incpath};
112 push @incs, '/usr/include/w32api', '/usr/X11R6/include'
113 if $^O eq 'cygwin';
114
115 @incs = grep -d, @incs;
116
117 @incs;
118}
119
120my @libs;
121sub library_search_path {
122 @libs and return @libs;
123
574c4fe0
TC
124 push @libs, map {; split /\Q$Config{path_sep}/ } @libpaths;
125 push @incs, split /\Q$Config{path_sep}/, $ENV{IM_LIBPATH}
126 if defined $ENV{IM_LIBPATH};
8aca6763 127 push @libs, '/usr/lib', '/usr/X11R6/lib'
0ddb7051
TC
128 unless $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/;
129 push @libs, split /\Q$Config{path_sep}/, $ENV{LIB}
130 if $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/ and $ENV{LIB};
131 push @libs, split ' ', $Config{loclibpth}
132 if $Config{loclibpth};
133 push @libs, split /\Q$Config{path_sep}/, $Config{libpth}
134 if $Config{libpth};
135 push @libs, '/usr/lib/w32api', '/usr/X11R6/lib'
136 if $^O eq 'cygwin';
137
138 @libs = grep -d, @libs;
139
140 @libs;
141}
142
0ddb7051
TC
143sub _find_file {
144 my ($name, @where) = @_;
145
146 grep -f File::Spec->catfile($_, $name), @where;
147}
148
149sub find_header {
574c4fe0 150 my ($name, $description) = @_;
8a7d6890
TC
151 my @found = _find_file($_[0], header_search_path());
152
153 if (@found) {
574c4fe0
TC
154 push @cflags, "-I$_" for grep !$seen_incdir{$_}, @found;
155 @seen_incdir{@found} = (1) x @found;
156 }
157 else {
158 print STDERR "Could not find $name ($description)\n";
8a7d6890
TC
159 }
160
161 @found;
0ddb7051
TC
162}
163
164sub find_lib {
574c4fe0 165 my ($name, $description) = shift;
0ddb7051 166 my @found;
574c4fe0 167 my $libname;
0ddb7051 168 if ($^O eq 'MSWin32' && $Config{_a} eq '.lib') {
574c4fe0 169 $libname = $name . $Config{_a};
91eba490 170 @found = _find_file($libname, library_search_path());
0ddb7051
TC
171 }
172 else {
574c4fe0 173 $libname = "lib" . $name . $Config{_a};
91eba490
TC
174 @found = _find_file($libname, library_search_path());
175 if (!@found && $Config{so}) {
176 $libname = "lib" . $name . "." . $Config{so};
177 @found = _find_file($libname, library_search_path());
178 }
0ddb7051
TC
179 }
180 if (@found) {
8a7d6890
TC
181 push @lflags, "-L$_" for grep !$seen_libdir{$_}, @found;
182 @seen_libdir{@found} = (1) x @found;
0ddb7051 183 }
574c4fe0
TC
184 else {
185 print STDERR "Could not find $libname ($description)\n";
186 }
187
0ddb7051
TC
188 @found;
189}