nasm/macros.pl
H. Peter Anvin a4835d466c Avoid #including .c files; instead compile as separate units
Don't #include .c files, even if they are auto-generated; instead
compile them as separate compilation units and let the linker do its
job.
2008-05-20 14:21:29 -07:00

54 lines
1.3 KiB
Perl

#!/usr/bin/perl -w
#
# macros.pl produce macros.c from standard.mac
#
# The Netwide Assembler is copyright (C) 1996 Simon Tatham and
# Julian Hall. All rights reserved. The software is
# redistributable under the license given in the file "LICENSE"
# distributed in the NASM archive.
use strict;
my $fname;
my $line = 0;
my $index = 0;
my $tasm_count;
undef $tasm_count;
open(OUTPUT,">macros.c") or die "unable to open macros.c\n";
print OUTPUT "/* This file auto-generated from standard.mac by macros.pl" .
" - don't edit it */\n";
print OUTPUT "\n";
print OUTPUT "#include \"tables.h\"\n";
print OUTPUT "\n";
print OUTPUT "const char * const nasm_stdmac[] = {\n";
foreach $fname ( @ARGV ) {
open(INPUT,$fname) or die "unable to open $fname\n";
while (<INPUT>) {
$line++;
chomp;
if (m/^\s*\*END\*TASM\*MACROS\*\s*$/) {
$tasm_count = $index;
} elsif (m/^\s*((\s*([^\"\';\s]+|\"[^\"]*\"|\'[^\']*\'))*)\s*(;.*)?$/) {
$_ = $1;
s/\\/\\\\/g;
s/"/\\"/g;
if (length > 0) {
print OUTPUT " \"$_\",\n";
$index++;
}
} else {
die "$fname:$line: error unterminated quote";
}
}
close(INPUT);
}
print OUTPUT " NULL\n};\n\n";
$tasm_count = $index unless ( defined($tasm_count) );
print OUTPUT "const char * const * nasm_stdmac_after_tasm = ",
"&nasm_stdmac[$tasm_count];\n";
close(OUTPUT);