- improved the error messages displayed when headers and libraries
authorTony Cook <tony@develop-help.com>
Mon, 7 Apr 2008 12:20:29 +0000 (12:20 +0000)
committerTony Cook <tony@develop-help.com>
Mon, 7 Apr 2008 12:20:29 +0000 (12:20 +0000)
  can't be found
  http://rt.cpan.org/Ticket/Display.html?id=32856

- added --incpath and --libpath options to Makefile.PL and also look
  in $ENV{IM_INCPATH} and $ENV{IM_LIBPATH} like Imager.

Changes
Makefile.PL

diff --git a/Changes b/Changes
index a15197d35fc50ce334590217a0c750f4f1c9c9c3..f8fcf13fcc853de0f5824a93dad75570147c1169 100755 (executable)
--- a/Changes
+++ b/Changes
@@ -1,9 +1,17 @@
 0.006 unreleased
-       - screenshot() on a non-toplevel Tk widget would crash when
-         calling the frame method.  Since this call appears to be
-         unnecessary I've removed it, and plan to run tests on a few
-         platforms to check I haven't broken anything.
-          RT #32843 - thanks to Slaven Rezic.
+
+- screenshot() on a non-toplevel Tk widget would crash when
+  calling the frame method.  Since this call appears to be
+  unnecessary I've removed it, and plan to run tests on a few
+  platforms to check I haven't broken anything.
+  RT #32843 - thanks to Slaven Rezic.
+
+- improved the error messages displayed when headers and libraries
+  can't be found
+  http://rt.cpan.org/Ticket/Display.html?id=32856
+
+- added --incpath and --libpath options to Makefile.PL and also look
+  in $ENV{IM_INCPATH} and $ENV{IM_LIBPATH} like Imager.
 
 0.005 12 Mar 2007
        - 0.005 release
index f6d95eefc6750be8fb18578b782e48e9e7ddcc97..e314bd36ae74b1215774f87c84f8eb42d2626f1d 100644 (file)
@@ -5,6 +5,13 @@ use Imager 0.54;
 use Imager::ExtUtils;
 use Config;
 use File::Spec;
+use Getopt::Long;
+
+my @incpaths; # places to look for headers
+my @libpaths; # places to look for libraries
+
+GetOptions("incpath=s", \@incpaths,
+           "libpath=s" => \@libpaths);
 
 my @objs = qw/Screenshot.o/;
 my @cflags;
@@ -12,13 +19,15 @@ my @lflags;
 my %seen_incdir;
 my %seen_libdir;
 my $X11_lib = $^O eq 'cygwin' ? 'X11.dll' : 'X11';
-if (find_header("X11/Xlib.h") and find_lib($X11_lib)) {
+if (find_header("X11/Xlib.h", "X11 header") 
+    and find_lib($X11_lib, "X11 library")) {
   push @objs, 'scx11.o';
   push @cflags, '-DSS_X11';
   push @lflags, '-l'.$X11_lib;
   print "Found X11\n";
 }
-if (find_header('windows.h') and find_lib('gdi32')) {
+if (find_header('windows.h', "Win32 header")
+    and find_lib('gdi32', "Win32 library")) {
   push @objs, 'scwin32.o';
   push @cflags, '-DSS_WIN32';
   if ($^O eq 'cygwin') {
@@ -28,9 +37,24 @@ if (find_header('windows.h') and find_lib('gdi32')) {
 }
 
 unless (@objs > 1) {
-  die "NA: Sorry, I can't find headers or libraries for a supported GUI\n"
+  die <<DEAD;
+
+NA: Sorry, I can't find headers or libraries for a supported GUI
+You need to install development headers and libraries for your GUI
+For Win32: Platform SDK or a substitute
+For X11: X11 headers and libraries, eg. the libX11-dev package on Debian
+
+DEAD
 }
 
+my $extra_meta = <<META;
+configure_requires:
+  Imager: 0.54
+build_requires:
+  Imager: 0.54
+  Test::More: 0.47
+META
+
 my %opts = 
   (
    NAME => 'Imager::Screenshot',
@@ -41,6 +65,7 @@ my %opts =
                },
    INC => Imager::ExtUtils->includes,
    TYPEMAPS => [ Imager::ExtUtils->typemap ],
+   EXTRA_META => $extra_meta,
   );
 
 $opts{LIBS} = "@lflags" if @lflags;
@@ -66,6 +91,9 @@ my @incs;
 sub header_search_path {
   @incs and return @incs;
 
+  push @incs, map {; split /\Q$Config{path_sep}/ } @incpaths;
+  push @incs, split /\Q$Config{path_sep}/, $ENV{IM_INCPATH}
+    if defined $ENV{IM_INCPATH};
   push @incs, '/usr/include', '/usr/X11R6/include'
     unless $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/;
   push @incs, split /\Q$Config{path_sep}/, $ENV{INCLUDE}
@@ -86,6 +114,9 @@ my @libs;
 sub library_search_path {
   @libs and return @libs;
 
+  push @libs, map {; split /\Q$Config{path_sep}/ } @libpaths;
+  push @incs, split /\Q$Config{path_sep}/, $ENV{IM_LIBPATH}
+    if defined $ENV{IM_LIBPATH};
   push @libs, '/usr/lib', '/usr/X11R6/lib'
     unless $^O eq 'MSWin32' && $Config{cc} =~ /\bcl\b/;
   push @libs, split /\Q$Config{path_sep}/, $ENV{LIB}
@@ -102,7 +133,6 @@ sub library_search_path {
   @libs;
 }
 
-
 sub _find_file {
   my ($name, @where) = @_;
 
@@ -110,28 +140,38 @@ sub _find_file {
 }
 
 sub find_header {
+  my ($name, $description) = @_;
   my @found = _find_file($_[0], header_search_path());
 
   if (@found) {
-      push @cflags, "-I$_" for grep !$seen_incdir{$_}, @found;
-      @seen_incdir{@found} = (1) x @found;
+    push @cflags, "-I$_" for grep !$seen_incdir{$_}, @found;
+    @seen_incdir{@found} = (1) x @found;
+  }
+  else {
+    print STDERR "Could not find $name ($description)\n";
   }
 
   @found;
 }
 
 sub find_lib {
-  my $name = shift;
+  my ($name, $description) = shift;
   my @found;
+  my $libname;
   if ($^O eq 'MSWin32' && $Config{_a} eq '.lib') {
-    @found = _find_file($name . $Config{_a}, library_search_path());
+    $libname = $name . $Config{_a};
   }
   else {
-    @found = _find_file("lib" . $name . $Config{_a}, library_search_path());
+    $libname = "lib" . $name . $Config{_a};
   }
+  @found = _find_file($libname, library_search_path());
   if (@found) {
     push @lflags, "-L$_" for grep !$seen_libdir{$_}, @found;
     @seen_libdir{@found} = (1) x @found;
   }
+  else {
+    print STDERR "Could not find $libname ($description)\n";
+  }
+
   @found;
 }