summaryrefslogblamecommitdiffstats
path: root/tools/update/ampolish
blob: c105f9e7b51ff136f4e73a6268dfed04e3dec1e7 (plain) (tree)








































































































                                                                                
#!/usr/bin/perl

#
# Perl script to beautify and enhance RTEMS automake Makefile.ams
#
# Reads from stdin and writes to stdout
#
# usage: 
# <path-to>/ampolish <Makefile.am >Makefile.am~
# mv Makefile.am~ Makefile.am
#
# ATTENTION: This file contains embedded tabs

my $subdirs_seen = "" ;

# find a relative up-path to a file $file, starting at directory $pre
sub find_file
{
  my $pre = $_[0] ;
  my $file= $_[1] ;

  my $top = "." ;
  if (not "$pre") { $pre = "." ; }

  for ( $str = "$pre" . "/" . "$top" ;
    ( -d "$str" ) ;
    $str = "$pre" . "/" . "$top" )
  {
    if ( -f "${str}/${file}" )  
    {
      return $top ; 
    }
    if ( "$top" eq "." )
    {
      $top = ".." ;
    }
    else
    {
      $top .= "/.." ;
    }
  } ;
  die "Can't find file ${file}\n" ;
}

# find relative up-path to configure.in
my $rtems_cfg = find_file(".","configure.in");

# find relative up-path from configure.in to VERSION
my $rtems_top = find_file("$rtems_cfg","VERSION");

my $nl_seen = 0 ;

while( <> )
{ # consume header
  last if ( /^[^#].*$/ ) ;
  print "$_" ;
}

print "\nAUTOMAKE_OPTIONS = foreign\n";
if ( "$rtems_cfg" eq "." )
{
  print "ACLOCAL = \@ACLOCAL\@ -I \$(RTEMS_TOPdir)/aclocal\n" 
}

while( <> )
{ 
  if ( /^[ 	]*$/o )
  {
    $nl_seen = $nl_seen+1;
  }

  if ( /^[ 	]*AUTOMAKE_OPTIONS.*$/o )
  { # remove the line
  }
  elsif ( /^[ 	]*ACLOCAL[ 	]*=[ 	]*\@ACLOCAL\@.*$/o )
  { # remove the line
  }
  elsif ( /^[ 	]*include[ 	]*\$\(top_srcdir\)[\.\/]*automake\/(.*)\.am$/o )
  {
    # remove the line 
  }
  elsif ( /^[ 	]*SUBDIRS.*$/o )
  {
    $subdirs_seen = "yes" ;
    print "$_" ;
    $nl_seen = 0 ;
  }
  elsif ( /^[   ]*$/o )
  {
    print "$_" if $nl_seen < 2 ;
  }
  else
  {
    print "$_" ;
    $nl_seen = 0;
  }
} # while

if ( "$subdirs_seen" )
{
  print "include \$(top_srcdir)/${rtems_top}/automake/subdirs.am\n" ;
}
print "include \$(top_srcdir)/${rtems_top}/automake/local.am\n" ;

;1