2 # Copyright (C) 2004 chromatic
3 # Copyright (C) 2004 David J. Goehrig
9 use base 'Module::Build';
15 # Module::Build doesn't seem to have a way to use separate flags for separate
16 # XS files, so here's the override that makes separate files build correctly:
19 my ($self, $file) = @_;
21 my $properties = $self->{properties};
23 my $file_args = $self->notes( 'file_flags' )->{$file};
24 my @old_values = @$properties{ keys %$file_args };
25 @$properties{ keys %$file_args } = values %$file_args;
26 $self->SUPER::process_xs( $file );
27 @$properties{ keys %$file_args } = @old_values;
30 # every platform has slightly different library and header paths
34 my $modpath = File::Spec->catfile(
35 'SDL', 'Build', ucfirst( $os ) . '.pm' );
36 my $module = 'SDL::Build::' . ucfirst( $os );
38 require $modpath or die "No module for $os platform\n";
43 # which headers are installed?
46 my ($self, $subsystems, $libraries) = @_;
47 my %includes_libs = $self->fetch_includes();
50 while ( my ($name, $subsystem) = each %$subsystems )
52 for my $library (@{ $subsystem->{libraries} })
54 my $lib = $libraries->{$library}
55 or die "Unknown library '$library' for '$name'\n";
57 my ($inc_dir, $link_dir) =
58 $self->find_header( $lib->{header}, \%includes_libs );
59 $enabled{$name}{ $library } = $inc_dir ? [ $inc_dir, $link_dir ]
67 # set the define flags for the libraries we have
70 my ($self, $libraries, $build_systems) = @_;
74 while (my ($subsystem, $buildable) = each %$build_systems)
76 for my $build (grep { $buildable->{ $_ } } keys %$buildable)
78 push @{ $defines{ $subsystem } }, "-D$libraries->{$build}{define}";
85 # set the include paths for the libraries we have
88 my ($self, $libraries, $build_systems) = @_;
92 while (my ($subsystem, $buildable) = each %$build_systems)
95 for my $build (grep { $buildable->{ $_ } } keys %$buildable)
97 $sub_include{ $buildable->{ $build }[0] }++;
100 $includes{ $subsystem } = [ map { "-I$_" } keys %sub_include ];
106 # set the linker paths and flags for the libraries we have
109 my ($self, $libraries, $build_systems) = @_;
113 while (my ($subsystem, $buildable) = each %$build_systems)
116 for my $build (grep { $buildable->{ $_ } } keys %$buildable)
118 $sub_links{ $buildable->{ $build }[1] }++;
119 push @{ $links{ $subsystem }{libs} }, "-l$build";
122 $links{ $subsystem }{paths} = [ map { "-L$_" } keys %sub_links ];
128 # save this all in a format process_xs() can understand
131 my ($self, $subsystems, $build, $defines, $includes, $links,
132 $sdl_compile, $sdl_link) = @_;
136 while (my ($subsystem, $buildable) = each %$build)
138 my $sub_file = $subsystems->{$subsystem}{file}{to};
139 my $sub_includes = join(' ', @{ $includes->{$subsystem} } );
141 $file_flags{ $sub_file } =
143 extra_compiler_flags =>
145 @{ $includes->{$subsystem} },
146 split(' ',$sdl_compile),
147 @{ $defines->{$subsystem} },
148 ( defined $Config{usethreads} ? ('-DUSE_THREADS', '-fPIC') : '-fPIC' ),
150 extra_linker_flags =>
152 @{ $links->{$subsystem}{paths} },
153 split(' ',$sdl_link),
154 @{ $links->{$subsystem}{libs} },
159 $self->notes( 'file_flags' => \%file_flags );
162 # look for a header somewhere on the system
165 my ($self, $header, $includes) = @_;
167 for my $inc_dir (keys %$includes)
169 next unless -e File::Spec->catfile( $inc_dir, $header );
170 return ($inc_dir, $includes->{$inc_dir});
176 my ($self, $config) = @_;
177 my $path = File::Spec->catfile(qw( lib SDL Config.pm ));
178 my $dd = Data::Dumper->new( [ $config ], [ 'sdl_config' ] );
179 my $hash = $dd->Dump();
180 (my $text = <<' END_HEADER' . $hash . <<' END_FOOTER');
188 my ($class, $define) = @_;
189 scalar grep { $$sdl_config{$_}{$define} } keys %$sdl_config;
197 open my $file, '>', $path or die "Cannot write to '$path': $!\n";