Merge branch 'redesign' of github.com:kthakore/SDL_perl into redesign
[sdlgit/SDL_perl.git] / Build.PL
1 #! perl -w
2 #
3 # Copyright (C) 2003 chromatic 
4 # Copyright (C) 2004 David J. Goehrig
5 # Copyright (C) 2009 Kartik Thakore
6
7 use strict;
8 use warnings;
9 use Carp;
10 use lib  'make/lib';
11
12 use Data::Dumper;
13 use SDL::Build;
14 use SDL::Utility;
15 use YAML;
16 use YAML::Node;
17
18 print STDERR <<BROKENWIN if ($^O =~ /MSWin.*|cygwin/ );
19 ******************************** !!!WARNING!!! ******************************** 
20 Windows support is currently experimental - you can continue, but you've been warned! 
21 If you are interested in helping please contact us at sdl-devel\@perl.org.
22 *******************************************************************************
23 BROKENWIN
24
25 my $sdl_compile_flags = SDL::Utility->sdl_c_flags();
26 my $sdl_link_flags    = SDL::Utility->sdl_libs();
27 # subsystem to build
28 #       file
29 #               location of source file => location of build file to get name right
30 #       libraries
31 #               name of shared library (soname)
32 #                       preprocessor definition
33 #                       name of header file
34 my %subsystems =
35 (
36         SDL => {
37                 file      => {
38                         from  => 'src/SDL.xs',
39                         to    => 'lib/SDL_perl.xs',
40                 },
41                 libraries => [qw( SDL SDL_image SDL_mixer SDL_net SDL_ttf SDL_gfx
42                                   png jpeg smpeg )],
43         },
44         Rect => {
45                 file      => {
46                         from  => 'src/Core/objects/Rect.xs',
47                         to    => 'lib/SDL/Rect.xs',
48                 },
49                 libraries => [qw( SDL  )],
50         },
51         Color => {
52                 file      => {
53                         from  => 'src/Core/objects/Color.xs',
54                         to    => 'lib/SDL/Color.xs',
55                 },
56                 libraries => [qw( SDL )],
57         },
58         Surface => {
59                 file      => {
60                         from  => 'src/Core/objects/Surface.xs',
61                         to    => 'lib/SDL/Surface.xs',
62                 },
63                 libraries => [qw( SDL SDL_image )],
64         },
65         PixelFormat => {
66                 file      => {
67                         from  => 'src/Core/objects/PixelFormat.xs',
68                         to    => 'lib/SDL/PixelFormat.xs',
69                 },
70                 libraries => [qw( SDL SDL_image )],
71         },
72         OpenGL => {
73                 file      => {
74                         from => 'src/OpenGL.xs',
75                         to   => 'lib/SDL/OpenGL.xs', 
76                 },
77                 libraries => [qw( SDL GL GLU )],
78         },
79         SFont => {
80                 file    => {
81                         from => 'src/SFont.xs',
82                         to   => 'lib/SDL/SFont.xs',
83                 },
84                 libraries => [qw( SDL SDL_image )],
85         },      
86 );
87
88 my %libraries = (
89         SDL         => {
90                 define => 'HAVE_SDL', 
91                 header => 'SDL.h',
92         },
93         SDL_image   => {
94                 define => 'HAVE_SDL_IMAGE',   
95                 header => 'SDL_image.h'
96         },
97         SDL_mixer   => {
98                 define => 'HAVE_SDL_MIXER',   
99                 header => 'SDL_mixer.h'
100         },
101         SDL_net     => {
102                 define => 'HAVE_SDL_NET',     
103                 header => 'SDL_net.h'
104         },
105         SDL_ttf     => {
106                 define => 'HAVE_SDL_TTF',     
107                 header => 'SDL_ttf.h'
108         },
109         SDL_gfx     => {
110                 define => 'HAVE_SDL_GFX',     
111                 header => 'SDL_gfxPrimitives.h'
112         },
113         png         => {
114                 define    => 'HAVE_PNG',
115                 header    => 'png.h',
116         },
117         jpeg        => {        
118                 define    => 'HAVE_JPEG',
119                 header    => 'jpeglib.h',
120         },
121         smpeg       => {
122                 define    => 'HAVE_SMPEG',
123                 header    => 'smpeg.h',
124         },
125         GL          => {
126                 define => 'HAVE_GL',  
127                 header => 'gl.h'
128         },
129         GLU         => {
130                 define => 'HAVE_GLU', 
131                 header => 'glu.h'
132         },
133 );
134
135 # need the platform-specific module to find include paths correctly
136 # see build/lib/SDL/Build/*pm
137 my $arch          = SDL::Build->get_arch( $^O );
138
139 # see which subsystems can be built -- do we have headers for them?
140 my $build_systems = $arch->find_subsystems( \%subsystems, \%libraries );
141
142 # now write SDL::Config
143 $arch->write_sdl_config( $build_systems );
144
145 # and fetch all of the information needed to compile
146 my $defines       = $arch->build_defines( \%libraries, $build_systems );
147 my $includes      = $arch->build_includes( \%libraries, $build_systems );
148 my $links         = $arch->build_links( \%libraries, $build_systems );
149
150 # mangle the compilable files into a format Module::Build can understand
151 my %xs = map { $subsystems{$_}{file}{from} => $subsystems{$_}{file}{to} }
152              keys %subsystems;
153 my $build   = SDL::Build->new(
154         module_name          => 'SDL',
155         dist_name            => 'SDL_Perl', 
156         license              => 'lgpl',
157         dist_version_from    => 'lib/SDL.pm',
158         configure_requires            =>
159         {
160                 'YAML'  => '0.68',
161                 'ExtUtils::CBuilder' => '0.260301',
162                 'Alien::SDL' => '0.7.1',
163         },
164         build_requires =>
165         {
166                 'Test::Simple' => '0.47',
167
168         },
169         build_recommends     =>
170         {
171                 'Pod::ToDemo'  => '0.20'                
172         },
173         c_source             => 'src',
174         xs_files             => \%xs,
175         meta_add             =>      
176         {
177                 no_index =>  { file => [ <make/lib/SDL/*.pm>, <make/lib/SDL/Build/*.pm>, <make/lib/ExtUtils/CBuilder/*>, <make/lib/ExtUtils/*>, <make/lib/ExtUtils/CBuilder/Platform/Windows.pm> ] },
178         },
179         dist_author          => 'David J. Goehrig <DGOEHRIG@cpan.org>, Kartik Thakore <KTHAKORE@cpan.org>',
180 );
181
182 if($arch eq 'Darwin')
183 {
184         $build->{c_source} = $arch->build_c_source( \%libraries, $build_systems );
185         $build->{c_sources} = $arch->build_c_sources( \%libraries, $build_systems );
186         $build->{install_base} = $arch->build_install_base( \%libraries, $build_systems );
187
188 }
189
190 # and here's where the real (and ugly) magic works... see SDL::Build
191 $build->set_flags(
192         \%subsystems,
193         $build_systems,
194         $defines,
195         $includes,
196         $links,
197         $sdl_compile_flags,
198         $sdl_link_flags,
199 );
200 # now we're ready to go!
201 $build->create_build_script();