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