[cage] Add some karma aliases for myself
[parrot.git] / tools / build / fixup_gen_file.pl
blob371bef72c19a59415c40882e82d7337ce7575bdd
1 #! perl
2 # Copyright (C) 2007, Parrot Foundation.
3 # $Id$
5 =head1 NAME
7 tools/build/fixup_gen_file.pl - mark a generated file as generated
9 =head1 SYNOPSIS
11 % perl tools/build/fixup_gen_file.pl <options> <generated_file> <dest_file>
13 =head1 DESCRIPTION
15 This script adds special headers and footers to files generated by tools
16 outside of Parrot's normal build process. This is so that people do not
17 accidentally modify these files.
19 =head1 OPTIONS
21 =over 4
23 =item noheaderizer
25 This option adds directives to C<dest_file> that instruct headerizer to ignore
26 the file.
28 =back
30 =cut
32 use strict;
33 use warnings;
35 use Getopt::Long;
36 use lib 'lib';
37 use Parrot::BuildUtil;
39 GetOptions( \my %opts, "noheaderizer", ) or die "error processing options";
41 my ( $gen_file, $source ) = @ARGV;
42 my $contents =
43 -e $gen_file
44 ? Parrot::BuildUtil::slurp_file($gen_file)
45 : die "Cannot find '$gen_file': $!\n";
47 # fix slashies in source filename for display in header
48 $source =~ s/\\/\//g;
50 my $header = Parrot::BuildUtil::generated_file_header( $source, 'c' );
52 my $noheaderizer = <<END_NOHEADERIZER;
53 /* HEADERIZER HFILE: none */
54 /* HEADERIZER STOP */
55 END_NOHEADERIZER
57 # if the generated file exists, make sure the header isn't there already
58 open( my ($gen_fh), '<', $gen_file )
59 or die "Cannot read '$gen_file': $!\n";
60 read $gen_fh, my $block, length $header;
61 exit if $block eq $header;
63 open( my $dest_fh, '>', $gen_file )
64 or die "Cannot write to '$gen_file': $!\n";
66 print {$dest_fh} $header, ( exists $opts{noheaderizer} ? $noheaderizer : () ), $contents;
68 close $dest_fh;
70 # Local Variables:
71 # mode: cperl
72 # cperl-indent-level: 4
73 # fill-column: 100
74 # End:
75 # vim: expandtab shiftwidth=4: