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