Skip to content

Commit

Permalink
Builder enhancements - proper disabling SDL submodules based on detec…
Browse files Browse the repository at this point in the history
…ted missing libs/headers
  • Loading branch information
kmx committed Mar 2, 2010
1 parent d492581 commit 1dae658
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 34 deletions.
11 changes: 7 additions & 4 deletions Build.PL
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@ my %subsystems =
### external libraries ### external libraries
# <library name> = symbolic library name # <library name> = symbolic library name
# <define> = value that will be used as -D<value> option when compiling XS code # <define> = value that will be used as -D<value> option when compiling XS code
# <header> = header related to the library that will be used for avalability detection # <header> = header related to the library that will be used for avalability detection,
# could be a sigle value or an array of values
# <lib> = value that will be used as -l<value> option when linking XS code # <lib> = value that will be used as -l<value> option when linking XS code
my %libraries = ( my %libraries = (
SDL => { SDL => {
Expand Down Expand Up @@ -452,7 +453,7 @@ my %libraries = (
}, },
GL => { GL => {
define => 'HAVE_GL', define => 'HAVE_GL',
header => 'GL/gl.h', header => [ 'GL/gl.h', 'GL/glext.h' ],
lib => ($^O eq 'MSWin32') ? 'opengl32' : 'GL', # xxx not nice lib => ($^O eq 'MSWin32') ? 'opengl32' : 'GL', # xxx not nice
}, },
GLU => { GLU => {
Expand Down Expand Up @@ -494,10 +495,14 @@ my $build = $package->new(
meta_add => meta_add =>
{ {
}, },
create_readme => 1,
dist_abstract => 'SDL bindings to Perl', dist_abstract => 'SDL bindings to Perl',
dist_author => 'Kartik Thakore <KTHAKORE@cpan.org>', dist_author => 'Kartik Thakore <KTHAKORE@cpan.org>',
); );


### Alien::SDL quick check
warn "###WARNING### Alien::SDL seems to be broken" unless Alien::SDL->config('prefix');

### see which subsystems can be built -- do we have headers for them? ### see which subsystems can be built -- do we have headers for them?
print "Gonna autodetect available libraries ...\n"; print "Gonna autodetect available libraries ...\n";
my $build_systems = $build->find_subsystems( \%subsystems, \%libraries ); my $build_systems = $build->find_subsystems( \%subsystems, \%libraries );
Expand All @@ -511,7 +516,6 @@ $build->config_data('sdl_ld_shlib_map', Alien::SDL->config('ld_shlib_map'));


### something that was originally special to MacOS/Darwin ### something that was originally special to MacOS/Darwin
# somebody MacOS/Darwin friendly should review whether it is still necessary # somebody MacOS/Darwin friendly should review whether it is still necessary
# xxx TODO xxx
$build->special_build_settings(); $build->special_build_settings();


### get some info into M::B notes ### get some info into M::B notes
Expand All @@ -521,7 +525,6 @@ $build->notes('libraries', \%libraries);
$build->notes('build_systems', $build_systems); $build->notes('build_systems', $build_systems);
$build->notes('sdl_cflags', Alien::SDL->config('cflags')); $build->notes('sdl_cflags', Alien::SDL->config('cflags'));
$build->notes('sdl_libs', Alien::SDL->config('libs')); $build->notes('sdl_libs', Alien::SDL->config('libs'));
$build->set_build_opts(); # creates notes('defines') and notes('links')
$build->set_file_flags(); # creates notes('file_flags') $build->set_file_flags(); # creates notes('file_flags')


# now we're ready to go! # now we're ready to go!
Expand Down
53 changes: 23 additions & 30 deletions inc/My/Builder.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ sub process_xs
my $properties = $self->{properties}; my $properties = $self->{properties};
my $file_args = $self->notes( 'file_flags' )->{$file}; my $file_args = $self->notes( 'file_flags' )->{$file};


return unless defined($file_args);

my @old_values = @$properties{ keys %$file_args }; my @old_values = @$properties{ keys %$file_args };
@$properties{ keys %$file_args } = values %$file_args; @$properties{ keys %$file_args } = values %$file_args;


Expand All @@ -65,71 +67,62 @@ sub find_subsystems
my %enabled; my %enabled;
while ( my ($name, $subsystem) = each %$subsystems ) while ( my ($name, $subsystem) = each %$subsystems )
{ {
my $param;
for my $library (@{ $subsystem->{libraries} }) for my $library (@{ $subsystem->{libraries} })
{ {
my $lib = $libraries->{$library} my $lib = $libraries->{$library}
or croak "Unknown library '$library' for '$name'\n"; or croak "Unknown library '$library' for '$name'\n";
unless (defined($found{$lib->{header}})) { my $h = ref($lib->{header}) eq 'ARRAY' ? $lib->{header} : [ $lib->{header} ];
$found{$lib->{header}} = Alien::SDL->check_header($lib->{header}) ? 1 : 0; my $need_check = 0;
foreach (@$h) {
$need_check = 1 unless $found{$_};
}
if ( !$need_check || Alien::SDL->check_header(@$h)) {
$found{$_} = 1 foreach (@$h);
$param->{libs}->{$library} = 1;
push @{ $param->{defines} }, "-D$libraries->{$library}{define}";
push @{ $param->{links} }, "-l$libraries->{$library}{lib}";
}
else {
$param = undef;
print "###WARNING### Disabling subsystem '$name'\n";
last;
} }
$enabled{$name}{$library} = 1 if $found{$lib->{header}};
} }
$enabled{$name} = $param if $param;
} }
return \%enabled; return \%enabled;
} }


# set the define flags and flags for the libraries we have
sub set_build_opts
{
my $self = shift;
my $libraries = $self->notes('libraries');
my $build_systems = $self->notes('build_systems');
my %defines;
my %links;

while (my ($subsystem, $buildable) = each %$build_systems)
{
for my $build (grep { $buildable->{ $_ } } keys %$buildable)
{
push @{ $defines{$subsystem} }, "-D$libraries->{$build}{define}";
push @{ $links{$subsystem} }, "-l$libraries->{$build}{lib}";
}
}

$self->notes('defines' => \%defines);
$self->notes('links' => \%links);
}

# save this all in a format process_xs() can understand # save this all in a format process_xs() can understand
sub set_file_flags sub set_file_flags
{ {
my $self = shift; my $self = shift;
my %file_flags; my %file_flags;
my %build_systems = %{$self->notes('build_systems')};


while (my ($subsystem, $buildable) = each %{$self->notes('build_systems')} ) while (my ($subsystem, $param) = each %build_systems )
{ {
my $sub_file = $self->notes('subsystems')->{$subsystem}{file}{to}; my $sub_file = $self->notes('subsystems')->{$subsystem}{file}{to};
$file_flags{$sub_file} = { $file_flags{$sub_file} = {
extra_compiler_flags => extra_compiler_flags =>
[ [
(split(' ', $self->notes('sdl_cflags'))), (split(' ', $self->notes('sdl_cflags'))),
@{$self->notes('defines')->{$subsystem}}, @{$param->{defines}},
( defined $Config{usethreads} ? ('-DUSE_THREADS', '-fPIC') : ('-fPIC' )), ( defined $Config{usethreads} ? ('-DUSE_THREADS', '-fPIC') : ('-fPIC' )),
], ],
extra_linker_flags => extra_linker_flags =>
[ [
(split(' ', $self->notes('sdl_libs'))), (split(' ', $self->notes('sdl_libs'))),
@{$self->notes('links')->{$subsystem}}, @{$param->{links}},
], ],
}, },
} }

$self->notes('file_flags' => \%file_flags); $self->notes('file_flags' => \%file_flags);
} }


# override the following functions in My::Builder::<platform> if necessary # override the following functions in My::Builder::<platform> if necessary
# both special to MacOS/Darwin, somebody should review whether it is still necessary # both special to MacOS/Darwin, somebody should review whether it is still necessary
# xxx TODO xxx
sub special_build_settings { } sub special_build_settings { }
sub build_bundle { } sub build_bundle { }


Expand Down

0 comments on commit 1dae658

Please sign in to comment.