diff -Nurd Imager-1.023.orig/CountColor/Makefile.PL Imager-1.023/CountColor/Makefile.PL
--- Imager-1.023.orig/CountColor/Makefile.PL	2015-08-27 07:32:40.000000000 -0400
+++ Imager-1.023/CountColor/Makefile.PL	2024-02-04 16:40:14.000000000 -0500
@@ -8,6 +8,7 @@
    VERSION_FROM => 'CountColor.pm',
    OBJECT => 'CountColor.o',
    INC => '-I..',
+   exists $ENV{IM_DFLAGS} ? (DEFINE => $ENV{IM_DFLAGS}) : (),
   );
 my $MM_ver = eval $ExtUtils::MakeMaker::VERSION;
 if ($MM_ver > 6.06) {
diff -Nurd Imager-1.023.orig/DynTest/Makefile.PL Imager-1.023/DynTest/Makefile.PL
--- Imager-1.023.orig/DynTest/Makefile.PL	2014-01-10 04:46:39.000000000 -0500
+++ Imager-1.023/DynTest/Makefile.PL	2024-02-04 16:40:14.000000000 -0500
@@ -7,7 +7,8 @@
    NAME => 'Imager::Filter::DynTest',
    VERSION_FROM => 'DynTest.pm',
    OBJECT => 'DynTest.o linstretch.o',
-   INC => '-I..'
+   INC => '-I..',
+   exists $ENV{IM_DFLAGS} ? (DEFINE => $ENV{IM_DFLAGS}) : (),
   );
 my $MM_ver = eval $ExtUtils::MakeMaker::VERSION;
 if ($MM_ver > 6.06) {
diff -Nurd Imager-1.023.orig/Flines/Makefile.PL Imager-1.023/Flines/Makefile.PL
--- Imager-1.023.orig/Flines/Makefile.PL	2015-08-27 07:32:40.000000000 -0400
+++ Imager-1.023/Flines/Makefile.PL	2024-02-04 16:40:14.000000000 -0500
@@ -7,7 +7,8 @@
    NAME => 'Imager::Filter::Flines',
    VERSION_FROM => 'Flines.pm',
    OBJECT => 'Flines.o',
-   INC => '-I..'
+   INC => '-I..',
+   exists $ENV{IM_DFLAGS} ? (DEFINE => $ENV{IM_DFLAGS}) : (),
   );
 my $MM_ver = eval $ExtUtils::MakeMaker::VERSION;
 if ($MM_ver > 6.06) {
diff -Nurd Imager-1.023.orig/ICO/Makefile.PL Imager-1.023/ICO/Makefile.PL
--- Imager-1.023.orig/ICO/Makefile.PL	2015-08-27 07:32:40.000000000 -0400
+++ Imager-1.023/ICO/Makefile.PL	2024-02-04 16:40:14.000000000 -0500
@@ -9,6 +9,7 @@
    OBJECT => 'ICO.o msicon.o imicon.o',
    INC => '-I..',
    clean => { FILES => 'testout' },
+   exists $ENV{IM_DFLAGS} ? (DEFINE => $ENV{IM_DFLAGS}) : (),
   );
 my $MM_ver = eval $ExtUtils::MakeMaker::VERSION;
 if ($MM_ver > 6.06) {
diff -Nurd Imager-1.023.orig/Makefile.PL Imager-1.023/Makefile.PL
--- Imager-1.023.orig/Makefile.PL	2024-01-05 17:02:25.000000000 -0500
+++ Imager-1.023/Makefile.PL	2024-02-04 16:40:14.000000000 -0500
@@ -339,12 +339,15 @@
   }
 }
 
+my @want_good = (qw/ FT2 GIF JPEG PNG T1 TIFF /);
 print "\n";
 print "Libraries found:\n" if @good;
 print "  $_\n" for @good;
+print "(expected: @want_good)\n";
 print "Libraries *not* found:\n" if @bad;
 print "  $_\n" for @bad;
 
+exit 1 unless ("@good" eq "@want_good");
 exit;
 
 
@@ -483,7 +486,7 @@
 
 sub init {
 
-  my @definc = qw(/usr/include);
+  my @definc = qw(@PREFIX@/include /usr/include);
   @definc{@definc}=(1) x @definc;
   @incs=
     (
@@ -500,12 +503,8 @@
     push @incs, grep -d, split /\Q$Config{path_sep}/, $Config{incpath};
   }
   push @incs, grep -d,
-      qw(/sw/include 
-         /usr/include/freetype2
-         /usr/local/include/freetype2
-         /usr/local/include/freetype1/freetype
-         /usr/include /usr/local/include /usr/include/freetype
-         /usr/local/include/freetype);
+      qw(@PREFIX@/include
+         /usr/include);
   if ($Config{ccflags}) {
     my @hidden = map { /^-I(.*)$/ ? ($1) : () } split ' ', $Config{ccflags};
     push @incs, @hidden;
@@ -537,7 +536,7 @@
     # it can't find and it doesn't look for -L in ldflags
     #@deflib{@hidden} = @hidden;
   }
-  push @libs, grep -d, qw(/usr/local/lib);
+  push @libs, grep -d, qw(@PREFIX@/lib);
 
   $formats{FT1}=
     {
diff -Nurd Imager-1.023.orig/Mandelbrot/Makefile.PL Imager-1.023/Mandelbrot/Makefile.PL
--- Imager-1.023.orig/Mandelbrot/Makefile.PL	2015-08-27 07:32:40.000000000 -0400
+++ Imager-1.023/Mandelbrot/Makefile.PL	2024-02-04 16:40:14.000000000 -0500
@@ -7,7 +7,8 @@
    NAME => 'Imager::Filter::Mandelbrot',
    VERSION_FROM => 'Mandelbrot.pm',
    OBJECT => 'Mandelbrot.o mandel.o',
-   INC => '-I..'
+   INC => '-I..',
+   exists $ENV{IM_DFLAGS} ? (DEFINE => $ENV{IM_DFLAGS}) : (),
   );
 my $MM_ver = eval $ExtUtils::MakeMaker::VERSION;
 if ($MM_ver > 6.06) {
diff -Nurd Imager-1.023.orig/SGI/Makefile.PL Imager-1.023/SGI/Makefile.PL
--- Imager-1.023.orig/SGI/Makefile.PL	2015-08-27 07:32:40.000000000 -0400
+++ Imager-1.023/SGI/Makefile.PL	2024-02-04 16:40:14.000000000 -0500
@@ -9,6 +9,7 @@
    OBJECT => 'SGI.o imsgi.o',
    INC => '-I..',
    clean => { FILES => 'testout' },
+   exists $ENV{IM_DFLAGS} ? (DEFINE => $ENV{IM_DFLAGS}) : (),
   );
 my $MM_ver = eval $ExtUtils::MakeMaker::VERSION;
 if ($MM_ver > 6.06) {
diff -Nurd Imager-1.023.orig/dynfilt/Makefile.PL Imager-1.023/dynfilt/Makefile.PL
--- Imager-1.023.orig/dynfilt/Makefile.PL	2012-09-28 19:58:04.000000000 -0400
+++ Imager-1.023/dynfilt/Makefile.PL	2024-02-04 16:40:14.000000000 -0500
@@ -17,6 +17,7 @@
     NAME      => 'Imager::plugins',
     SKIP      => [qw(all dynamic static )],
     clean     => {'FILES' => $libstr},
+    exists $ENV{IM_DFLAGS} ? (DEFINE => $ENV{IM_DFLAGS}) : (),
 );
 
 
diff -Nurd Imager-1.023.orig/lib/Imager/Color.pm Imager-1.023/lib/Imager/Color.pm
--- Imager-1.023.orig/lib/Imager/Color.pm	2022-07-09 07:32:29.000000000 -0400
+++ Imager-1.023/lib/Imager/Color.pm	2024-02-04 16:40:14.000000000 -0500
@@ -158,6 +158,8 @@
 
 my @x_search =
   (
+   '/opt/X11/share/X11/rgb.txt',   # OS X (modern xquartz)
+   '/usr/X11/share/X11/rgb.txt',   # OS X (original xorg)
    '/usr/share/X11/rgb.txt', # newer Xorg X11 dists use this
    '/usr/lib/X11/rgb.txt', # seems fairly standard
    '/usr/local/lib/X11/rgb.txt', # seems possible
diff -Nurd Imager-1.023.orig/lib/Imager/Probe.pm Imager-1.023/lib/Imager/Probe.pm
--- Imager-1.023.orig/lib/Imager/Probe.pm	2022-07-09 07:32:29.000000000 -0400
+++ Imager-1.023/lib/Imager/Probe.pm	2024-02-04 16:40:14.000000000 -0500
@@ -60,6 +60,9 @@
 
     $result or return;
 
+    if (exists $ENV{IM_DFLAGS}) {
+        $result->{DEFINE} = $ENV{IM_DFLAGS} . ' ' . $result->{DEFINE};
+    }
     $result = _probe_test($req, $result);
   }
 
@@ -412,8 +415,8 @@
      ),
      $^O eq "MSWin32" ? $ENV{LIB} : "",
      $^O eq "cygwin" ? "/usr/lib/w32api" : "",
+     "@PREFIX@/lib",
      "/usr/lib",
-     "/usr/local/lib",
      _gcc_lib_paths(),
      _dyn_lib_paths(),
     );
@@ -467,8 +470,8 @@
       grep $_,
       @Config{qw/locincpth incpath/}
      ),
+     "@PREFIX@/include",
      "/usr/include",
-     "/usr/local/include",
      _gcc_inc_paths(),
      _dyn_inc_paths(),
     );
diff -Nurd Imager-1.023.orig/t/200-file/100-files.t Imager-1.023/t/200-file/100-files.t
--- Imager-1.023.orig/t/200-file/100-files.t	2022-07-09 07:32:29.000000000 -0400
+++ Imager-1.023/t/200-file/100-files.t	2024-02-04 16:40:14.000000000 -0500
@@ -37,7 +37,6 @@
 PERL
   close SCRIPT;
   my $perl = $^X;
-  $perl = qq/"$perl"/ if $perl =~ / /;
   
   print "# script: $test_script\n";
   my $cmd = "$perl -Mblib $test_script t/200-file/100-files.t";
