Applied patch ready for merge
[sdlgit/SDL_perl.git] / Build.PL
1 #!/usr/bin/env perl
2 #
3 # Build.PL
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
32 use strict;
33 use warnings;
34 use Carp;
35 use lib  'make/lib';
36
37 use SDL::Build;
38 use YAML;
39
40 my $sdl_compile_flags = `sdl-config --cflags`;
41 my $sdl_link_flags    = `sdl-config --libs`;
42
43 if ($? >> 8)
44 {
45         croak "SDL doesn't appear to be installed.\n" .
46                 "Please check that sdl-config is in your path and try again.\n";
47 }
48
49 chomp( $sdl_compile_flags );
50 chomp( $sdl_link_flags );
51
52 # subsystem to build
53 #       file
54 #               location of source file => location of build file to get name right
55 #       libraries
56 #               name of shared library (soname)
57 #                       preprocessor definition
58 #                       name of header file
59 my %subsystems =
60 (
61         SDL => {
62                 file      => {
63                         from  => 'src/SDL.xs',
64                         to    => 'src/SDL_perl.xs',
65                 },
66                 libraries => [qw( SDL SDL_image SDL_mixer SDL_sound SDL_net SDL_ttf 
67                                 SDL_gfx SDL_svg png jpeg smpeg )],
68         },
69         OpenGL => {
70                 file      => {
71                         from => 'src/OpenGL.xs',
72                         to   => 'src/SDL/OpenGL.xs', 
73                 },
74                 libraries => [qw( SDL GL GLU )],
75         },
76         SFont => {
77                 file    => {
78                         from => 'src/SFont.xs',
79                         to   => 'src/SDL/SFont.xs',
80                 },
81                 libraries => [qw( SDL SDL_image )],
82         },      
83 );
84
85 my %libraries = (
86         SDL         => {
87                 define => 'HAVE_SDL', 
88                 header => 'SDL.h',
89         },
90         SDL_image   => {
91                 define => 'HAVE_SDL_IMAGE',   
92                 header => 'SDL_image.h'
93         },
94         SDL_mixer   => {
95                 define => 'HAVE_SDL_MIXER',   
96                 header => 'SDL_mixer.h'
97         },
98         SDL_sound => {
99                 define => 'HAVE_SDL_SOUND',
100                 header => 'SDL_sound.h'
101         },
102         SDL_net     => {
103                 define => 'HAVE_SDL_NET',     
104                 header => 'SDL_net.h'
105         },
106         SDL_ttf     => {
107                 define => 'HAVE_SDL_TTF',     
108                 header => 'SDL_ttf.h'
109         },
110         SDL_gfx     => {
111                 define => 'HAVE_SDL_GFX',     
112                 header => 'SDL_gfxPrimitives.h'
113         },
114         SDL_svg => {
115                 define => 'HAVE_SDL_SVG',
116                 header => 'SDL_svg.h'
117         },
118         png         => {
119                 define    => 'HAVE_PNG',
120                 header    => 'png.h',
121         },
122         jpeg        => {        
123                 define    => 'HAVE_JPEG',
124                 header    => 'jpeglib.h',
125         },
126         smpeg       => {
127                 define    => 'HAVE_SMPEG',
128                 header    => 'smpeg.h',
129         },
130         GL          => {
131                 define => 'HAVE_GL',  
132                 header => 'gl.h'
133         },
134         GLU         => {
135                 define => 'HAVE_GLU', 
136                 header => 'glu.h'
137         },
138 );
139
140 # need the platform-specific module to find include paths correctly
141 # see build/lib/SDL/Build/*pm
142 my $arch          = SDL::Build->get_arch( $^O );
143
144 print "[Build.PL] arch $arch\n";
145
146 # see which subsystems can be built -- do we have headers for them?
147 my $build_systems = $arch->find_subsystems( \%subsystems, \%libraries );
148
149 # now write SDL::Config
150 $arch->write_sdl_config( $build_systems );
151
152 # and fetch all of the information needed to compile
153 my $defines     = $arch->build_defines( \%libraries, $build_systems );
154 my $includes    = $arch->build_includes( \%libraries, $build_systems );
155 my $links       = $arch->build_links( \%libraries, $build_systems );
156 my $c_sources   = $arch->build_c_sources( \%libraries, $build_systems );
157 my $c_source    = $arch->build_c_source( \%libraries, $build_systems );
158 my $install_base = $arch->build_install_base( \%libraries, $build_systems );
159
160 # mangle the compilable files into a format Module::Build can understand
161 my %xs = map { $subsystems{$_}{file}{from} => $subsystems{$_}{file}{to} }
162              keys %subsystems;
163
164 my $build   = SDL::Build->new(
165         dist_name            => 'SDL_Perl', 
166         license              => 'lgpl',
167         dist_version_from    => 'lib/SDL.pm',
168         build_requires       =>
169         {
170                 'Test::Simple' => '0.47',
171                 'Module::Build' => '0.22',
172         },
173         build_recommends     =>
174         {
175                 'Pod::ToDemo'  => '0.20',
176         },
177         c_source => $c_source,
178         c_sources => $c_sources,
179         xs_files             => \%xs,
180         dist_author          => 'David J. Goehrig <DGOEHRIG@cpan.org>',
181         install_base => $install_base
182 );
183
184 # and here's where the real (and ugly) magic works... see SDL::Build
185 $build->set_flags(
186         \%subsystems,
187         $build_systems,
188         $defines,
189         $includes,
190         $links,
191         $sdl_compile_flags,
192         $sdl_link_flags,
193 );
194
195 # now we're ready to go!
196 $build->create_build_script();