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