output: macho -- Add support for N_PEXT in macho output
[nasm.git] / tools / syncfiles.pl
blob38524a8246f98eb17d0afd4b0b3763b628a664b2
1 #!/usr/bin/perl
2 ## --------------------------------------------------------------------------
3 ##
4 ## Copyright 1996-2009 The NASM Authors - All Rights Reserved
5 ## See the file AUTHORS included with the NASM distribution for
6 ## the specific copyright holders.
7 ##
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted provided that the following
10 ## conditions are met:
12 ## * Redistributions of source code must retain the above copyright
13 ## notice, this list of conditions and the following disclaimer.
14 ## * Redistributions in binary form must reproduce the above
15 ## copyright notice, this list of conditions and the following
16 ## disclaimer in the documentation and/or other materials provided
17 ## with the distribution.
18 ##
19 ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
20 ## CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
21 ## INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 ## DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 ## NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 ## LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 ## OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31 ## EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 ## --------------------------------------------------------------------------
36 # Sync the output file list between Makefiles
37 # Use the mkdep.pl parameters to get the filename syntax
39 # The first file is the source file; the other ones target.
41 %def_hints = ('object-ending' => '.o',
42 'path-separator' => '/',
43 'continuation' => "\\");
45 sub do_transform($$) {
46 my($l, $h) = @_;
47 my($ps) = $$h{'path-separator'};
49 $l =~ s/\x01/$$h{'object-ending'}/g;
50 $l =~ s/\x03/$$h{'continuation'}/g;
52 if ($ps eq '') {
53 # Remove the path separator and the preceeding directory
54 $l =~ s/[^\s\=]*\x02//g;
55 } else {
56 # Convert the path separator
57 $l =~ s/\x02/$ps/g;
60 return $l;
63 undef %line_lists;
65 $first = 1;
66 $first_file = $ARGV[0];
67 die unless (defined($first_file));
69 foreach $file (@ARGV) {
70 open(FILE, '<', $file) or die;
72 # First, read the syntax hints
73 %hints = %def_hints;
74 while (defined($line = <FILE>)) {
75 if ( $line =~ /^\s*\#\s*@([a-z0-9-]+):\s*\"([^\"]*)\"/ ) {
76 $hints{$1} = $2;
80 # Read and process the file
81 seek(FILE,0,0);
82 @lines = ();
83 undef $processing;
84 while (defined($line = <FILE>)) {
85 chomp $line;
86 if (defined($processing)) {
87 if ($line =~ /^\#-- End ([^-\#]*[^-#\s]) --\#$/) {
88 if ($1 ne $processing) {
89 die "$0: $file: Mismatched Begin and End lines (\"$processing\" -> \"$1\"\n";
91 push(@lines, $line."\n");
92 undef $processing;
93 } elsif ($first) {
94 my $xl = $line;
95 my $oe = "\Q$hints{'object-ending'}";
96 my $ps = "\Q$hints{'path-separator'}";
97 my $cn = "\Q$hints{'continuation'}";
99 $xl =~ s/${oe}(\s|$)/\x01$1/g;
100 $xl =~ s/${ps}/\x02/g;
101 $xl =~ s/${cn}$/\x03/;
102 push(@{$line_lists{$processing}}, $xl);
103 push(@lines, $line);
105 } else {
106 push(@lines, $line."\n");
107 if ($line =~ '#-- Begin ([^-\#]*[^-#\s]) --#') {
108 $processing = $1;
109 if ($first) {
110 if (defined($line_lists{$processing})) {
111 die "$0: $file: Repeated Begin block: $processing\n";
113 $line_lists{$processing} = [];
114 } elsif (!$first) {
115 if (!defined($line_lists{$processing})) {
116 die "$0: $file: Begin block without template\n";
118 push(@lines, "# Edit in $first_file, not here!\n");
119 foreach $l (@{$line_lists{$processing}}) {
120 push(@lines, do_transform($l, \%hints)."\n");
126 close(FILE);
128 # Write the file back out
129 if (!$first) {
130 open(FILE, '>', $file) or die;
131 print FILE @lines;
132 close(FILE);
135 undef @lines;
136 $first = 0;