On Thu, 2005-02-10 at 23:01 -0800, Mike Castle wrote:

Hi Mike,

> This is the patch that I use locally.
> 
> It serves two parts:
> 
> 1) Shows how to add new paths when you too have libraries in strange places
>    (the adding of the SDL directory)

You should be able to do this from the command line when you run perl
Build.PL.  I'm not entirely sure how well it works, but the intent is
there.

> 2) Exposes a bug in GL and smpeg handling within SDL_Perl:
>    * GL headers are supposed to be included as <GL/foo.h>, not <foo.h> (so
>      no need to look for an include/GL directory)
>    * smpeg.h is included as smpeg.h in Build.PL, but smpeg/smpeg.h in the .xs
>      (so no need to look for an include/smpeg directory)

Yeah, that seems like a better solution.

Here's a patch I just wrote to document what SDL::Build does and to put
a couple of these fixes in place.  I'm curious to hear whether this
works better for you (and for people having trouble building on other
platforms).

I think Windows is still horribly broken, but hopefully this fixes this
at least somewhat for other Unixy platforms.

If this patch doesn't apply cleanly to the build system (as Dave's
release uses slightly different paths), feel free to grab the latest
snapshot:

        http://wgz.org/chromatic/perl/sdl/SDL-Perl.tar.gz

-- c


Index: build_lib/SDL/Build/Freebsd.pm
===================================================================
--- build_lib/SDL/Build/Freebsd.pm	(revision 863)
+++ build_lib/SDL/Build/Freebsd.pm	(working copy)
@@ -1,29 +1,32 @@
-package SDL::Build::Linux;
+package SDL::Build::Freebsd;
 
 use base 'SDL::Build';
 
 sub fetch_includes
 {
 	return (
-	'/usr/local/include/SDL11' => '/usr/local/lib',
+		'/usr/include'             => '/usr/lib',
+		'/usr/include/SDL'         => '/usr/lib',
+		'/usr/include/smpeg'       => '/usr/lib',
+		'/usr/local/include'       => '/usr/local/lib',
+		'/usr/local/include/SDL'   => '/usr/local/lib',
+		'/usr/local/include/SDL11' => '/usr/local/lib',
+		'/usr/local/include/smpeg' => '/usr/local/lib',
+		'/usr/X11R6/include'       => '/usr/X11R6/lib',
+	);
+}
 
-	'/usr/local/include'       => '/usr/local/lib',
-	'/usr/local/include/gl'    => '/usr/local/lib',
-	'/usr/local/include/GL'    => '/usr/local/lib',
-	'/usr/local/include/SDL'   => '/usr/local/lib',
-	'/usr/local/include/smpeg' => '/usr/local/lib',
+sub build_links
+{
+	my $self  = shift;
+	my $links = $self->SUPER::build_links();
 
-	'/usr/include'              => '/usr/lib',
-	'/usr/include/gl'           => '/usr/lib',
-	'/usr/include/GL'           => '/usr/lib',
-	'/usr/include/SDL'          => '/usr/lib',
-	'/usr/include/smpeg'        => '/usr/lib',
+	for my $subsystem ( values %$links )
+	{
+		push @{ $subsystem{libs} }, '-pthread';
+	}
 
-	'/usr/X11R6/include'        => '/usr/X11R6/lib',
-	'/usr/X11R6/include/gl'     => '/usr/X11R6/lib',
-	'/usr/X11R6/include/GL'     => '/usr/X11R6/lib',
-
-	);
+	return $links;
 }
 
 1;
Index: build_lib/SDL/Build/Linux.pm
===================================================================
--- build_lib/SDL/Build/Linux.pm	(revision 863)
+++ build_lib/SDL/Build/Linux.pm	(working copy)
@@ -5,21 +5,13 @@
 sub fetch_includes
 {
 	return (
-	'/usr/local/include'       => '/usr/local/lib',
-	'/usr/local/include/gl'    => '/usr/local/lib',
-	'/usr/local/include/GL'    => '/usr/local/lib',
-	'/usr/local/include/SDL'   => '/usr/local/lib',
-	'/usr/local/include/smpeg' => '/usr/local/lib',
-
-	'/usr/include'              => '/usr/lib',
-	'/usr/include/gl'           => '/usr/lib',
-	'/usr/include/GL'           => '/usr/lib',
-	'/usr/include/SDL'          => '/usr/lib',
-	'/usr/include/smpeg'        => '/usr/lib',
-
-	'/usr/X11R6/include'        => '/usr/X11R6/lib',
-	'/usr/X11R6/include/gl'     => '/usr/X11R6/lib',
-	'/usr/X11R6/include/GL'     => '/usr/X11R6/lib',
+		'/usr/include'              => '/usr/lib',
+		'/usr/include/SDL'          => '/usr/lib',
+		'/usr/include/smpeg'        => '/usr/lib',
+		'/usr/local/include'        => '/usr/local/lib',
+		'/usr/local/include/SDL'    => '/usr/local/lib',
+		'/usr/local/include/smpeg'  => '/usr/local/lib',
+		'/usr/X11R6/include'        => '/usr/X11R6/lib',
 	);
 }
 
Index: build_lib/SDL/Build/Netbsd.pm
===================================================================
--- build_lib/SDL/Build/Netbsd.pm	(revision 863)
+++ build_lib/SDL/Build/Netbsd.pm	(working copy)
@@ -5,25 +5,16 @@
 sub fetch_includes
 {
 	return (
-	'/usr/pkg/include',        => '/usr/local/lib',
-	'/usr/pkg/include/SDL'     => '/usr/local/lib',
-	'/usr/pkg/include/smpeg'   => '/usr/local/lib',
-
-	'/usr/local/include'       => '/usr/local/lib',
-	'/usr/local/include/gl'    => '/usr/local/lib',
-	'/usr/local/include/GL'    => '/usr/local/lib',
-	'/usr/local/include/SDL'   => '/usr/local/lib',
-	'/usr/local/include/smpeg' => '/usr/local/lib',
-
-	'/usr/include'              => '/usr/lib',
-	'/usr/include/gl'           => '/usr/lib',
-	'/usr/include/GL'           => '/usr/lib',
-	'/usr/include/SDL'          => '/usr/lib',
-	'/usr/include/smpeg'        => '/usr/lib',
-
-	'/usr/X11R6/include'        => '/usr/X11R6/lib',
-	'/usr/X11R6/include/gl'     => '/usr/X11R6/lib',
-	'/usr/X11R6/include/GL'     => '/usr/X11R6/lib',
+		'/usr/include'             => '/usr/lib',
+		'/usr/include/SDL'         => '/usr/lib',
+		'/usr/include/smpeg'       => '/usr/lib',
+		'/usr/pkg/include',        => '/usr/local/lib',
+		'/usr/pkg/include/SDL'     => '/usr/local/lib',
+		'/usr/pkg/include/smpeg'   => '/usr/local/lib',
+		'/usr/local/include'       => '/usr/local/lib',
+		'/usr/local/include/SDL'   => '/usr/local/lib',
+		'/usr/local/include/smpeg' => '/usr/local/lib',
+		'/usr/X11R6/include'       => '/usr/X11R6/lib',
 	);
 }
 
Index: build_lib/SDL/Build.pm
===================================================================
--- build_lib/SDL/Build.pm	(revision 863)
+++ build_lib/SDL/Build.pm	(working copy)
@@ -126,11 +126,11 @@
 		},
 		GL          => {
 			define => 'HAVE_GL',  
-			header => 'gl.h'
+			header => catfile(qw( GL gl.h  )),
 		},
 		GLU         => {
 			define => 'HAVE_GLU', 
-			header => 'glu.h'
+			header => catfile(qw( GL glu.h )),
 		},
 	};
 }
@@ -197,8 +197,9 @@
 
 	for my $disabled (@disabled)
 	{
-		warn "Can't find $disabled headers; skipping.  Try running:\n" .
-			"$0 --with-" . lc($disabled) . "=/path/to/directory\n\n";
+		warn "Can't find $disabled headers; skipping.\n" .
+			"Ensure that you have its headers installed, then try running:\n" .
+			"\t$0 --with-" . lc($disabled) . "=/path/to/directory\n\n";
 		delete $subsystems->{ $disabled };
 	}
 
@@ -340,7 +341,7 @@
 
 sub opengl_headers
 {
-	return GL => 'gl.h', GLU => 'glu.h';
+	return map { uc( $_ ) => catfile( 'GL', $_ . '.h' ) } qw( gl glu );
 }
 
 sub copy_xs_file
@@ -415,3 +416,143 @@
 }
 
 1;
+
+__END__
+
+=head1 NAME
+
+SDL::Build - build process for SDL_perl
+
+=head1 SYNOPSIS
+
+See F<Build.PL> in the SDL_perl distribution for the example usage.
+
+=head1 DESCRIPTION
+
+This module governs the build process for SDL_perl.  Specifically, it allows
+building multiple XS files across several platforms.  This is tricky because
+different platforms have different ways of referring to libraries and headers
+and different requirements for auxiliary libraries.
+
+There are platform-specific subclasses to encapsulate this information; see
+C<SDL::Build::Linux>, for example.  You'll likely use one of these by default.
+Each subclass can override any of the methods here to provide platform-specific
+behavior.
+
+=head1 METHODS
+
+=over 4
+
+=item C<get_arch( $archname )>
+
+Loads the appropriate platform-specific module for the build platform.  This
+uses C<$^O> instead of C<Module::Build::os_type()> for more fine-grained
+control; FreeBSD differs from Linux in linking in its threading library, for
+example.
+
+=item C<process_xs( $xs_file )>
+
+Overrides the parent method in C<Module::Build> to add file-specific flags
+before building each XS file.  This is important to add specific linker and
+header include flags for different files.
+
+=item C<subsystems()>
+
+Returns a hash of hashes keyed on the name of various subsystems potentially to
+build.  Each subhash contains a C<file> key, with a hash containing C<from> and
+C<to> locations of where to copy the XS files for building, and a C<libraries>
+key with an array of libraries to link against for building this subsystem.
+
+=item C<libraries()>
+
+Returns a hash of hashes keyed on library name (as found in the data returned
+from C<subsystems()>) where each library has a C<define> symbol which will be
+true if the library exists on the system and a C<header> which identifies the
+header that must be present to link against the library.
+
+=item C<command_line_paths( @ARGV )>
+
+Processes any extra paths given on the command line when invoking F<Build.PL>
+to point to specific include directories for headers.  For example, to use the
+C<SDL_mixer> header found in F</usr/local/include/SDL/>, use:
+
+	$ perl Build.PL --with-SDL_mixer=/usr/local/include/SDL/
+
+=item C<find_subsystems( $subsystems, $libraries )>
+
+Looks through the platform's defined include paths and any paths given on the
+command line for the header for each subsystem's library.  If found, it will
+enable that library in the build.  Otherwise, it will give a warning message
+about disabling that library, suggesting how to fix it.
+
+=item C<build_defines( $libraries, $buildable_subsystems )>
+
+Returns a hash reference of the appropriate defines to set for building each
+subsystem, based on the available subsystem libraries.
+
+=item C<build_includes( $libraries, $buildable_subsystems )>
+
+Returns a hash reference of the appropriate header include paths to use for
+building each subsystem, based on the available subsystem libraries.
+
+=item C<build_links( $libraries, $buildable_subsystems )>
+
+Returns a hash reference of the appropriate library paths to use for linking
+each subsystem, based on the available subsystem libraries.
+
+=item C<set_flags( ... )>
+
+Sets all of the gathered data so that C<process_xs()> can retrieve it
+appropriately.  Hopefully you don't have to edit this one, though if it
+generates incorrect compiler commands, you will.
+
+=item C<find_header( $header, $include_directories )>
+
+Searches the directories given in the C<$include_directories> hashref for the
+given C<$header>, returning the directory of the header and the directory of
+the shared library to link against, if found.
+
+=item C<compile_flgas()>
+
+Looks for the compiler flags necessary to compile SDL on this platform; this
+uses C<sdl-config>, which you ought to have on your system.
+
+=item C<link_flags()>
+
+Looks for the compiler flags necessary to link against SDL on this platform;
+this uses C<sdl-config>, which you ought to have on your system.
+
+=item C<opengl_headers()>
+
+Returns a list of OpenGL subsystem names and their header files.  By default,
+the C<GL> library uses a header named F<gl.h> and the C<GLU> library uses a
+header named F<glu.h>.  This may be very different on your system.
+
+=item C<copy_xs_file( $subsystem, $from_path, $to_path )>
+
+Copies the file at C<$from_path> to C<$to_path>, rewriting its headers if
+necessary; this calls a method named C<${subsystem}_headers> (that is,
+C<opengl_headers()> for the OpenGL subsystem) to find the headers to rewrite.
+This I<may> be a mistake for OpenGL headers; it's not yet clear what the right
+solution is.
+
+=item C<replace_header( $headers, $line, $type )>
+
+Helper method for C<copy_xs_file()>.
+
+=item C<write_sdl_config( $config )>
+
+Writes the C<SDL::Config> module based on the configured and built subsystems.
+This makes it possible to upgrade SDL_perl based on an installed configuration
+and to test the enabled features in the tests or in real programs.
+
+=back
+
+=head1 AUTHOR
+
+chromatic, E<lt>chromatic at wgz dot orgE<gt>.  Please send all questions,
+patches, and bugs to E<lt>sdl-devel at perl dot orgE<gt>.
+
+=head1 BUGS
+
+No known bugs.
Index: Build.PL
===================================================================
--- Build.PL	(revision 863)
+++ Build.PL	(working copy)
@@ -29,7 +29,7 @@
 my %xs = map { $subsystems->{$_}{file}{from} => $subsystems->{$_}{file}{to} }
 	     keys %$subsystems;
 
-my $build   = SDL::Build->new(
+my $build   = $arch->new(
 	dist_name            => 'SDL_Perl', 
 	dist_author          => 'David J. Goehrig <[EMAIL PROTECTED]>',
 	dist_version_from    => 'lib/SDL.pm',

Reply via email to