summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRalf Corsepius <ralf.corsepius@rtems.org>2005-10-24 15:26:51 +0000
committerRalf Corsepius <ralf.corsepius@rtems.org>2005-10-24 15:26:51 +0000
commit39012a185de2b24a47abcad973a980806b78c179 (patch)
tree56791bab979771dba34e6edb8096beb744600bc7
parentfab90462e15e600073772a373079bb6250a25ad7 (diff)
downloadrtems-39012a185de2b24a47abcad973a980806b78c179.tar.bz2
New.
-rwxr-xr-xtools/build/ampolish3.in243
1 files changed, 243 insertions, 0 deletions
diff --git a/tools/build/ampolish3.in b/tools/build/ampolish3.in
new file mode 100755
index 0000000000..b65e649255
--- /dev/null
+++ b/tools/build/ampolish3.in
@@ -0,0 +1,243 @@
+#! /usr/bin/perl -w
+
+# Helper script to generate pre/tmpinstall rules for cpukit Makefile.am.
+#
+# Usage: ampolish3 Makefile.am > preinstall.am
+#
+# Reads a Makefile.am from stdin and writes corresponding
+# pre/tmpinstall rules to stdout.
+#
+# NOTE: This script is cpukit specific. It is not applicable to other
+# RTEMS Makefile.ams nor to Makefile.ams in general.
+#
+
+sub replace($);
+sub print_dirstamp($$$);
+
+# Predefined directory mappings
+# final-installation directory => temp installation directory
+my %dirmap = (
+ '$(includedir)' => '$(PROJECT_INCLUDE)',
+ '$(libdir)' => '$(PROJECT_LIB)',
+ '$(project_libdir)' => '$(PROJECT_LIB)',
+ '$(project_includedir)' => '$(PROJECT_INCLUDE)'
+ );
+
+## 1st pass: read in file
+my @buffer1 = () ;
+my %seen = ();
+
+{
+ my $mode = 0 ;
+ my $line = '';
+
+ while ( <> )
+ {
+ if ( $mode == 0 )
+ {
+ if ( /^([a-zA-Z0-9_]+\s*[\+]?[:=].*)\\$/o )
+ {
+ $line = "$1" ;
+ $mode = 1;
+ } else {
+ push @buffer1, $_ ;
+ }
+ } elsif ( $mode == 1 ) {
+ if ( /^(.*)\\$/o ) {
+ $line .= $1;
+ } else {
+ $line .= $_ ;
+ push @buffer1, $line ;
+ $line = '';
+ $mode = 0 ;
+ }
+ }
+ }
+}
+
+#foreach my $l ( @buffer1 ) { print STDERR "1<$l>"; }
+
+# Filter out all Makefile code not relevant here
+my @buffer2 = ();
+foreach my $l ( @buffer1 ) {
+ if ( $l=~ /^\t.*$/o )
+ { #ignore: Production of a make rule.
+ } elsif ( $l =~ /^\s*([a-zA-Z0-9_]*dir)\s*\=\s*(.*)\s*$/o )
+ { # dirs
+ push @buffer2, "$l";
+ $dirmap{"\$\($1\)"} = replace($2);
+ } elsif ( $l =~ /^\s*noinst_(.*)\s*[\+]?\=(.*)$/o )
+ { #ignore: noinst_* are not relevant here.
+ } elsif ( $l =~ /^\s*(nodist_|dist_|)(project_|)(include)_(HEADERS)\s*\=(.*)/o )
+ {
+ push @buffer2, "$3dir = \$($3dir)\n";
+ push @buffer2, "$l";
+ } elsif ( $l =~ /^\s*(nodist_|dist_|)(project_|)([a-zA-Z0-9_]+)_(HEADERS)\s*[\+]?\=(.*)/o )
+ {
+ push @buffer2, "$l";
+ } elsif ( $l =~ /^\s*(nodist_|dist_|)(project_[a-zA-Z0-9_]+)_(DATA|SCRIPTS|LIBRARIES|PROGRAMS)\s*[\+]?\=(.*)/o )
+ {
+ push @buffer2, "$l";
+ } elsif ( $l =~ /^\s*(if|else|endif)\s*.*$/o )
+ { # conditionals
+ push @buffer2, "$l";
+ }
+}
+
+# foreach my $l ( @buffer2 ) { print STDERR "$l"; }
+
+my @buffer3 = ();
+
+foreach my $l ( @buffer2 ) {
+ if ( $l =~ /^\s*([a-zA-Z0-9_]*dir)\s*\=\s*(.*)\s*$/o )
+ { # dirs
+ my $v = $dirmap{"\$\($1\)"};
+ print_dirstamp(\@buffer3,$v,"PREINSTALL_DIRS");
+ $seen{"PREINSTALL_DIRS"} = 1;
+ } elsif ( $l =~ /^\s*(nodist_|)([a-zA-Z0-9_]*)_HEADERS\s*[\+]?\=(.*)$/o )
+ {
+ my $v = $dirmap{"\$\($2dir\)"};
+ my @instfiles = split(' ',$3);
+ foreach my $f ( @instfiles )
+ {
+ my $x ;
+ my $i = rindex($f,'/');
+ if ($i < 0) {
+ $x="$f";
+ } else {
+ $x = substr($f,$i+1);
+ }
+ push @buffer3,
+ "$v/$x: $f $v/\$(dirstamp)\n",
+ "\t\$(INSTALL_DATA) \$< $v/$x\n",
+ "PREINSTALL_FILES += $v/$x\n\n";
+ $seen{"PREINSTALL_FILES"} = 1;
+ }
+ } elsif ( $l =~ /^\s*(nodist_|)([a-zA-Z0-9_]*)_SCRIPTS\s*[\+]?\=(.*)$/o )
+ {
+ my $v = $dirmap{"\$\($2dir\)"};
+ my @instfiles = split(' ',$3);
+ foreach my $f ( @instfiles )
+ {
+ my $x ;
+ my $i = rindex($f,'/');
+ if ($i < 0) {
+ $x="$f";
+ } else {
+ $x = substr($f,$i+1);
+ }
+ push @buffer3,
+ "$v/$x: $f $v/\$(dirstamp)\n",
+ "\t\$(INSTALL_SCRIPT) \$< $v/$x\n",
+ "PREINSTALL_FILES += $v/$x\n\n";
+ $seen{"PREINSTALL_FILES"} = 1;
+ }
+ } elsif ( $l =~ /^\s*(nodist_|)([a-zA-Z0-9_]*)_PROGRAMS\s*[\+]?\=(.*)$/o )
+ {
+ my $v = $dirmap{"\$\($2dir\)"};
+ my @instfiles = split(' ',$3);
+ foreach my $f ( @instfiles )
+ {
+ my $x ;
+ my $i = rindex($f,'/');
+ if ($i < 0) {
+ $x="$f";
+ } else {
+ $x = substr($f,$i+1);
+ }
+ push @buffer3,
+ "$v/$x: $f $v/\$(dirstamp)\n",
+ "\t\$(INSTALL_PROGRAM) \$< $v/$x\n",
+ "PREINSTALL_FILES += $v/$x\n\n";
+ $seen{"PREINSTALL_FILES"} = 1;
+ }
+ } elsif ( $l =~ /^\s*(nodist_|)([a-zA-Z0-9_]*)_LIBRARIES\s*[\+]?\=(.*)$/o )
+ {
+ my $v = $dirmap{"\$\($2dir\)"};
+ my @instfiles = split(' ',$3);
+ foreach my $f ( @instfiles )
+ {
+ my $x ;
+ my $i = rindex($f,'/');
+ if ($i < 0) {
+ $x="$f";
+ } else {
+ $x = substr($f,$i+1);
+ }
+ push @buffer3,
+ "$v/$x: $f $v/\$(dirstamp)\n",
+ "\t\$(INSTALL_DATA) \$< $v/$x\n",
+ "TMPINSTALL_FILES += $v/$x\n\n";
+ $seen{"TMPINSTALL_FILES"} = 1;
+ }
+ } elsif ( $l =~ /^\s*(nodist_|)([a-zA-Z0-9_]*)_DATA\s*[\+]?\=(.*)$/o )
+ {
+ my $v = $dirmap{"\$\($2dir\)"};
+ my @instfiles = split(' ',$3);
+ foreach my $f ( @instfiles )
+ {
+ my $x ;
+ my $i = rindex($f,'/');
+ if ($i < 0) {
+ $x="$f";
+ } else {
+ $x = substr($f,$i+1);
+ }
+ push @buffer3,
+ "$v/$x: $f $v/\$(dirstamp)\n",
+ "\t\$(INSTALL_DATA) \$< $v/$x\n",
+ "TMPINSTALL_FILES += $v/$x\n\n";
+ $seen{"TMPINSTALL_FILES"} = 1;
+ }
+ } elsif ( $l =~ /^\s*(if|else|endif)\s*.*$/o )
+ { # conditionals
+ push @buffer3, "$l";
+ }
+}
+
+# foreach my $l ( @buffer3 ) { print STDERR "$l"; }
+
+my $output;
+$output .= "## Automatically generated by ampolish3 - Do not edit\n\n";
+$output .= "if AMPOLISH3\n";
+$output .= "\$(srcdir)/preinstall.am: Makefile.am\n";
+$output .= "\t\$(AMPOLISH3) \$(srcdir)/Makefile.am > \$(srcdir)/preinstall.am\n";
+$output .= "endif\n\n";
+
+foreach my $k ( keys %seen )
+{
+ $output .= "$k =\n";
+ if ( $k =~ /.*FILES/o ) {
+ $output .= "CLEANFILES += \$($k)\n";
+ } elsif ( $k =~ /.*DIRS/o ) {
+ $output .= "DISTCLEANFILES += \$($k)\n";
+ }
+ $output .= "\n";
+}
+
+# Pretty printing
+$output .= join ( '', @buffer3 );
+$output =~ s/\nelse\n+endif/\nendif/g;
+$output =~ s/\n\n+endif/\nendif/g;
+$output =~ s/\nif [a-zA-Z0-9_!]+\n+endif//g;
+print STDOUT $output;
+
+exit 0;
+
+sub replace($)
+{
+ my ($v) = @_;
+ foreach my $i ( keys %dirmap )
+ {
+ $v =~ s/\Q$i/$dirmap{$i}/g;
+ }
+ return $v;
+}
+
+sub print_dirstamp($$$)
+{
+ my ($obuf,$file,$inst) = @_ ;
+ push @{$obuf}, "$file/\$(dirstamp):\n\t\@\$\(mkdir_p\) $file\n" ;
+ push @{$obuf}, "\t\@: \> $file/\$(dirstamp)\n" ;
+ push @{$obuf}, "$inst += $file/\$(dirstamp)\n\n" ;
+}