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