Brought all packages under eye of strict, warnings and love of Carp, For
[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 SDL::Build;
13 use YAML;
14 use YAML::Node;
15
16 my $sdl_compile_flags = `sdl-config --cflags`;
17 my $sdl_link_flags    = `sdl-config --libs`;
18
19 if ($? >> 8)
20 {
21         croak "SDL doesn't appear to be installed.\n" .
22                 "Please check that sdl-config is in your path and try again.\n";
23 }
24
25 chomp( $sdl_compile_flags );
26 chomp( $sdl_link_flags );
27
28 # subsystem to build
29 #       file
30 #               location of source file => location of build file to get name right
31 #       libraries
32 #               name of shared library (soname)
33 #                       preprocessor definition
34 #                       name of header file
35 my %subsystems =
36 (
37         SDL => {
38                 file      => {
39                         from  => 'src/SDL.xs',
40                         to    => './SDL_perl.xs',
41                 },
42                 libraries => [qw( SDL SDL_image SDL_mixer SDL_net SDL_ttf SDL_gfx
43                                   png jpeg smpeg )],
44         },
45         OpenGL => {
46                 file      => {
47                         from => 'src/OpenGL.xs',
48                         to   => 'SDL/OpenGL.xs', 
49                 },
50                 libraries => [qw( SDL GL GLU )],
51         },
52         SFont => {
53                 file    => {
54                         from => 'src/SFont.xs',
55                         to   => 'SDL/SFont.xs',
56                 },
57                 libraries => [qw( SDL SDL_image )],
58         },      
59 );
60
61 my %libraries = (
62         SDL         => {
63                 define => 'HAVE_SDL', 
64                 header => 'SDL.h',
65         },
66         SDL_image   => {
67                 define => 'HAVE_SDL_IMAGE',   
68                 header => 'SDL_image.h'
69         },
70         SDL_mixer   => {
71                 define => 'HAVE_SDL_MIXER',   
72                 header => 'SDL_mixer.h'
73         },
74         SDL_net     => {
75                 define => 'HAVE_SDL_NET',     
76                 header => 'SDL_net.h'
77         },
78         SDL_ttf     => {
79                 define => 'HAVE_SDL_TTF',     
80                 header => 'SDL_ttf.h'
81         },
82         SDL_gfx     => {
83                 define => 'HAVE_SDL_GFX',     
84                 header => 'SDL_gfxPrimitives.h'
85         },
86         png         => {
87                 define    => 'HAVE_PNG',
88                 header    => 'png.h',
89         },
90         jpeg        => {        
91                 define    => 'HAVE_JPEG',
92                 header    => 'jpeglib.h',
93         },
94         smpeg       => {
95                 define    => 'HAVE_SMPEG',
96                 header    => 'smpeg.h',
97         },
98         GL          => {
99                 define => 'HAVE_GL',  
100                 header => 'gl.h'
101         },
102         GLU         => {
103                 define => 'HAVE_GLU', 
104                 header => 'glu.h'
105         },
106 );
107
108 # need the platform-specific module to find include paths correctly
109 # see build/lib/SDL/Build/*pm
110 my $arch          = SDL::Build->get_arch( $^O );
111
112 # see which subsystems can be built -- do we have headers for them?
113 my $build_systems = $arch->find_subsystems( \%subsystems, \%libraries );
114
115 # now write SDL::Config
116 $arch->write_sdl_config( $build_systems );
117
118 # and fetch all of the information needed to compile
119 my $defines       = $arch->build_defines( \%libraries, $build_systems );
120 my $includes      = $arch->build_includes( \%libraries, $build_systems );
121 my $links         = $arch->build_links( \%libraries, $build_systems );
122
123 # mangle the compilable files into a format Module::Build can understand
124 my %xs = map { $subsystems{$_}{file}{from} => $subsystems{$_}{file}{to} }
125              keys %subsystems;
126 my $build   = SDL::Build->new(
127         module_name          => 'SDL',
128         dist_name            => 'SDL_Perl', 
129         license              => 'lgpl',
130         dist_version_from    => 'lib/SDL.pm',
131         build_requires       =>
132         {
133                 'Test::Simple' => '0.47',
134                 'Module::Build' => '0.22',
135         },
136         build_recommends     =>
137         {
138                 'Pod::ToDemo'  => '0.20',
139         },
140         c_source             => 'src',
141         xs_files             => \%xs,
142         dist_author          => 'David J. Goehrig <DGOEHRIG@cpan.org>',
143 );
144
145 # and here's where the real (and ugly) magic works... see SDL::Build
146 $build->set_flags(
147         \%subsystems,
148         $build_systems,
149         $defines,
150         $includes,
151         $links,
152         $sdl_compile_flags,
153         $sdl_link_flags,
154 );
155
156 # now we're ready to go!
157 $build->create_build_script();