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