source: rtems/ampolish3 @ 62181b21

4.11
Last change on this file since 62181b21 was 65c6425, checked in by Joel Sherrill <joel.sherrill@…>, on May 3, 2012 at 5:24:46 PM

Remove CVS Id Strings (manual edits after script)

These modifications were required by hand after running the script.
In some cases, the file names did not match patterns. In others,
the format of the file did not match any common patterns.

  • Property mode set to 100755
File size: 7.5 KB
Line 
1#! /usr/bin/perl -w
2#
3# Copyright (C) 2005, 2006 Ralf Corsépius, Ulm, Germany
4#
5# Permission to use, copy, modify, and distribute this software
6# is freely granted, provided that this notice is preserved.
7
8# Helper script to generate pre/tmpinstall rules for RTEMS Makefile.am.
9#
10# Usage: ampolish3 Makefile.am > preinstall.am
11#
12# Reads a Makefile.am from stdin and writes corresponding
13# pre/tmpinstall rules to stdout.
14
15sub replace($);
16sub print_dirstamp($$$);
17
18# Predefined directory mappings:
19#
20# final-installation directory => temp installation directory
21my %dirmap = (
22   '$(includedir)'              => '$(PROJECT_INCLUDE)',
23   '$(libdir)'                  => '$(PROJECT_LIB)',
24   '$(project_libdir)'          => '$(PROJECT_LIB)',
25   '$(project_includedir)'      => '$(PROJECT_INCLUDE)'
26  );
27
28# Conventions on automake primaries:
29#
30# *_HEADERS -> preinstall
31# noinst*_HEADERS -> noinst
32# noinst_*_LIBRARIES -> noinst
33# project_*_LIBRARIES -> tmpinstall
34# *_LIBRARIES -> ignore (no preinstallation)
35# dist_project_*_DATA -> preinstall (bsp_specs,linkcmds)
36# project_*_DATA -> tmpinstall (*.o, *.a)
37# dist_*_DATA -> ignore (no preinstallation)
38# *SCRIPTS -> ignore (no preinstallation)
39# noinst_*_PROGRAMS -> noinst
40# project_*_PROGRAMS -> tmpinstall
41# *_PROGRAMS -> ignore (no preinstallation)
42
43## 1st pass: read in file
44my @buffer1 = () ;
45my %seen = ();
46my %predefs = ();
47
48{
49  my $mode = 0 ;
50  my $line = '';
51
52  while ( <> )
53  {
54    if ( $mode == 0 )
55    {
56      if ( /^([a-zA-Z0-9_]+\s*[\+]?[:=].*)\\$/o )
57      {
58        $line = "$1" ;
59        $mode = 1;
60      } else {
61        push @buffer1, $_ ;
62      }
63    } elsif ( $mode == 1 ) {
64      if ( /^(.*)\\$/o ) {
65        $line .= $1;
66      } else {
67        $line .= $_ ;
68        push @buffer1, $line ;
69        $line = '';
70        $mode = 0 ;
71      }
72    }
73  }
74}
75
76#foreach my $l ( @buffer1 ) { print STDERR "1:<$l>"; }
77
78# Filter out all Makefile code not relevant here
79my @buffer2 = ();
80foreach my $l ( @buffer1 ) {
81  if ( $l=~ /^\t.*$/o )
82  { #ignore: Production of a make rule.
83  } elsif ( $l =~ /^\s*([a-zA-Z0-9_]*dir)\s*\=\s*(.*)\s*$/o )
84  { # dirs
85    push @buffer2, "$l";
86    $dirmap{"\$\($1\)"} = replace($2);
87  } elsif ( $l =~ /^\s*noinst_(.*)\s*[\+]?\=(.*)$/o )
88  {
89    #ignore: noinst_* are not relevant here.
90  } elsif ( $l =~ /^\s*(nodist_|dist_|)(project_|)([a-zA-Z0-9_]+)_(HEADERS|LIBRARIES|DATA|SCRIPTS|PROGRAMS)\s*([\+]?\=)\s*(.*)/o )
91  {
92    if ( ( "$5" eq '=' ) ) {
93      my $v = $dirmap{"\$\($3dir\)"};
94      if ( $v =~ /\$\(PROJECT_[^\)]+\)$/ )
95      {
96         $predefs{"$v"} = 1;
97      }
98    }
99    foreach my $f ( split(' ',$6) ) {
100      push @buffer2, "$1$2$3_$4 +=$f\n";
101    }
102  } elsif ( $l =~ /^\s*(if|else|endif)\s*.*$/o )
103  { # conditionals
104    push @buffer2, "$l";
105  }
106
107  # Check if Makefile.am already contains CLEANFILES or DISTCLEANFILES
108  if ( $l =~ /^\s*(CLEANFILES|DISTCLEANFILES|SUBDIRS)\s*\=.*$/o )
109  {
110    $predefs{"$1"} = 1;
111  }
112}
113
114if ( $predefs{"\$(PROJECT_INCLUDE)"} ){
115  unshift @buffer2, "includedir = \$(includedir)\n";
116}
117if ( $predefs{"\$(PROJECT_LIB)"} ){
118  unshift @buffer2, "libdir = \$(libdir)\n";
119}
120
121# foreach my $l ( @buffer2 ) { print STDERR "2:<$l>"; }
122
123my @buffer3 = ();
124
125foreach my $l ( @buffer2 ) {
126 if ( $l =~ /^\s*([a-zA-Z0-9_]*dir)\s*\=\s*(.*)\s*$/o )
127  { # dirs
128    my $v = $dirmap{"\$\($1\)"};
129    print_dirstamp(\@buffer3,$v,"PREINSTALL_DIRS");
130    $seen{"PREINSTALL_DIRS"} = 1;
131  } elsif ( $l =~ /^\s*(nodist_|dist_|)(project_|)([a-zA-Z0-9_]+)_HEADERS\s*\+\=(.*)/o )
132  { # preinstall
133    my $v = $dirmap{"\$\($3dir\)"};
134    my $f = $4;
135    my $x ; my $i = rindex($f,'/');
136    if ($i < 0) { $x="$f";
137    } else { $x = substr($f,$i+1);
138    }
139    push @buffer3,
140          "$v/$x: $f $v/\$(dirstamp)\n",
141          "\t\$(INSTALL_DATA) \$< $v/$x\n",
142          "PREINSTALL_FILES += $v/$x\n\n";
143    $seen{"PREINSTALL_FILES"} = 1;
144  } elsif ( $l =~ /^\s*(nodist_|dist_|)(project_)([a-zA-Z0-9_]+)_LIBRARIES\s*\+\=(.*)/o )
145  { # tmpinstall
146    my $v = $dirmap{"\$\($3dir\)"};
147    my $f = $4;
148    my $x ; my $i = rindex($f,'/');
149    if ($i < 0) { $x="$f";
150    } else { $x = substr($f,$i+1);
151    }
152    push @buffer3,
153          "$v/$x: $f $v/\$(dirstamp)\n",
154          "\t\$(INSTALL_DATA) \$< $v/$x\n",
155          "TMPINSTALL_FILES += $v/$x\n\n";
156    $seen{"TMPINSTALL_FILES"} = 1;
157  } elsif ( $l =~ /^\s*(nodist_|dist_|)([a-zA-Z0-9_]+)_LIBRARIES\s*\+\=(.*)/o )
158  { # ignore
159  } elsif ( $l =~ /^\s*(dist_)(project_)([a-zA-Z0-9_]+)_DATA\s*\+\=(.*)/o )
160  { # preinstall
161    my $v = $dirmap{"\$\($3dir\)"};
162    my $f = $4;
163    my $x ; my $i = rindex($f,'/');
164    if ($i < 0) { $x="$f";
165    } else { $x = substr($f,$i+1);
166    }
167    push @buffer3,
168          "$v/$x: $f $v/\$(dirstamp)\n",
169          "\t\$(INSTALL_DATA) \$< $v/$x\n",
170          "PREINSTALL_FILES += $v/$x\n\n";
171    $seen{"PREINSTALL_FILES"} = 1;
172  } elsif ( $l =~ /^\s*(nodist_|)(project_)([a-zA-Z0-9_]+)_DATA\s*\+\=(.*)/o )
173  { # tmpinstall
174    my $v = $dirmap{"\$\($3dir\)"};
175    my $f = $4;
176    my $x ; my $i = rindex($f,'/');
177    if ($i < 0) { $x="$f";
178    } else { $x = substr($f,$i+1);
179    }
180    push @buffer3,
181          "$v/$x: $f $v/\$(dirstamp)\n",
182          "\t\$(INSTALL_DATA) \$< $v/$x\n",
183          "TMPINSTALL_FILES += $v/$x\n\n";
184    $seen{"TMPINSTALL_FILES"} = 1;
185  } elsif ( $l =~ /^\s*(dist_|)([a-zA-Z0-9_]+)_DATA\s*\+\=(.*)/o )
186  { # ignore
187  } elsif ( $l =~ /^\s*(nodist_|dist_|)([a-zA-Z0-9_]+)_SCRIPTS\s*\+\=(.*)/o )
188  { # ignore
189  } elsif ( $l =~ /^\s*(nodist_|dist_|)(project_)([a-zA-Z0-9_]+)_PROGRAMS\s*\+\=(.*)/o )
190  { # tmpinstall
191    my $v = $dirmap{"\$\($3dir\)"};
192
193    my $f = $4;
194    my $x ; my $i = rindex($f,'/');
195    if ($i < 0) { $x="$f";
196    } else { $x = substr($f,$i+1);
197    }
198    push @buffer3,
199          "$v/$x: $f $v/\$(dirstamp)\n",
200          "\t\$(INSTALL_PROGRAM) \$< $v/$x\n",
201          "TMPINSTALL_FILES += $v/$x\n\n";
202    $seen{"TMPINSTALL_FILES"} = 1;
203  } elsif ( $l =~ /^\s*(nodist_|dist_|)([a-zA-Z0-9_]+)_PROGRAMS\s*\+\=(.*)/o )
204  { # ignore
205  } elsif ( $l =~ /^\s*(if|else|endif)\s*.*$/o )
206  { # conditionals
207    push @buffer3, "$l";
208  }
209}
210
211# foreach my $l ( @buffer3 ) { print STDERR "3:<$l>"; }
212
213my $output;
214$output .= "## Automatically generated by ampolish3 - Do not edit\n\n";
215$output .=  "if AMPOLISH3\n";
216$output .=  "\$(srcdir)/preinstall.am: Makefile.am\n";
217$output .= "\t\$(AMPOLISH3) \$(srcdir)/Makefile.am > \$(srcdir)/preinstall.am\n";
218$output .= "endif\n\n";
219
220foreach my $k ( keys %seen )
221{
222  if ( $k =~ /PREINSTALL_FILES/o ) {
223    $output .= "all-am: \$(PREINSTALL_FILES)\n\n";
224
225    $output .= "$k =\n";
226    $output .= "CLEANFILES ";
227    if ( $predefs{"CLEANFILES"} ) { $output .= "+"; }
228    $output .= "= \$($k)\n";
229    $predefs{"CLEANFILES"} = 1;
230  } elsif ( $k =~ /TMPINSTALL_FILES/o ) {
231
232    $output .= "all-local: \$(TMPINSTALL_FILES)\n\n";
233
234    $output .= "$k =\n";
235    $output .= "CLEANFILES ";
236    if ( $predefs{"CLEANFILES"} ) { $output .= "+"; }
237    $output .= "= \$($k)\n";
238    $predefs{"CLEANFILES"} = 1;
239  } elsif ( $k =~ /.*DIRS/o ) {
240    $output .= "$k =\n";
241    $output .= "DISTCLEANFILES ";
242    if ( $predefs{"DISTCLEANFILES"} ) { $output .= "+"; }
243    $output .= "= \$($k)\n";
244    $predefs{"DISTCLEANFILES"} = 1;
245  }
246  $output .= "\n";
247}
248
249# Pretty printing
250$output .= join ( '', @buffer3 );
251$output =~ s/\nelse\n+endif/\nendif/g;
252$output =~ s/\n\n+endif/\nendif/g;
253$output =~ s/\nif [a-zA-Z0-9_!]+\n+endif//g;
254print STDOUT $output;
255
256exit 0;
257
258sub replace($)
259{
260  my ($v) = @_;
261  foreach my $i ( keys %dirmap )
262  {
263    $v =~ s/\Q$i/$dirmap{$i}/g;
264  }
265  return $v;
266}
267
268sub print_dirstamp($$$)
269{
270  my ($obuf,$file,$inst) = @_ ;
271  push @{$obuf}, "$file/\$(dirstamp):\n\t\@\$\(MKDIR_P\) $file\n" ;
272  push @{$obuf}, "\t\@: \> $file/\$(dirstamp)\n" ;
273  push @{$obuf}, "$inst += $file/\$(dirstamp)\n\n" ;
274}
Note: See TracBrowser for help on using the repository browser.