2 # Copyright (C) 2004 chromatic
3 # Copyright (C) 2004 David J. Goehrig
11 use base 'Module::Build';
17 # Module::Build doesn't seem to have a way to use separate flags for separate
18 # XS files, so here's the override that makes separate files build correctly:
21 my ($self, $file) = @_;
23 my $properties = $self->{properties};
25 my $file_args = $self->notes( 'file_flags' )->{$file};
26 my @old_values = @$properties{ keys %$file_args };
27 @$properties{ keys %$file_args } = values %$file_args;
28 $self->SUPER::process_xs( $file );
29 @$properties{ keys %$file_args } = @old_values;
32 # every platform has slightly different library and header paths
36 my $modpath = File::Spec->catfile(
37 'SDL', 'Build', ucfirst( $os ) . '.pm' );
38 my $module = 'SDL::Build::' . ucfirst( $os );
40 require $modpath or croak "No module for $os platform\n";
45 # which headers are installed?
48 my ($self, $subsystems, $libraries) = @_;
49 my %includes_libs = $self->fetch_includes();
52 while ( my ($name, $subsystem) = each %$subsystems )
54 for my $library (@{ $subsystem->{libraries} })
56 my $lib = $libraries->{$library}
57 or croak "Unknown library '$library' for '$name'\n";
59 my ($inc_dir, $link_dir) =
60 $self->find_header( $lib->{header}, \%includes_libs );
61 $enabled{$name}{ $library } = $inc_dir ? [ $inc_dir, $link_dir ]
69 # set the define flags for the libraries we have
72 my ($self, $libraries, $build_systems) = @_;
76 while (my ($subsystem, $buildable) = each %$build_systems)
78 for my $build (grep { $buildable->{ $_ } } keys %$buildable)
80 push @{ $defines{ $subsystem } }, "-D$libraries->{$build}{define}";
87 # set the include paths for the libraries we have
90 my ($self, $libraries, $build_systems) = @_;
94 while (my ($subsystem, $buildable) = each %$build_systems)
97 for my $build (grep { $buildable->{ $_ } } keys %$buildable)
99 $sub_include{ $buildable->{ $build }[0] }++;
102 $includes{ $subsystem } = [ map { "-I$_" } keys %sub_include ];
108 # set the linker paths and flags for the libraries we have
111 my ($self, $libraries, $build_systems) = @_;
115 while (my ($subsystem, $buildable) = each %$build_systems)
118 for my $build (grep { $buildable->{ $_ } } keys %$buildable)
120 $sub_links{ $buildable->{ $build }[1] }++;
121 push @{ $links{ $subsystem }{libs} }, "-l$build";
124 $links{ $subsystem }{paths} = [ map { "-L$_" } keys %sub_links ];
130 # save this all in a format process_xs() can understand
133 my ($self, $subsystems, $build, $defines, $includes, $links,
134 $sdl_compile, $sdl_link) = @_;
138 while (my ($subsystem, $buildable) = each %$build)
140 my $sub_file = $subsystems->{$subsystem}{file}{to};
141 my $sub_includes = join(' ', @{ $includes->{$subsystem} } );
143 $file_flags{ $sub_file } =
145 extra_compiler_flags =>
147 @{ $includes->{$subsystem} },
148 split(' ',$sdl_compile),
149 @{ $defines->{$subsystem} },
150 ( defined $Config{usethreads} ? ('-DUSE_THREADS', '-fPIC') : '-fPIC' ),
152 extra_linker_flags =>
154 @{ $links->{$subsystem}{paths} },
155 split(' ',$sdl_link),
156 @{ $links->{$subsystem}{libs} },
161 $self->notes( 'file_flags' => \%file_flags );
164 # look for a header somewhere on the system
167 my ($self, $header, $includes) = @_;
169 for my $inc_dir (keys %$includes)
171 next unless -e File::Spec->catfile( $inc_dir, $header );
172 return ($inc_dir, $includes->{$inc_dir});
178 my ($self, $config) = @_;
179 my $path = File::Spec->catfile(qw( lib SDL Config.pm ));
180 my $dd = Data::Dumper->new( [ $config ], [ 'sdl_config' ] );
181 my $hash = $dd->Dump();
182 (my $text = <<' END_HEADER' . $hash . <<' END_FOOTER');
190 my ($class, $define) = @_;
191 scalar grep { $$sdl_config{$_}{$define} } keys %$sdl_config;
199 open my $file, '>', $path or croak "Cannot write to '$path': $!\n";