-package SDL::Build::MSWin32;
-
-use strict;
+#!/usr/bin/env perl
+#
+# MSWin32.pm
+#
+# Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org>
+#
+# ------------------------------------------------------------------------------
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# ------------------------------------------------------------------------------
+#
+# Please feel free to send questions, suggestions or improvements to:
+#
+# David J. Goehrig
+# dgoehrig@cpan.org
+#
+package SDL::Build::MSWin32;
+use Data::Dumper;
+use Config;
+use Carp;
use base 'SDL::Build';
-use File::Spec::Functions;
-sub fetch_includes
+sub process_xs
{
- die "Environment variable INCLUDE is empty\n" unless $ENV{INCLUDE};
-
- return map { $_ => 1 } grep { $_ } split( ';', $ENV{INCLUDE} );
+ my ($self, $file) = @_;
+ $file =~ s/\\/\//g; #replace \ for / (Win32 needs this);
+ $self->SUPER::process_xs($file);
}
-sub find_header
+sub opengl_headers
{
- for my $key (qw( LIBS PATH ))
- {
- die "Environment variable $key is empty\n" unless $ENV{$key};
- }
-
- my ( $self, $header, $includes ) = @_;
- ( my $dll = $header ) =~ s/\.h/\.dll/;
-
- my $include_dir;
-
- for my $inc_dir ( keys %$includes )
- {
- next unless -e catfile( $inc_dir, $header );
- $include_dir = $inc_dir;
- }
-
- return unless $include_dir;
-
- for my $lib_path ( map { split(';', ( $ENV{$_} || '' )) }
- qw( LIB LIBS PATH ) )
- {
- return ( $include_dir, $header ) if -e catfile( $lib_path, $dll );
- }
+ return GL => 'SDL_opengl.h';
}
-sub link_flags
-{
- return 'SDL.lib';
-}
-
-sub compile_flags
-{
- return;
-}
-
-sub subsystems
-{
- my $self = shift;
- my $subsystems = $self->SUPER::subsystems();
- my $gl_ss_method = $self->gl_vendor( $ENV{SDL_GL_VENDOR} ) . '_subsystems';
-
- $subsystems->{OpenGL}{libraries} = $self->$gl_ss_method();
- return $subsystems;
-}
-
-sub libraries
+sub fetch_includes
{
- my $self = shift;
- my $libraries = $self->SUPER::libraries();
- my $gl_lib_method = $self->gl_vendor( $ENV{SDL_GL_VENDOR} ) . '_libraries';
-
- $libraries->{OpenGL}{define} .= ' -D' . $self->$gl_lib_method();
- return $libraries;
+ my ($sdlinc, $sdllib);
+ if(defined($ENV{SDL_INST_DIR})) {
+ $sdlinc = $ENV{SDL_INST_DIR}.'/include';
+ $sdllib = $ENV{SDL_INST_DIR}.'/lib';
+ }
+ else {
+ $sdlinc = $Config{incpath};
+ $sdllib = $Config{libpth};
+ }
+ return (
+ $sdlinc => $sdllib,
+ $sdlinc.'/gl' => $sdllib,
+ $sdlinc.'/GL' => $sdllib,
+ $sdlinc.'/SDL' => $sdllib,
+ $sdlinc.'/smpeg' => $sdllib,
+ );
}
-sub gl_vendor
+# we need to override build_links method because on Windows we need to replace
+# some library names - see %replace hash below
+sub build_links
{
- my ( $self, $vendor ) = @_;
-
- return 'ms_gl' unless defined $vendor;
-
- return 'mesa_gl' if $vendor eq 'MESA';
- return 'ms_gl' if $vendor eq 'MS';
-
- die "Unrecognized GL vendor '$vendor'\n";
-}
+ my ($self, $libraries, $build_systems) = @_;
-sub ms_gl_subsystems
-{
- return [qw( OpenGL GLU )];
-}
+ my %links;
+ my %replace = (
+ GL => opengl32,
+ GLU => glu32,
+ );
-sub mesa_gl_subsystems
-{
- return [qw( mesagl mesaglu osmesa )];
+ while (my ($subsystem, $buildable) = each %$build_systems)
+ {
+ my %sub_links;
+ for my $build (grep { $buildable->{ $_ } } keys %$buildable)
+ {
+ $sub_links{ $buildable->{ $build }[1] }++;
+ my $newbuild = $replace{$build} || $build;
+ push @{ $links{ $subsystem }{libs} }, "-l$newbuild";
+ }
+
+ $links{ $subsystem }{paths} = [ map { "-L$_" } keys %sub_links ];
+ }
+ return \%links;
}
-sub ms_gl_libraries
+sub alt_link_flags
{
- define => 'OPENGL_VENDOR_MS';
-}
+ my $self = shift;
+ my $sdl_dir = shift;
-sub mesa_gl_libraries
-{
- define => 'OPENGL_VENDOR_MESA';
+ return $self->SUPER::alt_link_flags($sdl_dir).' -mwindows -lSDLmain -lSDL';
}
-sub link_c
+sub alt_compile_flags
{
- my $self = shift;
- my ( $blib, $rib ) = @_;
-
- # until ExtUtils::ParseXS is patched, avoid warnings from cl.exe
- $_[-1] =~ s{\\}{/}g;
-
- $rib =~ s{^src[\\/]}{};
- $rib =~ s{[\\/]}{::}g;
+ my $self = shift;
+ my $sdl_dir = shift;
- local $self->{properties}{module_name} = $rib;
- $self->SUPER::link_c( @_ );
+ return $self->SUPER::alt_compile_flags($sdl_dir).' -D_GNU_SOURCE=1 -Dmain=SDL_main';
}
1;