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