Add hack for windows building on mingw
Kartik Thakore [Sun, 9 Aug 2009 22:46:06 +0000 (18:46 -0400)]
Build.PL
inc/Utility.pm [deleted file]
make/lib/SDL/Build.pm
make/lib/SDL/Build/MSWin32.pm
make/lib/SDL/Utility.pm [new file with mode: 0644]

index a32db79..f2d146d 100644 (file)
--- a/Build.PL
+++ b/Build.PL
@@ -11,12 +11,12 @@ use lib  'make/lib';
 
 use Data::Dumper;
 use SDL::Build;
+use SDL::Utility;
 use YAML;
 use YAML::Node;
-use inc::Utility qw(sdl_libs sdl_c_flags);
 
-my $sdl_compile_flags = sdl_c_flags();
-my $sdl_link_flags    = sdl_libs();
+my $sdl_compile_flags = SDL::Utility->sdl_c_flags();
+my $sdl_link_flags    = SDL::Utility->sdl_libs();
 # subsystem to build
 #      file
 #              location of source file => location of build file to get name right
diff --git a/inc/Utility.pm b/inc/Utility.pm
deleted file mode 100644 (file)
index 8247e18..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-package inc::Utility;
-use strict;
-use warnings;
-use Carp;
-
-BEGIN{
-       require Exporter;
-       our @ISA = qw(Exporter);
-       our @EXPORT_OK = qw(sdl_con_found sdl_libs sdl_c_flags); 
-}
-
-#checks to see if sdl-config is availabe
-#
-sub sdl_con_found
-{
-       `sdl-config --libs`;
-       return 0 if ($? >> 8);
-       return 1;
-}
-
-sub sdl_libs
-{
-       if(sdl_con_found)
-       {
-               local $_ = `sdl-config --libs`;
-               return chomp($_);
-       }
-       else
-       {
-               return undef;
-       }
-}
-
-sub sdl_c_flags
-{
-        if(sdl_con_found)
-        {
-                       local $_  = `sdl-config --cflags`;
-               return chomp($_);
-        }
-       else
-       {
-               return undef;
-       }
-}
-
-1;
index 3cade52..bcc03a5 100644 (file)
@@ -223,6 +223,8 @@ sub write_sdl_config
        print $file $text;
 }
 
+
+
 # Subclass  Darwin to build Objective-C addons
 
 sub filter_support {
@@ -248,6 +250,24 @@ sub process_support_files {
        }
 }
 
+# get link flags with a given a sdl_dir
+sub alt_link_flags
+{
+       my($self) = @_;
+       my $sdl_dir = shift;
+
+       return '-L"'.$sdl_dir.'\lib"';
+}
+
+# get compile flags with a given a sdl_dir
+sub alt_compile_flags
+{
+        my($self) = @_;
+        my $sdl_dir = shift;
+
+        return '-L"'.$sdl_dir.'\include\SDL"'; 
+}
+
 # Override to create a MacOS Bundle
 sub ACTION_bundle
 {
index 402b358..13d3ee9 100644 (file)
@@ -37,10 +37,12 @@ use base 'SDL::Build';
 use File::Spec::Functions;
 
 sub fetch_includes
-{
-       croak "Environment variable INCLUDE is empty\n" unless $ENV{INCLUDE};
+{      
 
+       warn "Environment variable INCLUDE is empty\n" unless $ENV{INCLUDE} 
+               and
        return map { $_ => 1 } grep { $_ } split( ';', $ENV{INCLUDE} );
+       return '-I.';
 }
 
 sub find_header
@@ -148,4 +150,28 @@ sub link_c
        $self->SUPER::link_c( @_ );
 }
 
+sub sdl_libs
+{
+       my $self = shift;
+       my $sdl_inst_dir = shift;
+
+
+}
+
+sub alt_link_flags
+{
+       my $self = shift;
+       my $sdl_dir = shift;
+
+       return $self->SUPER::alt_link_flags($sdl_dir).' -lmingw32 -mwindows -lSDLmain -lSDL.dll';
+}
+
+sub alt_compile_flags
+{
+       my $self = shift;
+       my $sdl_dir = shift;
+
+       return $self->SUPER::alt_compile_flages($sdl_dir).' -D_GNU_SOURCE=1 -Dmain=SDL_main';
+}
+
 1;
diff --git a/make/lib/SDL/Utility.pm b/make/lib/SDL/Utility.pm
new file mode 100644 (file)
index 0000000..425884b
--- /dev/null
@@ -0,0 +1,69 @@
+package SDL::Utility;
+use strict;
+use warnings;
+use Carp;
+
+
+BEGIN{
+       require Exporter;
+       our @ISA = qw(Exporter);
+       our @EXPORT_OK = qw(sdl_con_found sdl_libs sdl_c_flags); 
+}
+       my $arch =  SDL::Build->get_arch( $^O );
+
+use lib '../';
+use SDL::Build;
+
+#checks to see if sdl-config is availabe
+#
+sub sdl_con_found
+{
+       `sdl-config --libs`;
+       return 0 if ($? >> 8);
+       return 1;
+}
+
+#This should check if the folder actually has the SDL files
+sub check_sdl_dir
+{
+       return 0 unless $ENV{SDL_INST_DIR} and return $ENV{SDL_INST_DIR};
+}
+
+sub sdl_libs
+{
+       if(sdl_con_found)
+       {
+               local $_ = `sdl-config --libs`;
+               return chomp($_);
+       }       
+       elsif( check_sdl_dir() )
+       {
+               return $arch->alt_link_flags( check_sdl_dir() ) ;
+       }
+       else
+       {
+               #ask to download
+               croak 'SDL not installed';
+               return 0;
+       }
+}
+
+sub sdl_c_flags
+{
+        if(sdl_con_found)
+        {
+                       local $_  = `sdl-config --cflags`;
+               return chomp($_);
+        }
+       elsif ( check_sdl_dir() )
+       {
+               return $arch->alt_compile_flags( check_sdl_dir() );
+}
+       else
+       {
+               #ask to download
+               croak 'SDL not installed';
+       }
+}
+
+1;