source: rtems/tools/build/ampolish3.in @ 9db0ec2

4.104.114.84.95
Last change on this file since 9db0ec2 was 9db0ec2, checked in by Ralf Corsepius <ralf.corsepius@…>, on Jan 12, 2006 at 4:02:51 AM

2006-10-12 Ralf Corsepius <ralf.corsepius@…>

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