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