initial screenshot attempt
[imager-screenshot.git] / Makefile.PL
CommitLineData
a9735f1a
TC
1use strict;\r
2use ExtUtils::MakeMaker;\r
3use Imager::ExtUtils;\r
4use Config;\r
5use File::Spec;\r
6\r
7my @objs = qw/Screenshot.o/;\r
8my @cflags;\r
9my @lflags;\r
10#if (find_header("X11.h") and find_lib("X11")) {\r
11# push @objs, 'scx11.o';\r
12# push @cflags, '-DSS_X11';\r
13# push @lflags, '-lX11';\r
14# print "Found X11\n";\r
15#}\r
16if (find_header('windows.h') and find_lib('gdi32')) {\r
17 push @objs, 'scwin32.o';\r
18 push @cflags, '-DSS_WIN32';\r
19 push @lflags, '-lgdi32' if $^O eq 'cygwin';\r
20 print "Found Win32\n";\r
21}\r
22\r
23unless (@objs) {\r
24 WriteEmptyMakefile();\r
25 die "Sorry, I can't find headers or libraries for a supported GUI\n"\r
26}\r
27\r
28my %opts = \r
29 (\r
30 NAME => 'Imager::Screenshot',\r
31 VERSION_FROM => 'Screenshot.pm',\r
32 OBJECT => "@objs",\r
33 PREREQ_PM => {\r
34 'Imager' => 0.54,\r
35 },\r
36 INC => Imager::ExtUtils->includes,\r
37 TYPEMAPS => [ Imager::ExtUtils->typemap ],\r
38 );\r
39\r
40$opts{LIBS} = "@lflags" if @lflags;\r
41$opts{INC} .= " @cflags" if @cflags;\r
42\r
43if ($ExtUtils::MakeMaker::VERSION > 6.06) {\r
44 $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>';\r
45 $opts{ABSTRACT} = 'Screen/Window capture to Imager images';\r
46}\r
47\r
48WriteMakefile(%opts);\r
49\r
50my @incs;\r
51sub header_search_path {\r
52 @incs and return @incs;\r
53\r
54 push @incs, split /\Q$Config{path_sep}/, $ENV{INCLUDE}\r
55 if $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/ and $ENV{INCLUDE};\r
56 push @incs, split ' ', $Config{locincpth}\r
57 if $Config{locincpth};\r
58 push @incs, split /\Q$Config{path_sep}/, $Config{incpath}\r
59 if $Config{incpath};\r
60\r
61 @incs = grep -d, @incs;\r
62\r
63 @incs;\r
64}\r
65\r
66my @libs;\r
67sub library_search_path {\r
68 @libs and return @libs;\r
69\r
70 push @libs, split /\Q$Config{path_sep}/, $ENV{LIB}\r
71 if $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/ and $ENV{LIB};\r
72 push @libs, split ' ', $Config{loclibpth}\r
73 if $Config{loclibpth};\r
74 push @libs, split /\Q$Config{path_sep}/, $Config{libpth}\r
75 if $Config{libpth};\r
76\r
77 @libs = grep -d, @libs;\r
78\r
79 @libs;\r
80}\r
81\r
82\r
83sub _find_file {\r
84 my ($name, @where) = @_;\r
85\r
86 grep -f File::Spec->catfile($_, $name), @where;\r
87}\r
88\r
89sub find_header {\r
90 _find_file($_[0], header_search_path());\r
91}\r
92\r
93sub find_lib {\r
94 my $name = shift;\r
95 if ($^O eq 'MSWin32') {\r
96 return _find_file($name . $Config{_a}, library_search_path());\r
97 }\r
98 else {\r
99 return _find_file("lib" . $name . $Config{_a}, library_search_path());\r
100 }\r
101}\r