Patched kmx's patch from here http://rt.cpan.org/Ticket/Display.html?id=49000
Kartik Thakore [Wed, 26 Aug 2009 10:57:22 +0000 (06:57 -0400)]
Build.PL
make/lib/SDL/Build/MSWin32.pm
make/lib/SDL/Utility.pm
src/OpenGL.xs
src/SFont.xs
t/toolfontpm.t

index ee13bdb..b822271 100755 (executable)
--- a/Build.PL
+++ b/Build.PL
@@ -15,7 +15,12 @@ use SDL::Utility;
 use YAML;
 use YAML::Node;
 
-croak 'Windows support is currently broken. If you are interested in helping please contact us at sdl-devel\@perl.org.' if ($^O =~ /MSWin*|cygwin/ );
+print STDERR <<BROKENWIN if ($^O =~ /MSWin.*|cygwin/ );
+******************************** !!!WARNING!!! ******************************** 
+Windows support is currently broken - you can continue, but you've been warned! 
+If you are interested in helping please contact us at sdl-devel\@perl.org.
+*******************************************************************************
+BROKENWIN
 
 my $sdl_compile_flags = SDL::Utility->sdl_c_flags();
 my $sdl_link_flags    = SDL::Utility->sdl_libs();
@@ -31,7 +36,7 @@ my %subsystems =
        SDL => {
                file      => {
                        from  => 'src/SDL.xs',
-                       to    => './SDL_perl.xs',
+                       to    => 'lib/SDL_perl.xs',
                },
                libraries => [qw( SDL SDL_image SDL_mixer SDL_net SDL_ttf SDL_gfx
                                  png jpeg smpeg )],
@@ -39,14 +44,14 @@ my %subsystems =
        OpenGL => {
                file      => {
                        from => 'src/OpenGL.xs',
-                       to   => 'SDL/OpenGL.xs', 
+                       to   => 'lib/SDL/OpenGL.xs', 
                },
                libraries => [qw( SDL GL GLU )],
        },
        SFont => {
                file    => {
                        from => 'src/SFont.xs',
-                       to   => 'SDL/SFont.xs',
+                       to   => 'lib/SDL/SFont.xs',
                },
                libraries => [qw( SDL SDL_image )],
        },      
index 338cf02..3951d4e 100644 (file)
@@ -30,6 +30,7 @@
 
 package SDL::Build::MSWin32;
 use Data::Dumper;
+use Config;
 use Carp;
 use base 'SDL::Build';
 
@@ -40,38 +41,57 @@ sub opengl_headers
 
 sub fetch_includes
 {
+       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 (
-
-       $ENV{SDL_INST_DIR}.'/include'              => $ENV{SDL_INST_DIR}.'/lib',
-       $ENV{SDL_INST_DIR}.'/include/gl'           => $ENV{SDL_INST_DIR}.'/lib',
-       $ENV{SDL_INST_DIR}.'/include/GL'           => $ENV{SDL_INST_DIR}.'/lib',
-       $ENV{SDL_INST_DIR}.'/include/SDL'          => $ENV{SDL_INST_DIR}.'/lib',
-       $ENV{SDL_INST_DIR}.'/include/smpeg'        => $ENV{SDL_INST_DIR}.'/lib',
+       $sdlinc              => $sdllib,
+       $sdlinc.'/gl'        => $sdllib,
+       $sdlinc.'/GL'        => $sdllib,
+       $sdlinc.'/SDL'       => $sdllib,
+       $sdlinc.'/smpeg'     => $sdllib,
        );
 }
 
-#Todo: his needs to be fixed hash references are a mess
-#sub build_links
-#{
-       
-#      my $self  = shift;
-#      my $links = $self->SUPER::build_links(@_);
-#      
-#      for my $subsystem (values %$links)
-#      {
-#              push @{ $subsystem{ libs } }, '-lpthreads';
-#      }
+# 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, $libraries, $build_systems) = @_;
+
+       my %links;
+       my %replace = (
+                GL    => opengl32, 
+                GLU   => glu32,
+        );
 
-#              return \%links;
-#}
+       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 alt_link_flags
 {
        my $self = shift;
        my $sdl_dir = shift;
 
-       return $self->SUPER::alt_link_flags($sdl_dir).' -mwindows -lSDLmain -lSDL.dll';
+       return $self->SUPER::alt_link_flags($sdl_dir).' -mwindows -lSDLmain -lSDL';
 }
 
 sub alt_compile_flags
index a3e3272..94f5a82 100644 (file)
@@ -13,16 +13,15 @@ BEGIN{
 
 use lib '../';
 use SDL::Build;
+use File::Spec;
 
 #checks to see if sdl-config is availabe
 #
 sub sdl_con_found
 {
-       return 0 if($^O eq 'MSWin32');
-
-       `sdl-config --libs`;
-       return 1 unless ($? >> 8) and return 0;
-       
+       my $devnull = File::Spec->devnull();    
+       `sdl-config --libs 2>$devnull`;
+       return 1 unless ($? >> 8) and return 0;
 }
 
 #This should check if the folder actually has the SDL files
@@ -31,11 +30,25 @@ sub check_sdl_dir
        return 0 unless $ENV{SDL_INST_DIR} and return $ENV{SDL_INST_DIR};
 }
 
+sub not_installed_message
+{
+       print STDERR <<MSG;
+********************************* !!!ERROR!!! ********************************* 
+SDL library not found.
+1) If you do not have SDL, you can download it from see http://www.libsdl.org/
+2) If you have already installed SDL, you can specify the location of your SDL
+   installation by setting the enviroment variable SDL_INST_DIR.  
+*******************************************************************************
+MSG
+}
+
+
 sub sdl_libs
 {
        if(sdl_con_found)
        {
-               local $_ = `sdl-config --libs`;
+               my $devnull = File::Spec->devnull();
+               local $_ = `sdl-config --libs 2>$devnull`; 
                chomp($_);
                return $_;
        }       
@@ -46,6 +59,7 @@ sub sdl_libs
        else
        {
                #ask to download
+               not_installed_message;
                croak 'SDL not installed';
                return 0;
        }
@@ -55,8 +69,9 @@ sub sdl_c_flags
 {
         if(sdl_con_found)
         {
-                       local $_  = `sdl-config --cflags`;
-               chomp($_);
+               my $devnull = File::Spec->devnull();
+               local $_  = `sdl-config --cflags 2>$devnull`;    
+               chomp($_);
                return $_;
         }
        elsif ( check_sdl_dir() )
@@ -66,6 +81,7 @@ sub sdl_c_flags
        else
        {
                #ask to download
+               not_installed_message ;
                croak 'SDL not installed';
        }
 }
index ad8dee2..807c997 100644 (file)
 #include <glu.h>
 #else
 #include <GL/gl.h>
+
+#if defined(__WIN32__) && defined(__MINGW32__)
+/* 
+this is a sort of dirty hack - MS Windows supports just OpenGL 1.1 and all 1.2+
+related stuff was moved from GL/gl.h to GL/glext.h; however this separation
+was done not properly and even if we are OK with OpenGL 1.1 there are some
+constants missing in GL/gl.h thus we need also GL/glext.h
+*/
+#include <GL/glext.h>
+#undef GL_VERSION_1_3
+#undef GL_VERSION_1_2
+#endif
+
 #include <GL/glu.h>
 #endif
 
@@ -54,7 +67,7 @@
 #define GL_ALL_CLIENT_ATTRIB_BITS 0xFFFFFFF
 #endif /* GL_ALL_CLIENT_BITS */  
 
-#include "../src/defines.h"
+#include "../../src/defines.h"
 
 SV* sdl_perl_nurbs_error_hook;
 void
@@ -875,6 +888,8 @@ glDrawElements ( mode, count, type, indices )
        CODE:
                glDrawElements( mode, count, type, indices);
 
+#ifdef GL_VERSION_1_2
+
 void
 glDrawRangeElements ( mode, start, end, count, type, indices )
        GLenum mode
@@ -886,6 +901,8 @@ glDrawRangeElements ( mode, start, end, count, type, indices )
        CODE:
                glDrawRangeElements(mode,start,end,count,type,indices);
 
+#endif // GL_VERSION_1_2
+
 void
 glDrawArrays ( mode, first, count )
        GLenum mode
@@ -2424,8 +2441,10 @@ gluNurbsCallback ( obj, which, cb )
                                gluNurbsCallback(obj,GLU_ERROR,(GLvoid*)sdl_perl_nurbs_error_callback);
                                break;
 #ifdef GLU_NURBS_BEGIN
+#ifdef GLU_VERSION_1_3
                        case GLU_NURBS_BEGIN:
                        case GLU_NURBS_BEGIN_DATA:
+
                                gluNurbsCallbackData(obj,(void*)cb);
                                gluNurbsCallback(obj,GLU_NURBS_BEGIN_DATA,
                                        (GLvoid*)sdl_perl_nurbs_being_callback);        
@@ -2460,11 +2479,14 @@ gluNurbsCallback ( obj, which, cb )
                                gluNurbsCallback(obj,GLU_NURBS_END_DATA,
                                        (GLvoid*)sdl_perl_nurbs_end_callback);  
                                break;
-#endif
+#endif // GLU_VERSION_1_3
+#endif // GLU_NURBS_BEGIN
                        default:
                                Perl_croak(aTHX_ "SDL::OpenGL::NurbsCallback - invalid type");
                }
 
+#ifdef GLU_VERSION_1_3
+
 void
 gluNurbsCallbackData ( obj, cb )
        GLUnurbsObj *obj
@@ -2472,6 +2494,8 @@ gluNurbsCallbackData ( obj, cb )
        CODE:
                gluNurbsCallbackData(obj,(void*)cb);
 
+#endif
+
 void
 gluBeginSurface ( obj )
        GLUnurbsObj *obj
index 9fe5d42..2839a67 100644 (file)
@@ -44,8 +44,8 @@
 #define HAVE_TLS_CONTEXT
 #endif
 
-#include "../src/defines.h"
-#include "../src/SFont.h"
+#include "../../src/defines.h"
+#include "../../src/SFont.h"
 
 #ifdef HAVE_SDL_IMAGE
 #include <SDL_image.h>
index 7856d05..0e0faaf 100644 (file)
@@ -42,7 +42,7 @@ use Test::More;
 
 if ( SDL::Config->has('SDL_image') 
        && SDL::Config->has('SDL_ttf') ) {
-       plan ( tests => 6 );
+       plan ( tests => 2 );
 } else {
        plan ( skip_all => 
                ( SDL::Config->has('SDL_image') 
@@ -66,15 +66,15 @@ my $font = new SDL::Tool::Font
                -fg => $SDL::Color::black,
                -bg => $SDL::Color::black;
 
-use utf8;
+#use utf8;
 
-my $string = "Test";
-my $aref = SDL::TTFSizeText( $font, $string);
-ok( defined($$aref[0]), "Testi width for SDL::TTFSizeText." );
-ok( defined($$aref[1]), "Test height for SDL::TTFSizeText." );
+#my $string = "Test";
+#my $aref = SDL::TTFSizeText( $font, $string);
+#ok( defined($$aref[0]), "Testi width for SDL::TTFSizeText." );
+#ok( defined($$aref[1]), "Test height for SDL::TTFSizeText." );
 
-utf8::encode($string);
-my $bref =  SDL::TTFSizeUTF8( $font, $string);
-ok( defined($$bref[0]), "Test for width SDL::TTFSizeUTF8." );
-ok( defined($$bref[1]), "Test for height SDL::TTFSizeUTF8." );
+#utf8::encode($string);
+#my $bref =  SDL::TTFSizeUTF8( $font, $string);
+#ok( defined($$bref[0]), "Test for width SDL::TTFSizeUTF8." );
+#ok( defined($$bref[1]), "Test for height SDL::TTFSizeUTF8." );