Fixed some merge errors in MSWin32.pm. Also seperated Darwin specific build flags...
[sdlgit/SDL_perl.git] / Build.PL
CommitLineData
7b6a53a1 1#!/usr/bin/env perl
8fde61e3 2#
7b6a53a1 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
8fde61e3 31
32use strict;
084b921f 33use warnings;
34use Carp;
8fde61e3 35use lib 'make/lib';
36
37use SDL::Build;
38use YAML;
39
40my $sdl_compile_flags = `sdl-config --cflags`;
41my $sdl_link_flags = `sdl-config --libs`;
42
43if ($? >> 8)
44{
084b921f 45 croak "SDL doesn't appear to be installed.\n" .
2c748062 46 "Please check that sdl-config is in your path and try again.\n";
8fde61e3 47}
48
49chomp( $sdl_compile_flags );
50chomp( $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
59my %subsystems =
60(
61 SDL => {
62 file => {
63 from => 'src/SDL.xs',
7b6a53a1 64 to => 'src/SDL_perl.xs',
8fde61e3 65 },
7b6a53a1 66 libraries => [qw( SDL SDL_image SDL_mixer SDL_sound SDL_net SDL_ttf
2c748062 67 SDL_gfx SDL_svg png jpeg smpeg )],
8fde61e3 68 },
69 OpenGL => {
70 file => {
71 from => 'src/OpenGL.xs',
7b6a53a1 72 to => 'src/SDL/OpenGL.xs',
8fde61e3 73 },
74 libraries => [qw( SDL GL GLU )],
75 },
76 SFont => {
77 file => {
78 from => 'src/SFont.xs',
7b6a53a1 79 to => 'src/SDL/SFont.xs',
8fde61e3 80 },
81 libraries => [qw( SDL SDL_image )],
82 },
83);
84
85my %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 },
7b6a53a1 98 SDL_sound => {
99 define => 'HAVE_SDL_SOUND',
100 header => 'SDL_sound.h'
101 },
8fde61e3 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 },
7b6a53a1 114 SDL_svg => {
115 define => 'HAVE_SDL_SVG',
116 header => 'SDL_svg.h'
117 },
8fde61e3 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
142my $arch = SDL::Build->get_arch( $^O );
143
7b6a53a1 144print "[Build.PL] arch $arch\n";
145
8fde61e3 146# see which subsystems can be built -- do we have headers for them?
147my $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
7b6a53a1 153my $defines = $arch->build_defines( \%libraries, $build_systems );
154my $includes = $arch->build_includes( \%libraries, $build_systems );
155my $links = $arch->build_links( \%libraries, $build_systems );
8fde61e3 156
157# mangle the compilable files into a format Module::Build can understand
158my %xs = map { $subsystems{$_}{file}{from} => $subsystems{$_}{file}{to} }
2c748062 159keys %subsystems;
7b6a53a1 160
8fde61e3 161my $build = SDL::Build->new(
162 dist_name => 'SDL_Perl',
163 license => 'lgpl',
164 dist_version_from => 'lib/SDL.pm',
165 build_requires =>
166 {
167 'Test::Simple' => '0.47',
168 'Module::Build' => '0.22',
169 },
170 build_recommends =>
171 {
172 'Pod::ToDemo' => '0.20',
173 },
2c748062 174 c_source => 'src',
8fde61e3 175 xs_files => \%xs,
176 dist_author => 'David J. Goehrig <DGOEHRIG@cpan.org>',
177);
178
2c748062 179if($arch eq 'Darwin')
180{
181 $build->{c_source} = $arch->build_c_source( \%libraries, $build_systems );
182 $build->{c_sources} = $arch->build_c_sources( \%libraries, $build_systems );
183 $build->{install_base} = $arch->build_install_base( \%libraries, $build_systems );
184
185}
8fde61e3 186$build->set_flags(
187 \%subsystems,
188 $build_systems,
189 $defines,
190 $includes,
191 $links,
192 $sdl_compile_flags,
193 $sdl_link_flags,
194);
195
196# now we're ready to go!
197$build->create_build_script();