#!/usr/bin/perl
|
#!/usr/bin/perl
|
|
|
use strict ;
|
use strict ;
|
|
|
sub print_macro($$);
|
sub print_macro($$);
|
|
|
#
|
#
|
# Perl script to beautify and enhance RTEMS autoconf Makefile.ins
|
# Perl script to beautify and enhance RTEMS autoconf Makefile.ins
|
#
|
#
|
# Reads from stdin and writes to stdout
|
# Reads from stdin and writes to stdout
|
#
|
#
|
# usage:
|
# usage:
|
# acpolish Makefile.in~
|
# acpolish Makefile.in~
|
# mv Makefile.in~ Makefile.in
|
# mv Makefile.in~ Makefile.in
|
#
|
#
|
# Note: This tool is not indented to be exported from the source-tree
|
# Note: This tool is not indented to be exported from the source-tree
|
#
|
#
|
|
|
if ( -f "Makefile.am" )
|
if ( -f "Makefile.am" )
|
{
|
{
|
# Refuse to work on Makefile.ins generated from automake;
|
# Refuse to work on Makefile.ins generated from automake;
|
# redirecting STDOUT to Makefile.in will trash the Makefile.in ;-
|
# redirecting STDOUT to Makefile.in will trash the Makefile.in ;-
|
|
|
die "acpolish must not be run in automake directories" ;
|
die "acpolish must not be run in automake directories" ;
|
}
|
}
|
|
|
my $experimental = 0 ; # enable experimental/unsafe features
|
my $experimental = 0 ; # enable experimental/unsafe features
|
my $verbose = 0 ;
|
my $verbose = 0 ;
|
my $build_pgms_seen = "" ;
|
my $build_pgms_seen = "" ;
|
my $make_exe_seen = 0 ;
|
my $make_exe_seen = 0 ;
|
my $install_seen = 0 ;
|
my $install_seen = 0 ;
|
my $top_builddir = "";
|
my $top_builddir = "";
|
my $subdir = "";
|
my $subdir = "";
|
my @installdirs = () ;
|
my @installdirs = () ;
|
|
|
my @pieces = () ;
|
my @pieces = () ;
|
my @files = () ;
|
my @files = () ;
|
my @variants = () ;
|
my @variants = () ;
|
my @vars = () ;
|
my @vars = () ;
|
|
|
# Strip off duplicate entries from a list
|
# Strip off duplicate entries from a list
|
sub purge($)
|
sub purge($)
|
{
|
{
|
my $list = $_[0] ; # Reference to list !
|
my $list = $_[0] ; # Reference to list !
|
my (@tmp) = () ;
|
my (@tmp) = () ;
|
|
|
foreach my $l ( @{$list} )
|
foreach my $l ( @{$list} )
|
{
|
{
|
my $i = 1 ;
|
my $i = 1 ;
|
foreach my $t (@tmp)
|
foreach my $t (@tmp)
|
{
|
{
|
if ( $t eq $l )
|
if ( $t eq $l )
|
{
|
{
|
$i = 0 ;
|
$i = 0 ;
|
last ;
|
last ;
|
}
|
}
|
}
|
}
|
push @tmp,$l if ($i) ;
|
push @tmp,$l if ($i) ;
|
}
|
}
|
|
|
@{$list} = @tmp ;
|
@{$list} = @tmp ;
|
}
|
}
|
|
|
sub find_root
|
sub find_root
|
{
|
{
|
$top_builddir = "." ;
|
$top_builddir = "." ;
|
$subdir="";
|
$subdir="";
|
my $pwd = `pwd`; chomp $pwd;
|
my $pwd = `pwd`; chomp $pwd;
|
$pwd .= "/" ;
|
$pwd .= "/" ;
|
my $len ;
|
my $len ;
|
|
|
if ( -f "configure.in" ) { return $top_builddir ; }
|
if ( -f "configure.in" ) { return $top_builddir ; }
|
my $i = rindex($pwd,'/');
|
my $i = rindex($pwd,'/');
|
|
|
$len = $i;
|
$len = $i;
|
$pwd = substr($pwd,0,$len);
|
$pwd = substr($pwd,0,$len);
|
$i = rindex($pwd,'/');
|
$i = rindex($pwd,'/');
|
$subdir = substr($pwd,$i+1,$len - 1);
|
$subdir = substr($pwd,$i+1,$len - 1);
|
$top_builddir = ".." ;
|
$top_builddir = ".." ;
|
|
|
while( -d "$top_builddir" )
|
while( -d "$top_builddir" )
|
{
|
{
|
if ( -f "${top_builddir}/configure.in" )
|
if ( -f "${top_builddir}/configure.in" )
|
{
|
{
|
return $top_builddir ;
|
return $top_builddir ;
|
}
|
}
|
$len=$i;
|
$len=$i;
|
$pwd = substr($pwd,0,$len);
|
$pwd = substr($pwd,0,$len);
|
$i = rindex($pwd,'/');
|
$i = rindex($pwd,'/');
|
$subdir = substr($pwd,$i+1,$len - 1) . "/$subdir";
|
$subdir = substr($pwd,$i+1,$len - 1) . "/$subdir";
|
$top_builddir .= "/.." ;
|
$top_builddir .= "/.." ;
|
} ;
|
} ;
|
die "Can't find configure.in\n" ;
|
die "Can't find configure.in\n" ;
|
}
|
}
|
|
|
find_root();
|
find_root();
|
|
|
my @buffer = () ;
|
my @buffer = () ;
|
|
|
sub subst_line
|
sub subst_line
|
{
|
{
|
# substitute obsolete variables
|
# substitute obsolete variables
|
if ( /^([^\s]*)[\s]+$/o )
|
if ( /^([^\s]*)[\s]+$/o )
|
{ # strip trailing spaces
|
{ # strip trailing spaces
|
$_ = "$1\n";
|
$_ = "$1\n";
|
}
|
}
|
if ( /^(.*)MKLIB(.*)$/o )
|
if ( /^(.*)MKLIB(.*)$/o )
|
{
|
{
|
s/MKLIB/RANLIB/g ;
|
s/MKLIB/RANLIB/g ;
|
}
|
}
|
if ( /^(.*)\$\(INSTINCFLAGS\)(.*)$/o )
|
if ( /^(.*)\$\(INSTINCFLAGS\)(.*)$/o )
|
{
|
{
|
s/\$\(INSTINCFLAGS\)/-m 644/g ;
|
s/\$\(INSTINCFLAGS\)/-m 644/g ;
|
}
|
}
|
if ( /^(.*)ASM(_FILES|_PIECES|_O_FILES)(.*)$/o )
|
if ( /^(.*)ASM(_FILES|_PIECES|_O_FILES)(.*)$/o )
|
{
|
{
|
s/ASM_FILES/S_FILES/g ;
|
s/ASM_FILES/S_FILES/g ;
|
s/ASM_PIECES/S_PIECES/g ;
|
s/ASM_PIECES/S_PIECES/g ;
|
s/ASM_O_FILES/S_O_FILES/g ;
|
s/ASM_O_FILES/S_O_FILES/g ;
|
print STDERR "ASM: $_" if ( $verbose > 0) ;
|
print STDERR "ASM: $_" if ( $verbose > 0) ;
|
}
|
}
|
if ( /^(.*)MP_PIECES(.*)$/o )
|
if ( /^(.*)MP_PIECES(.*)$/o )
|
{ # HACK: this is not always correct
|
{ # HACK: this is not always correct
|
s/MP_PIECES/MP_C_PIECES/g ;
|
s/MP_PIECES/MP_C_PIECES/g ;
|
print STDERR "MP_PIECES: $_" if ( $verbose > 0 );
|
print STDERR "MP_PIECES: $_" if ( $verbose > 0 );
|
}
|
}
|
if ( /^(.*)\$\(RTEMS_BSP\)(.*)$/o )
|
if ( /^(.*)\$\(RTEMS_BSP\)(.*)$/o )
|
{
|
{
|
s/\$\(RTEMS_BSP\)/\@RTEMS_BSP\@/g ;
|
s/\$\(RTEMS_BSP\)/\@RTEMS_BSP\@/g ;
|
}
|
}
|
if ( /^(.*)\$\(RTEMS_ROOT\)\/mkinstalldirs(.*)$/o )
|
if ( /^(.*)\$\(RTEMS_ROOT\)\/mkinstalldirs(.*)$/o )
|
{
|
{
|
$_ = "$1\$\(mkinstalldirs\)$2\n" ;
|
$_ = "$1\$\(mkinstalldirs\)$2\n" ;
|
}
|
}
|
if ( /^(.*)\$\{(.*)_FILES\}(.*)$/o )
|
if ( /^(.*)\$\{(.*)_FILES\}(.*)$/o )
|
{
|
{
|
$_ = "$1\$\($2_FILES\)$3\n" ;
|
$_ = "$1\$\($2_FILES\)$3\n" ;
|
}
|
}
|
if ( /^(.*)\$\{(.*)_PIECES\}(.*)$/o )
|
if ( /^(.*)\$\{(.*)_PIECES\}(.*)$/o )
|
{
|
{
|
$_ = "$1\$\($2_PIECES\)$3\n" ;
|
$_ = "$1\$\($2_PIECES\)$3\n" ;
|
}
|
}
|
if ( /^(.*)\$\(PROJECT_ROOT\)\/\@RTEMS_BSP\@\/lib\/include(.*)$/o )
|
if ( /^(.*)\$\(PROJECT_ROOT\)\/\@RTEMS_BSP\@\/lib\/include(.*)$/o )
|
{
|
{
|
$_ = "$1\$\(PROJECT_INCLUDE\)$2\n" ;
|
$_ = "$1\$\(PROJECT_INCLUDE\)$2\n" ;
|
}
|
}
|
if ( /^(.*)\$\{PROJECT_RELEASE\}(.*)$/o )
|
if ( /^(.*)\$\{PROJECT_RELEASE\}(.*)$/o )
|
{
|
{
|
$_ = "$1\$\(PROJECT_RELEASE\)$2\n" ;
|
$_ = "$1\$\(PROJECT_RELEASE\)$2\n" ;
|
}
|
}
|
if ( /^(.*\$\(INSTALL_[A-Z]+\))[\s]+-m[\s]+([54])([0-9][0-9].*)$/o )
|
if ( /^(.*\$\(INSTALL_[A-Z]+\))[\s]+-m[\s]+([54])([0-9][0-9].*)$/o )
|
{
|
{
|
my $v = $2 + 2 ;
|
my $v = $2 + 2 ;
|
$_ = "$1 -m $v$3\n" ;
|
$_ = "$1 -m $v$3\n" ;
|
}
|
}
|
if ( /^H_FILES[\s]*=[\s]*\$\(wildcard[\s]+\$\(srcdir\)\/\*\.h\)[\s]*$/o )
|
if ( /^H_FILES[\s]*=[\s]*\$\(wildcard[\s]+\$\(srcdir\)\/\*\.h\)[\s]*$/o )
|
{
|
{
|
my $files =`ls *.h 2>/dev/null`;
|
my $files =`ls *.h 2>/dev/null`;
|
print STDERR "WARNING: Replacing \"\(wildcard... in $_\n" ;
|
print STDERR "WARNING: Replacing \"\(wildcard... in $_\n" ;
|
my $line = "H_FILES =";
|
my $line = "H_FILES =";
|
my @l = split(' ',$files) ;
|
my @l = split(' ',$files) ;
|
foreach(@l) { $line .= " \$\(srcdir\)/$_"; }
|
foreach(@l) { $line .= " \$\(srcdir\)/$_"; }
|
$line .= "\n" ;
|
$line .= "\n" ;
|
$_ = "$line" ;
|
$_ = "$line" ;
|
}
|
}
|
if ( /^(.*)RTEMS_HAS_([A-Z]+)(.*)$/o )
|
if ( /^(.*)RTEMS_HAS_([A-Z]+)(.*)$/o )
|
{
|
{
|
print STDERR "WARNING: Replacing RTEMS_HAS_$2 with HAS_$2\n" ;
|
print STDERR "WARNING: Replacing RTEMS_HAS_$2 with HAS_$2\n" ;
|
$_ = "$1HAS_$2$3\n" ;
|
$_ = "$1HAS_$2$3\n" ;
|
}
|
}
|
if ( /^[\s]*\$[({]PGM[)}]:[\s]*(.*)\$([({]SRCS[)}])(.*)$/o )
|
if ( /^[\s]*\$[({]PGM[)}]:[\s]*(.*)\$([({]SRCS[)}])(.*)$/o )
|
{
|
{
|
$_ = "\$(PGM):$1$3\n" ;
|
$_ = "\$(PGM):$1$3\n" ;
|
}
|
}
|
if ( /^.*\$\(make\-exe\).*$/o )
|
if ( /^.*\$\(make\-exe\).*$/o )
|
{
|
{
|
$make_exe_seen = 1 ;
|
$make_exe_seen = 1 ;
|
}
|
}
|
if ( /^.*\$\(INSTALL_(DATA|SCRIPT|PROGRAM)\)(.*)$/o )
|
if ( /^.*\$\(INSTALL_(DATA|SCRIPT|PROGRAM)\)(.*)$/o )
|
{
|
{
|
$install_seen = 1 ;
|
$install_seen = 1 ;
|
}
|
}
|
}
|
}
|
|
|
{
|
{
|
# 1st PASS:
|
# 1st PASS:
|
# * Read input file
|
# * Read input file
|
# * concatenate multiple lines
|
# * concatenate multiple lines
|
# * Remove obsolete variables
|
# * Remove obsolete variables
|
|
|
my @ibuf = () ;
|
my @ibuf = () ;
|
my $line = "" ;
|
my $line = "" ;
|
|
|
while ( )
|
while ( )
|
{
|
{
|
&subst_line ;
|
&subst_line ;
|
if ( /^(#.*)$/o )
|
if ( /^(#.*)$/o )
|
{ # preserve comments
|
{ # preserve comments
|
$line = "$_" ;
|
$line = "$_" ;
|
push @ibuf, $line ;
|
push @ibuf, $line ;
|
$line = "" ;
|
$line = "" ;
|
}
|
}
|
elsif ( /^.*\\$/o )
|
elsif ( /^.*\\$/o )
|
{ # multilines
|
{ # multilines
|
chop ;
|
chop ;
|
$line .= "$_\\" ;
|
$line .= "$_\\" ;
|
}
|
}
|
else
|
else
|
{
|
{
|
$line .= "$_" ;
|
$line .= "$_" ;
|
push @ibuf, $line ;
|
push @ibuf, $line ;
|
$line = "" ;
|
$line = "" ;
|
}
|
}
|
}
|
}
|
@buffer = @ibuf;
|
@buffer = @ibuf;
|
}
|
}
|
|
|
{
|
{
|
# 2nd PASS:
|
# 2nd PASS:
|
# * remove automatically generated lines
|
# * remove automatically generated lines
|
# * process some selected make rules
|
# * process some selected make rules
|
my $line = "" ;
|
my $line = "" ;
|
my @tbuf = () ;
|
my @tbuf = () ;
|
foreach (@buffer)
|
foreach (@buffer)
|
{
|
{
|
if ( /^[\t](.*)$/o )
|
if ( /^[\t](.*)$/o )
|
{ # make rule production
|
{ # make rule production
|
my $line = $1 ;
|
my $line = $1 ;
|
tr/\\/ / ;
|
tr/\\/ / ;
|
my @l = split(/;/,$_);
|
my @l = split(/;/,$_);
|
foreach (@l)
|
foreach (@l)
|
{ # try to get installation directories
|
{ # try to get installation directories
|
if ( /^.*\$\(mkinstalldirs\).*\s\$\(INSTALLDIRS\)$/o )
|
if ( /^.*\$\(mkinstalldirs\).*\s\$\(INSTALLDIRS\)$/o )
|
{
|
{
|
}
|
}
|
elsif ( /^.*\$\(mkinstalldirs\).*\s([^\s]+)$/o )
|
elsif ( /^.*\$\(mkinstalldirs\).*\s([^\s]+)$/o )
|
{
|
{
|
push @installdirs, "$1" ;
|
push @installdirs, "$1" ;
|
}
|
}
|
elsif ( /^.*\$\(INSTALL_CHANGE\).*\s([^\s]+)(\/[^\.\s]+\.[^\s\/]+)$/o )
|
elsif ( /^.*\$\(INSTALL_CHANGE\).*\s([^\s]+)(\/[^\.\s]+\.[^\s\/]+)$/o )
|
{
|
{
|
# print STDERR "WARNING - DIR1: $1 <$2> " ;
|
# print STDERR "WARNING - DIR1: $1 <$2> " ;
|
push @installdirs, "$1" ;
|
push @installdirs, "$1" ;
|
}
|
}
|
elsif ( /^.*\$\(INSTALL_CHANGE\).*\s([^\s]+)$/o )
|
elsif ( /^.*\$\(INSTALL_CHANGE\).*\s([^\s]+)$/o )
|
{
|
{
|
# print STDERR "DIR2 $1\n" ;
|
# print STDERR "DIR2 $1\n" ;
|
push @installdirs, "$1" ;
|
push @installdirs, "$1" ;
|
}
|
}
|
}
|
}
|
push @tbuf, "§3$line"
|
push @tbuf, "§3$line"
|
}
|
}
|
elsif ( /^[\s]*\#.*$/o )
|
elsif ( /^[\s]*\#.*$/o )
|
{ # comment
|
{ # comment
|
push @tbuf, "$_" ;
|
push @tbuf, "$_" ;
|
}
|
}
|
elsif ( /^[\s]*([A-Z_]*)_FILES[\s]*\=[\s]*(.*)$/o )
|
elsif ( /^[\s]*([A-Z_]*)_FILES[\s]*\=[\s]*(.*)$/o )
|
{ # *_FILES = ... Macros
|
{ # *_FILES = ... Macros
|
if ( /^[\s]*([A-Z_]*_|)(CC|C|EQ|H|I|O|S|X)_FILES[\s]*\=[\s]*(.*)$/o )
|
if ( /^[\s]*([A-Z_]*_|)(CC|C|EQ|H|I|O|S|X)_FILES[\s]*\=[\s]*(.*)$/o )
|
{
|
{
|
# print STDERR "FILES: <$1>--<$2>--<$3>\n" ;
|
# print STDERR "FILES: <$1>--<$2>--<$3>\n" ;
|
my $f = "$1$2_FILES" ;
|
my $f = "$1$2_FILES" ;
|
${"var_$f"}="$3" ;
|
${"var_$f"}="$3" ;
|
if ( ( $experimental > 0 )
|
if ( ( $experimental > 0 )
|
and ( ( "$2" eq "C" ) or ( "$2" eq "CC" ) or ( "$2" eq "S" )
|
and ( ( "$2" eq "C" ) or ( "$2" eq "CC" ) or ( "$2" eq "S" )
|
or ( "$2" eq "I" ) or ( "$2" eq "H" ) ) )
|
or ( "$2" eq "I" ) or ( "$2" eq "H" ) ) )
|
{
|
{
|
my $p = "$1$2_PIECES" ;
|
my $p = "$1$2_PIECES" ;
|
if ( not defined ${"var_$p"} )
|
if ( not defined ${"var_$p"} )
|
{
|
{
|
print STDERR "ADDING $p\n" ;
|
print STDERR "ADDING $p\n" ;
|
${"var_$p"} = "" ;
|
${"var_$p"} = "" ;
|
push @tbuf, "§4$p\n" ;
|
push @tbuf, "§4$p\n" ;
|
push @pieces, "$p" ;
|
push @pieces, "$p" ;
|
}
|
}
|
}
|
}
|
# place a marker
|
# place a marker
|
push @tbuf, "§4$f\n" ;
|
push @tbuf, "§4$f\n" ;
|
push @files, "$f" ;
|
push @files, "$f" ;
|
}
|
}
|
else
|
else
|
{ # found a bug
|
{ # found a bug
|
print STDERR "UNKNOWN _FILES: $_\n" ;
|
print STDERR "UNKNOWN _FILES: $_\n" ;
|
my $f = "$1_FILES" ;
|
my $f = "$1_FILES" ;
|
${"var_$f"}="$2" ;
|
${"var_$f"}="$2" ;
|
# place a marker
|
# place a marker
|
push @tbuf, "§4$f\n" ;
|
push @tbuf, "§4$f\n" ;
|
push @files, "$f" ;
|
push @files, "$f" ;
|
}
|
}
|
}
|
}
|
elsif ( /^[\s]*([A-Z_]*)_PIECES[\s]*\=[\s]*(.*)$/o )
|
elsif ( /^[\s]*([A-Z_]*)_PIECES[\s]*\=[\s]*(.*)$/o )
|
{ # *_PIECES = ... Macros
|
{ # *_PIECES = ... Macros
|
if ( /^[\s]*([A-Z][A-Z0-9_]*_|)(CC|C|EQ|H|I|O|S|X|REL)_PIECES[\s]*\=[\s]*(.*)$/o )
|
if ( /^[\s]*([A-Z][A-Z0-9_]*_|)(CC|C|EQ|H|I|O|S|X|REL)_PIECES[\s]*\=[\s]*(.*)$/o )
|
{
|
{
|
my $p = "$1$2_PIECES" ;
|
my $p = "$1$2_PIECES" ;
|
|
|
if ( not defined ${"var_$p"} )
|
if ( not defined ${"var_$p"} )
|
{
|
{
|
${"var_$p"} = "$3" ;
|
${"var_$p"} = "$3" ;
|
push @tbuf, "§4$p\n" ;
|
push @tbuf, "§4$p\n" ;
|
push @pieces, "$p" ;
|
push @pieces, "$p" ;
|
}
|
}
|
else
|
else
|
{
|
{
|
${"var_$p"} .= " $3" ;
|
${"var_$p"} .= " $3" ;
|
}
|
}
|
}
|
}
|
elsif ( /^[\s]*(BSP|CPU|GENERIC)_PIECES[\s]*\=[\s]*(.*)$/o )
|
elsif ( /^[\s]*(BSP|CPU|GENERIC)_PIECES[\s]*\=[\s]*(.*)$/o )
|
{ # Explicit exceptions from the *_PIECES naming conventions
|
{ # Explicit exceptions from the *_PIECES naming conventions
|
# They should better be replaced in future
|
# They should better be replaced in future
|
my $p = "$1_PIECES" ;
|
my $p = "$1_PIECES" ;
|
${"var_$p"}="$2" ;
|
${"var_$p"}="$2" ;
|
# place a marker
|
# place a marker
|
push @tbuf, "§4$p\n" ;
|
push @tbuf, "§4$p\n" ;
|
push @pieces, "$p" ;
|
push @pieces, "$p" ;
|
}
|
}
|
else
|
else
|
{ # found a bug
|
{ # found a bug
|
print STDERR "UNKNOWN _PIECES: $_\n" ;
|
print STDERR "UNKNOWN _PIECES: $_\n" ;
|
my $p = "$1_PIECES" ;
|
my $p = "$1_PIECES" ;
|
${"var_$p"}="$2" ;
|
${"var_$p"}="$2" ;
|
# place a marker
|
# place a marker
|
push @tbuf, "§4$p\n" ;
|
push @tbuf, "§4$p\n" ;
|
push @pieces, "$p" ;
|
push @pieces, "$p" ;
|
}
|
}
|
}
|
}
|
elsif ( /^[\s]*([A-Z_]+)_PIECES_([^\s]+)_V[\s]*\=[\s]*(.*)$/o )
|
elsif ( /^[\s]*([A-Z_]+)_PIECES_([^\s]+)_V[\s]*\=[\s]*(.*)$/o )
|
{ # *_PIECES_.._V = ... Macros
|
{ # *_PIECES_.._V = ... Macros
|
if ( /^[\s]*([A-Z][A-Z0-9_]*_|)(CC|C|EQ|H|I|O|S|X|REL)_PIECES_([^\s]+)_V[\s]*\=[\s]*(.*)$/o )
|
if ( /^[\s]*([A-Z][A-Z0-9_]*_|)(CC|C|EQ|H|I|O|S|X|REL)_PIECES_([^\s]+)_V[\s]*\=[\s]*(.*)$/o )
|
{
|
{
|
my @l = split(/_/,$3);
|
my @l = split(/_/,$3);
|
my $v = "$1$2-$#l" ;
|
my $v = "$1$2-$#l" ;
|
if ( not defined @{"variants_$v"} ) { push @variants, "$v" ; }
|
if ( not defined @{"variants_$v"} ) { push @variants, "$v" ; }
|
|
|
my $p = "$1$2_PIECES_$3_V" ;
|
my $p = "$1$2_PIECES_$3_V" ;
|
push @{"variants_${v}"}, "$p" ;
|
push @{"variants_${v}"}, "$p" ;
|
|
|
${"var_$p"}="$4" ;
|
${"var_$p"}="$4" ;
|
# place a marker
|
# place a marker
|
push @tbuf, "§4$p\n" ;
|
push @tbuf, "§4$p\n" ;
|
push @pieces, "$p" ;
|
push @pieces, "$p" ;
|
}
|
}
|
else
|
else
|
{ # found a bug
|
{ # found a bug
|
print STDERR "UNKNOWN _PIECES: $_\n" ;
|
print STDERR "UNKNOWN _PIECES: $_\n" ;
|
my $p = "$1_PIECES" ;
|
my $p = "$1_PIECES" ;
|
${"var_$p"}="$2" ;
|
${"var_$p"}="$2" ;
|
# place a marker
|
# place a marker
|
push @tbuf, "§4$p\n" ;
|
push @tbuf, "§4$p\n" ;
|
push @pieces, "$p" ;
|
push @pieces, "$p" ;
|
}
|
}
|
}
|
}
|
elsif ( /^[\s]*([^\s+=]+)[\s]*\=[\s]*(.*)$/o )
|
elsif ( /^[\s]*([^\s+=]+)[\s]*\=[\s]*(.*)$/o )
|
{ # makefile variables
|
{ # makefile variables
|
if ( ( "$1" eq "subdir" )
|
if ( ( "$1" eq "subdir" )
|
or ( "$1" eq "top_srcdir" )
|
or ( "$1" eq "top_srcdir" )
|
or ( "$1" eq "top_builddir" )
|
or ( "$1" eq "top_builddir" )
|
or ( "$1" eq "RTEMS_ROOT" )
|
or ( "$1" eq "RTEMS_ROOT" )
|
or ( "$1" eq "PROJECT_ROOT" )
|
or ( "$1" eq "PROJECT_ROOT" )
|
or ( "$1" eq "INSTALL" )
|
or ( "$1" eq "INSTALL" )
|
or ( "$1" eq "PACKHEX" )
|
or ( "$1" eq "PACKHEX" )
|
or ( "$1" eq "INSTALL_CHANGE" )
|
or ( "$1" eq "INSTALL_CHANGE" )
|
or ( "$1" eq "mkinstalldirs" )
|
or ( "$1" eq "mkinstalldirs" )
|
or ( "$1" eq "ACLOCAL" )
|
or ( "$1" eq "ACLOCAL" )
|
or ( "$1" eq "AUTOCONF" )
|
or ( "$1" eq "AUTOCONF" )
|
or ( "$1" eq "ACLOCAL_M4" )
|
or ( "$1" eq "ACLOCAL_M4" )
|
or ( "$1" eq "ACLOCAL_AMFLAGS" )
|
or ( "$1" eq "ACLOCAL_AMFLAGS" )
|
)
|
)
|
{
|
{
|
print STDERR "REMOVE: $1\n" if $verbose ;
|
print STDERR "REMOVE: $1\n" if $verbose ;
|
}
|
}
|
elsif ( "$1" eq "srcdir" )
|
elsif ( "$1" eq "srcdir" )
|
{ # place marker
|
{ # place marker
|
push @tbuf, "§0\n";
|
push @tbuf, "§0\n";
|
}
|
}
|
elsif ( "$1" eq "INSTALLDIRS" )
|
elsif ( "$1" eq "INSTALLDIRS" )
|
{ # process the block
|
{ # process the block
|
my $input = $2 ;
|
my $input = $2 ;
|
$input =~ s/\\\\/ /g ;
|
$input =~ s/\\\\/ /g ;
|
my @l = split(' ',$input);
|
my @l = split(' ',$input);
|
foreach (@l)
|
foreach (@l)
|
{
|
{
|
if ( /[\s]*([^\s]+)[\s]*$/o )
|
if ( /[\s]*([^\s]+)[\s]*$/o )
|
{
|
{
|
push @installdirs, "$1" ;
|
push @installdirs, "$1" ;
|
}
|
}
|
}
|
}
|
}
|
}
|
else
|
else
|
{
|
{
|
# print STDERR "MACRO: <$1> = <$2>\n";
|
# print STDERR "MACRO: <$1> = <$2>\n";
|
my $p = "$1" ;
|
my $p = "$1" ;
|
${"var_$p"}="$2" ;
|
${"var_$p"}="$2" ;
|
# place a marker
|
# place a marker
|
push @tbuf, "§4$p\n" ;
|
push @tbuf, "§4$p\n" ;
|
push @vars, "$p" ;
|
push @vars, "$p" ;
|
}
|
}
|
}
|
}
|
elsif ( /^[\s]*([^\s+=]+)[\s]*\+\=[\s]*(.*)$/o )
|
elsif ( /^[\s]*([^\s+=]+)[\s]*\+\=[\s]*(.*)$/o )
|
{ # makefile variable addition
|
{ # makefile variable addition
|
# print STDERR "MACRO: <$1> += <$2>\n";
|
# print STDERR "MACRO: <$1> += <$2>\n";
|
my $p = "$1" ;
|
my $p = "$1" ;
|
if ( not defined ${"var_$p+"} )
|
if ( not defined ${"var_$p+"} )
|
{
|
{
|
# place a marker
|
# place a marker
|
push @tbuf, "§5$p\n" ;
|
push @tbuf, "§5$p\n" ;
|
push @vars, "$p+" ;
|
push @vars, "$p+" ;
|
}
|
}
|
else
|
else
|
{
|
{
|
print STDERR "WARNING += $_" ;
|
print STDERR "WARNING += $_" ;
|
}
|
}
|
${"var_$p+"} .=" $2" ;
|
${"var_$p+"} .=" $2" ;
|
}
|
}
|
elsif ( /^[\s]*(\@[^\s]+\@)$/o )
|
elsif ( /^[\s]*(\@[^\s]+\@)$/o )
|
{ # autoconf variable
|
{ # autoconf variable
|
if ( "$1" eq "\@SET_MAKE\@" )
|
if ( "$1" eq "\@SET_MAKE\@" )
|
{
|
{
|
}
|
}
|
else
|
else
|
{
|
{
|
push @tbuf, "$1\n" ;
|
push @tbuf, "$1\n" ;
|
}
|
}
|
}
|
}
|
elsif ( /^[\s]*include[\s]+(.*)$/o )
|
elsif ( /^[\s]*include[\s]+(.*)$/o )
|
{ # include line
|
{ # include line
|
push @tbuf, "$_" ;
|
push @tbuf, "$_" ;
|
if ( /^include[\s\t]*.*(directory|leaf|lib)\.cfg.*$/o )
|
if ( /^include[\s\t]*.*(directory|leaf|lib)\.cfg.*$/o )
|
{
|
{
|
push @tbuf, "§1\n" ;
|
push @tbuf, "§1\n" ;
|
push @tbuf, "PACKHEX = \@PACKHEX\@\n" if ( $make_exe_seen == 1 ) ;
|
push @tbuf, "PACKHEX = \@PACKHEX\@\n" if ( $make_exe_seen == 1 ) ;
|
push @tbuf, "§2\n" ;
|
push @tbuf, "§2\n" ;
|
}
|
}
|
}
|
}
|
elsif ( /^[\s]*(ifeq|ifneq|else|endif)[\s]+(.*)$/o )
|
elsif ( /^[\s]*(ifeq|ifneq|else|endif)[\s]+(.*)$/o )
|
{ # gmake conditionals
|
{ # gmake conditionals
|
# Most of them are removed, but we still have some :-
|
# Most of them are removed, but we still have some :-
|
push @tbuf, "$1 $2\n" ;
|
push @tbuf, "$1 $2\n" ;
|
}
|
}
|
elsif ( /^\@.*_(TRUE|FALSE)\@.*$/o )
|
elsif ( /^\@.*_(TRUE|FALSE)\@.*$/o )
|
{ # automake conditionals
|
{ # automake conditionals
|
# HACK: Don't know how to handle them, so let's pass them through
|
# HACK: Don't know how to handle them, so let's pass them through
|
push @tbuf, "$_" ;
|
push @tbuf, "$_" ;
|
}
|
}
|
elsif ( /^[\s]*([^:]+)[\s]*(:[:]*)[\s]*(.*)$/o )
|
elsif ( /^[\s]*([^:]+)[\s]*(:[:]*)[\s]*(.*)$/o )
|
{
|
{
|
if ( "$2" eq "::" )
|
if ( "$2" eq "::" )
|
{
|
{
|
# Warn about "::"-rules
|
# Warn about "::"-rules
|
# Will be silently removed below.
|
# Will be silently removed below.
|
print STDERR "WARNING: Removing \"::\" in RULE $_\n" ;
|
print STDERR "WARNING: Removing \"::\" in RULE $_\n" ;
|
}
|
}
|
|
|
if ( ( "$1" eq "Makefile" )
|
if ( ( "$1" eq "Makefile" )
|
or ( "$1" eq "\$\(INSTALLDIRS\)" )
|
or ( "$1" eq "\$\(INSTALLDIRS\)" )
|
or ( "$1" eq "\$\(ACLOCAL_M4\)" )
|
or ( "$1" eq "\$\(ACLOCAL_M4\)" )
|
or ( "$1" eq "config\.status" )
|
or ( "$1" eq "config\.status" )
|
or ( "$1" eq "\$\(srcdir\)/configure" )
|
or ( "$1" eq "\$\(srcdir\)/configure" )
|
)
|
)
|
{ # delete entry
|
{ # delete entry
|
shift @buffer ;
|
shift @buffer ;
|
}
|
}
|
elsif ( ( "$1" eq "all" )
|
elsif ( ( "$1" eq "all" )
|
or ( "$1" eq "preinstall" ) )
|
or ( "$1" eq "preinstall" ) )
|
{
|
{
|
# Note the dependencies
|
# Note the dependencies
|
# Not yet exploited, but could be useful for dependency
|
# Not yet exploited, but could be useful for dependency
|
# tracking in future
|
# tracking in future
|
if ( defined ${"var_$1"} )
|
if ( defined ${"var_$1"} )
|
{ ${"var_$1"} .= " $3" ; }
|
{ ${"var_$1"} .= " $3" ; }
|
else
|
else
|
{ ${"var_$1"} = "$3" ; }
|
{ ${"var_$1"} = "$3" ; }
|
push @tbuf, "$1: $3\n" ;
|
push @tbuf, "$1: $3\n" ;
|
}
|
}
|
else
|
else
|
{ # make rule
|
{ # make rule
|
push @tbuf, "$1: $3\n" ;
|
push @tbuf, "$1: $3\n" ;
|
}
|
}
|
}
|
}
|
elsif ( /^[\s]*$/o )
|
elsif ( /^[\s]*$/o )
|
{ # empty line
|
{ # empty line
|
push @tbuf, "\n" ;
|
push @tbuf, "\n" ;
|
}
|
}
|
else
|
else
|
{
|
{
|
die "PASS 2: Unhandled $_" ;
|
die "PASS 2: Unhandled $_" ;
|
}
|
}
|
}
|
}
|
@buffer = @tbuf ;
|
@buffer = @tbuf ;
|
@tbuf = @installdirs ;
|
@tbuf = @installdirs ;
|
@installdirs = () ;
|
@installdirs = () ;
|
foreach ( @tbuf )
|
foreach ( @tbuf )
|
{
|
{
|
if ( /^([^\s]+)(\/[^\.\s]+\.[^\s\/]+)$/o )
|
if ( /^([^\s]+)(\/[^\.\s]+\.[^\s\/]+)$/o )
|
{
|
{
|
print STDERR "WARNING - stripping of file: $1 <$2> " if ( $verbose > 1 );
|
print STDERR "WARNING - stripping of file: $1 <$2> " if ( $verbose > 1 );
|
push @installdirs, "$1" ;
|
push @installdirs, "$1" ;
|
}
|
}
|
else
|
else
|
{
|
{
|
push @installdirs, "$_" ;
|
push @installdirs, "$_" ;
|
}
|
}
|
}
|
}
|
purge \@installdirs ;
|
purge \@installdirs ;
|
purge \@pieces ;
|
purge \@pieces ;
|
}
|
}
|
|
|
# A fragment to debug conditionals
|
# A fragment to debug conditionals
|
#foreach( @variants )
|
#foreach( @variants )
|
#{
|
#{
|
# my $v = $_ ;
|
# my $v = $_ ;
|
# print STDERR "VARIANT: $v\n";
|
# print STDERR "VARIANT: $v\n";
|
# foreach (@{"variants_${v}"})
|
# foreach (@{"variants_${v}"})
|
# {
|
# {
|
# print STDERR "* $_\n;" ;
|
# print STDERR "* $_\n;" ;
|
# }
|
# }
|
#}
|
#}
|
|
|
# sanity check on *_FILES macros
|
# sanity check on *_FILES macros
|
# too fragile for the time being,
|
# too fragile for the time being,
|
# therefore disabled by default
|
# therefore disabled by default
|
if ( $experimental > 1 )
|
if ( $experimental > 1 )
|
{
|
{
|
foreach( @files )
|
foreach( @files )
|
{
|
{
|
my $file = "$_" ;
|
my $file = "$_" ;
|
my $line = ${"var_$_"} ;
|
my $line = ${"var_$_"} ;
|
$line =~ tr /\\/ /;
|
$line =~ tr /\\/ /;
|
my @l = split(' ',$line);
|
my @l = split(' ',$line);
|
my @o = () ;
|
my @o = () ;
|
foreach (@l)
|
foreach (@l)
|
{
|
{
|
if ( /^([^\.]+)\.([a-z]+)$/o )
|
if ( /^([^\.]+)\.([a-z]+)$/o )
|
{
|
{
|
print STDERR "$file: *.$2 in $_\n" ;
|
print STDERR "$file: *.$2 in $_\n" ;
|
}
|
}
|
elsif ( /^\$\(.*\)$/o )
|
elsif ( /^\$\(.*\)$/o )
|
{
|
{
|
print STDERR "$file: REF: $_\n" ;
|
print STDERR "$file: REF: $_\n" ;
|
}
|
}
|
else
|
else
|
{
|
{
|
print STDERR "$file: UNHANDLED: $_\n" ;
|
print STDERR "$file: UNHANDLED: $_\n" ;
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
# print STDERR "PASS 2: @buffer" ;
|
# print STDERR "PASS 2: @buffer" ;
|
|
|
{
|
{
|
# PASS 3:
|
# PASS 3:
|
# * output to new Makefile
|
# * output to new Makefile
|
# * prettyprint newlines
|
# * prettyprint newlines
|
|
|
my $nl_seen = 0 ;
|
my $nl_seen = 0 ;
|
foreach ( @buffer )
|
foreach ( @buffer )
|
{
|
{
|
if ( /^$/o )
|
if ( /^$/o )
|
{
|
{
|
$nl_seen++ ;
|
$nl_seen++ ;
|
print "\n" if ( $nl_seen < 2 );
|
print "\n" if ( $nl_seen < 2 );
|
}
|
}
|
elsif ( /^\§0$/o )
|
elsif ( /^\§0$/o )
|
{
|
{
|
print "\@SET_MAKE\@\n" ;
|
print "\@SET_MAKE\@\n" ;
|
print "srcdir = \@srcdir\@\n" ;
|
print "srcdir = \@srcdir\@\n" ;
|
print "top_srcdir = \@top_srcdir\@\n" ;
|
print "top_srcdir = \@top_srcdir\@\n" ;
|
print "top_builddir = $top_builddir\n" ;
|
print "top_builddir = $top_builddir\n" ;
|
if ( "$subdir" )
|
if ( "$subdir" )
|
{
|
{
|
print "subdir = $subdir\n";
|
print "subdir = $subdir\n";
|
}
|
}
|
else
|
else
|
{
|
{
|
print "\nACLOCAL = aclocal\n" ;
|
print "\nACLOCAL = aclocal\n" ;
|
print "AUTOCONF = autoconf\n" ;
|
print "AUTOCONF = autoconf\n" ;
|
print "ACLOCAL_M4 = \$(top_srcdir)/aclocal.m4\n" ;
|
print "ACLOCAL_M4 = \$(top_srcdir)/aclocal.m4\n" ;
|
print "ACLOCAL_AMFLAGS = -I \@RTEMS_TOPdir\@/aclocal\n" ;
|
print "ACLOCAL_AMFLAGS = -I \@RTEMS_TOPdir\@/aclocal\n" ;
|
}
|
}
|
print "\nRTEMS_ROOT = \@RTEMS_ROOT\@\n" ;
|
print "\nRTEMS_ROOT = \@RTEMS_ROOT\@\n" ;
|
print "PROJECT_ROOT = \@PROJECT_ROOT\@\n\n" ;
|
print "PROJECT_ROOT = \@PROJECT_ROOT\@\n\n" ;
|
$nl_seen = 1 ;
|
$nl_seen = 1 ;
|
}
|
}
|
elsif ( /^\§1$/o )
|
elsif ( /^\§1$/o )
|
{
|
{
|
print "\n" ;
|
print "\n" ;
|
print "INSTALL = \@INSTALL\@\n" if ( $install_seen > 0 );
|
print "INSTALL = \@INSTALL\@\n" if ( $install_seen > 0 );
|
print "INSTALL_CHANGE = \@INSTALL_CHANGE\@\n" ;
|
print "INSTALL_CHANGE = \@INSTALL_CHANGE\@\n" ;
|
$nl_seen = 0 ;
|
$nl_seen = 0 ;
|
}
|
}
|
elsif ( /^\§2$/o )
|
elsif ( /^\§2$/o )
|
{ # Handle installdirs related items
|
{ # Handle installdirs related items
|
if ( $#installdirs >= 0 )
|
if ( $#installdirs >= 0 )
|
{
|
{
|
print "mkinstalldirs = \$(SHELL) \$(top_srcdir)/\@RTEMS_TOPdir\@/mkinstalldirs\n\n" ;
|
print "mkinstalldirs = \$(SHELL) \$(top_srcdir)/\@RTEMS_TOPdir\@/mkinstalldirs\n\n" ;
|
my $line = join( ' ',@installdirs );
|
my $line = join( ' ',@installdirs );
|
&print_macro( "INSTALLDIRS =", $line );
|
&print_macro( "INSTALLDIRS =", $line );
|
print "\n\$(INSTALLDIRS):\n\t\@\$(mkinstalldirs) \$(INSTALLDIRS)\n\n" ;
|
print "\n\$(INSTALLDIRS):\n\t\@\$(mkinstalldirs) \$(INSTALLDIRS)\n\n" ;
|
$nl_seen = 1 ;
|
$nl_seen = 1 ;
|
}
|
}
|
}
|
}
|
elsif ( /^\§3(.*)$/o )
|
elsif ( /^\§3(.*)$/o )
|
{ # pretty print a shell script fragment/make production
|
{ # pretty print a shell script fragment/make production
|
my @l = split(/\\\\/,$1);
|
my @l = split(/\\\\/,$1);
|
if ( $#l >= 0 ) { my $i = shift @l ; print "\t$i"; }
|
if ( $#l >= 0 ) { my $i = shift @l ; print "\t$i"; }
|
foreach( @l ) { print "\\\n$_"; }
|
foreach( @l ) { print "\\\n$_"; }
|
print "\n" ;
|
print "\n" ;
|
$nl_seen = 0 ;
|
$nl_seen = 0 ;
|
}
|
}
|
elsif ( /^\§4(.*)$/o )
|
elsif ( /^\§4(.*)$/o )
|
{ # pretty print a make variable
|
{ # pretty print a make variable
|
&print_macro( "$1 =", ${"var_$1"} );
|
&print_macro( "$1 =", ${"var_$1"} );
|
$nl_seen = 0 ;
|
$nl_seen = 0 ;
|
}
|
}
|
elsif ( /^\§5(.*)$/o )
|
elsif ( /^\§5(.*)$/o )
|
{ # pretty print an addition to a make variable
|
{ # pretty print an addition to a make variable
|
&print_macro( "$1 +=", ${"var_$1+"}) ;
|
&print_macro( "$1 +=", ${"var_$1+"}) ;
|
$nl_seen = 0 ;
|
$nl_seen = 0 ;
|
}
|
}
|
else
|
else
|
{
|
{
|
$nl_seen = 0 ;
|
$nl_seen = 0 ;
|
print "$_" ;
|
print "$_" ;
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
# Add rules for config.status generated files
|
# Add rules for config.status generated files
|
if ( "$build_pgms_seen" )
|
if ( "$build_pgms_seen" )
|
{
|
{
|
print "%: \$(srcdir)/%.in \$(top_builddir)/config.status\n" ;
|
print "%: \$(srcdir)/%.in \$(top_builddir)/config.status\n" ;
|
print " cd \$(top_builddir) \\\n" ;
|
print " cd \$(top_builddir) \\\n" ;
|
print " && CONFIG_FILES=" ;
|
print " && CONFIG_FILES=" ;
|
print "\$(subdir)/" if ( "$subdir" );
|
print "\$(subdir)/" if ( "$subdir" );
|
print "\$@ CONFIG_HEADERS= \$(SHELL) ./config.status\n";
|
print "\$@ CONFIG_HEADERS= \$(SHELL) ./config.status\n";
|
}
|
}
|
else
|
else
|
{
|
{
|
print "Makefile: \$(srcdir)/Makefile.in \$(top_builddir)/config.status\n" ;
|
print "Makefile: \$(srcdir)/Makefile.in \$(top_builddir)/config.status\n" ;
|
print "\tcd \$(top_builddir) \\\n" ;
|
print "\tcd \$(top_builddir) \\\n" ;
|
print "\t && CONFIG_FILES=" ;
|
print "\t && CONFIG_FILES=" ;
|
print "\$(subdir)/" if ( "$subdir" );
|
print "\$(subdir)/" if ( "$subdir" );
|
print "\$@ CONFIG_HEADERS= \$(SHELL) ./config.status\n";
|
print "\$@ CONFIG_HEADERS= \$(SHELL) ./config.status\n";
|
}
|
}
|
|
|
if ( ! "$subdir" )
|
if ( ! "$subdir" )
|
{
|
{
|
print "\n\$(ACLOCAL_M4): \@MAINTAINER_MODE_TRUE\@ configure.in\n" ;
|
print "\n\$(ACLOCAL_M4): \@MAINTAINER_MODE_TRUE\@ configure.in\n" ;
|
print "\tcd \$(srcdir) && \$(ACLOCAL) \$(ACLOCAL_AMFLAGS)\n" ;
|
print "\tcd \$(srcdir) && \$(ACLOCAL) \$(ACLOCAL_AMFLAGS)\n" ;
|
print "\nconfig.status: \$(srcdir)/configure \$(CONFIG_STATUS_DEPENDENCIES)\n" ;
|
print "\nconfig.status: \$(srcdir)/configure \$(CONFIG_STATUS_DEPENDENCIES)\n" ;
|
print "\t\$(SHELL) ./config.status --recheck\n" ;
|
print "\t\$(SHELL) ./config.status --recheck\n" ;
|
print "\$(srcdir)/configure: \@MAINTAINER_MODE_TRUE\@\$(srcdir)/configure.in";
|
print "\$(srcdir)/configure: \@MAINTAINER_MODE_TRUE\@\$(srcdir)/configure.in";
|
print " \$(ACLOCAL_M4)\n" ;
|
print " \$(ACLOCAL_M4)\n" ;
|
print "\tcd \$(srcdir) && \$(AUTOCONF)\n"
|
print "\tcd \$(srcdir) && \$(AUTOCONF)\n"
|
}
|
}
|
|
|
exit 0 ;
|
exit 0 ;
|
|
|
sub print_macro($$)
|
sub print_macro($$)
|
{
|
{
|
my ($line,$input) = @_ ;
|
my ($line,$input) = @_ ;
|
$input =~ s/\\\\/ /g;
|
$input =~ s/\\\\/ /g;
|
my @l = split(' ',$input);
|
my @l = split(' ',$input);
|
|
|
foreach (@l) {
|
foreach (@l) {
|
if ( ( length($line) + length($_) ) < 76 )
|
if ( ( length($line) + length($_) ) < 76 )
|
{
|
{
|
$line .= " $_";
|
$line .= " $_";
|
}
|
}
|
else
|
else
|
{
|
{
|
print "$line \\\n";
|
print "$line \\\n";
|
$line = " $_" ;
|
$line = " $_" ;
|
}
|
}
|
}
|
}
|
print "$line\n" ;
|
print "$line\n" ;
|
}
|
}
|
|
|
|
|