Mark Perl scripts executable
[nasm/autotest.git] / syncfiles.pl
blob5be984ace0acad3a1d2f34a0d23eb1aa79f38600
1 #!/usr/bin/perl
3 # Sync the output file list between Makefiles
4 # Use the mkdep.pl parameters to get the filename syntax
6 # The first file is the source file; the other ones target.
7 # The initial file is assumed to be in Unix notation.
9 %def_hints = ('object-ending' => '.o',
10 'path-separator' => '/',
11 'continuation' => "\\");
13 sub do_transform($$) {
14 my($l, $h) = @_;
16 $l =~ s/\x01/$$h{'object-ending'}/g;
17 $l =~ s/\x02/$$h{'path-separator'}/g;
18 $l =~ s/\x03/$$h{'continuation'}/g;
20 return $l;
23 @file_list = ();
25 $first = 1;
26 $first_file = $ARGV[0];
27 die unless (defined($first_file));
29 foreach $file (@ARGV) {
30 open(FILE, "< $file\0") or die;
32 # First, read the syntax hints
33 %hints = %def_hints;
34 while (defined($line = <FILE>)) {
35 if ($line =~ /^\#\s+\@(\S+)\:\s*\"([^\"]+)\"/) {
36 $hints{$1} = $2;
40 # Read and process the file
41 seek(FILE,0,0);
42 @lines = ();
43 $processing = 0;
44 while (defined($line = <FILE>)) {
45 chomp $line;
46 if ($processing) {
47 if ($line eq '#--- End File Lists ---#') {
48 push(@lines, $line."\n");
49 $processing = 0;
50 } elsif ($first) {
51 my $xl = $line;
52 my $oe = "\Q$hints{'object-ending'}";
53 my $ps = "\Q$hints{'path-separator'}";
54 my $cn = "\Q$hints{'continuation'}";
56 $xl =~ s/${oe}(\s|$)/\x01$1/g;
57 $xl =~ s/${ps}/\x02/g;
58 $xl =~ s/${cn}$/\x03/;
59 push(@file_list, $xl);
60 push(@lines, $line);
62 } else {
63 push(@lines, $line."\n");
64 if ($line eq '#--- Begin File Lists ---#') {
65 $processing = 1;
66 if (!$first) {
67 push(@lines, "# Edit in $first_file, not here!\n");
68 foreach $l (@file_list) {
69 push(@lines, do_transform($l, \%hints)."\n");
75 close(FILE);
77 # Write the file back out
78 if (!$first) {
79 open(FILE, "> $file\0") or die;
80 print FILE @lines;
81 close(FILE);
84 undef @lines;
85 $first = 0;