Debian Codegraph @

inc/My/Builder.pm

raw ◀ ▶
2 Debian patches touch this file
1 package My::Builder;
2 use 5.008;
3 use strict;
4 use warnings FATAL => 'all';
5 use ExtUtils::CBuilder qw();
6 use File::Basename qw(fileparse);
7 use File::Copy qw(move);
8 use File::Slurp qw(read_file write_file);
9 use File::Spec::Functions qw(catdir catfile rootdir);
10 use IO::File qw();
•11 use Module::Build qw();
12 use autodie qw(:all move read_file write_file);
13 use parent 'Module::Build';
14 use Locale::Maketext::Extract;
15
16 use lib 'lib';
17 use Games::FrozenBubble;
18
19 sub ACTION_run {
20 my ($self) = @_;
21 $self->depends_on('code');
22 $self->depends_on('installdeps');
23 my $bd = $self->{properties}->{base_dir};
24
25 # prepare INC
26 local @INC = @INC;
27 local @ARGV = @{$self->args->{ARGV}};
28 my $script = shift @ARGV;
29 unshift @INC, (File::Spec->catdir($bd, $self->blib, 'lib'), File::Spec->catdir($bd, $self->blib, 'arch'));
30
31 if ($script) {
32 # scenario: ./Build run bin/scriptname param1 param2
33 do($script);
34 }
35 else {
36 # scenario: ./Build run
37 my ($first_script) = ( glob('bin/*'), glob('script/*')); # take the first script in bin or script subdir
38 print STDERR "No params given to run action - gonna start: '$first_script'\n";
39 do($first_script);
40 }
41 }
42
43 sub ACTION_build {
44 my ($self) = @_;
45 #$self->depends_on('messages'); #temporarily disabled by kmx, the new ACTION_messages() needs more testing
46 $self->depends_on('server');
47 $self->SUPER::ACTION_build;
48 return;
49 }
50
51 sub ACTION_symbols {
52 my ($self) = @_;
53 {
54 my $out = IO::File->new(catfile(qw(lib Games FrozenBubble Symbols.pm)), 'w');
55 $out->print("package Games::FrozenBubble::Symbols;\n\@syms = qw(");
56 {
57 my $in = IO::File->new(catfile(Alien::SDL->config('prefix'), qw(include SDL SDL_keysym.h)), 'r');
58 while (defined($_ = $in->getline)) {
59 $out->print("$1 ") if /SDLK_(\S+)/;
60 }
61 }
62 $out->print(");\n1;\n");
63 }
64 return;
65 }
66
67 sub ACTION_messages {
68 my ($self) = @_;
69 my $pot = catfile(qw(share locale frozen-bubble.pot));
70 my $script = catfile(qw(bin frozen-bubble));
71
72 return if (-e $pot) && ((-M $pot) < (-M $script)); # frozen-bubble.pot is newer than bin/frozen-bubble
73
74 unlink $pot if -f $pot;
75 print "Gonna extract all translation strings\n";
76 my $ex1 = Locale::Maketext::Extract->new(verbose => 1, warnings => 0);
77 $ex1->extract_file($script);
78 $ex1->compile(1);
79 $ex1->write_po($pot);
80
81 for my $lang (glob(catfile(qw(share locale), '*.po'))) {
82 print "Processing $lang\n";
83 my $ex2 = Locale::Maketext::Extract->new();
84 $ex2->read_po('share/locale/frozen-bubble.pot');
85 $ex2->read_po($lang);
86 $ex2->compile(1);
87 $ex2->write_po($lang);
88 }
89
90 return;
91 }
92
93 sub ACTION_server {
94 if($^O =~ /(w|W)in/ or $^O =~ /darwin/)
95 {
96 print STDERR "###Cannot build fb-server on windows or darwin need glib\n";
97 return;
98 }
99 my ($self) = @_;
100 my $server_directory = 'server';
101 my $otarget = 'fb-server';
102 return if (-e 'bin/'.$otarget );
103 # CBuilder doesn't take shell quoting into consideration,
104 # so the -DVERSION macro does not work like in the former Makefile.
105 # Instead, I'll just preprocess the two files with perl.
106 {
107 my $version = $Games::FrozenBubble::RELEASE_VERSION;
108 # perl -pie again has problems with shell quoting for the -e'' part.
109 for my $cfile (
110 map {catfile($server_directory, $_)} qw(fb-server.c_tmp net.c_tmp)
111 ) {
112 my $csource = read_file($cfile);
113 $csource =~ s{" VERSION "}{$version};
114 $cfile =~ s/_tmp//;
115 write_file($cfile, $csource);
116 }
117 }
118
119 {
120 my $cbuilder = ExtUtils::CBuilder->new;
121 my @ofiles;
122 for my $cfile (qw(fb-server.c log.c tools.c game.c net.c)) {
123 push @ofiles, $cbuilder->compile(
124 source => catfile($server_directory, $cfile),
125 extra_compiler_flags => [
126 qw(-g -Wall -Werror -pipe), # verbatim from Makefile
127 '-I' . $server_directory, # does not seem to be necessary
128 $cbuilder->split_like_shell(`pkg-config glib-2.0 --cflags`),
129 $cbuilder->split_like_shell(`pkg-config glib-2.0 --libs`),
•130 $cbuilder->split_like_shell($ENV{CPPFLAGS}),
131 ],
132 );
133 }
134 $cbuilder->link_executable(
135 objects => \@ofiles,
136 exe_file => catfile($server_directory, $otarget),
137 extra_linker_flags => [
138 $cbuilder->split_like_shell(`pkg-config glib-2.0 --libs`),
139 ],
140 );
141 }
142
143 move(catfile($server_directory, $otarget), 'bin');
144 return;
145 }
146
147 1;