Find SDL libraries in Perl's include/lib path.
Rocco Caputo [Sun, 27 Sep 2009 18:57:17 +0000 (14:57 -0400)]
Search Perl's include and lib paths for SDL libraries.  Previously, it
would search in all possible places, and pick up versions that may be
compiled differently.  My hypothesis is that the ones in Perl's paths
are more likely to be built the same way as Perl itself.

make/lib/SDL/Build/Darwin.pm

index 2dd2222..76f1252 100644 (file)
@@ -34,29 +34,62 @@ use base 'SDL::Build';
 
 sub fetch_includes
 {
+       use Config;
+
+       my (@include_path, @lib_path);
+
+       {
+               my %seen;
+               foreach (
+                       ($Config{ccflags} =~ /-I(\S+)/g),
+                       ($Config{cppflags} =~ /-I(\S+)/g),
+               ) {
+                       foreach my $sdl_lib_dir ($_, "$_/SDL") {
+                               next unless -f "$sdl_lib_dir/SDL.h";
+                               push @include_path, $sdl_lib_dir unless $seen{$sdl_lib_dir}++;
+                       }
+               }
+       }
+
+       {
+               my %seen;
+               foreach (
+                       ($Config{libpth} =~ /(\S+)/g),
+                       ($Config{libsdirs} =~ /(\S+)/g),
+                       ($Config{libspath} =~ /(\S+)/g),
+                       ($Config{lddlflags} =~ /-I(\S+)/g),
+                       ($Config{ldflags} =~ /-I(\S+)/g),
+               ) {
+                       next unless -f "$_/libSDL.a";
+                       push @lib_path, $_ unless $seen{$_}++;
+               }
+       }
+
+       die "Can't find an SDL library" unless @include_path and @lib_path;
+       warn "Found SDL headers in $include_path[0] and library in $lib_path[0]";
+
        return (
-       '/usr/local/include/SDL'   => '/usr/local/lib',
-       '/usr/local/include'       => '/usr/local/lib',
-       '/usr/local/include/smpeg' => '/usr/local/lib',
-       '/usr/include/SDL'         => '/usr/lib',
-       '/usr/include'             => '/usr/lib',
-       '/usr/include/smpeg'       => '/usr/lib',
-       '/usr/local/include/GL'    => '/usr/local/lib',
-       '/usr/local/include/gl'    => '/usr/local/lib',
-       '/usr/include/GL'          => '/usr/lib', 
-       '/usr/include/gl'          => '/usr/lib', 
-       '/opt/local/include/SDL'   => '/opt/local/lib',         # Mac Ports
-       '/opt/local/include'   => '/opt/local/lib',             # Mac Ports
-
-       '/System/Library/Frameworks/SDL_mixer.framework/Headers'     => '../../lib',
-       '/System/Library/Frameworks/SDL_image.framework/Headers'     => '../../lib',
-       '/System/Library/Frameworks/SDL_ttf.framework/Headers'       => '../../lib',
-       '/System/Library/Frameworks/libogg.framework/Headers'        => '../../lib',
-       '/System/Library/Frameworks/libvorbis.framework/Headers'     => '../../lib',
-       '/System/Library/Frameworks/libvorbisfile.framework/Headers' => '../../lib',
-       '/System/Library/Frameworks/libvorbisenc.framework/Headers'  => '../../lib',
-       '../../include'                                              => '../../lib',
-       '/System/Library/Frameworks/OpenGL.framework/Headers'        => '/System/Library/Frameworks/OpenGL.framework/Libraries',
+               $include_path[0] => $lib_path[0],
+
+               # Local libraries.
+               '/usr/local/include/smpeg' => '/usr/local/lib',
+               '/usr/local/include/GL'    => '/usr/local/lib',
+               '/usr/local/include/gl'    => '/usr/local/lib',
+
+               # System libraries.
+               '/usr/include/smpeg'       => '/usr/lib',
+               '/usr/include/GL'          => '/usr/lib', 
+               '/usr/include/gl'          => '/usr/lib', 
+
+               # System-wide frameworks.
+               '/System/Library/Frameworks/libogg.framework/Headers'        => '../../lib',
+               '/System/Library/Frameworks/libvorbis.framework/Headers'     => '../../lib',
+               '/System/Library/Frameworks/libvorbisfile.framework/Headers' => '../../lib',
+               '/System/Library/Frameworks/libvorbisenc.framework/Headers'  => '../../lib',
+               '/System/Library/Frameworks/OpenGL.framework/Headers'        => '/System/Library/Frameworks/OpenGL.framework/Libraries',
+
+               # System libraries.
+               '/System/Library/Frameworks/OpenGL.framework/Headers'        => '/System/Library/Frameworks/OpenGL.framework/Libraries',
        );
 }