957d7e591dbcfc38ebc50e586941437e85f9d844
[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         return map { $_ => 1 } grep { $_ } split( ';', $ENV{INCLUDE} ) if $ENV{INCLUDE};
44         return '-I.';
45 }
46
47 sub find_header
48 {
49         for my $key (qw( LIBS PATH ))
50         {
51                 #this needs to be carp because some users will have SDL libs in same folder
52                 carp "Environment variable $key is empty\n" unless $ENV{$key};
53                 carp "This will probably fail the compile \nSet $key manually or try building anyway\n"  unless $ENV{$key}; 
54         }
55
56         my ( $self, $header, $includes ) = @_;
57         ( my $dll = $header ) =~ s/\.h/\.dll/;
58
59         my $include_dir;
60
61         for my $inc_dir ( keys %$includes )
62         {
63                 next unless -e catfile( $inc_dir, $header );
64                 $include_dir = $inc_dir;
65         }
66
67         return unless $include_dir;
68
69         for my $lib_path ( map { split(';', ( $ENV{$_} || '' )) }
70                                    qw( LIB LIBS PATH ) )
71         {
72                 return ( $include_dir, $header ) if -e catfile( $lib_path, $dll );
73         }
74 }
75
76 sub link_flags
77 {
78         return 'SDL.lib';
79 }
80
81 sub compile_flags
82 {
83         return;
84 }
85
86 sub subsystems
87 {
88         my $self         = shift;
89         my $subsystems   = $self->SUPER::subsystems();
90         my $gl_ss_method = $self->gl_vendor( $ENV{SDL_GL_VENDOR} ) . '_subsystems';
91
92         $subsystems->{OpenGL}{libraries} = $self->$gl_ss_method();
93         return $subsystems;
94 }
95
96 sub libraries
97 {
98         my $self          = shift;
99         my $libraries     = $self->SUPER::libraries();
100         my $gl_lib_method = $self->gl_vendor( $ENV{SDL_GL_VENDOR} ) . '_libraries';
101
102         $libraries->{OpenGL}{define} .= ' -D' . $self->$gl_lib_method();
103         return $libraries;
104 }
105
106 sub gl_vendor
107 {
108         my ( $self, $vendor ) = @_;
109
110         return 'ms_gl' unless defined $vendor;
111         return 'mesa_gl' if $vendor eq 'MESA';
112         return 'ms_gl'   if $vendor eq 'MS';
113         croak "Unrecognized GL vendor '$vendor'\n";
114
115 }
116
117 sub ms_gl_subsystems
118 {
119         return [qw( OpenGL GLU )];
120 }
121
122 sub mesa_gl_subsystems
123 {
124         return [qw( mesagl mesaglu osmesa )];
125 }
126
127 sub ms_gl_libraries
128 {
129         define => 'OPENGL_VENDOR_MS';
130 }
131
132 sub mesa_gl_libraries
133 {
134         define => 'OPENGL_VENDOR_MESA';
135 }
136
137 sub link_c
138 {
139         my $self           = shift;
140         my ( $blib, $rib ) = @_;
141
142         # until ExtUtils::ParseXS is patched, avoid warnings from cl.exe
143         $_[-1] =~ s{\\}{/}g;
144
145         $rib   =~ s{^src[\\/]}{};
146         $rib   =~ s{[\\/]}{::}g;
147
148         local $self->{properties}{module_name} = $rib;
149         $self->SUPER::link_c( @_ );
150 }
151
152 sub sdl_libs
153 {
154         my $self = shift;
155         my $sdl_inst_dir = shift;
156
157
158 }
159
160 sub alt_link_flags
161 {
162         my $self = shift;
163         my $sdl_dir = shift;
164
165         return $self->SUPER::alt_link_flags($sdl_dir).' -lmingw32 -mwindows -lSDLmain -lSDL.dll';
166 }
167
168 sub alt_compile_flags
169 {
170         my $self = shift;
171         my $sdl_dir = shift;
172
173         return $self->SUPER::alt_compile_flags($sdl_dir).' -D_GNU_SOURCE=1 -Dmain=SDL_main';
174 }
175
176 1;