]> git.imager.perl.org - imager.git/blobdiff - Makefile.PL
make sure flipping paletted images is covered
[imager.git] / Makefile.PL
index f13b7e1636f0158a589e29a61452d0f3d30f1072..0b71b80745f2e1e62689641b8b6f1838d5b2f8d2 100644 (file)
@@ -5,9 +5,10 @@ use Cwd;
 use Config;
 use File::Spec;
 use Getopt::Long;
-use vars qw(%Recommends);
 use ExtUtils::Manifest qw(maniread);
 use vars qw(%formats $VERBOSE $INCPATH $LIBPATH $NOLOG $DEBUG_MALLOC $MANUAL $CFLAGS $LFLAGS $DFLAGS);
+use lib 'inc';
+use Devel::CheckLib;
 
 #
 # IM_INCPATH      colon seperated list of paths to extra include paths
@@ -24,7 +25,8 @@ use vars qw(%formats $VERBOSE $INCPATH $LIBPATH $NOLOG $DEBUG_MALLOC $MANUAL $CF
 # IM_CFLAGS       Extra flags to pass to the compiler
 # IM_LFLAGS       Extra flags to pass to the linker
 # IM_DFLAGS       Extra flags to pass to the preprocessor
-# IM_SUPPRESS_PROMPT  Suppress the prompt asking about gif support
+
+my $KEEP_FILES = $ENV{IMAGER_KEEP_FILES};
 
 getenv();     # get environment variables
 
@@ -39,6 +41,7 @@ my @libpaths; # places to look for libraries
 my $noexif; # non-zero to disable EXIF parsing of JPEGs
 my $no_gif_set_version; # disable calling EGifSetGifVersion
 my $coverage; # build for coverage testing
+my $assert; # build with assertions
 GetOptions("help" => \$help,
            "enable=s" => \@enable,
            "disable=s" => \@disable,
@@ -48,7 +51,12 @@ GetOptions("help" => \$help,
            "nolog" => \$NOLOG,
           "noexif" => \$noexif,
            "nogifsetversion" => \$no_gif_set_version,
-          'coverage' => \$coverage);
+          'coverage' => \$coverage,
+          "assert|a" => \$assert);
+
+if ($ENV{AUTOMATED_TESTING}) {
+  $assert = 1;
+}
 
 if ($VERBOSE) { 
   print "Verbose mode\n"; 
@@ -67,6 +75,10 @@ else {
   push @defines, [ IMAGER_LOG => 1, "Logging system" ];
 }
 
+if ($assert) {
+  push @defines, [ IM_ASSERT => 1, "im_assert() are effective" ];
+}
+
 if ($DEBUG_MALLOC) {
   push @defines, [ IMAGER_DEBUG_MALLOC => 1, "Use Imager's DEBUG malloc()" ];
   print "Malloc debugging enabled\n";
@@ -156,10 +168,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 color.o fills.o imgdouble.o limits.o hlines.o
-              imext.o scale.o rubthru.o render.o paste.o compose.o);
-
-$Recommends{Imager} =
-  { 'Parse::RecDescent' => 0 };
+              imext.o scale.o rubthru.o render.o paste.o compose.o flip.o);
 
 my %opts=(
           'NAME'         => 'Imager',
@@ -168,7 +177,7 @@ my %opts=(
           'DEFINE'       => "$OSDEF $CFLAGS",
           'INC'          => "$lib_cflags $DFLAGS $F_INC",
           'OBJECT'       => join(' ', @objs, $F_OBJECT),
-          clean          => { FILES=>'testout meta.tmp rubthru.c scale.c conv.c  filters.c gaussian.c render.c rubthru.c' },
+          clean          => { FILES=>'testout rubthru.c scale.c conv.c  filters.c gaussian.c render.c rubthru.c' },
           PM             => gen_PM(),
          PREREQ_PM      => { 'Test::More' => 0.47 },
          );
@@ -189,8 +198,17 @@ 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 ($MM_ver > 6.10) {
-  $opts{NO_META} = 1;
+
+if ($MM_ver >= 6.46) {
+  $opts{META_MERGE} =
+    {
+     recommends =>
+     {
+      "Parse::RecDescent" => 0
+     },
+     license => "perl",
+     dynamic_config => 1,
+    };
 }
 
 make_imconfig(\@defines);
@@ -198,7 +216,7 @@ make_imconfig(\@defines);
 if ($VERBOSE) { print Dumper(\%opts); }
 mkdir('testout',0777); # since we cannot include it in the archive.
 
-make_metafile(\%opts);
+-d "probe" and rmdir "probe";
 
 WriteMakefile(%opts);
 
@@ -223,7 +241,7 @@ imconfig.h : Makefile.PL
        $(PERLRUN) Makefile.PL
        $(ECHO) "==> Your Makefile has been rebuilt - re-run your make command <=="
 '.qq!
-lib/Imager/APIRef.pod : \$(C_FILES) apidocs.perl
+lib/Imager/APIRef.pod : \$(C_FILES) \$(H_FILES) apidocs.perl
        $perl apidocs.perl lib/Imager/APIRef.pod
 
 !.join('', map _im_rule($perl, $_), @ims)
@@ -335,22 +353,8 @@ sub grep_directory {
   return map $path, @l;
 }
 
-
-sub checkformat {
-  my $frm=shift;
-
-  print "  checkformat($frm)\n" if $VERBOSE;
-  
-  my $probe_array = $formats{$frm}{'code'};
-  if ($probe_array) {
-    print "    Calling probe function\n" if $VERBOSE;
-    if (ref $probe_array ne 'ARRAY') {
-      $probe_array = [ $probe_array ];
-    }
-    for my $func (@$probe_array) {
-      return 1 if $func->($formats{$frm}, $frm);
-    }
-  }
+sub _probe_default {
+  my ($format, $frm) = @_;
 
   my $lib_check=$formats{$frm}{'libcheck'};
   my $inc_check=$formats{$frm}{'inccheck'};
@@ -378,6 +382,44 @@ sub checkformat {
   return 0;
 }
 
+sub checkformat {
+  my $frm=shift;
+
+  print "  checkformat($frm)\n" if $VERBOSE;
+  
+  my $format = $formats{$frm};
+
+  my @probes;
+  if (my $code = $format->{'code'}) {
+    if (ref $code eq 'ARRAY') {
+      push @probes, @$code;
+    }
+    else {
+      push @probes, $code;
+    }
+  }
+  push @probes, \&_probe_default;
+
+  print "    Calling probe function\n" if $VERBOSE;
+  my $found;
+  for my $func (@probes) {
+    if ($func->($format, $frm)) {
+      ++$found;
+      last;
+    }
+  }
+
+  $found or return;
+
+  if ($format->{postcheck}) {
+    print "    Calling postcheck function\n" if $VERBOSE;
+    $format->{postcheck}->($format, $frm)
+      or return;
+  }
+
+  return 1;
+}
+
 
 sub pathcheck {
   if ($VERBOSE) {
@@ -487,7 +529,8 @@ sub init {
                    objfiles=>'tiff.o',
                    docs=>q{
                            In order to use tiff with this module you need to have libtiff
-                           installed on your computer}
+                           installed on your computer},
+                   postcheck => \&postcheck_tiff,
                   };
 
   $formats{'png'}={
@@ -870,9 +913,16 @@ sub catfile {
 sub is_exe {
   my ($name) = @_;
 
+  my @exe_suffix = $Config{_exe};
+  if ($^O eq 'MSWin32') {
+    push @exe_suffix, qw/.bat .cmd/;
+  }
+
   for my $dir (File::Spec->path) {
-    -x catfile($dir, "$name$Config{_exe}")
-      and return 1;
+    for my $suffix (@exe_suffix) {
+      -x catfile($dir, "$name$suffix")
+       and return 1;
+    }
   }
 
   return;
@@ -894,6 +944,12 @@ Other options:
     Add to the include search path
   --libpath dir
     Add to the library search path
+  --coverage
+    Build for coverage testing.
+  --assert
+    Build with assertions active.
+  --noexif
+    Disable EXIF parsing.
 EOS
   exit 1;
 
@@ -934,70 +990,6 @@ sub gen_PM {
   \%pm;
 }
 
-sub make_metafile {
-  my ($opts) = @_;
-
-  # extract the version
-  my $version = MM->parse_version($opts->{VERSION_FROM})
-    or die "Could not extract version number from $opts->{VERSION_FROM}\n";
-
-  # we don't set this on older EU::MM and it corrupts META.yml
-  # so don't generate it
-  return unless $opts->{AUTHOR};
-
-  my $meta = <<YAML;
---- #YAML:1.0
-name: $opts->{NAME}
-version: $version
-version_from: $opts->{VERSION_FROM}
-author:
-YAML
-  for my $author (split /,\s*/, $opts->{AUTHOR}) {
-    $meta .= " - $author\n";
-  }
-  $meta .= <<YAML;
-abstract: $opts->{ABSTRACT}
-installdirs: site
-YAML
-  if (keys %{$Recommends{$opts->{NAME}}}) {
-    $meta .= "recommends:\n";
-    while (my ($module, $version) = each %{$Recommends{$opts->{NAME}}}) {
-      $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;
-  if (open META, "< META.yml") {
-    my $old_meta = do { local $/; <META> };
-    close META;
-
-    $save_meta = $old_meta ne $meta;
-  }
-  else {
-    ++$save_meta;
-  }
-  if ($save_meta) {
-    print "Updating META.yml\n";
-    open META, "> META.yml" or die "Cannot create META.yml: $!";
-    print META $meta;
-    close META;
-  }
-}
-
 my $home;
 sub _tilde_expand {
   my ($path) = @_;
@@ -1019,6 +1011,74 @@ sub _tilde_expand {
   $path;
 }
 
+sub postcheck_tiff {
+  my ($format, $frm) = @_;
+
+  -d "probe" or mkdir "probe";
+
+  my $tiffver_name = "probe/tiffver.txt";
+
+  my $lib;
+  if ($Config{cc} =~ /\b(cl|bcc)\b/) {
+    $lib = "libtiff";
+  }
+  else {
+    $lib = "tiff";
+  }
+
+  my $good =
+    eval {
+      assert_lib
+       (
+        debug => $VERBOSE,
+        incpath => $format->{incdir},
+        libpath => $format->{libdir},
+        lib => $lib,
+        header => [ qw(stdio.h tiffio.h) ],
+        function => <<FUNCTION,
+  {
+    const char *vers = TIFFGetVersion();
+    FILE *f = fopen("$tiffver_name", "wb");
+    if (!f)
+      return 1;
+    fputs(vers, f);
+    if (fclose(f))
+      return 1;
+    return 0;
+  }
+FUNCTION
+       );
+      1;
+    };
+
+  unless ($good && -s $tiffver_name
+         && open(VERS, "< probe/tiffver.txt")) {
+    unlink $tiffver_name unless $KEEP_FILES;
+    print <<EOS;
+    **tiff: cannot determine libtiff version number
+      tiff: DISABLED
+EOS
+    return;
+  }
+
+  # version file seems to be there, load it up
+  my $ver_str = do { local $/; <VERS> };
+  close VERS;
+  unlink $tiffver_name unless $KEEP_FILES;
+
+  my ($version) = $ver_str =~ /(\d+\.\d+\.\d+)/;
+
+  if ($version eq '3.9.0') {
+    print <<EOS;
+    **tiff: libtiff 3.9.0 introduced a serious bug, please install 3.9.1
+      tiff: DISABLED
+EOS
+    return;
+  }
+
+  return 1;
+}
+
 # This isn't a module, but some broken tools, like
 # Module::Depends::Instrusive insist on treating it like one.
 #