#
package SDL::Build::MSWin32;
-
-use strict;
-use warnings;
-usr Carp;
+use Data::Dumper;
+use Config;
+use Carp;
use base 'SDL::Build';
-use File::Spec::Functions;
-
-sub fetch_includes
-{
- croak "Environment variable INCLUDE is empty\n" unless $ENV{INCLUDE};
-
- return map { $_ => 1 } grep { $_ } split( ';', $ENV{INCLUDE} );
-}
-
-sub find_header
-{
- for my $key (qw( LIBS PATH ))
- {
- #this needs to be carp because some users will have SDL libs in same folder
- carp "Environment variable $key is empty\n" unless $ENV{$key};
- carp "This will probably fail the compile \nSet $key manually or try building anyway\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 );
- }
-}
-sub link_flags
+sub process_xs
{
- return 'SDL.lib';
+ my ($self, $file) = @_;
+ $file =~ s/\\/\//g; #replace \ for / (Win32 needs this);
+ $self->SUPER::process_xs($file);
}
-sub compile_flags
+sub opengl_headers
{
- 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;
+ return GL => 'SDL_opengl.h';
}
-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 ) = @_;
+ my ($self, $libraries, $build_systems) = @_;
- return 'ms_gl' unless defined $vendor;
- return 'mesa_gl' if $vendor eq 'MESA';
- return 'ms_gl' if $vendor eq 'MS';
- croak "Unrecognized GL vendor '$vendor'\n";
+ my %links;
+ my %replace = (
+ GL => opengl32,
+ GLU => glu32,
+ );
+ 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_subsystems
-{
- return [qw( OpenGL GLU )];
-}
-
-sub mesa_gl_subsystems
+sub alt_link_flags
{
- return [qw( mesagl mesaglu osmesa )];
-}
+ my $self = shift;
+ my $sdl_dir = shift;
-sub ms_gl_libraries
-{
- define => 'OPENGL_VENDOR_MS';
+ return $self->SUPER::alt_link_flags($sdl_dir).' -mwindows -lSDLmain -lSDL';
}
-sub mesa_gl_libraries
+sub alt_compile_flags
{
- define => 'OPENGL_VENDOR_MESA';
-}
-
-sub link_c
-{
- 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;