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