From df49c60c9671e4a28e636964d744c1f59fb6cb68 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Mon, 12 Jun 2000 15:00:15 +0000 Subject: Merged from 4.5.0-beta3a --- tools/update/Makefile.am | 25 +- tools/update/acpolish | 62 +++-- tools/update/ampolish | 526 ++++++++++++++++++++++++++++++++++++++----- tools/update/cipolish | 15 +- tools/update/rtems-polish.sh | 2 +- 5 files changed, 516 insertions(+), 114 deletions(-) (limited to 'tools/update') diff --git a/tools/update/Makefile.am b/tools/update/Makefile.am index 05a1bf959e..6277439559 100644 --- a/tools/update/Makefile.am +++ b/tools/update/Makefile.am @@ -4,6 +4,7 @@ AUTOMAKE_OPTIONS = foreign 1.4 ACLOCAL_AMFLAGS = -I $(RTEMS_TOPdir)/aclocal + ## NOTE: It doesn't make much sense to install these files CLEANFILES = update word-replace @@ -12,16 +13,10 @@ if PERL # All files in this directory depend on having perl. # Do not handle them if perl is missing. -noinst_SCRIPTS = \ -acpolish \ -ampolish \ -cipolish \ -rtems-polish.sh \ -word-replace \ -update +noinst_SCRIPTS = acpolish ampolish cipolish rtems-polish.sh word-replace \ + update -noinst_DATA = \ -310_to_320_list +noinst_DATA = 310_to_320_list update: $(srcdir)/update.in $(top_builddir)/config.status @cd $(top_builddir) \ @@ -35,13 +30,7 @@ word-replace: $(srcdir)/word-replace.in $(top_builddir)/config.status endif -EXTRA_DIST = \ -310_to_320_list \ -update.in \ -word-replace.in \ -acpolish \ -ampolish \ -cipolish \ -rtems-polish.sh +EXTRA_DIST = 310_to_320_list update.in word-replace.in acpolish ampolish \ + cipolish rtems-polish.sh -include $(top_srcdir)/../../automake/local.am +include $(top_srcdir)/../../automake/host.am diff --git a/tools/update/acpolish b/tools/update/acpolish index 5de711f60c..0a739fd9cf 100755 --- a/tools/update/acpolish +++ b/tools/update/acpolish @@ -1,10 +1,8 @@ #!/usr/bin/perl -# use strict 'subs' ; -# use strict 'vars' ; -# use strict 'refs' ; +use strict ; -# use strict ; +sub print_macro($$); # # Perl script to beautify and enhance RTEMS autoconf Makefile.ins @@ -40,27 +38,6 @@ my @files = () ; my @variants = () ; my @vars = () ; -sub print_macro($$) -{ - my $line = $_[0] ; - my $input = $_[1] ; - $input =~ s/\\\\/ /g; - my @l = split(' ',$input); - - foreach (@l) { - if ( ( length($line) + length($_) ) < 76 ) - { - $line .= " $_"; - } - else - { - print "$line \\\n"; - $line = " $_" ; - } - } - print "$line\n" ; -} - # Strip off duplicate entries from a list sub purge($) { @@ -180,8 +157,8 @@ sub subst_line { my $files =`ls *.h 2>/dev/null`; print STDERR "WARNING: Replacing \"\(wildcard... in $_\n" ; - $line = "H_FILES ="; - @l = split(' ',$files) ; + my $line = "H_FILES ="; + my @l = split(' ',$files) ; foreach(@l) { $line .= " \$\(srcdir\)/$_"; } $line .= "\n" ; $_ = "$line" ; @@ -214,7 +191,7 @@ sub subst_line my @ibuf = () ; my $line = "" ; - while ( <> ) + while ( ) { &subst_line ; if ( /^(#.*)$/o ) @@ -618,7 +595,7 @@ if ( $experimental > 1 ) { print "mkinstalldirs = \$(SHELL) \$(top_srcdir)/\@RTEMS_TOPdir\@/mkinstalldirs\n\n" ; my $line = join( ' ',@installdirs ); - print_macro "INSTALLDIRS =", $line ; + &print_macro( "INSTALLDIRS =", $line ); print "\n\$(INSTALLDIRS):\n\t\@\$(mkinstalldirs) \$(INSTALLDIRS)\n\n" ; $nl_seen = 1 ; } @@ -633,12 +610,12 @@ if ( $experimental > 1 ) } elsif ( /^\§4(.*)$/o ) { # pretty print a make variable - print_macro "$1 =", ${"var_$1"} ; + &print_macro( "$1 =", ${"var_$1"} ); $nl_seen = 0 ; } elsif ( /^\§5(.*)$/o ) { # pretty print an addition to a make variable - print_macro "$1 +=", ${"var_$1+"} ; + &print_macro( "$1 +=", ${"var_$1+"}) ; $nl_seen = 0 ; } else @@ -678,4 +655,25 @@ print " \$(ACLOCAL_M4)\n" ; print "\tcd \$(srcdir) && \$(AUTOCONF)\n" } -;1 +exit 0 ; + +sub print_macro($$) +{ + my ($line,$input) = @_ ; + $input =~ s/\\\\/ /g; + my @l = split(' ',$input); + + foreach (@l) { + if ( ( length($line) + length($_) ) < 76 ) + { + $line .= " $_"; + } + else + { + print "$line \\\n"; + $line = " $_" ; + } + } + print "$line\n" ; +} + diff --git a/tools/update/ampolish b/tools/update/ampolish index 265a3bc76c..0856798ce6 100755 --- a/tools/update/ampolish +++ b/tools/update/ampolish @@ -1,5 +1,9 @@ #!/usr/bin/perl +package main ; + +use strict ; + # # Perl script to beautify and enhance RTEMS automake Makefile.ams # @@ -9,9 +13,341 @@ # /ampolish Makefile.am~ # mv Makefile.am~ Makefile.am # -# ATTENTION: This file contains embedded tabs -my $subdirs_seen = "" ; +my @vars ; +my @conditions = ( "" ) ; +my @buffer = (); +my %var_ ; + +define_variable( "\$(AUTOMAKE_OPTIONS)", ( "foreign", "1.4" ) ); +define_variable( "\$(VPATH)", ( "\@srcdir\@" ) ); + +# 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"); + +if ( "$rtems_top" eq "." ) { $rtems_top = "" ; } +else { $rtems_top .= "/" ; } + +{ +# PASS1: +# read input file and concatenate multiple lines into single lines. + + my @ibuf = () ; + + while( ) + { # consume header + last if ( /^[^#].*$/ ) ; + push @ibuf, "$_" ; + } + + push @ibuf, "§header\n" ; + + do + { + if ( /^(#.*)$/o ) + { # preserve comments + push @ibuf, "$_" ; + } + elsif ( /^(\t.*)\\[\s]*$/o ) + { # multilines for scripts + my $line = "$1§" ; + while( ) + { + if ( /^(.*)\\[\s]*$/o ) + { + $line .= "$1§" ; + } + else + { + $line .= "$_" ; + push @ibuf, $line ; + last ; + } + } + } + elsif ( /^(.*)\\[\s]*$/o ) + { # multilines + my $line = "$1" ; + while( ) + { + if ( /^(.*)\\[\s]*$/o ) + { + $line .= "$1" ; + } + else + { + $line .= "$_" ; + $line =~ s%[\s]+% %g ; + push @ibuf, "$line\n" ; + last ; + } + } + } + else + { + push @ibuf, "$_" ; + } + } while ( ) ; + @buffer = @ibuf ; +} + +{ +# PASS2: +# fix obsolete constructs + my @ibuf = () ; + + foreach ( @buffer ) + { +# tr /\{\}/\(\)/ ; + + if ( /^(TMP|PRE)INSTALL_FILES[\s]*=(.*)$/o ) + { # force "+=" + push @ibuf, "$1INSTALL_FILES +=$2\n" ; + } + elsif ( /^(VPATH|EXTRA_DIST)[\s]*\+=(.*)$/o ) + { # force "=" + push @ibuf, "$1 = $2\n" ; + } + elsif ( /^[\s]*ACLOCAL[\s]*=[\s]*\@ACLOCAL\@.*$/o ) + { # remove the line + } + elsif ( /^[\s]*(ACLOCAL_AMFLAGS)[\s\t]*[\+]*=[\s]*(.*)[\s]*$/o ) + { # remove the line + } + elsif ( /^[\s]*(AM_CFLAGS)[\s\t]*[\+]*=[\s]*\$\(CFLAGS_OS_V\)[\s]*$/o ) + { # remove the line + } + elsif ( /^[\s]*debug-am:.*$/o ) + { # remove the line + } + elsif ( /^[\s]*all(\-am):(.*)$/o ) + { # replace the line + push @ibuf, "all-local:$2\n" ; + } + elsif ( /^[\s]*profile-am:.*$/o ) + { # remove the line + } + elsif ( /^[\s]*include[\s\t]*\$\(RTEMS_ROOT\)\/make\/lib.cfg[\s]*$/o ) + { + push @ibuf, "include \$(top_srcdir)/${rtems_top}automake/lib.am\n" ; + } + elsif ( /^(.*[^\s])[\s]*$/o ) + { # remove trailing spaces + push @ibuf, "$1\n" ; + } + else + { + push @ibuf, "$_" ; + } + } + @buffer = @ibuf ; +} + +# print STDERR "\n", @buffer, "\n" ; + +{ + my @ibuf = () ; + foreach ( @buffer ) + { + if ( /^#(.*)$/o ) + { + push @ibuf, "#$1\n" ; + } + elsif ( /^[\s]*if[\s\t]+([a-zA-Z0-9_]+)[\s\t]*$/o ) + { + push @conditions, "\@" . $1 . "_TRUE\@" ; + push @ibuf, "if $1\n" ; + } + elsif ( /^[\s]*else[\s\t]*$/o ) + { + @conditions[$#conditions] =~ s/_TRUE\@$/_FALSE\@/; + push @ibuf, "else\n" ; + } + elsif ( /^[\s]*endif[\s\t]*$/o ) + { + pop @conditions ; + push @ibuf, "endif\n" ; + } + elsif ( /^§.*$/o ) + { + push @ibuf, "$_" ; + } + elsif ( /^[\s]*(VPATH)[\s\t]*([\+]*)=[\s]*(.*)[\s]*$/o ) + { + my $lh = "\$($1)" ; + my @rh = split( /:/,"$3"); + if ( $#conditions > 0 ) + { + print STDERR "WARNING: $1 must not be set inside of conditionals!\n" + } + define_variable( "$lh", @rh ); + + } + elsif ( /^[\s]*(AUTOMAKE_OPTIONS)[\s\t]*([\+]*)=[\s]*(.*)$/o ) + { + my $lh = "\$($1)" ; + my @rh = &split_vars("$3"); + + if ( $#conditions > 0 ) + { + print STDERR "WARNING: $1 must not be set inside of conditionals!\n" + } + + define_variable( "$lh", @rh ); + } + elsif ( /^[\s]*([a-zA-Z0-9_]+)[\s\t]*([\+]*)=[\s]*(.*)$/o ) + { + my $lh = join ('',@conditions) . "\$($1)" ; + my @rh = &split_vars("$3"); + my $seen = variable_seen( "$lh" ) ; + + if ( $#conditions > 0 ) + { + define_variable( "\$($1)", () ); + } + + define_variable( "$lh", @rh ); + + if ( not $seen ) + { + push @ibuf, "§$2var_$lh\n" ; + } + } + elsif ( /^[\s]*include[\s\t]*\$\(top_srcdir\)[\.\/]*automake\/(.*)\.am$/o ) + { + if ( "$1" eq "lib" ) + { + push @ibuf, "include \$(top_srcdir)/${rtems_top}automake/$1.am\n" ; + } + elsif ( "$1" eq "local" ) + { + $main::seen_local = 1 ; + } + elsif ( "$1" eq "host" ) + { + $main::seen_host = 1 ; + } + } + elsif ( /^[\s]*include[\s\t]*(.*)$/o ) + { + push @ibuf, "include $1\n" ; + } + elsif ( /^\t(.*)$/o ) + { + push @ibuf, "\t$1\n" ; + } + elsif ( /^(.*)\:(.*)$/o ) + { + push @ibuf, "$1:$2\n" ; + } + elsif ( /^[\s]*$/o ) + { + push @ibuf, "\n" ; + } + else + { + die "ERROR: Don't know how to handle <$_>" ; + } + } # for + @buffer = @ibuf ; +} # while + +die "Conditional stack corrupted" if ( $#conditions != 0 ); + +foreach( @vars ) +{ + purge( \@{$var_{"$_"}} ); +} + +# print STDERR "\n", @buffer, "\n" ; + + +{ + my @ibuf = () ; + foreach( @buffer ) + { + if ( /^#.*$/o ) + { + push @ibuf, "$_" ; + } + elsif( /^§header$/o ) + { + my $l = $var_{"\$(AUTOMAKE_OPTIONS)"} ; + push @ibuf, "\nAUTOMAKE_OPTIONS = @{$l}\n" ; + if ( "$rtems_cfg" eq "." ) + { + push @ibuf, "ACLOCAL_AMFLAGS = -I \$(RTEMS_TOPdir)/aclocal\n" ; + } + if ( defined( @{$var_{"\$(VPATH)"}} ) ) + { + if ( $#{$var_{"\$(VPATH)"}} > 0 ) + { + my $l = join (':',@{$var_{"\$(VPATH)"}}) ; + push @ibuf, "\nVPATH = $l\n" ; + } + } + push @ibuf, "\n" ; + } + elsif ( /^§(\+|)var_(.*)\$\((.*)\)$/o ) + { + print_var(\@ibuf, "$3 $1=", $var_{"$2\$($3)"}) ; + } + elsif ( /^\t.*$/o ) + { + &print_script(\@ibuf, "$_"); + } + elsif ( /^[\s]*if[\s]+([a-zA-Z0-9_]+)[\s\t]*$/o ) + { + push @conditions, "\@$1_TRUE\@" ; + push @ibuf, "if $1\n" ; + } + elsif ( /^[\s]*else[\s]*$/o ) + { + @conditions[$#conditions] =~ s/_TRUE\@$/_FALSE\@/; + push @ibuf, "else\n" ; + } + elsif ( /^[\s]*endif[\s]*$/o ) + { + pop @conditions ; + push @ibuf, "endif\n" ; + } + else + { + print_line(\@ibuf,$_); + } + } + + if ( variable_seen("\$(SUBDIRS)") ) + { + push @ibuf, "include \$(top_srcdir)/${rtems_top}automake/subdirs.am\n" ; + } + + if ( defined( $main::seen_host ) ) + { + push @ibuf, "include \$(top_srcdir)/${rtems_top}automake/host.am\n" ; + } + else + { + push @ibuf, "include \$(top_srcdir)/${rtems_top}automake/local.am\n" ; + } + + @buffer = @ibuf ; +} + +#print STDERR "\n", @buffer, "\n" ; + +{ ## pretty print + my $out = join ('',@buffer) ; + $out =~ s/\s\#\n(\#\n)+/\n/g ; + $out =~ s/\n\n\#\n\n/\n/g ; + $out =~ s/\n\n[\n]*/\n\n/g ; + print $out ; +} + +exit 0; # find a relative up-path to a file $file, starting at directory $pre sub find_file @@ -22,7 +358,7 @@ sub find_file my $top = "." ; if (not "$pre") { $pre = "." ; } - for ( $str = "$pre" . "/" . "$top" ; + for ( my $str = "$pre" . "/" . "$top" ; ( -d "$str" ) ; $str = "$pre" . "/" . "$top" ) { @@ -42,78 +378,154 @@ sub find_file 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"); - -if ( "$rtems_top" eq "." ) -{ $rtems_top = "" ; } -else { $rtems_top .= "/" ; } - -my $nl_seen = 0 ; - -while( <> ) -{ # consume header - last if ( /^[^#].*$/ ) ; - print "$_" ; +sub variable_seen($) +{ + my $label = "$_[0]" ; + my $res = defined $var_{"$label"}; +#print STDERR "SEEN: $label ->$res<\n" ; + return $res ; } -print "\nAUTOMAKE_OPTIONS = foreign 1.4\n"; -if ( "$rtems_cfg" eq "." ) +sub define_variable($$) { - print "ACLOCAL_AMFLAGS = -I \$(RTEMS_TOPdir)/aclocal\n" -} + my ($label,@value) = @_ ; -while( <> ) -{ - if ( /^[\s\t]*$/o ) + if ( not variable_seen("$label") ) { - $nl_seen = $nl_seen+1; +#print STDERR "DEFINING: $label\n" ; + push @vars, "$label" ; } - if ( /^[\s\t]*AUTOMAKE_OPTIONS.*$/o ) - { # remove the line - } - elsif ( /^[\s\t]*ACLOCAL[\s\t]*=[\s\t]*\@ACLOCAL\@.*$/o ) - { # remove the line - } - elsif ( /^[\s\t]*ACLOCAL_AMFLAGS[\s\t]*=[\s\t]*.*$/o ) - { # remove the line + foreach my $i ( @{value} ) + { + push @{$var_{"$label"}}, $i ; } - elsif ( /^[\s\t]*include[\s\t]*\$\(top_srcdir\)[\.\/]*automake\/(.*)\.am$/o ) +} + +# Strip off duplicate entries from a list +sub purge($) +{ + my $list = $_[0] ; # Reference to list ! + my (@tmp) = () ; + + foreach my $l ( @{$list} ) { - if ( "$1" eq "lib" ) + my $i = 1 ; + foreach my $t (@tmp) { - print "include \$(top_srcdir)/${rtems_top}automake/$1.am\n" ; + if ( $t eq $l ) + { + $i = 0 ; + last ; + } } + push @tmp,$l if ($i) ; } - elsif ( /^[\s\t]*include[\s\t]*\$\(RTEMS_ROOT\)\/make\/lib.cfg$/o ) - { - print "include \$(top_srcdir)/${rtems_top}automake/lib.am\n" ; - } - elsif ( /^[\s\t]*SUBDIRS.*$/o ) + + @{$list} = @tmp ; +} + +# +# Break the right hand side of a variable assignment into separate chunks +# +sub split_vars($) +{ + my $line = $_[0] ; + my (@buf) = split(//,"$line") ; + + my $begin = 0 ; + my @res = () ; + + my $depth = 0 ; + my $state = 0 ; + + my $len = $#buf + 1 ; + for ( my $i = 0 ; $i < $len ; $i++ ) { - $subdirs_seen = "yes" ; - print "$_" ; - $nl_seen = 0 ; + my $c = @buf[$i] ; + if ( $state == 0 ) + { + if ( "$c" ne " " ) + { # token + $begin = $i ; + $state++ ; + } + if ( "$c" eq "\$" ) + { # variable + $depth++ ; + } + } + elsif ( $state == 1 ) + { + if ( ( "$c" eq "\)" ) or ( "$c" eq "\}" ) ) + { # variable + $depth-- ; + } + elsif ( ("$c" eq " " ) and ( $depth == 0 ) ) + { + push @res, substr($line,$begin,$i-$begin); + $state-- ; + } + elsif ( "$c" eq "\$" ) + { # variable + $depth++ ; + } + } + else + { + die "split_vars: unknown mode\n" ; + } } - elsif ( /^[ ]*$/o ) + + if ( $state > 0 ) { - print "$_" if $nl_seen < 2 ; + push @res, substr($line,$begin,$len-$begin); + $state = 0 } - else - { - print "$_" ; - $nl_seen = 0; + return @res ; +} + +sub print_var($$$) +{ + my ($ibuf,$line,$l) = @_ ; # $l .. reference to list + + foreach (@{$l}) { + if ( ( length($line) + length($_) ) < 76 ) + { + $line .= " $_"; + } + else + { + push @{$ibuf}, "$line \\\n"; + $line = " $_" ; + } } -} # while + push @{$ibuf}, "$line\n" ; +} -if ( "$subdirs_seen" ) +sub print_line($$) { - print "include \$(top_srcdir)/${rtems_top}automake/subdirs.am\n" ; + my ($ibuf,$input) = @_ ; + my @l = split( / /, $input ); + my $line = shift @l ; + + foreach my $i (@l) { + if ( ( length($line) + length($i) ) < 76 ) + { + $line .= " $i"; + } + else + { + push @{$ibuf}, "$line \\\n"; + $line = " $i" ; + } + } + push @{$ibuf}, "$line" ; } -print "include \$(top_srcdir)/${rtems_top}automake/local.am\n" ; -;1 +sub print_script($$) +{ + my ($ibuf,$input) = @_ ; + $input =~ s%§%\\\n%g ; + push @{$ibuf}, $input ; +} diff --git a/tools/update/cipolish b/tools/update/cipolish index c04e0c52c6..dd3bb8084f 100755 --- a/tools/update/cipolish +++ b/tools/update/cipolish @@ -12,15 +12,18 @@ # $Id$ -# find relative up-path to configure.in +use strict ; + +my @vars = () ; +my @buffer = () ; + +# find relative up-path to VERSION my $rtems_cfg = &find_file(".","VERSION"); my $rtems_root = &find_root() ; $rtems_root =~ tr/\//\-/ ; my $rtems_name = "rtems" ; $rtems_name .= "-" . "$rtems_root" if (length($rtems_root) > 0 ) ; -my @buffer = () ; - while ( <> ) { push @buffer, "$_" ; @@ -126,8 +129,8 @@ while ( <> ) { if ( /^[\s]*(RTEMS_ENABLE_LIBCDIR).*$/o ) { - if ( ( not defined $var_RTEMS_PROG_CC_FOR_TARGET ) - and ( not defined $var_RTEMS_PROG_CXX_FOR_TARGET ) + if ( ( not defined $main::var_RTEMS_PROG_CC_FOR_TARGET ) + and ( not defined $main::var_RTEMS_PROG_CXX_FOR_TARGET ) ) { push @tbuf, "$_" ; @@ -165,7 +168,7 @@ sub find_file($$) my $top = "." ; if (not "$pre") { $pre = "." ; } - for ( $str = "$pre" . "/" . "$top" ; + for ( my $str = "$pre" . "/" . "$top" ; ( -d "$str" ) ; $str = "$pre" . "/" . "$top" ) { diff --git a/tools/update/rtems-polish.sh b/tools/update/rtems-polish.sh index 83e3d0e390..df0cc8a0e7 100755 --- a/tools/update/rtems-polish.sh +++ b/tools/update/rtems-polish.sh @@ -37,7 +37,7 @@ usage() exit 1; } -# Check for auxillary files +# Check for auxiliary files aux_files="../../VERSION ampolish acpolish cipolish" for i in ${aux_files}; do if test ! -f ${perltools}/$i; then -- cgit v1.2.3