#!/usr/bin/perl
|
#!/usr/bin/perl
|
|
|
#
|
#
|
# Perl script to beautify and enhance RTEMS configure.in
|
# Perl script to beautify and enhance RTEMS configure.in
|
#
|
#
|
# Reads from stdin and writes to stdout
|
# Reads from stdin and writes to stdout
|
#
|
#
|
# usage:
|
# usage:
|
# acpolish configure.in~
|
# acpolish configure.in~
|
# mv configure.in~ configure.in
|
# mv configure.in~ configure.in
|
#
|
#
|
|
|
# $Id: cipolish,v 1.2 2001-09-27 12:02:54 chris Exp $
|
# $Id: cipolish,v 1.2 2001-09-27 12:02:54 chris Exp $
|
|
|
use strict ;
|
use strict ;
|
|
|
my @vars = () ;
|
my @vars = () ;
|
my @buffer = () ;
|
my @buffer = () ;
|
my %var_ ;
|
my %var_ ;
|
|
|
# find relative up-path to VERSION
|
# find relative up-path to VERSION
|
my $rtems_cfg = &find_file(".","VERSION");
|
my $rtems_cfg = &find_file(".","VERSION");
|
my $rtems_root = &find_root() ;
|
my $rtems_root = &find_root() ;
|
$rtems_root =~ tr/\//\-/ ;
|
$rtems_root =~ tr/\//\-/ ;
|
my $rtems_name = "rtems" ;
|
my $rtems_name = "rtems" ;
|
$rtems_name .= "-" . "$rtems_root" if (length($rtems_root) > 0 ) ;
|
$rtems_name .= "-" . "$rtems_root" if (length($rtems_root) > 0 ) ;
|
|
|
while ( <> )
|
while ( <> )
|
{
|
{
|
push @buffer, "$_" ;
|
push @buffer, "$_" ;
|
}
|
}
|
|
|
{
|
{
|
my @tbuf = () ;
|
my @tbuf = () ;
|
|
|
foreach ( @buffer )
|
foreach ( @buffer )
|
{
|
{
|
if ( /^#.*list.*Makefile.*$/o ) {}
|
if ( /^#.*list.*Makefile.*$/o ) {}
|
elsif ( /^dnl[\s]+check.*target.*cc.*$/o ) {}
|
elsif ( /^dnl[\s]+check.*target.*cc.*$/o ) {}
|
elsif ( /^[\s]*AC_CONFIG_AUX_DIR\(.*\)[\s]*$/o )
|
elsif ( /^[\s]*AC_CONFIG_AUX_DIR\(.*\)[\s]*$/o )
|
{
|
{
|
push @tbuf, "AC_CONFIG_AUX_DIR($rtems_cfg)\n" ;
|
push @tbuf, "AC_CONFIG_AUX_DIR($rtems_cfg)\n" ;
|
}
|
}
|
elsif ( /^[\s]*RTEMS_TOP\(.*\)[\s]*$/o )
|
elsif ( /^[\s]*RTEMS_TOP\(.*\)[\s]*$/o )
|
{
|
{
|
push @tbuf, "RTEMS_TOP($rtems_cfg)\n" ;
|
push @tbuf, "RTEMS_TOP($rtems_cfg)\n" ;
|
}
|
}
|
elsif ( /^[\s]*AM_INIT_AUTOMAKE\(.*\)[\s]*$/o )
|
elsif ( /^[\s]*AM_INIT_AUTOMAKE\(.*\)[\s]*$/o )
|
{
|
{
|
push @tbuf, "AM_INIT_AUTOMAKE($rtems_name,\$RTEMS_VERSION,no)\n" ;
|
push @tbuf, "AM_INIT_AUTOMAKE($rtems_name,\$RTEMS_VERSION,no)\n" ;
|
}
|
}
|
elsif ( /^[\s]*AC_SUBST\(RTEMS_HAS_POSIX_API\)[\s]*$/o )
|
elsif ( /^[\s]*AC_SUBST\(RTEMS_HAS_POSIX_API\)[\s]*$/o )
|
{
|
{
|
#remove the line
|
#remove the line
|
}
|
}
|
elsif ( /^[\s]*AC_SUBST\(RTEMS_HAS_ITRON_API\)[\s]*$/o )
|
elsif ( /^[\s]*AC_SUBST\(RTEMS_HAS_ITRON_API\)[\s]*$/o )
|
{
|
{
|
#remove the line
|
#remove the line
|
}
|
}
|
elsif ( /^[\s]*AC_SUBST\(RTEMS_HAS_HWAPI\)[\s]*$/o )
|
elsif ( /^[\s]*AC_SUBST\(RTEMS_HAS_HWAPI\)[\s]*$/o )
|
{
|
{
|
#remove the line
|
#remove the line
|
}
|
}
|
elsif ( /^[\s]*AC_SUBST\(RTEMS_USE_MACROS\)[\s]*$/o )
|
elsif ( /^[\s]*AC_SUBST\(RTEMS_USE_MACROS\)[\s]*$/o )
|
{
|
{
|
#remove the line
|
#remove the line
|
}
|
}
|
elsif ( /^[\s]*AC_SUBST\(RTEMS_HAS_MULTIPROCESSING\)[\s]*$/o )
|
elsif ( /^[\s]*AC_SUBST\(RTEMS_HAS_MULTIPROCESSING\)[\s]*$/o )
|
{
|
{
|
#remove the line
|
#remove the line
|
}
|
}
|
elsif ( /^[\s]*AC_SUBST\(RTEMS_HAS_RDBG\)[\s]*$/o )
|
elsif ( /^[\s]*AC_SUBST\(RTEMS_HAS_RDBG\)[\s]*$/o )
|
{
|
{
|
#remove the line
|
#remove the line
|
}
|
}
|
elsif ( /^[\s\t]*AC_SUBST\(RTEMS_USE_OWN_PDIR\)[\s]*$/o )
|
elsif ( /^[\s\t]*AC_SUBST\(RTEMS_USE_OWN_PDIR\)[\s]*$/o )
|
{ # obsolete option
|
{ # obsolete option
|
#remove the line
|
#remove the line
|
}
|
}
|
elsif ( /^[\s\t]*RTEMS_ENABLE_GMAKE_PRINT[ ]*$/o )
|
elsif ( /^[\s\t]*RTEMS_ENABLE_GMAKE_PRINT[ ]*$/o )
|
{ # obsolete macro
|
{ # obsolete macro
|
#remove the line
|
#remove the line
|
}
|
}
|
elsif ( /^[\s]*AC_SUBST\(RTEMS_HAS_NETWORKING\)[\s]*$/o )
|
elsif ( /^[\s]*AC_SUBST\(RTEMS_HAS_NETWORKING\)[\s]*$/o )
|
{
|
{
|
#remove the line
|
#remove the line
|
}
|
}
|
elsif ( /^[\s]*AC_SUBST\(RTEMS_LIBC_DIR\)[\s]*$/o )
|
elsif ( /^[\s]*AC_SUBST\(RTEMS_LIBC_DIR\)[\s]*$/o )
|
{
|
{
|
#remove the line
|
#remove the line
|
}
|
}
|
elsif ( /^[\s]*AC_SUBST\(PROJECT_ROOT\)[\s]*$/o )
|
elsif ( /^[\s]*AC_SUBST\(PROJECT_ROOT\)[\s]*$/o )
|
{
|
{
|
#remove the line
|
#remove the line
|
}
|
}
|
elsif ( /^[\s]*AC_SUBST\(RTEMS_GAS_CODE16\)[\s]*$/o )
|
elsif ( /^[\s]*AC_SUBST\(RTEMS_GAS_CODE16\)[\s]*$/o )
|
{
|
{
|
#remove the line
|
#remove the line
|
}
|
}
|
elsif ( /^[\s]*PROJECT_ROOT[\s]*=.*$/o )
|
elsif ( /^[\s]*PROJECT_ROOT[\s]*=.*$/o )
|
{
|
{
|
#remove the line
|
#remove the line
|
}
|
}
|
elsif ( /^[\s]*(RTEMS_ENABLE_LIBCDIR).*$/o )
|
elsif ( /^[\s]*(RTEMS_ENABLE_LIBCDIR).*$/o )
|
{ #remove the line
|
{ #remove the line
|
&define_variable("$1","");
|
&define_variable("$1","");
|
push @tbuf, "$_" ;
|
push @tbuf, "$_" ;
|
}
|
}
|
elsif ( /^[\s]*(RTEMS_PROG_CC_FOR_TARGET).*$/o )
|
elsif ( /^[\s]*(RTEMS_PROG_CC_FOR_TARGET).*$/o )
|
{
|
{
|
&define_variable("$1","");
|
&define_variable("$1","");
|
push @tbuf, "$_" ;
|
push @tbuf, "$_" ;
|
}
|
}
|
elsif ( /^[\s]*(RTEMS_PROG_CXX_FOR_TARGET).*$/o )
|
elsif ( /^[\s]*(RTEMS_PROG_CXX_FOR_TARGET).*$/o )
|
{
|
{
|
&define_variable("$1","");
|
&define_variable("$1","");
|
push @tbuf, "$_" ;
|
push @tbuf, "$_" ;
|
}
|
}
|
else
|
else
|
{
|
{
|
push @tbuf, "$_" ;
|
push @tbuf, "$_" ;
|
}
|
}
|
} # foreach
|
} # foreach
|
@buffer = @tbuf ;
|
@buffer = @tbuf ;
|
}
|
}
|
|
|
{
|
{
|
my @tbuf = () ;
|
my @tbuf = () ;
|
foreach ( @buffer )
|
foreach ( @buffer )
|
{
|
{
|
if ( /^[\s]*(RTEMS_ENABLE_LIBCDIR).*$/o )
|
if ( /^[\s]*(RTEMS_ENABLE_LIBCDIR).*$/o )
|
{
|
{
|
if ( ( not variable_seen( "RTEMS_PROG_CC_FOR_TARGET" ) )
|
if ( ( not variable_seen( "RTEMS_PROG_CC_FOR_TARGET" ) )
|
and ( not variable_seen( "RTEMS_PROG_CXX_FOR_TARGET" ) )
|
and ( not variable_seen( "RTEMS_PROG_CXX_FOR_TARGET" ) )
|
)
|
)
|
{
|
{
|
push @tbuf, "$_" ;
|
push @tbuf, "$_" ;
|
}
|
}
|
}
|
}
|
elsif ( /^AC_OUTPUT.*$/o )
|
elsif ( /^AC_OUTPUT.*$/o )
|
{
|
{
|
push @tbuf, "# Explicitly list all Makefiles here\n" ;
|
push @tbuf, "# Explicitly list all Makefiles here\n" ;
|
push @tbuf, "$_" ;
|
push @tbuf, "$_" ;
|
}
|
}
|
else
|
else
|
{
|
{
|
push @tbuf, "$_" ;
|
push @tbuf, "$_" ;
|
}
|
}
|
}
|
}
|
@buffer = @tbuf ;
|
@buffer = @tbuf ;
|
}
|
}
|
|
|
{ ## pretty print
|
{ ## pretty print
|
my $out = join ('',@buffer) ;
|
my $out = join ('',@buffer) ;
|
$out =~ s/\s\#\n(\#\n)+/\n/g ;
|
$out =~ s/\s\#\n(\#\n)+/\n/g ;
|
$out =~ s/\n\n\#\n\n/\n/g ;
|
$out =~ s/\n\n\#\n\n/\n/g ;
|
$out =~ s/\n\n[\n]*/\n\n/g ;
|
$out =~ s/\n\n[\n]*/\n\n/g ;
|
print $out ;
|
print $out ;
|
}
|
}
|
|
|
exit 1 ;
|
exit 1 ;
|
|
|
# find a relative up-path to a file $file, starting at directory $pre
|
# find a relative up-path to a file $file, starting at directory $pre
|
sub find_file($$)
|
sub find_file($$)
|
{
|
{
|
my $pre = $_[0] ;
|
my $pre = $_[0] ;
|
my $file= $_[1] ;
|
my $file= $_[1] ;
|
|
|
my $top = "." ;
|
my $top = "." ;
|
if (not "$pre") { $pre = "." ; }
|
if (not "$pre") { $pre = "." ; }
|
|
|
for ( my $str = "$pre" . "/" . "$top" ;
|
for ( my $str = "$pre" . "/" . "$top" ;
|
( -d "$str" ) ;
|
( -d "$str" ) ;
|
$str = "$pre" . "/" . "$top" )
|
$str = "$pre" . "/" . "$top" )
|
{
|
{
|
if ( -f "${str}/${file}" )
|
if ( -f "${str}/${file}" )
|
{
|
{
|
return $top ;
|
return $top ;
|
}
|
}
|
if ( "$top" eq "." )
|
if ( "$top" eq "." )
|
{
|
{
|
$top = ".." ;
|
$top = ".." ;
|
}
|
}
|
else
|
else
|
{
|
{
|
$top .= "/.." ;
|
$top .= "/.." ;
|
}
|
}
|
} ;
|
} ;
|
die "Can't find file ${file}\n" ;
|
die "Can't find file ${file}\n" ;
|
}
|
}
|
|
|
sub find_root()
|
sub find_root()
|
{
|
{
|
my $top_builddir = "." ;
|
my $top_builddir = "." ;
|
my $subdir="";
|
my $subdir="";
|
my $pwd = `pwd`; chomp $pwd;
|
my $pwd = `pwd`; chomp $pwd;
|
$pwd .= "/" ;
|
$pwd .= "/" ;
|
my $len ;
|
my $len ;
|
|
|
if ( -f "VERSION" ) { return $subdir ; }
|
if ( -f "VERSION" ) { return $subdir ; }
|
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}/VERSION" )
|
if ( -f "${top_builddir}/VERSION" )
|
{
|
{
|
return $subdir ;
|
return $subdir ;
|
}
|
}
|
$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 VERSION\n" ;
|
die "Can't find VERSION\n" ;
|
}
|
}
|
|
|
sub variable_seen($)
|
sub variable_seen($)
|
{
|
{
|
my $label = "$_[0]" ;
|
my $label = "$_[0]" ;
|
my $res = defined $var_{"$label"};
|
my $res = defined $var_{"$label"};
|
#print STDERR "SEEN: $label ->$res<\n" ;
|
#print STDERR "SEEN: $label ->$res<\n" ;
|
return $res ;
|
return $res ;
|
}
|
}
|
|
|
sub define_variable($$)
|
sub define_variable($$)
|
{
|
{
|
my ($label,@value) = @_ ;
|
my ($label,@value) = @_ ;
|
|
|
if ( not variable_seen("$label") )
|
if ( not variable_seen("$label") )
|
{
|
{
|
# print STDERR "DEFINING $label\n" ;
|
# print STDERR "DEFINING $label\n" ;
|
push @vars, "$label" ;
|
push @vars, "$label" ;
|
}
|
}
|
|
|
foreach my $i ( @{value} )
|
foreach my $i ( @{value} )
|
{
|
{
|
push @{$var_{"$label"}}, $i ;
|
push @{$var_{"$label"}}, $i ;
|
}
|
}
|
}
|
}
|
|
|
|
|