PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/inc/My/Builder.pm

http://github.com/PerlGameDev/SDL
Perl | 196 lines | 126 code | 26 blank | 44 comment | 16 complexity | d0dcdb469721d258b1182f25d749f9ab MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0
  1. #!/usr/bin/env perl
  2. #
  3. # Build.pm
  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. package My::Builder;
  31. use strict;
  32. use warnings;
  33. use base 'Module::Build';
  34. use Carp;
  35. use File::Spec;
  36. use Config;
  37. use Alien::SDL::ConfigData;
  38. our $config = {};
  39. # Module::Build doesn't seem to have a way to use separate flags for separate
  40. # XS files, so here's the override that makes separate files build correctly:
  41. sub process_xs {
  42. my ( $self, $file ) = @_;
  43. my $properties = $self->{properties};
  44. my $file_args = $self->notes('file_flags')->{$file};
  45. return unless defined($file_args);
  46. my @old_values = @$properties{ keys %$file_args };
  47. @$properties{ keys %$file_args } = values %$file_args;
  48. $self->SUPER::process_xs($file);
  49. @$properties{ keys %$file_args } = @old_values;
  50. }
  51. # which headers are installed?
  52. sub find_subsystems {
  53. my ( $self, $subsystems, $libraries ) = @_;
  54. my %found;
  55. my %enabled;
  56. while ( my ( $name, $subsystem ) = each %$subsystems ) {
  57. my $param;
  58. for my $library ( @{ $subsystem->{libraries} } ) {
  59. my $lib = $libraries->{$library}
  60. or Carp::confess "Unknown library '$library' for '$name'\n";
  61. my $h =
  62. ref( $lib->{header} ) eq 'ARRAY'
  63. ? $lib->{header}
  64. : [ $lib->{header} ];
  65. my $need_check = 0;
  66. foreach (@$h) {
  67. $need_check = 1 unless $found{$_};
  68. }
  69. if ( !$need_check || Alien::SDL->check_header(@$h) ) {
  70. $found{$_} = 1 foreach (@$h);
  71. $param->{libs}->{$library} = 1;
  72. push @{ $param->{defines} }, "-D$libraries->{$library}{define}";
  73. push @{ $param->{links} }, "-l$libraries->{$library}{lib}";
  74. } else {
  75. # I disabled that, so the libs are compiled but the HAVE_* defines are not set
  76. # so we can e.g. 'use SDL::Pango;' (FROGGS)
  77. # $param = undef;
  78. print "###WARNING### Disabling subsystem '$name'\n";
  79. last;
  80. }
  81. }
  82. $enabled{$name} = $param if $param;
  83. }
  84. return \%enabled;
  85. }
  86. # create mapping table: { SDL::Any::Lib => [ list of libs ], SDL::Any::OtherLib => [ list of libs ] ... }
  87. # to keep information what libs (.dll|.so) to load via Dynaloader for which module
  88. sub translate_table {
  89. my ( $self, $subsystems, $libraries ) = @_;
  90. my %ret;
  91. foreach my $m ( keys %$subsystems ) {
  92. my $p = $subsystems->{$m}->{file}->{to};
  93. $p =~ s|^lib/(.*)\.xs|$1|;
  94. $p =~ s|/|::|g;
  95. my @list =
  96. map ( $libraries->{$_}->{lib}, @{ $subsystems->{$m}->{libraries} } );
  97. $ret{$p} = \@list;
  98. }
  99. return \%ret;
  100. }
  101. # save this all in a format process_xs() can understand
  102. sub set_file_flags {
  103. my $self = shift;
  104. my %file_flags;
  105. my %build_systems = %{ $self->notes('build_systems') };
  106. #TODO: Search for execinfo.h signal.h and turn this on.
  107. # This should also be turned on only during CPAN tests
  108. my $debug = ' -DNOSIGCATCH '; #default until headers found
  109. if ( Alien::SDL->check_header(qw(execinfo.h signal.h))
  110. && $ENV{AUTOMATED_TESTING} )
  111. {
  112. $debug .= ' -g -rdynamic ' unless ( $^O =~ /(win|darwin|bsd)/i );
  113. } else {
  114. $debug .= ' -O2 ';
  115. }
  116. my $arch = ' ';
  117. $arch = '-arch' . $ENV{SDL_ARCH} if $ENV{SDL_ARCH};
  118. while ( my ( $subsystem, $param ) = each %build_systems ) {
  119. my $sub_file = $self->notes('subsystems')->{$subsystem}{file}{to};
  120. my $extra_compiler_flags = [
  121. ( split( ' ', $arch . $debug . $self->notes('sdl_cflags') ) ),
  122. @{ $param->{defines} },
  123. ];
  124. push(@{$extra_compiler_flags}, '-DUSE_THREADS') if defined $Config{usethreads};
  125. push(@{$extra_compiler_flags}, '-fPIC') if $^O ne 'MSWin32';
  126. $file_flags{$sub_file} = {
  127. extra_compiler_flags => $extra_compiler_flags,
  128. extra_linker_flags => [
  129. ( split( ' ', $self->notes('sdl_libs') ) ),
  130. @{ $param->{links} },
  131. ],
  132. };
  133. }
  134. $self->notes( 'file_flags' => \%file_flags );
  135. }
  136. # override the following functions in My::Builder::<platform> if necessary
  137. sub ACTION_build {
  138. my $self = shift;
  139. printf(
  140. "[Alien::SDL] Build option used:\n\t%s\n",
  141. ${ Alien::SDL::ConfigData->config('build_params') }{'title'} || 'n.a.'
  142. );
  143. $self->SUPER::ACTION_build;
  144. $self->ACTION_bundle;
  145. }
  146. # both special to MacOS/Darwin, somebody should review whether it is still necessary
  147. sub special_build_settings { }
  148. sub build_bundle { }
  149. # build_bundle() currently defined only for MacOS
  150. sub ACTION_bundle {
  151. my ($self) = @_;
  152. $self->depends_on('build');
  153. $self->build_bundle();
  154. }
  155. # inc/My/Darwin.pm will override Install method for MacOS
  156. sub ACTION_install {
  157. my ($self) = @_;
  158. require ExtUtils::Install;
  159. $self->depends_on('build');
  160. ExtUtils::Install::install(
  161. $self->install_map, 1, 0,
  162. $self->{args}{uninst} || 0
  163. );
  164. }
  165. sub ACTION_test {
  166. my ($self) = @_;
  167. $self->depends_on('build');
  168. $self->SUPER::ACTION_test();
  169. }
  170. 1;