]> git.imager.perl.org - imager-screenshot.git/blob - Makefile.PL
changes for mingw
[imager-screenshot.git] / Makefile.PL
1 #!perl -w\r
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
11 my $X11_lib = $^O eq 'cygwin' ? 'X11.dll' : 'X11';\r
12 if (find_header("X11/Xlib.h") and find_lib($X11_lib)) {\r
13   push @objs, 'scx11.o';\r
14   push @cflags, '-DSS_X11';\r
15   push @lflags, '-l'.$X11_lib;\r
16   print "Found X11\n";\r
17 }\r
18 if (find_header('windows.h') and find_lib('gdi32')) {\r
19   push @objs, 'scwin32.o';\r
20   push @cflags, '-DSS_WIN32';\r
21   if ($^O eq 'cygwin') {\r
22     push @lflags, '-L/usr/lib/w32api', '-lgdi32';\r
23   }\r
24   print "Found Win32\n";\r
25 }\r
26 \r
27 unless (@objs > 1) {\r
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
57   push @incs, '/usr/include'\r
58     unless $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/;\r
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
65   push @incs, '/usr/include/w32api', '/usr/X11R6/include'\r
66     if $^O eq 'cygwin';\r
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
77   push @libs, '/usr/lib'\r
78     unless $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/;\r
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
85   push @libs, '/usr/lib/w32api', '/usr/X11R6/lib'\r
86     if $^O eq 'cygwin';\r
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
106   my @found;\r
107   if ($^O eq 'MSWin32' && $Config{_a} eq '.lib') {\r
108     @found = _find_file($name . $Config{_a}, library_search_path());\r
109   }\r
110   else {\r
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
115   }\r
116   @found;\r
117 }\r