diff --git a/Graphics/PLplot/Makefile.PL b/Graphics/PLplot/Makefile.PL
index 59cdf64..25d9688 100644
--- a/Graphics/PLplot/Makefile.PL
+++ b/Graphics/PLplot/Makefile.PL
@@ -1,5 +1,5 @@
-# Makefile.PL for a package defined by PP code.
-
+use strict;
+use warnings;
 use ExtUtils::MakeMaker;
 use Config;
 use File::Spec;
@@ -18,6 +18,7 @@ use Data::Dumper;
 # end comment this block out for PDL internal version
 
 my $pdl_installed = 1; # uncomment for PDL-internal version
+my ($plplot_lib_path, $plplot_include_path);
 
 if (!$pdl_installed) {
   # write dummy makefile if PDL not installed
@@ -39,7 +40,6 @@ unlink ("OPTIONS!"); # remove file used to communicate with plplot.pd
 # use $Config{"so"} to get the extension name
 #
 my $libname = "libplplotd." . $Config{"so"};
-my $libname_static = "libplplotd.a";
 my $incname = "plplot.h";
 my $devnull = File::Spec->devnull(); # Portable null device.
 
@@ -59,6 +59,7 @@ unless ($found_plplot) {
 }
 
 foreach my $libdir (
+		    split(/ /, $Config{libpth}),
 		    $ENV{PLPLOT_LIBDIR},
 		    $PDL::Config{WHERE_PLPLOT_LIBS},
 		    '/usr/local/plplot/lib64',
@@ -75,25 +76,32 @@ foreach my $libdir (
 		                  # Add new library paths here!!
 		    ) {
 
+  next unless $libdir;
   if (-e "$libdir/$libname") {
     $plplot_lib_path = $libdir;
     $ENV{LD_LIBRARY_PATH} .= ":$libdir";
     last;
-  } elsif (-e "$libdir/$libname_static") {
+  } elsif (-e "$libdir/libplplotd.a") {
+    $plplot_lib_path = $libdir;
+    $ENV{LD_LIBRARY_PATH} .= ":$libdir";
+    $libname = 'libplplotd.a';
+    last;
+  } elsif (-e "$libdir/libplplotd.dll.a") {
     $plplot_lib_path = $libdir;
     $ENV{LD_LIBRARY_PATH} .= ":$libdir";
-    $libname = $libname_static;
+    $libname = 'libplplotd.dll.a';
     last;
   }
 
 }
 
 unless (defined ($plplot_lib_path)) {
-  buildDummy ("Cannot find plplot library ($libname), skipping PDL::Graphics::PLplot\n");
+  buildDummy ("Cannot find plplot library ($libname), skipping PDL::Graphics::PLplot");
   return if (caller); exit;
 }
 
 foreach my $incdir (
+		    "$Config{usrinc}/plplot",
 		    $ENV{PLPLOT_INCDIR},
 		    $PDL::Config{WHERE_PLPLOT_INCLUDE},
                     '/usr/local/plplot/include',
@@ -110,10 +118,10 @@ foreach my $incdir (
 		                  # Add new header paths here!!
 		    ) {
 
-  if (-e "$incdir/$incname") {
+  if (defined($incdir) && -e "$incdir/$incname") {
     $plplot_include_path = "-I$incdir";
     if ($incdir =~ m|/plplot$|) {
-      $inc2 = $incdir;
+      my $inc2 = $incdir;
       $inc2 =~ s|/plplot$||;
       $plplot_include_path .= " -I$inc2";
     }
@@ -122,7 +130,7 @@ foreach my $incdir (
 }
 
 unless (defined ($plplot_include_path)) {
-  buildDummy ("Cannot find plplot header file ($incname), skipping PDL::Graphics::PLplot\n");
+  buildDummy ("Cannot find plplot header file ($incname), skipping PDL::Graphics::PLplot");
   return if (caller); exit;
 }
 
@@ -134,7 +142,7 @@ EOC
 
 unless ($size == 8) {
   print "          Sizeof(PLFLT) must be 8. PLplot must be compiled --with-double (IE ./configure --with-double)\n";
-  buildDummy ("Cannot find good set of libraries for linking PLplot, try fiddling perldl.conf\n");
+  buildDummy ("Cannot find good set of libraries for linking PLplot, try fiddling perldl.conf");
   return if (caller); exit;
 }
 
@@ -154,7 +162,7 @@ foreach my $l (
 }
 
 unless (defined($libs)) {
-  buildDummy ("Cannot find good set of libraries for linking PLplot, try fiddling perldl.conf\n");
+  buildDummy ("Cannot find good set of libraries for linking PLplot, try fiddling perldl.conf");
   return if (caller); exit;
 }
 
@@ -180,19 +188,15 @@ close   $fh;
 
 $PDL::Config{WITH_PLPLOT} = 1;
 
+my @pack = (["plplot.pd", qw(PLplot PDL::Graphics::PLplot)]);
 
-#
-## new way to get writemakefile args...
-#
-@pack = (["plplot.pd",PLplot,PDL::Graphics::PLplot]);
-
-#%hash = pdlpp_stdargs_int(@::pack);  # use this for module inside PDL source
-%hash = pdlpp_stdargs(@::pack);          # use this for separate module          
+#%hash = pdlpp_stdargs_int(@pack);  # use this for module inside PDL source
+my %hash = pdlpp_stdargs(@pack);          # use this for separate module
 
 # $hash{'PREREQ_PM'} = { PDL => 0 };
 $hash{'OPTIMIZE'}  = '-g'; # If you want to debug, uncomment this.
 $hash{'VERSION_FROM'}   = 'plplot.pd';
-$hash{'META_MERGE'}   = {provides => {PDL::Graphics::PLplot => {file => 'plplot.pd', version => 0.57}}};
+$hash{'META_MERGE'}   = {provides => {'PDL::Graphics::PLplot' => {file => 'plplot.pd', version => 0.57}}};
 
 $hash{'LIBS'}      = [$libs];
 # add this to allow one to use the /ops/tools/lib plplot libs even when
@@ -203,13 +207,14 @@ $hash{'INC'}      .= " $plplot_include_path";
 $hash{'clean'}     = {'FILES'  =>
                         'PLplot.pm PLplot.xs PLplot.o PLplot.c PLplot.bs *svg.* *.xfig temp* OPTIONS! Makefile.old'};
 
-#my $postamble = pdlpp_postamble(@::pack); # use for external module
-my $postamble = pdlpp_postamble_int(@::pack); # use for install inside PDL distro
-
-WriteMakefile(%hash);
+#my $postamble = pdlpp_postamble(@pack); # use for external module
+my $postamble = pdlpp_postamble_int(@pack); # use for install inside PDL distro
 
 # Add genpp rule
-sub MY::postamble { $postamble };
+undef &MY::postamble; # suppress warning
+*MY::postamble = sub { $postamble };
+
+WriteMakefile(%hash);
 
 sub test_func_exists {
 
@@ -259,8 +264,11 @@ sub compileAndRun {
   system "$cc $ccflags $flags temp.c $flags -o temp > $devnull 2>&1";
   unlink('./temp.c');
   die "Cannot compile test program: $code" unless (-e 'temp' or -e 'temp.exe');
-  return unless ($run);
-
+  unless ($run){
+      unlink './temp';
+      unlink './temp.exe';
+      return;
+  }
   my $res = `./temp`;
   unlink ('./temp');
   return $res;
@@ -268,9 +276,6 @@ sub compileAndRun {
 
 sub buildDummy {
   my $msg = shift;
-  $msg .= "\n      Not building PDL::Graphics::PLplot\n";
-  warn $msg . "\n";
-  $msg =~ s/\n//g;
-  write_dummy_make( $msg );
+  write_dummy_make( "$msg\nNot building PDL::Graphics::PLplot" );
   $PDL::Config{WITH_PLPLOT} = 0;
 }
diff --git a/Graphics/PLplot/plplot.pd b/Graphics/PLplot/plplot.pd
index 215c96b..9f68130 100644
--- a/Graphics/PLplot/plplot.pd
+++ b/Graphics/PLplot/plplot.pd
@@ -1,7 +1,8 @@
 use Config;
 
-my $ptrsize = length($Config{'byteorder'}); # 4 or 8 bytes
-my $int_ptr_type = ($ptrsize == 4) ? 'I32' : 'long';
+my $ptrsize = $Config{'ptrsize'};
+my $int_ptr_type = ($ptrsize == 4) ? $Config{i32type} : $Config{i64type}; # pointer type in C code
+my $pp_ptr_type  = ($ptrsize == 4) ? 'int' : 'longlong';    # pointer type in pp_def Pars sections
 
 # User can set this global variable to 1 if he wants
 # to use the normal plplot order of arguments, not the PP-required
@@ -2011,6 +2012,11 @@ pp_addhdr(<<'EOH');
 #include <plplotP.h>
 #include <plevent.h>
 #include <stdio.h>
+
+#ifdef plwidth
+#define c_plwid c_plwidth
+#endif
+
 EOH
 
 # The create_low_level_constants function is used to make the #define'd
@@ -2246,7 +2252,7 @@ C:
 
 perl:
 
-  my ($legend_width, $legend_height) = 
+  my ($legend_width, $legend_height) =
     pllegend ($position, $opt, $x, $y, $plot_width, $bg_color, $nlegend,
     \@opt_array,
     $text_offset, $text_scale, $text_spacing, $test_justification,
@@ -3447,7 +3453,7 @@ EOC
 
 pp_def ('plAllocGrid',
         NoPthread => 1,
-        Pars => 'double xg(nx); double yg(ny); int [o] grid()',
+        Pars => "double xg(nx); double yg(ny); $pp_ptr_type [o] grid()",
         GenericTypes => [D],
         Doc => 'FIXME: documentation here!',
         Code => '
@@ -3496,7 +3502,7 @@ pp_add_exported (plFreeGrid);
 
 pp_def ('plAlloc2dGrid',
         NoPthread => 1,
-        Pars => 'double xg(nx,ny); double yg(nx,ny); int [o] grid()',
+        Pars => "double xg(nx,ny); double yg(nx,ny); $pp_ptr_type [o] grid()",
         GenericTypes => [D],
         Doc => 'FIXME: documentation here!',
         Code => '
@@ -3639,7 +3645,11 @@ mapform_callback (PLINT n, PLFLT* x, PLFLT* y)
   pdl *x_pdl, *y_pdl;
   PLFLT *tx, *ty;
   SV *x_sv, *y_sv;
+#if defined(PDL_CORE_VERSION) && PDL_CORE_VERSION >= 10
+  PDL_Indx dims, i;
+#else
   int dims, i;
+#endif
   I32 count, ax;
   dSP;
 
@@ -3766,7 +3776,7 @@ void labelfunc_callback (PLINT axis, PLFLT value, char *label_text, PLINT length
     croak ("labelfunc: must return one perl scalar");
 
   // Copy label into output string
-  snprintf( label_text, length, (char *)SvPV_nolen(ST(0)) );
+  snprintf( label_text, length, "%s", (char *)SvPV_nolen(ST(0)) );
 
   PUTBACK;
   FREETMPS;
@@ -4622,7 +4632,7 @@ pp_addpm (<<'EOPM');
 
 =for sig
 
-my ($legend_width, $legend_height) = 
+my ($legend_width, $legend_height) =
     pllegend ($position, $opt, $x, $y, $plot_width, $bg_color, $nlegend,
     \@opt_array,
     $text_offset, $text_scale, $text_spacing, $test_justification,
@@ -4695,35 +4705,35 @@ PPCODE:
     elem = av_fetch((AV *)SvRV(text_rv),            i, 0); text[i]            = (char *)SvPV_nolen(*elem);
     box_colors[i] = 0;
     if (SvROK(box_colors_rv)) {
-      elem = av_fetch((AV *)SvRV(box_colors_rv),    i, 0); 
+      elem = av_fetch((AV *)SvRV(box_colors_rv),    i, 0);
       if (elem && SvOK(*elem)) {
         box_colors[i] = (int)SvIV(*elem);
       }
     }
     box_patterns[i] = 0;
     if (SvROK(box_patterns_rv)) {
-      elem = av_fetch((AV *)SvRV(box_patterns_rv),  i, 0); 
+      elem = av_fetch((AV *)SvRV(box_patterns_rv),  i, 0);
       if (elem && SvOK(*elem)) {
         box_patterns[i] = (int)SvIV(*elem);
       }
     }
     box_scales[i] = 0.0;
     if (SvROK(box_scales_rv)) {
-      elem = av_fetch((AV *)SvRV(box_scales_rv),    i, 0); 
+      elem = av_fetch((AV *)SvRV(box_scales_rv),    i, 0);
       if (elem && SvOK(*elem)) {
         box_scales[i] = (double)SvNV(*elem);
       }
     }
     box_line_widths[i] = 0;
     if (SvROK(box_line_widths_rv)) {
-      elem = av_fetch((AV *)SvRV(box_line_widths_rv), i, 0); 
+      elem = av_fetch((AV *)SvRV(box_line_widths_rv), i, 0);
       if (elem && SvOK(*elem)) {
         box_line_widths[i] = (int)SvIV(*elem);
       }
     }
     line_colors[i] = 0;
     if (SvROK(line_colors_rv)) {
-      elem = av_fetch((AV *)SvRV(line_colors_rv), i, 0); 
+      elem = av_fetch((AV *)SvRV(line_colors_rv), i, 0);
       if (elem && SvOK(*elem)) {
         line_colors[i] = (int)SvIV(*elem);
       }
@@ -4731,7 +4741,7 @@ PPCODE:
 
     line_styles[i] = 0;
     if (SvROK(line_styles_rv)) {
-      elem = av_fetch((AV *)SvRV(line_styles_rv), i, 0); 
+      elem = av_fetch((AV *)SvRV(line_styles_rv), i, 0);
       if (elem && SvOK(*elem)) {
         line_styles[i] = (int)SvIV(*elem);
       }
@@ -4739,7 +4749,7 @@ PPCODE:
 
     line_widths[i] = 0;
     if (SvROK(line_widths_rv)) {
-      elem = av_fetch((AV *)SvRV(line_widths_rv), i, 0); 
+      elem = av_fetch((AV *)SvRV(line_widths_rv), i, 0);
       if (elem && SvOK(*elem)) {
         line_widths[i] = (int)SvIV(*elem);
       }
@@ -4747,7 +4757,7 @@ PPCODE:
 
     symbol_colors[i] = 0;
     if (SvROK(symbol_colors_rv)) {
-      elem = av_fetch((AV *)SvRV(symbol_colors_rv), i, 0); 
+      elem = av_fetch((AV *)SvRV(symbol_colors_rv), i, 0);
       if (elem && SvOK(*elem)) {
         symbol_colors[i] = (int)SvIV(*elem);
       }
@@ -4755,7 +4765,7 @@ PPCODE:
 
     symbol_scales[i] = 0.0;
     if (SvROK(symbol_scales_rv)) {
-      elem = av_fetch((AV *)SvRV(symbol_scales_rv), i, 0); 
+      elem = av_fetch((AV *)SvRV(symbol_scales_rv), i, 0);
       if (elem && SvOK(*elem)) {
         symbol_scales[i] = (double)SvNV(*elem);
       }
@@ -4763,7 +4773,7 @@ PPCODE:
 
     symbol_numbers[i] = 0;
     if (SvROK(symbol_numbers_rv)) {
-      elem = av_fetch((AV *)SvRV(symbol_numbers_rv), i, 0); 
+      elem = av_fetch((AV *)SvRV(symbol_numbers_rv), i, 0);
       if (elem && SvOK(*elem)) {
         symbol_numbers[i] = (int)SvIV(*elem);
       }
@@ -4771,7 +4781,7 @@ PPCODE:
 
     symbols[i] = "0";
     if (SvROK(symbols_rv)) {
-      elem = av_fetch((AV *)SvRV(symbols_rv), i, 0); 
+      elem = av_fetch((AV *)SvRV(symbols_rv), i, 0);
       if (elem && SvOK(*elem)) {
         symbols[i] = (char *)SvPV_nolen(*elem);
       }
@@ -4865,13 +4875,13 @@ EOPM
 pp_addxs (<<"EOC");
 void
 plbtime (ctime)
-  double ctime 
+  double ctime
 PPCODE:
   PLINT year;
   PLINT month;
   PLINT day;
   PLINT hour;
-  PLINT min; 
+  PLINT min;
   PLFLT sec;
   c_plbtime(&year, &month, &day, &hour, &min, &sec, ctime);
   EXTEND (SP, 6);
@@ -4895,7 +4905,7 @@ pp_addpm (<<'EOPM');
 
 =for ref
 
-Configure transformation between continuous and broken-down time (and                                                           
+Configure transformation between continuous and broken-down time (and
 vice versa) for current stream.
 
 =cut
@@ -4916,8 +4926,8 @@ plconfigtime(scale, offset1, offset2, ccontrol, ifbtime_offset, year, month, day
   int min
   double sec
 PPCODE:
-  c_plconfigtime((PLFLT) scale, (PLFLT) offset1, (PLFLT) offset2, 
-                 (PLINT) ccontrol, (PLBOOL) ifbtime_offset, (PLINT) year, 
+  c_plconfigtime((PLFLT) scale, (PLFLT) offset1, (PLFLT) offset2,
+                 (PLINT) ccontrol, (PLBOOL) ifbtime_offset, (PLINT) year,
                  (PLINT) month, (PLINT) day, (PLINT) hour, (PLINT) min, (PLFLT) sec);
 EOC
 pp_add_exported ('plconfigtime');
