]> git.imager.perl.org - imager.git/blobdiff - Makefile.PL
Imager 0.58 release
[imager.git] / Makefile.PL
index 8cdb5ef5369f7f9017d01cc8310fcd77c6477243..56b0852f7a95d66c764d53ae84e8b39458dfbf0b 100644 (file)
@@ -36,17 +36,19 @@ my @enable; # list of drivers to enable
 my @disable; # or list of drivers to disable
 my @incpaths; # places to look for headers
 my @libpaths; # places to look for libraries
-my $noprobe; # non-zero to disable newer probes
 my $noexif; # non-zero to disable EXIF parsing of JPEGs
+my $no_gif_set_version; # disable calling EGifSetGifVersion
+my $coverage; # build for coverage testing
 GetOptions("help" => \$help,
            "enable=s" => \@enable,
            "disable=s" => \@disable,
            "incpath=s", \@incpaths,
            "libpath=s" => \@libpaths,
-           "noprobe" => \$noprobe,
            "verbose|v" => \$VERBOSE,
            "nolog" => \$NOLOG,
-          "noexif" => \$noexif);
+          "noexif" => \$noexif,
+           "nogifsetversion" => \$no_gif_set_version,
+          'coverage' => \$coverage);
 
 if ($VERBOSE) { 
   print "Verbose mode\n"; 
@@ -82,7 +84,6 @@ my @libs; # all the places to look for libraries
 
 init();       # initialize global data
 pathcheck();  # Check if directories exist
-distcheck();  # for building dists
 
 if (exists $ENV{IM_ENABLE}) {
   my %en = map { $_, 1 } split ' ', $ENV{IM_ENABLE};
@@ -155,7 +156,7 @@ my @objs = qw(Imager.o draw.o polygon.o image.o io.o iolayer.o
               regmach.o trans2.o quant.o error.o convert.o
               map.o tags.o palimg.o maskimg.o img16.o rotate.o
               bmp.o tga.o rgb.o color.o fills.o imgdouble.o limits.o hlines.o
-              imext.o scale.o rubthru.o);
+              imext.o scale.o rubthru.o render.o);
 
 $Recommends{Imager} =
   { 'Parse::RecDescent' => 0 };
@@ -167,15 +168,28 @@ my %opts=(
           'DEFINE'       => "$OSDEF $CFLAGS",
           'INC'          => "$lib_cflags $DFLAGS $F_INC",
           'OBJECT'       => join(' ', @objs, $F_OBJECT),
-          clean          => { FILES=>'testout meta.tmp' },
+          clean          => { FILES=>'testout meta.tmp rubthru.c scale.c' },
           PM             => gen_PM(),
+         PREREQ_PM      => { 'Test::More' => 0.47 },
          );
 
-if ($ExtUtils::MakeMaker::VERSION > 6.06) {
+if ($coverage) {
+    if ($Config{gccversion}) {
+       push @ARGV, 'OPTIMIZE=-ftest-coverage -fprofile-arcs';
+       #$opts{dynamic_lib} = { OTHERLDFLAGS => '-ftest-coverage -fprofile-arcs' };
+    }
+    else {
+       die "Don't know the coverage C flags for your compiler\n";
+    }
+}
+
+# eval to prevent warnings about versions with _ in them
+my $MM_ver = eval $ExtUtils::MakeMaker::VERSION;
+if ($MM_ver > 6.06) {
   $opts{AUTHOR} = 'Tony Cook <tony@imager.perl.org>, Arnar M. Hrafnkelsson';
   $opts{ABSTRACT} = 'Perl extension for Generating 24 bit Images';
 }
-if ($ExtUtils::MakeMaker::VERSION > 6.10) {
+if ($MM_ver > 6.10) {
   $opts{NO_META} = 1;
 }
 
@@ -302,11 +316,13 @@ sub gifcheck {
 
   push @defines, [ IM_GIFMAJOR => $major, "Parsed giflib version" ];
   push @defines, [ IM_GIFMINOR => $minor ];
+  push @defines, [ IM_NO_SET_GIF_VERSION => 1, "Disable EGifSetGifVersion" ]
+    if $no_gif_set_version;
 }
 
 
-sub gd {
-  my($path,$chk)=@_;
+sub grep_directory {
+  my($path, $chk)=@_;
 
 #    print "checking path $path\n";
   if ( !opendir(DH,$path) ) {
@@ -325,29 +341,41 @@ sub checkformat {
 
   print "  checkformat($frm)\n" if $VERBOSE;
   
-  my $code = $formats{$frm}{'code'};
-  if ($code && !$noprobe) {
+  my $probe_array = $formats{$frm}{'code'};
+  if ($probe_array) {
     print "    Calling probe function\n" if $VERBOSE;
-    return 1 if $code->($formats{$frm}, $frm);
+    if (ref $probe_array ne 'ARRAY') {
+      $probe_array = [ $probe_array ];
+    }
+    for my $func (@$probe_array) {
+      return 1 if $func->($formats{$frm}, $frm);
+    }
   }
 
-  my $libchk=$formats{$frm}{'libcheck'};
-  my $incchk=$formats{$frm}{'inccheck'};
+  my $lib_check=$formats{$frm}{'libcheck'};
+  my $inc_check=$formats{$frm}{'inccheck'};
 
-  my @l;
-  for my $lp (@libs) {
-    push(@l, gd($lp,$libchk));
+  if ($lib_check) {
+    my @l;
+    for my $lp (@libs) {
+      push(@l, grep_directory($lp,$lib_check));
+    }
+    
+    my @i;
+    for my $ip (@incs) {
+      push(@i, $ip) if $inc_check->($ip,$frm);
+    }
+    
+    printf("%10s: includes %s - libraries %s\n",$frm,(@i?'found':'not found'),(@l?'found':'not found'));
+    $formats{$frm}{incdir} = \@i;
+    $formats{$frm}{libdir} = \@l;
+    return 1 if scalar(@i && @l);
   }
-
-  my @i;
-  for my $ip (@incs) {
-    push(@i, $ip) if $incchk->($ip,$frm);
+  else {
+    printf("%10s: not available\n", $frm);
   }
 
-  printf("%10s: includes %s - libraries %s\n",$frm,(@i?'found':'not found'),(@l?'found':'not found'));
-  $formats{$frm}{incdir} = \@i;
-  $formats{$frm}{libdir} = \@l;
-  return scalar(@i && @l);
+  return 0;
 }
 
 
@@ -392,6 +420,9 @@ sub init {
   if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) {
     push(@incs, split /;/, $ENV{INCLUDE}) if exists $ENV{INCLUDE};
   }
+  if ($Config{incpath}) {
+    push @incs, grep -d, split /\Q$Config{path_sep}/, $Config{incpath};
+  }
   push @incs, grep -d,
       qw(/sw/include 
          /usr/include/freetype2
@@ -461,7 +492,7 @@ sub init {
                   def=>'HAVE_LIBPNG',
                   inccheck=>sub { -e catfile($_[0], 'png.h') },
                   libcheck=>sub { $_[0] eq "libpng$aext" or $_[0] eq "libpng.$lext" },
-                  libfiles=>'-lpng -lz',
+                  libfiles=>$^O eq 'MSWin32' ? '-lpng -lzlib' : '-lpng -lz',
                   objfiles=>'png.o',
                   docs=>q{
                           Png stands for Portable Network Graphics and is intended as
@@ -544,19 +575,25 @@ Uses the Win32 GDI for rendering text.
 This currently only works on under normal Win32 and cygwin.
 DOCS
                    };
-  $formats{'freetype2'} = {
-                           order=>'29',
-                           def=>'HAVE_FT2',
-                           inccheck=>sub { -e catfile($_[0], 'ft2build.h') },
-                           libcheck=>sub { $_[0] eq "libfreetype$aext" or $_[0] eq "libfreetype.$lext" },
-                           libfiles=>'-lfreetype',
-                           objfiles=>'freetyp2.o',
-                           docs=><<DOCS,
+  $formats{'freetype2'} = 
+  {
+   order=>'29',
+   def=>'HAVE_FT2',
+   # we always use a probe function
+   #inccheck=>sub { -e catfile($_[0], 'ft2build.h') },
+   #libcheck=>sub { $_[0] eq "libfreetype$aext" or $_[0] eq "libfreetype.$lext" },
+   libfiles=>'-lfreetype',
+   objfiles=>'freetyp2.o',
+   docs=><<DOCS,
 Freetype 2 supports both Truetype and Type 1 fonts, both of which are
 scalable.  It also supports a variety of other fonts.
 DOCS
-                           code => \&freetype2_probe,
-                          };
+   code =>
+   [ 
+    \&freetype2_probe_ftconfig,
+    \&freetype2_probe_scan
+   ],
+  };
 
   # Make fix indent
   for (keys %formats) { $formats{$_}->{docs} =~ s/^\s+/  /mg; }
@@ -677,7 +714,7 @@ sub freetype1_probe {
 }
 
 # probes for freetype2 by trying to run freetype-config
-sub freetype2_probe {
+sub freetype2_probe_ftconfig {
   my ($frm, $frmkey) = @_;
 
   is_exe('freetype-config') or return;
@@ -716,6 +753,82 @@ sub freetype2_probe {
   return 1;
 }
 
+# attempt to probe for freetype2 by scanning directories
+# we can't use the normal scan since we need to find the directory
+# containing most of the includes
+sub freetype2_probe_scan {
+  my ($frm, $frmkey) = @_;
+
+  my $found_inc;
+  my $found_inc2;
+ INCS:
+  for my $inc (@incs) {
+    my $path = File::Spec->catfile($inc, 'ft2build.h');
+    -e $path or next;
+
+    # try to find what it's including
+    my $ftheader;
+    open FT2BUILD, "< $path"
+      or next;
+    while (<FT2BUILD>) {
+      if (m!^\s*\#\s*include\s+<([\w/.]+)>!
+         || m!^\s*\#\s*include\s+"([\w/.]+)"!) {
+       $ftheader = $1;
+       last;
+      }
+    }
+    close FT2BUILD;
+    $ftheader
+      or next;
+    # non-Unix installs put this directly under the same directory in
+    # theory
+    if (-e File::Spec->catfile($inc, $ftheader)) {
+      $found_inc = $inc;
+      last INCS;
+    }
+    for my $subdir (qw/freetype2 freetype/) {
+      $path = File::Spec->catfile($inc, $subdir, 'fterrors.h');
+      -e $path and next;
+
+      $found_inc = $inc;
+      $found_inc2 = File::Spec->catdir($inc, $subdir);
+      last INCS;
+    }
+  }
+
+  my $found_lib;
+ LIBS:
+  for my $lib (@libs) {
+    my $a_path = File::Spec->catfile($lib, "libfreetype$aext");
+    my $l_path = File::Spec->catfile($lib, "libfreetype.$lext");
+    if (-e $a_path || -e $l_path) {
+      $found_lib = $lib;
+      last LIBS;
+    }
+  }
+
+  printf("%10s: includes %s - libraries %s\n", $frmkey,
+        ($found_inc ? 'found' : 'not found'), 
+        ($found_lib ? 'found' : 'not found'));
+
+  return unless $found_inc && $found_lib;
+
+  $frm->{cflags} = _make_I($found_inc);
+  $frm->{cflags} .= " " . _make_I($found_inc2) if $found_inc2;
+  $frm->{libfiles} = "-lfreetype";
+
+  return 1;
+}
+
+sub _make_I {
+  my ($inc_dir) = @_;
+
+  $definc{$inc_dir}
+    and return '';
+
+  $inc_dir =~ / / ? qq!-I"$inc_dir"! : "-I$inc_dir";
+}
+
 # probes for libpng via pkg-config
 sub png_probe {
   my ($frm, $frmkey) = @_;
@@ -778,8 +891,6 @@ Other options:
     Add to the include search path
   --libpath dir
     Add to the library search path
-  --noprobe
-    Don't use pkg-config or freetype2-config to probe for freetype2 and libpng
 EOS
   exit 1;
 
@@ -846,10 +957,19 @@ YAML
       $meta .= "  $module: $version\n";
     }
   }
+  if ($opts->{PREREQ_PM}) {
+    $meta .= "requires:\n";
+    while (my ($module, $version) = each %{$opts->{PREREQ_PM}}) {
+      $meta .= "  $module: $version\n";
+    }
+  }
   $meta .= <<YAML;
 license: perl
 dynamic_config: 1
 distribution_type: module
+meta-spec:
+  version: 1.3
+  url: http://module-build.sourceforge.net/META-spec-v1.3.html
 generated_by: $opts->{NAME} version $version
 YAML
   my $save_meta;
@@ -870,31 +990,3 @@ YAML
   }
 }
 
-# this is intended to only be running on the development
-# machines
-sub distcheck {
-  if (-e '.svn') {
-    # update Changes if needed
-    my $write_changes;
-    # get the last revision from Changes
-    if (open CHANGES, "< Changes") {
-      <CHANGES>;
-      my ($changes_rev) = <CHANGES> =~ /^r(\d+)/
-       or ++$write_changes;
-
-      my ($revision) = grep s/^Revision: //, `svn info`
-       or die "Could not get Revision from svn";
-      chomp $revision;
-
-      $write_changes ||= $changes_rev != $revision;
-      close CHANGES;
-    }
-    else {
-      ++$write_changes;
-    }
-    if ($write_changes) {
-      print "Updating Changes file\n";
-      system 'svn log -v -r HEAD:943 >Changes';
-    }
-  }
-}