summaryrefslogtreecommitdiff
path: root/syncfiles.pl
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-06-15 16:54:29 -0700
committerH. Peter Anvin <hpa@zytor.com>2008-06-15 16:54:29 -0700
commit7806e96508788e6db786025b00ac78464b18f482 (patch)
tree1c9d290fe6c414b2c8fe4ba65c86bdadda743aa9 /syncfiles.pl
parenteb96812e9fc9af8a14408e3e510b0321b58ce5db (diff)
downloadnasm-7806e96508788e6db786025b00ac78464b18f482.tar.gz
nasm-7806e96508788e6db786025b00ac78464b18f482.tar.bz2
nasm-7806e96508788e6db786025b00ac78464b18f482.zip
Script to automagically synchronize the object file lists
Add a script to automagically synchronize the list of object files between the various Makefiles.
Diffstat (limited to 'syncfiles.pl')
-rwxr-xr-xsyncfiles.pl86
1 files changed, 86 insertions, 0 deletions
diff --git a/syncfiles.pl b/syncfiles.pl
new file mode 100755
index 0000000..5be984a
--- /dev/null
+++ b/syncfiles.pl
@@ -0,0 +1,86 @@
+#!/usr/bin/perl
+#
+# Sync the output file list between Makefiles
+# Use the mkdep.pl parameters to get the filename syntax
+#
+# The first file is the source file; the other ones target.
+# The initial file is assumed to be in Unix notation.
+#
+%def_hints = ('object-ending' => '.o',
+ 'path-separator' => '/',
+ 'continuation' => "\\");
+
+sub do_transform($$) {
+ my($l, $h) = @_;
+
+ $l =~ s/\x01/$$h{'object-ending'}/g;
+ $l =~ s/\x02/$$h{'path-separator'}/g;
+ $l =~ s/\x03/$$h{'continuation'}/g;
+
+ return $l;
+}
+
+@file_list = ();
+
+$first = 1;
+$first_file = $ARGV[0];
+die unless (defined($first_file));
+
+foreach $file (@ARGV) {
+ open(FILE, "< $file\0") or die;
+
+ # First, read the syntax hints
+ %hints = %def_hints;
+ while (defined($line = <FILE>)) {
+ if ($line =~ /^\#\s+\@(\S+)\:\s*\"([^\"]+)\"/) {
+ $hints{$1} = $2;
+ }
+ }
+
+ # Read and process the file
+ seek(FILE,0,0);
+ @lines = ();
+ $processing = 0;
+ while (defined($line = <FILE>)) {
+ chomp $line;
+ if ($processing) {
+ if ($line eq '#--- End File Lists ---#') {
+ push(@lines, $line."\n");
+ $processing = 0;
+ } elsif ($first) {
+ my $xl = $line;
+ my $oe = "\Q$hints{'object-ending'}";
+ my $ps = "\Q$hints{'path-separator'}";
+ my $cn = "\Q$hints{'continuation'}";
+
+ $xl =~ s/${oe}(\s|$)/\x01$1/g;
+ $xl =~ s/${ps}/\x02/g;
+ $xl =~ s/${cn}$/\x03/;
+ push(@file_list, $xl);
+ push(@lines, $line);
+ }
+ } else {
+ push(@lines, $line."\n");
+ if ($line eq '#--- Begin File Lists ---#') {
+ $processing = 1;
+ if (!$first) {
+ push(@lines, "# Edit in $first_file, not here!\n");
+ foreach $l (@file_list) {
+ push(@lines, do_transform($l, \%hints)."\n");
+ }
+ }
+ }
+ }
+ }
+ close(FILE);
+
+ # Write the file back out
+ if (!$first) {
+ open(FILE, "> $file\0") or die;
+ print FILE @lines;
+ close(FILE);
+ }
+
+ undef @lines;
+ $first = 0;
+}