Stupid mistake
[sdlgit/SDL_perl.git] / make / lib / SDL / Build / MSWin32.pm
1 #!/usr/bin/env perl
2 #
3 # MSWin32.pm
4 #
5 # Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org>
6 #
7 # ------------------------------------------------------------------------------
8 #
9 # This library is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public
11 # License as published by the Free Software Foundation; either
12 # version 2.1 of the License, or (at your option) any later version.
13
14 # This library is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # Lesser General Public License for more details.
18
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with this library; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 #
23 # ------------------------------------------------------------------------------
24 #
25 # Please feel free to send questions, suggestions or improvements to:
26 #
27 #       David J. Goehrig
28 #       dgoehrig@cpan.org
29 #
30
31 package SDL::Build::MSWin32;
32
33 use strict;
34 use warnings;
35 use Carp;
36 use base 'SDL::Build';
37 use File::Spec::Functions;
38
39 sub fetch_includes
40 {       
41
42         warn "Environment variable INCLUDE is empty\n" unless $ENV{INCLUDE} 
43                 and
44         return map { $_ => 1 } grep { $_ } split( ';', $ENV{INCLUDE} );
45         return '-I.';
46 }
47
48 sub find_header
49 {
50         for my $key (qw( LIBS PATH ))
51         {
52                 #this needs to be carp because some users will have SDL libs in same folder
53                 carp "Environment variable $key is empty\n" unless $ENV{$key};
54                 carp "This will probably fail the compile \nSet $key manually or try building anyway\n"  unless $ENV{$key}; 
55         }
56
57         my ( $self, $header, $includes ) = @_;
58         ( my $dll = $header ) =~ s/\.h/\.dll/;
59
60         my $include_dir;
61
62         for my $inc_dir ( keys %$includes )
63         {
64                 next unless -e catfile( $inc_dir, $header );
65                 $include_dir = $inc_dir;
66         }
67
68         return unless $include_dir;
69
70         for my $lib_path ( map { split(';', ( $ENV{$_} || '' )) }
71                                    qw( LIB LIBS PATH ) )
72         {
73                 return ( $include_dir, $header ) if -e catfile( $lib_path, $dll );
74         }
75 }
76
77 sub link_flags
78 {
79         return 'SDL.lib';
80 }
81
82 sub compile_flags
83 {
84         return;
85 }
86
87 sub subsystems
88 {
89         my $self         = shift;
90         my $subsystems   = $self->SUPER::subsystems();
91         my $gl_ss_method = $self->gl_vendor( $ENV{SDL_GL_VENDOR} ) . '_subsystems';
92
93         $subsystems->{OpenGL}{libraries} = $self->$gl_ss_method();
94         return $subsystems;
95 }
96
97 sub libraries
98 {
99         my $self          = shift;
100         my $libraries     = $self->SUPER::libraries();
101         my $gl_lib_method = $self->gl_vendor( $ENV{SDL_GL_VENDOR} ) . '_libraries';
102
103         $libraries->{OpenGL}{define} .= ' -D' . $self->$gl_lib_method();
104         return $libraries;
105 }
106
107 sub gl_vendor
108 {
109         my ( $self, $vendor ) = @_;
110
111         return 'ms_gl' unless defined $vendor;
112         return 'mesa_gl' if $vendor eq 'MESA';
113         return 'ms_gl'   if $vendor eq 'MS';
114         croak "Unrecognized GL vendor '$vendor'\n";
115
116 }
117
118 sub ms_gl_subsystems
119 {
120         return [qw( OpenGL GLU )];
121 }
122
123 sub mesa_gl_subsystems
124 {
125         return [qw( mesagl mesaglu osmesa )];
126 }
127
128 sub ms_gl_libraries
129 {
130         define => 'OPENGL_VENDOR_MS';
131 }
132
133 sub mesa_gl_libraries
134 {
135         define => 'OPENGL_VENDOR_MESA';
136 }
137
138 sub link_c
139 {
140         my $self           = shift;
141         my ( $blib, $rib ) = @_;
142
143         # until ExtUtils::ParseXS is patched, avoid warnings from cl.exe
144         $_[-1] =~ s{\\}{/}g;
145
146         $rib   =~ s{^src[\\/]}{};
147         $rib   =~ s{[\\/]}{::}g;
148
149         local $self->{properties}{module_name} = $rib;
150         $self->SUPER::link_c( @_ );
151 }
152
153 sub sdl_libs
154 {
155         my $self = shift;
156         my $sdl_inst_dir = shift;
157
158
159 }
160
161 sub alt_link_flags
162 {
163         my $self = shift;
164         my $sdl_dir = shift;
165
166         return $self->SUPER::alt_link_flags($sdl_dir).' -lmingw32 -mwindows -lSDLmain -lSDL.dll';
167 }
168
169 sub alt_compile_flags
170 {
171         my $self = shift;
172         my $sdl_dir = shift;
173
174         return $self->SUPER::alt_compile_flages($sdl_dir).' -D_GNU_SOURCE=1 -Dmain=SDL_main';
175 }
176
177 1;