]> git.imager.perl.org - imager-screenshot.git/blame - Makefile.PL
- improved the error messages displayed when headers and libraries
[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
TC
40 die <<DEAD;
41
42NA: Sorry, I can't find headers or libraries for a supported GUI
43You need to install development headers and libraries for your GUI
44For Win32: Platform SDK or a substitute
45For X11: X11 headers and libraries, eg. the libX11-dev package on Debian
46
47DEAD
0ddb7051
TC
48}
49
574c4fe0
TC
50my $extra_meta = <<META;
51configure_requires:
52 Imager: 0.54
53build_requires:
54 Imager: 0.54
55 Test::More: 0.47
56META
57
0ddb7051
TC
58my %opts =
59 (
60 NAME => 'Imager::Screenshot',
61 VERSION_FROM => 'Screenshot.pm',
62 OBJECT => "@objs",
63 PREREQ_PM => {
64 'Imager' => 0.54,
65 },
66 INC => Imager::ExtUtils->includes,
67 TYPEMAPS => [ Imager::ExtUtils->typemap ],
574c4fe0 68 EXTRA_META => $extra_meta,
0ddb7051
TC
69 );
70
71$opts{LIBS} = "@lflags" if @lflags;
72$opts{INC} .= " @cflags" if @cflags;
73
37819a40
TC
74# avoid "... isn't numberic in numeric gt ..." warnings for dev versions
75my $eu_mm_version = eval $ExtUtils::MakeMaker::VERSION;
76if ($eu_mm_version > 6.06) {
0ddb7051
TC
77 $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>';
78 $opts{ABSTRACT} = 'Screen/Window capture to Imager images';
79}
80
37819a40
TC
81# LICENSE was introduced in 6.30_01, but Debian etch includes
82# (as of 2007/01/12) an ExtUtils::MakeMaker versioned 6.30_01 without
83# LICENSE support
84if ($eu_mm_version > 6.3001) {
770c534e
TC
85 $opts{LICENSE} = 'perl';
86}
87
0ddb7051
TC
88WriteMakefile(%opts);
89
90my @incs;
91sub header_search_path {
92 @incs and return @incs;
93
574c4fe0
TC
94 push @incs, map {; split /\Q$Config{path_sep}/ } @incpaths;
95 push @incs, split /\Q$Config{path_sep}/, $ENV{IM_INCPATH}
96 if defined $ENV{IM_INCPATH};
8a7d6890 97 push @incs, '/usr/include', '/usr/X11R6/include'
0ddb7051
TC
98 unless $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/;
99 push @incs, split /\Q$Config{path_sep}/, $ENV{INCLUDE}
100 if $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/ and $ENV{INCLUDE};
101 push @incs, split ' ', $Config{locincpth}
102 if $Config{locincpth};
103 push @incs, split /\Q$Config{path_sep}/, $Config{incpath}
104 if $Config{incpath};
105 push @incs, '/usr/include/w32api', '/usr/X11R6/include'
106 if $^O eq 'cygwin';
107
108 @incs = grep -d, @incs;
109
110 @incs;
111}
112
113my @libs;
114sub library_search_path {
115 @libs and return @libs;
116
574c4fe0
TC
117 push @libs, map {; split /\Q$Config{path_sep}/ } @libpaths;
118 push @incs, split /\Q$Config{path_sep}/, $ENV{IM_LIBPATH}
119 if defined $ENV{IM_LIBPATH};
8aca6763 120 push @libs, '/usr/lib', '/usr/X11R6/lib'
0ddb7051
TC
121 unless $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/;
122 push @libs, split /\Q$Config{path_sep}/, $ENV{LIB}
123 if $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/ and $ENV{LIB};
124 push @libs, split ' ', $Config{loclibpth}
125 if $Config{loclibpth};
126 push @libs, split /\Q$Config{path_sep}/, $Config{libpth}
127 if $Config{libpth};
128 push @libs, '/usr/lib/w32api', '/usr/X11R6/lib'
129 if $^O eq 'cygwin';
130
131 @libs = grep -d, @libs;
132
133 @libs;
134}
135
0ddb7051
TC
136sub _find_file {
137 my ($name, @where) = @_;
138
139 grep -f File::Spec->catfile($_, $name), @where;
140}
141
142sub find_header {
574c4fe0 143 my ($name, $description) = @_;
8a7d6890
TC
144 my @found = _find_file($_[0], header_search_path());
145
146 if (@found) {
574c4fe0
TC
147 push @cflags, "-I$_" for grep !$seen_incdir{$_}, @found;
148 @seen_incdir{@found} = (1) x @found;
149 }
150 else {
151 print STDERR "Could not find $name ($description)\n";
8a7d6890
TC
152 }
153
154 @found;
0ddb7051
TC
155}
156
157sub find_lib {
574c4fe0 158 my ($name, $description) = shift;
0ddb7051 159 my @found;
574c4fe0 160 my $libname;
0ddb7051 161 if ($^O eq 'MSWin32' && $Config{_a} eq '.lib') {
574c4fe0 162 $libname = $name . $Config{_a};
0ddb7051
TC
163 }
164 else {
574c4fe0 165 $libname = "lib" . $name . $Config{_a};
0ddb7051 166 }
574c4fe0 167 @found = _find_file($libname, library_search_path());
0ddb7051 168 if (@found) {
8a7d6890
TC
169 push @lflags, "-L$_" for grep !$seen_libdir{$_}, @found;
170 @seen_libdir{@found} = (1) x @found;
0ddb7051 171 }
574c4fe0
TC
172 else {
173 print STDERR "Could not find $libname ($description)\n";
174 }
175
0ddb7051
TC
176 @found;
177}