#!/usr/bin/perl
# 
# This file is part of Games-Risk
# 
# This software is Copyright (c) 2008 by Jerome Quelin.
# 
# This is free software, licensed under:
# 
#   The GNU General Public License, Version 3, June 2007
# 

use 5.010;
use strict;
use warnings;

# update messages.pot file with new strings detected.
use Cwd                   qw{ cwd };
use File::Spec::Functions qw{ catfile catdir };
use File::Find::Rule;

my $cwd = cwd;
my $pot_file  = catfile( $cwd, 'lib', 'LocaleData', 'Games-Risk-messages.pot' );
my $pmfiles   = catfile( $cwd, 'files.txt' );

# build list of perl modules from where to extract strings
my @pmfiles = grep {/^lib/}
    File::Find::Rule->file->name("*.pm")->relative->in($cwd);
open my $fh, '>', $pmfiles or die "cannot open '$pmfiles': $!\n";
print $fh map { "$_$/" } @pmfiles;
close $fh;

unlink $pot_file;
system(
    "xgettext",
    "--keyword=T",
    "--from-code=utf-8",
    "--package-name=Games-Risk",
    "--copyright-holder='Jerome Quelin'",
    "--msgid-bugs-address=bug-games-risk\@rt.cpan.org",
    "-o", $pot_file,
    "-f", $pmfiles
) == 0 or die "xgettext exited with return code " . ($? >> 8);

# cleanup
unlink $pmfiles;
