File: Build.PL

package info (click to toggle)
libparse-debianchangelog-perl 1.2.0-13
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 976 kB
  • sloc: perl: 1,380; makefile: 25
file content (313 lines) | stat: -rw-r--r-- 10,971 bytes parent folder | download | duplicates (2)
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#!/usr/bin/perl
# Based on Build.PL from po4a

use Module::Build;
use strict;
use warnings;

my $builder = Module::Build->subclass
    (
     class => 'My::Builder',
     code => q{
	 { use strict;
         use String::ShellQuote;
         __PACKAGE__->add_property('po_faketime_cmd');
	 my $bin_po_dir = 'po';
	 my $bin_pot_file = 'bin.pot';
	 my $bin_po_prefix = 'bin.';
	 my $bin_pot_path = "$bin_po_dir/$bin_pot_file";
	 my $doc_po_dir = 'po';
	 my $doc_pot_file = 'doc.pot';
	 my $doc_po_prefix = 'doc.';
	 my $doc_pot_path = "$doc_po_dir/$doc_pot_file";
	 my $base_dir = '..';
	 my $bin_mo_file = 'Parse-DebianChangelog';
	 my $doc_mo_file = 'Parse-DebianChangelog-Pod';
	 my $po4a_path = '';

	 sub ACTION_build {
	     my $self = shift;
	     $self->depends_on('code');
	     $self->depends_on('docs');
	     $self->depends_on('distmeta'); # regenerate META.yml
	     $self->depends_on('man');
	     $self->depends_on('postats');
	 }
	 sub ACTION_install {
	     my $self = shift;

	     require ExtUtils::Install;
#	    $self->depends_on('build');

	     ExtUtils::Install::install($self->install_map, 1, 0,
					$self->{args}{uninst}||0);
	 }
	 sub ACTION_binpo {
	     my $self = shift;

	     my @files = sort( (keys(%{$self->script_files()}),
				@{$self->rscan_dir('lib',qr/\.pm$/)}));

	     unless ($self->up_to_date(\@files, $bin_pot_path)) {
		 print "XX Update $bin_pot_path\n";
		 my $podfiles = join ("", map { " $base_dir/$_" } @files);
		 system("cd $bin_po_dir; ".$self->po_faketime_str." xgettext --copyright-holder=\"Frank Lichtenheld\" --keyword=__g --msgid-bugs-address=frank\@lichtenheld.de -L Perl $podfiles -o $bin_pot_file.new") && die;
		 if ( -e $bin_pot_path) {
		     my $diff = qx(diff -q -I'#:' -I'POT-Creation-Date:' -I'PO-Revision-Date:' $bin_pot_path $bin_pot_path.new);
		     if ( $diff eq "" ) {
			 unlink "$bin_pot_path.new" || die;
			 # touch it
			 my ($atime, $mtime) = (time,time);
			 utime $atime, $mtime, $bin_pot_path;
		     } else {
			 rename "$bin_pot_path.new", $bin_pot_path || die;
		     }
		 } else {
		     rename "$bin_pot_path.new", $bin_pot_path || die;
		 }
	     } else {
		 print "XX $bin_pot_path uptodate.\n";
	     }

	     # update languages
	     @files = @{$self->rscan_dir($bin_po_dir,qr/\/\Q$bin_po_prefix\E.*\.po$/)};
	     foreach (@files) {
		 next if m|/.#|;
		 $_ =~ /.*\/(?:.*\.)?(.*)\.po$/;
		 my $lang = $1;

		 unless ($self->up_to_date($bin_pot_path,
					   "$bin_po_dir/$bin_po_prefix$lang.po")) {
		     print "XX Sync $bin_po_dir/$bin_po_prefix$lang.po: ";
		     system(@{$self->po_faketime_cmd},
                            'msgmerge', "$bin_po_dir/$bin_po_prefix$lang.po",
			    "$bin_pot_path",
			    "-o", "$bin_po_dir/$bin_po_prefix$lang.po.new")
			 && die;
		     # Typically all that changes was a date. I'd
		     # prefer not to cvs commit such changes, so
		     # detect and ignore them.
		     my $diff = qx(diff -q -I'#:' -I'POT-Creation-Date:' -I'PO-Revision-Date:' $bin_po_dir/$bin_po_prefix$lang.po $bin_po_dir/$bin_po_prefix$lang.po.new);
		     if ($diff eq "") {
			 unlink "$bin_po_dir/$bin_po_prefix$lang.po.new" || die;
			 # touch it
			 my ($atime, $mtime) = (time,time);
			 utime $atime, $mtime,
			       "$bin_po_dir/$bin_po_prefix$lang.po";
		     } else {
			 rename "$bin_po_dir/$bin_po_prefix$lang.po.new",
			       "$bin_po_dir/$bin_po_prefix$lang.po" || die;
		    }
		 } else {
		     print "XX $bin_po_dir/$bin_po_prefix$lang.po uptodate.\n";
		 }
		 unless ($self->up_to_date("$bin_po_dir/$bin_po_prefix$lang.po",
					   "blib/po/$lang/LC_MESSAGES/$bin_mo_file.mo")) {
		     print "X Generate $bin_mo_file.mo for $lang.\n";
		     system('mkdir', '-p', "blib/po/$lang/LC_MESSAGES") && die;
		     system(@{$self->po_faketime_cmd}, 'msgfmt', '-o',
			    "blib/po/$lang/LC_MESSAGES/$bin_mo_file.mo",
			    "$bin_po_dir/$bin_po_prefix$lang.po") && die;
		 } else {
		     print "XX $bin_mo_file.mo for $lang uptodate.\n";
		 }
	     }

	 }
	 sub ACTION_manpo {
	     my $self = shift;

	     # update pot
	     my @files = sort( (keys(%{$self->script_files()}),
				@{$self->rscan_dir('lib',qr/\.pm$/)}));
	     unless ($self->up_to_date(\@files, $doc_pot_path)) {
		 my $podfiles = join ("", map {" -m $base_dir/$_" } @files);
		 print "XX Update documentation pot files: ";
		 system("cd $doc_po_dir; ".$self->po_faketime_str." ${po4a_path}po4a-updatepo -f pod $podfiles -M utf-8 -p $doc_pot_file")
		     && die;
		 my ($atime, $mtime) = (time,time);
		 utime $atime, $mtime, $doc_pot_path;

	     } else {
		 print "XX Documentation pot file uptodate.\n";
	     }

	     # update languages
	     @files = @{$self->rscan_dir($doc_po_dir,qr/\.po$/)};
	     foreach (@files) {
		 $_ =~ /.*\/(?:.*\.)?(.*)\.po$/;
		 my $lang = $1;

		 unless ($self->up_to_date($doc_pot_path,
					   "$doc_po_dir/$doc_po_prefix$lang.po")) {
		     print "XX Update documentation $doc_po_prefix$lang.po: ";
		     system(@{$self->po_faketime_cmd},
                            'msgmerge', "$doc_po_dir/$doc_po_prefix$lang.po",
			    "$doc_pot_path",
			    '-o', "$doc_po_dir/$doc_po_prefix$lang.po.new")
			 && die;

		     # Typically all that changes was a date. I'd
		     # prefer not to cvs commit such changes, so
		     # detect and ignore them.
		     my $diff = qx(diff -q -I'#:' -I'POT-Creation-Date:' -I'PO-Revision-Date:' $doc_po_dir/$doc_po_prefix$lang.po $doc_po_dir/$doc_po_prefix$lang.po.new);
		     if ( $diff eq "" ) {
			 unlink "$doc_po_dir/$doc_po_prefix$lang.po.new" || die;
			 my ($atime, $mtime) = (time,time);
			 utime $atime, $mtime,
			       "$doc_po_dir/$doc_po_prefix$lang.po";
		     } else {
			 rename "$doc_po_dir/$doc_po_prefix$lang.po.new",
			       "$doc_po_dir/$doc_po_prefix$lang.po" || die;
		     }
		 } else {
		     print "XX Documentation $doc_po_prefix$lang.po uptodate.\n";
		 }
		 unless ($self->up_to_date("$doc_po_dir/$doc_po_prefix$lang.po",
					   "blib/po/$lang/LC_MESSAGES/$doc_mo_file.mo")) {
		     print "X Generate $doc_mo_file.mo for $lang.\n";
		     system('mkdir', '-p', "blib/po/$lang/LC_MESSAGES") && die;
		     system(@{$self->po_faketime_cmd}, 'msgfmt', '-o',
			    "blib/po/$lang/LC_MESSAGES/$doc_mo_file.mo",
			    "$doc_po_dir/$doc_po_prefix$lang.po") && die;
		 } else {
		     print "XX $doc_mo_file.mo for $lang uptodate.\n";
		 }
	     }
	 }
	 sub ACTION_man {
	     my $self = shift;

	     $self->depends_on('manpo');
	     use Pod::Man;

	     my $options = "-v -f pod -M utf-8 -L iso8859-1";

	     #get the languages
	     my @langs = @{$self->rscan_dir($doc_po_dir,qr/\.po$/)};
	     my $i=0;
	     while ($i < @langs) {
		 $langs[$i] =~ /.*\/(?:.*\.)?(.*)\.po$/;
		 $langs[$i] = $1;
		 $i++;
	     }

	     system("rm", "-rf", "blib/man") && die;
	     system("mkdir", "-p", "blib/man") && die;

	     # Translate binaries manpages
	     my $parser = Pod::Man->new (release => "parsechangelog",
					 center => "parsechangelog",
					 section => "1p");

	     foreach my $lang (@langs) {
		 print ("X Translate binary manpages to $lang\n");
		 foreach my $file (keys(%{$self->script_files()})) {
		     system($self->po_faketime_str." ${po4a_path}po4a-translate $options -m $file -p $doc_po_dir/$doc_po_prefix$lang.po -l blib/man/$file")
			 && die;
		     if (-e "blib/man/$file") {
			 system("mkdir", "-p", "blib/man/$lang/man1") && die;
			 $parser->parse_from_file ("blib/man/$file",
						   "blib/man/$lang/man1/$file.1p");
			 system("gzip", "-9f", "blib/man/$lang/man1/$file.1p")
			     && die;
			 system("rm", "-f", "blib/man/$file")
			     && die;
		     }
		 }
	     }

	     # Translate modules manpages
	     $parser = Pod::Man->new (release => "Parse::DebianChangelog",
				      center => "Parse::DebianChangelog",
				      section => "3pm");

	     foreach my $lang (@langs) {
		 print ("X Translate module manpages to $lang\n");
		 foreach my $file (@{$self->rscan_dir('lib',qr/\.pm$/)}) {
		     $file =~ /.*\/(.*)\.pm$/;
		     my $filename = $1;
		     system($self->po_faketime_str." ${po4a_path}po4a-translate $options -m $file -p $doc_po_dir/$doc_po_prefix$lang.po -l blib/man/$filename")
			 && die;
		     if (-e "blib/man/$filename") {
			 system ("mkdir", "-p", "blib/man/$lang/man3") && die;
			 $parser->parse_from_file ("blib/man/$filename",
						   "blib/man/$lang/man3/Parse::DebianChangelog::$filename.3pm")
			     || die;
			 system ("gzip", "-9f",
				 "blib/man/$lang/man3/Parse::DebianChangelog::$filename.3pm")
			     && die "Cannot gzip blib/man/$lang/man3/Parse::DebianChangelog::$filename.3pm";
			 system ("rm", "-f", "blib/man/$filename") && die;
		     }
		 }
	     }

	 }
	 sub ACTION_dist {
	     my ($self) = @_;

	     $self->depends_on('test');
	     $self->depends_on('distdir');

	     my $dist_dir = $self->dist_dir;

	     if ( -e "$dist_dir.tar.gz") {
		 # Delete the distfile if it already exists
		 system ("rm", "$dist_dir.tar.gz") && die;
	     }

	     $self->make_tarball($dist_dir);
	     $self->delete_filetree($dist_dir);
	 }
	 sub ACTION_postats {
	     my $self = shift;
	     $self->depends_on('binpo');
	     $self->depends_on('manpo');
	     $self->postats($bin_po_dir);
	     $self->postats($doc_po_dir) unless $bin_po_dir eq $doc_po_dir;
	 }
	 sub postats {
	     my ($self,$dir) = (shift,shift);
	     my $potsize = `(cd $dir;ls -sh *.pot) | sed -n -e 's/^ *\\\\([^[:blank:]]*\\\\).*\$/\\\\1/p'`;
	     $potsize =~ /(.*)/;
	     print "$dir (pot: $1)\n";
	     my @files = @{$self->rscan_dir($dir,qr/\.po$/)};
	     foreach (@files) {
		 my $file = $_;
		 $file =~ /.*\/(?:.*\.)?(.*)\.po$/;
		 my $lang = $1;
		 my $stat = `msgfmt -o /dev/null -c -v --statistics $file 2>&1`;
		 print "  $lang: $stat";
	     }
	 }
         sub po_faketime_str {
             my $self = shift;
             # return '"' . join('" "', @{$self->po_faketime_cmd}) . '"';
             return shell_quote @{$self->po_faketime_cmd};
         } }
     },
     );

my $base= $Config::Config{man1dir};
$base =~ s/\/man\/man1//;

my $po_build_date = $ENV{PO_BUILD_DATE};

my $b = $builder->new
    ( module_name => 'Parse-DebianChangelog',
      license => 'gpl',
      dist_version_from => 'lib/Parse/DebianChangelog.pm', # finds $VERSION
      requires => { 'Date::Parse' => 0,
		    'Locale::gettext' => 0 },
      recommends => { 'IO::String' => 0, 'HTML::Parser' => 0,
		      'HTML::Entities' => 0, 'HTML::Template' => 0,
		      'XML::Simple' => 0 },
      build_requires => { 'Test::Pod' => 0, 'Test::Pod::Coverage' => 0 },
      script_files => [ 'bin/parsechangelog' ],
      add_to_cleanup => [ 'messages.mo', 'blib', '$doc_pot_path~' ],
      install_path => {po => $base.'/locale', man => $base.'/man'},
      create_packlist => 0,
      dist_abstract => 'parse Debian changelogs and output them in other formats',
      dist_author => ['Frank Lichtenheld <djpig@debian.org>'],
      po_faketime_cmd => defined $po_build_date ? ['faketime', '-f', $po_build_date] : [],
      )->create_build_script;