File: Builder.pm

package info (click to toggle)
frozen-bubble 2.212-9
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 31,736 kB
  • sloc: perl: 8,571; ansic: 1,200; sh: 92; makefile: 15
file content (147 lines) | stat: -rw-r--r-- 4,809 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package My::Builder;
use 5.008;
use strict;
use warnings FATAL => 'all';
use ExtUtils::CBuilder qw();
use File::Basename qw(fileparse);
use File::Copy qw(move);
use File::Slurp qw(read_file write_file);
use File::Spec::Functions qw(catdir catfile rootdir);
use IO::File qw();
use Module::Build '0.36' => qw();
use autodie qw(:all move read_file write_file);
use parent 'Module::Build';
use Locale::Maketext::Extract;

use lib 'lib';
use Games::FrozenBubble;

sub ACTION_run {
    my ($self) = @_;
    $self->depends_on('code');
    $self->depends_on('installdeps');
    my $bd = $self->{properties}->{base_dir};

    # prepare INC
    local @INC = @INC;
    local @ARGV = @{$self->args->{ARGV}};
    my $script = shift @ARGV;
    unshift @INC, (File::Spec->catdir($bd, $self->blib, 'lib'), File::Spec->catdir($bd, $self->blib, 'arch'));

    if ($script) {
      # scenario: ./Build run bin/scriptname param1 param2
      do($script);
    }
    else {
      # scenario: ./Build run
      my ($first_script) = ( glob('bin/*'), glob('script/*')); # take the first script in bin or script subdir
      print STDERR "No params given to run action - gonna start: '$first_script'\n";
      do($first_script);
    }
}

sub ACTION_build {
    my ($self) = @_;
    #$self->depends_on('messages'); #temporarily disabled by kmx, the new ACTION_messages() needs more testing
    $self->depends_on('server');
    $self->SUPER::ACTION_build;
    return;
}

sub ACTION_symbols {
    my ($self) = @_;
    {
        my $out = IO::File->new(catfile(qw(lib Games FrozenBubble Symbols.pm)), 'w');
        $out->print("package Games::FrozenBubble::Symbols;\n\@syms = qw(");
        {
            my $in = IO::File->new(catfile(Alien::SDL->config('prefix'), qw(include SDL SDL_keysym.h)), 'r');
            while (defined($_ = $in->getline)) {
                $out->print("$1 ") if /SDLK_(\S+)/;
            }
        }
        $out->print(");\n1;\n");
    }
    return;
}

sub ACTION_messages {
    my ($self) = @_;
    my $pot = catfile(qw(share locale frozen-bubble.pot));
    my $script = catfile(qw(bin frozen-bubble));

    return if (-e $pot) && ((-M $pot) < (-M $script)); # frozen-bubble.pot is newer than bin/frozen-bubble

    unlink $pot if -f $pot;
    print "Gonna extract all translation strings\n";
    my $ex1 = Locale::Maketext::Extract->new(verbose => 1, warnings  => 0);
    $ex1->extract_file($script);
    $ex1->compile(1);
    $ex1->write_po($pot);

    for my $lang (glob(catfile(qw(share locale), '*.po'))) {
        print "Processing $lang\n";
        my $ex2 = Locale::Maketext::Extract->new();
        $ex2->read_po('share/locale/frozen-bubble.pot');
        $ex2->read_po($lang);
        $ex2->compile(1);
        $ex2->write_po($lang);
    }

    return;
}

sub ACTION_server {
    if($^O =~ /(w|W)in/ or $^O =~ /darwin/)
    {
        print STDERR "###Cannot build fb-server on windows or darwin need glib\n";
        return;
    }
    my ($self) = @_;
    my $server_directory = 'server';
    my $otarget          = 'fb-server';
	return if (-e 'bin/'.$otarget );
    # CBuilder doesn't take shell quoting into consideration,
    # so the -DVERSION macro does not work like in the former Makefile.
    # Instead, I'll just preprocess the two files with perl.
    {
        my $version = $Games::FrozenBubble::RELEASE_VERSION;
        # perl -pie again has problems with shell quoting for the -e'' part.
        for my $cfile (
            map {catfile($server_directory, $_)} qw(fb-server.c_tmp net.c_tmp)
        ) {
            my $csource = read_file($cfile);
            $csource =~ s{" VERSION "}{$version};
            $cfile =~ s/_tmp//;
            write_file($cfile, $csource);
        }
    }

    {
        my $cbuilder = ExtUtils::CBuilder->new;
        my @ofiles;
        for my $cfile (qw(fb-server.c log.c tools.c game.c net.c)) {
            push @ofiles, $cbuilder->compile(
                source               => catfile($server_directory, $cfile),
                extra_compiler_flags => [
                    qw(-g -Wall -Werror -pipe), # verbatim from Makefile
                    '-I' . $server_directory, # does not seem to be necessary
                    $cbuilder->split_like_shell(`pkg-config glib-2.0 --cflags`),
                    $cbuilder->split_like_shell(`pkg-config glib-2.0 --libs`),
                    $cbuilder->split_like_shell($ENV{CPPFLAGS}),
                ],
            );
        }
        $cbuilder->link_executable(
            objects            => \@ofiles,
            exe_file           => catfile($server_directory, $otarget),
            extra_linker_flags => [
                $cbuilder->split_like_shell(`pkg-config glib-2.0 --libs`),
            ],
        );
    }

    move(catfile($server_directory, $otarget), 'bin');
    return;
}

1;