changes for mingw
[imager-screenshot.git] / Makefile.PL
CommitLineData
dcdbb706 1#!perl -w\r
a9735f1a
TC
2use strict;\r
3use ExtUtils::MakeMaker;\r
4use Imager::ExtUtils;\r
5use Config;\r
6use File::Spec;\r
7\r
8my @objs = qw/Screenshot.o/;\r
9my @cflags;\r
10my @lflags;\r
dcdbb706
TC
11my $X11_lib = $^O eq 'cygwin' ? 'X11.dll' : 'X11';\r
12if (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
18if (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 27unless (@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
31my %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
46if ($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
51WriteMakefile(%opts);\r
52\r
53my @incs;\r
54sub 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
73my @libs;\r
74sub 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
94sub _find_file {\r
95 my ($name, @where) = @_;\r
96\r
97 grep -f File::Spec->catfile($_, $name), @where;\r
98}\r
99\r
100sub find_header {\r
101 _find_file($_[0], header_search_path());\r
102}\r
103\r
104sub 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