source: rtems/tools/update/acpolish @ 6693a68

4.104.114.84.95
Last change on this file since 6693a68 was 6693a68, checked in by Joel Sherrill <joel.sherrill@…>, on 07/26/99 at 20:00:37

This is part of a major patch from Ralf Corsepius <corsepiu@…>
to move RTEMS more to automake/autoconf and GNU compliance.

Finally, here they are: the "big-patch" patches - merged into one big
patch (~1.5MB).

Sorry for the delay, but testing took much more time than I had expected

  • esp. reworking the acpolish script triggered many more tiny issues than I had expected (cf. below).

At least, now you've got something to spend your weekend with :-.

WARNINGS:

  • I've gone a little (??) further than I had announced before.
  • Several directories have been moved.
  • Several files have been added and removed
  • I have tested it with many BSPs/CPUs and a variety of permutiations of configuration flags, but not with all.
  • Most parts of the patch are automatically generated, however there are many tiny manual modifications.

APPLYING THE PATCH:

./autogen -c
mkdir tools
mv c/src/exec/score/tools tools/cpu
mv c/build-tools tools/build
mv c/update-tools tools/update
patch -p1 -E < rtems-rc-19990709-0.diff
./autogen

If the patch doesn't apply to rtems-cvs, I would suggest that you should
try to apply it brute-force and then to run tools/update/rtems-polish.sh
-ac -am afterwards. A recursive diff between rtems-19990709 + patch and
rtems-cvs + patch then should report only a few dozen significant
changes to configuration files which need to be merged manually (IIRC, I
did not change any source files).

* Attention: There are files to be removed, moved, copied and added
in/to CVS!

NEWS/CHANGES:

  1. Configuration takes place in 3 stages: 1. per host (toplevel configure script), 2. per target (c/configure), 3. per bsp c/src/configure automatically triggered from ./configure and c/Makefile.am.
  2. Building of subdirectory c/ takes place in c/$(target_alias) for cross-targets in c/ for native targets
  3. Building of subdirectory c/src takes place in c/${target_alias}/<bsp> for cross-targets, c/<bsp> for native targets
  4. c/build-tools moved to tools/build
  5. c/src/exec/score/cpu/tools moved to tools/cpu (=cpu-tools split out)
  6. c/update-tools moved to tools/update
  7. New subdirectory c/src/make, handles files from make/ on a per BSP basis
  8. Maintainer mode support: Ie. if configuring with --enable-maintainer-mode disabled (the default), then tracking of many dependencies will be disabled in Makefiles. Esp. many dependencies for auto* generated files will be switched off in Makefiles. Ie. if not using "--enable-maintainer-mode" many auto* generated files will not be updated automatically, i.e. normal users should not be required to have auto* tools anymore (untested).
  9. Independent configuration scripts for / (toplevel), tools/build, tools/cpu, tools/update, c/, c/src/, c/src/exec, c/src/lib, c/src/tests, c/src/make
  10. Automake support for all directories above and besides c/src
  11. "preinstall" now is implemented as depth-first recursive make target
  1. host compiled tools (exception bsp-tools) are accessed in location in the build tree instead of inside the build-tree when building RTEMS.
  2. RTEMS_ROOT and PROJECT_ROOT now point to directories inside the build-tree - many tiny changes as consequence from this.
  3. --with-cross-host support removed (offically announced obsolete by cygnus)
  4. Changing the order of building libraries below c/src/lib/
  5. Former toplevel configure script broken into aclocal/*.m4 macros
  6. Newlib now detected by configure macros, RTEMS_HAS_NEWLIB removed from *cfg.
  7. sptables.h now generated by autoconf
  8. Rules for "mkinstalldirs temporary installation tree" moved from c/Makefile to subdirectories.
  9. Cpu-tools do not get installed.
  10. FIX: Use ACLOCAL_AMFLAGS instead of ACLOCAL = -I ... in Makefile.ams which are in directories with own configure scripts.
  11. Hardcoding BSP names into libbsp/.../tools to avoid RTEMS_BSP get overridden from the environment.
  12. FIX: Handling of MP_PIECES in various Makefiles
  13. FIX: Removing "::" rules from some Makefile.ins
  14. FIX: File permission chaos: (-m 444 and -m 555 vs. -m 644 and -m 755) - Now all include files use -m 644.
  15. Removed many gnumake-conditionals in Makefile.ins - Partially replaced with automake-conditional, partially replaced with conditionalized Makefile variables (... _yes_V)
  16. Massively reworked acpolish: acpolish now parses Makefile.ins and interprets parts of the Makefile.ins.
  17. FIX: Some $(wildcard $(srcdir)/*.h) macros removed / replaced with explicit lists of files in Makefile.ins.
  18. FIX: Replacing MKLIB with RANLIB in Makefile.ins
  19. HACK: Add preinstallation for pc386 specific $(PROJECT_RELEASE)/BootImgs? directory

... many more details, I can't recall

KNOWN BUGS:

  1. make [debug|profile]_install do not do what they are promissing. "make [debug|profile] install" does what "make [debug|profile]_install" has been doing. Proposal: remove [debug|profile]_install
  2. Dependencies between temporary installation tree and source tree are not yet handled correctly.
  3. Dependencies between temporary installation tree and source tree are handled ineffencently (Using INSTALL_CHANGE instead of make dependencies)
  4. RTEMS_ROOT, PROJECT_ROOT, top_builddir, RTEMS_TOPdir now are redundant.
  5. The new configure scripts still are in their infancy. They contain redundant checks and might still contain bugs, too.
  6. RTEMS autoconf Makefile.ins use a mixture of configuration information gathered in c/$(target_alias)/<bsp>/make and of information collected from their configure scripts.
  7. make dist is not fully functional
  8. Subdirectory host-/build-/target- configure options (--target, --host, --build) do not conform to Cygnus/GNU conventions.
  9. Some RTEMS autoconf Makefile.in's makefile targets are not supported in automake Makefile.ams/ins (e.g. get, clobber).
  10. Some automake standard targets are not propagated from toplevel and c/Makefile.am to autoconf subdirectories (eg. make dist).
  11. rpcgen generated files are not part of the source-tree (Automake conventions favor supplying generated files inside the source-tree, however there is no support for rpcgen generated files in automake, cf. yacc/lex support in automake).
  12. RTEMS_HAS_RDBG handling is flaky. make/*.cfg use RTEMS_HAS_RDBG per CPU, while librdb's sources can only be built per BSP. Raises the more general question whether librdbg located correctly in the source-tree.
  13. All make/*cfg files are configured per cpu, currently there is no location to store per-bsp configuration information --> bsp.cfg, per aconfig.h?
  14. "make install" without having run "make all" beforehand does not work.
  15. handling of --enable-multiprocessing seems to be broken in make/custom/*
  16. Makefile.ins still exploit many gmake features.
  17. File permisson chaos on libraries (no explict -m for libraries/rels/etc).
  18. mcp750 Makefiles are broken (Note: I *do* mean buggy - I am not talking about "not-conforming to conventions", here :-).
  19. Dependencies between configure scripts are not handled, eg. aborting "make RTEMS_BSP=<bsp>" can leave the build-tree in an unusable state.
  20. "make clean" does not delete <build-tree>/<bsp>. This is intentional for now, because rerunning "make" after "make clean" requires an explicit "make preinstall" afterwards now. This should be done automatically, but doesn't work in this case for now. To work around this problem <build-tree>/<bsp> is kept during "make clean" for now (HACK).

TODO:

  1. split out host-compiled bsp-tools
  2. Use Cygnus/GNU standards for cross-compiling target-subdir (CC=CC_FOR_TARGET .. configure --host=${target_alias} --build=`config.guess'}), to be added to toplevel configure script after splitting out bsp-tools.
  3. Exploit per cpu support directory (c/src/<cpu>)- Splitting out per-cpu libraries - Are there any?
  4. Further automake support
  5. Converting subdirectories into standalone / self-contained subdirectories (Esp. moving their headers to the same common root as their sources, eg. mv lib/include/rtems++ lib/librtems++/include/rtems++) - This is the main obstacle which prevents moving further towards automake.
  6. Propagating values from *.cfg into Makefiles instead of propagating them at make time via Makefile-fragments (i.e. try to avoid using *.cfg).
  7. Testing on cygwin host (I *do* expect cygwin specific problems).
  8. The ARCH in o-$(ARCH)-$(VARIANT) build-subdirectories is not needed anymore.

GENERAL ISSUES:

  1. Temporary installation tree -- Ian and I seem to disagree basically. Though I think that I understand his argumentation, I do not share it. IMO, his way of using the buildtree is mis-using the build-tree, relying on an inofficial feature of RTEMS's current implementation, which doesn't even work correctly in the current build-tree, though it attempts hard to do so. From my very POV, it unnecessarily complicates the structures of the source- and build-trees. It is not supported by automake (No automatic generation for the necessary rules) and complicates the transition to automake significantly (Generating the rules with an enhanced version of acpolish could be possible). As Ian correctly pointed out, here a management decision is needed - though I don't see the need to draw this decision in short terms.
  1. preinstallation generally is a sure means to spoil the structure of the source tree, IMHO (No ranting intended, I am completly serious about this one). eg. through tree dependencies. The worst problem related to this I have found in the meantime is bsp_specs. bsp_specs is part of libbsp, ie. there is *no* way to build *any* part of the source tree *without* having a BSP *preinstalled*. Note: This issue is related to issue 1., but is not identical - The difference is the change of the order make rules have to be triggered. While preinstallation triggers rules spread all over the source tree before a "make all" can be run, a temporary installation tree could also be installed by post "make all" hooks (all-local:, to be run after make all in a directory is completed) if the directories' dependencies would be a tree,
  1. Stuctural dependencies between subdirectories.
  2. Depth of the source tree (Prevents multilibbing and introduces many unnecessary configure scripts).
  3. per cpu vs. per bsp configuration (There are no real per-cpu parts yets :-).
  4. automake does not support $makefiles in AC_OUTPUT. Unlike before, we now should try to avoid RTEMS_CHECK_MAKEFILE and to hard-code as much paths to Makefiles as possible.
  5. General redesign of the source tree
  6. Main installation point - Changing it to ${prefix}/${target_alias}. ?

Besides item 8. (which is a must, IMHO), as far as I see most of them
can not be solved soon and will remain issues in the mid- to long-term
:-.

REMARKS:

  • You (as the maintainer) should always use --enable-maintainer-mode when building RTEMS to ensure that maintainer mode generated files (esp. those in c/src/make) will be updated when make/* files have changed.
  • Use @RTEMS_BSP@ in Makefile.ins and Makefile.ams below c/src/, $(RTEMS_BSP) or ${RTEMS_BSP} will be overridden from environment variables when using make RTEMS_BSP="....".
  • c/src/make is a temporary cludge until configuration issues are solved. At the moment it is configured per bsp, but contains per-target/cpu info only. Its main purpose now is to circumvent modifying make/*.cfg files, because I consider make/* to be frozen for backward compatibilty.
  • This patch should only affect configuration files. At least I do not remember having touched any source files.
  • To build the bare bsp you now need to mention it in --enable-rtemsbsp.

Example: building gensh1 and sh1/bare simultaneously:
../rtems-rc-19990709-1/configure --target=sh-rtems \
--enable-rtemsbsp="bare gensh1" \
--prefix=/tmp/rtems \
--enable-bare-cpu-cflags='-DMHZ=20 -m1
-DCPU_CONSOLE_DEVNAME=\"/dev/null\"' \
--enable-bare-cpu-model=sh7032 \
--enable-maintainer-mode \
--enable-cxx
make
make install

  • The next steps in development would be to split out bsp-tools and then to change to Cygnus/GNU canonicalization conventions for building the c/ subdirectory afterwards (i.e. many standard AC_*.m4 macros could be used instead of customized versions)

FINAL REMARK:
The issues mentioned in the lists above sound much worser than the
situation actually is. Most of them are not specific to this patch, but
are also valid for the snapshot. I just wrote down what I came across
when working on the patch over the last few weeks.

I wouldn't be too surprised if you don't like the patch at the current
point in development. I am willing to discuss details and problems, I
also have no problem if you would post-pone applying this patch to times
after 4.1, but rejecting it as a whole for all times would be a false
management decision, IMHO.

Therefore I would suggest that you, if your time constaints allow it,
should at least play a little while with this patch to understand what
is going on and before drawing a decision on how to handle this
proposal. I know this patch is neither perfect nor complete, but I
consider it to be a major breakthrough. Don't be anxious because of the
size of the patch, the core of the patch is rather small, the size is
mainly the side effect of some systematic cleanups inside the Makefiles
(result of acpolish).

Feel free to ask if you encounter problems, if you don't understand
something or if you meet bugs - I am far from being perfect and am
prepared to answer them.

Ralf.

--
Ralf Corsepius
Forschungsinstitut fuer Anwendungsorientierte Wissensverarbeitung (FAW)
Helmholtzstr. 16, 89081 Ulm, Germany Tel: +49/731/501-8690
mailto:corsepiu@… FAX: +49/731/501-999
http://www.faw.uni-ulm.de

  • Property mode set to 100755
File size: 13.9 KB
Line 
1#!/usr/bin/perl
2
3# use strict 'subs' ;
4# use strict 'vars' ;
5# use strict 'refs' ;
6
7# use strict ;
8
9#
10# Perl script to beautify and enhance RTEMS autoconf Makefile.ins
11#
12# Reads from stdin and writes to stdout
13#
14# usage:
15# acpolish <Makefile.in >Makefile.in~
16# mv Makefile.in~ Makefile.in
17#
18# Note: This tool is not indented to be exported from the source-tree
19#
20
21if ( -f "Makefile.am" )
22{
23  # Refuse to work on Makefile.ins generated from automake;
24  # redirecting STDOUT to Makefile.in will trash the Makefile.in ;-
25
26  die "acpolish must not be run in automake directories" ;
27}
28
29my $experimental = 0 ; # enable experimental/unsafe features
30my $verbose = 0 ;
31my $build_pgms_seen = "" ;
32my $make_exe_seen = 0 ;
33my $install_seen = 0 ;
34my $top_builddir = "";
35my $subdir = "";
36my @installdirs = () ;
37
38my @pieces = () ;
39my @files = () ;
40my @variants = () ;
41my @vars = () ;
42
43sub print_macro($$)
44{
45  my $line = $_[0] ;
46  my $input  = $_[1] ;
47  $input =~ s/\\\\/ /g;
48  my @l = split(' ',$input);
49
50  foreach (@l) {
51    if ( ( length($line) + length($_) ) < 76 )
52    {
53          $line .= " $_";
54    }
55    else
56    {
57           print "$line \\\n";
58           $line = "    $_" ;
59    }
60  }
61  print "$line\n" ;
62}
63
64# Strip off duplicate entries from a list
65sub purge($)
66{
67  my $list = $_[0] ; # Reference to list !
68  my (@tmp) = () ;
69
70  foreach my $l ( @{$list} )
71  {
72    my $i = 1 ;
73    foreach my $t (@tmp)
74    {
75      if ( $t eq $l )
76      {
77        $i = 0 ;
78        last ;
79      }
80    }
81    push @tmp,$l if ($i) ;
82  }
83
84  @{$list} = @tmp ;
85}
86
87sub find_root
88{
89  $top_builddir = "." ;
90  $subdir="";
91  my $pwd = `pwd`; chomp $pwd;
92  $pwd .= "/" ;
93  my $len ;
94
95  if ( -f "configure.in" )  { return $top_builddir ; }
96  my $i = rindex($pwd,'/');
97
98  $len = $i;
99  $pwd = substr($pwd,0,$len);
100  $i = rindex($pwd,'/');
101  $subdir = substr($pwd,$i+1,$len - 1);
102  $top_builddir = ".." ; 
103
104  while( -d "$top_builddir" )
105  {
106    if ( -f "${top_builddir}/configure.in" ) 
107    {
108      return $top_builddir ;
109    }
110    $len=$i;
111    $pwd = substr($pwd,0,$len);
112    $i = rindex($pwd,'/');
113    $subdir = substr($pwd,$i+1,$len - 1) . "/$subdir";
114    $top_builddir .= "/.." ; 
115  } ;
116  die "Can't find configure.in\n" ;
117}
118
119find_root();
120
121my @buffer = () ;
122
123sub subst_line
124{
125# substitute obsolete variables
126  if ( /^([^\s]*)[\s]+$/o )
127  { # strip trailing spaces
128    $_ = "$1\n";
129  }
130  if ( /^(.*)MKLIB(.*)$/o )
131  {
132    s/MKLIB/RANLIB/g ;
133  }
134  if ( /^(.*)\$\(INSTINCFLAGS\)(.*)$/o )
135  {
136    s/\$\(INSTINCFLAGS\)/-m 644/g ;
137  }
138  if ( /^(.*)ASM(_FILES|_PIECES|_O_FILES)(.*)$/o )
139  {
140    s/ASM_FILES/S_FILES/g ;
141    s/ASM_PIECES/S_PIECES/g ;
142    s/ASM_O_FILES/S_O_FILES/g ;
143    print STDERR "ASM: $_"  if ( $verbose > 0) ;
144  }
145  if ( /^(.*)MP_PIECES(.*)$/o )
146  { # HACK: this is not always correct
147    s/MP_PIECES/MP_C_PIECES/g ;
148    print STDERR "MP_PIECES: $_"  if ( $verbose > 0 );
149  }
150  if ( /^(.*)\$\(RTEMS_BSP\)(.*)$/o )
151  {
152    s/\$\(RTEMS_BSP\)/\@RTEMS_BSP\@/g ;
153  }
154  if ( /^(.*)\$\(RTEMS_ROOT\)\/mkinstalldirs(.*)$/o )
155  {
156    $_ = "$1\$\(mkinstalldirs\)$2\n" ;
157  }
158  if ( /^(.*)\$\{(.*)_FILES\}(.*)$/o )
159  {
160    $_ = "$1\$\($2_FILES\)$3\n" ;
161  }
162  if ( /^(.*)\$\{(.*)_PIECES\}(.*)$/o )
163  {
164    $_ = "$1\$\($2_PIECES\)$3\n" ;
165  }
166  if ( /^(.*)\$\(PROJECT_ROOT\)\/\@RTEMS_BSP\@\/lib\/include(.*)$/o )
167  {
168    $_ = "$1\$\(PROJECT_INCLUDE\)$2\n" ;
169  }
170  if ( /^(.*)\$\{PROJECT_RELEASE\}(.*)$/o )
171  {
172    $_ = "$1\$\(PROJECT_RELEASE\)$2\n" ;
173  }
174  if ( /^(.*\$\(INSTALL_[A-Z]+\))[\s]+-m[\s]+([54])([0-9][0-9].*)$/o )
175  {
176    my $v = $2 + 2 ;
177    $_ = "$1 -m $v$3\n" ;
178  }
179  if ( /^H_FILES[\s]*=[\s]*\$\(wildcard[\s]+\$\(srcdir\)\/\*\.h\)[\s]*$/o )
180  {
181     my $files =`ls *.h 2>/dev/null`;
182     print STDERR "WARNING: Replacing \"\(wildcard... in $_\n" ;
183     $line = "H_FILES =";
184     @l = split(' ',$files) ;
185     foreach(@l) { $line .= " \$\(srcdir\)/$_"; }
186     $line .= "\n" ;
187     $_ = "$line" ;
188  }
189  if ( /^.*\$\(make\-exe\).*$/o )
190  {
191    $make_exe_seen = 1 ;
192  }
193  if ( /^.*\$\(INSTALL_(DATA|SCRIPT|PROGRAM)\)(.*)$/o )
194  {
195    $install_seen = 1 ;
196  }
197}
198
199{
200# 1st PASS:
201# * Read input file
202# * concatenate multiple lines
203# * Remove obsolete variables
204
205  my @ibuf = () ;
206  my $line = "" ;
207
208  while ( <> )
209  {
210    &subst_line ;
211    if ( /^(#.*)$/o )
212    { # preserve comments
213      $line = "$_" ;
214      push @ibuf, $line ;
215      $line = "" ;
216    }
217    elsif ( /^.*\\$/o )
218    { # multilines
219      chop ;
220      $line .= "$_\\" ;
221    }
222    else
223    {
224      $line .= "$_" ;
225      push @ibuf, $line ;
226      $line = "" ;
227    }
228  }
229  @buffer = @ibuf;
230}
231
232{
233# 2nd PASS:
234# * remove automatically generated lines
235# * process some selected make rules
236  my $line = "" ;
237  my @tbuf = () ;
238  foreach (@buffer)
239  {
240    if ( /^[\t](.*)$/o )
241    { # make rule production
242      my $line = $1 ;
243      tr/\\/ / ;
244      my @l = split(/;/,$_);     
245      foreach (@l)
246      { # try to get installation directories
247        if ( /^.*\$\(mkinstalldirs\).*\s\$\(INSTALLDIRS\)$/o )
248        {
249        }
250        elsif ( /^.*\$\(mkinstalldirs\).*\s([^\s]+)$/o )
251        {
252          push @installdirs, "$1" ;
253        }
254        elsif ( /^.*\$\(INSTALL_CHANGE\).*\s([^\s]+)$/o )
255        {
256          push @installdirs, "$1" ;
257        }
258      }
259      push @tbuf, "§3$line"
260    }
261    elsif ( /^[\s]*\#.*$/o )
262    { # comment
263      push @tbuf, "$_" ;
264    }
265    elsif ( /^[\s]*([A-Z_]*)_FILES[\s]*\=[\s]*(.*)$/o )
266    { # *_FILES = ... Macros
267      if ( /^[\s]*([A-Z_]*_|)(CC|C|EQ|H|I|O|S|X)_FILES[\s]*\=[\s]*(.*)$/o )
268      {
269#        print STDERR "FILES: <$1>--<$2>--<$3>\n" ;
270        my $f = "$1$2_FILES" ;
271        ${"var_$f"}="$3" ;
272        if ( ( $experimental > 0 )
273          and ( ( "$2" eq "C" ) or ( "$2" eq "CC" ) or ( "$2" eq "S" )
274          or ( "$2" eq "I" ) or ( "$2" eq "H" ) ) )
275        {
276          my $p = "$1$2_PIECES" ;
277          if ( not defined ${"var_$p"} )
278          {
279            print STDERR "ADDING $p\n" ;
280            ${"var_$p"} = "" ;
281            push @tbuf, "§4$p\n" ;
282            push @pieces, "$p" ;
283          }
284        }
285        # place a marker
286        push @tbuf, "§4$f\n" ;
287        push @files, "$f" ;
288      }
289      else
290      { # found a bug
291        print STDERR "UNKNOWN _FILES: $_\n" ;
292        my $f = "$1_FILES" ;
293        ${"var_$f"}="$2" ;
294        # place a marker
295        push @tbuf, "§4$f\n" ;
296        push @files, "$f" ;
297      }
298    }
299    elsif ( /^[\s]*([A-Z_]*)_PIECES[\s]*\=[\s]*(.*)$/o )
300    { # *_PIECES = ... Macros
301      if ( /^[\s]*([A-Z][A-Z0-9_]*_|)(CC|C|EQ|H|I|O|S|X|REL)_PIECES[\s]*\=[\s]*(.*)$/o )
302      {
303        my $p = "$1$2_PIECES" ;
304
305        if ( not defined ${"var_$p"} )
306        {
307          ${"var_$p"} = "$3" ;
308          push @tbuf, "§4$p\n" ;
309          push @pieces, "$p" ;
310        }
311        else
312        {
313          ${"var_$p"} .= " $3" ;
314        }
315      }
316      elsif ( /^[\s]*(BSP|CPU|GENERIC)_PIECES[\s]*\=[\s]*(.*)$/o )
317      { # Explicit exceptions from the *_PIECES naming conventions
318        # They should better be replaced in future
319        my $p = "$1_PIECES" ;
320        ${"var_$p"}="$2" ;
321        # place a marker
322        push @tbuf, "§4$p\n" ;
323        push @pieces, "$p" ;
324      }
325      else
326      { # found a bug
327        print STDERR "UNKNOWN _PIECES: $_\n" ;
328        my $p = "$1_PIECES" ;
329        ${"var_$p"}="$2" ;
330        # place a marker
331        push @tbuf, "§4$p\n" ;
332        push @pieces, "$p" ;
333      }
334    }
335    elsif ( /^[\s]*([A-Z_]+)_PIECES_([^\s]+)_V[\s]*\=[\s]*(.*)$/o )
336    { # *_PIECES_.._V = ... Macros
337      if ( /^[\s]*([A-Z][A-Z0-9_]*_|)(CC|C|EQ|H|I|O|S|X|REL)_PIECES_([^\s]+)_V[\s]*\=[\s]*(.*)$/o )
338      {
339        my @l = split(/_/,$3);
340        my $v = "$1$2-$#l" ;
341        if ( not defined @{"variants_$v"} ) { push @variants, "$v" ; }
342
343        my $p = "$1$2_PIECES_$3_V" ;
344        push @{"variants_${v}"}, "$p" ;
345
346        ${"var_$p"}="$4" ;
347        # place a marker
348        push @tbuf, "§4$p\n" ;
349        push @pieces, "$p" ;
350      }
351      else
352      { # found a bug
353        print STDERR "UNKNOWN _PIECES: $_\n" ;
354        my $p = "$1_PIECES" ;
355        ${"var_$p"}="$2" ;
356        # place a marker
357        push @tbuf, "§4$p\n" ;
358        push @pieces, "$p" ;
359      }
360    }
361    elsif ( /^[\s]*([^\s+=]+)[\s]*\=[\s]*(.*)$/o )
362    { # makefile variable
363      if ( ( "$1" eq "subdir" )
364        or ( "$1" eq "top_srcdir" )
365        or ( "$1" eq "top_builddir" )
366        or ( "$1" eq "RTEMS_ROOT" )
367        or ( "$1" eq "PROJECT_ROOT" )
368        or ( "$1" eq "INSTALL" )
369        or ( "$1" eq "PACKHEX" )
370        or ( "$1" eq "INSTALL_CHANGE" )
371        or ( "$1" eq "mkinstalldirs" )
372      )
373      {
374        print STDERR "REMOVE: $1\n" if $verbose ;
375      }
376      elsif ( "$1" eq "srcdir" )
377      { # place marker
378        push @tbuf, "§0\n";
379      }
380      elsif ( "$1" eq "INSTALLDIRS" )
381      { # process the block
382        my $input = $2 ;
383        $input =~ s/\\\\/ /g ;
384        my @l = split(' ',$input);
385        foreach (@l)
386        {
387          if ( /[\s]*([^\s]+)[\s]*$/o )
388          {
389            push @installdirs, "$1" ;
390          }
391        }
392      }
393      else
394      {
395# print STDERR "MACRO: <$1> = <$2>\n";
396        my $p = "$1" ;
397        ${"var_$p"}="$2" ;
398        # place a marker
399        push @tbuf, "§4$p\n" ;
400        push @vars, "$p" ;
401      }
402    }
403    elsif ( /^[\s]*([^\s+=]+)[\s]*\+\=[\s]*(.*)$/o )
404    { # makefile variable addition
405# print STDERR "MACRO: <$1> += <$2>\n";
406        my $p = "$1" ;
407        ${"var_$p+"}="$2" ;
408        # place a marker
409        push @tbuf, "§5$p\n" ;
410        push @vars, "$p+" ;
411    }
412    elsif ( /^[\s]*(\@[^\s]+\@)$/o )
413    { # autoconf variable
414      if ( "$1" eq "\@SET_MAKE\@" )
415      {
416      }
417      else
418      {
419        push @tbuf, "$1\n" ;
420      }
421    }
422    elsif ( /^[\s]*include[\s]+(.*)$/o )
423    { # include line
424      push @tbuf, "$_" ;
425      if ( /^include[\s\t]*.*(directory|leaf|lib)\.cfg.*$/o )
426      {
427        push @tbuf, "§1\n" ;
428        push @tbuf, "PACKHEX = \@PACKHEX\@\n" if ( $make_exe_seen == 1 ) ;
429        push @tbuf, "§2\n" ;
430      }
431    }
432    elsif ( /^[\s]*(ifeq|ifneq|else|endif)[\s]+(.*)$/o )
433    { # gmake conditionals
434      # Most of them are removed, but we still have some :-
435      push @tbuf, "$1 $2\n" ;
436    }
437    elsif ( /^[\s]*([^:]+)[\s]*(:[:]*)[\s]*(.*)$/o )
438    {
439      if ( "$2" eq "::" )
440      {
441        # Warn about "::"-rules
442        # Will be silently removed below.
443        print STDERR "WARNING: Removing \"::\" in RULE $_\n" ;
444      }
445
446      if ( ( "$1" eq "Makefile" )
447        or ( "$1" eq "\$\(INSTALLDIRS\)" ) )
448      { # delete entry
449        shift @buffer ;
450      }
451      elsif ( ( "$1" eq "all" )
452        or    ( "$1" eq "preinstall" ) )
453      {
454        # Note the dependencies
455        # Not yet exploited, but could be useful for dependency
456        # tracking in future
457        if ( defined ${"var_$1"} )
458          { ${"var_$1"} .= " $3" ; }
459        else
460          { ${"var_$1"} = "$3" ; }
461        push @tbuf, "$1: $3\n" ;
462      }
463      else
464      { # make rule
465        push @tbuf, "$1: $3\n" ;
466      }
467    }
468    elsif ( /^[\s]*$/o )
469    { # empty line
470      push @tbuf, "\n" ;
471    }
472    else
473    {
474      die "PASS 2: Unhandled $_" ;
475    }
476  }
477  @buffer = @tbuf ;
478  purge \@installdirs ;
479  purge \@pieces ;
480}
481
482# A fragment to debug conditionals
483#foreach( @variants )
484#{
485#  my $v = $_ ;
486#  print STDERR "VARIANT: $v\n";
487#  foreach (@{"variants_${v}"})
488#  {
489#    print STDERR "* $_\n;" ;
490#  }
491#}
492
493# sanity check on *_FILES macros
494# too fragile for the time being,
495# therefore disabled by default
496if ( $experimental > 1 )
497{
498  foreach( @files )
499  {
500    my $file = "$_" ;
501    my $line = ${"var_$_"} ;
502    $line =~ tr /\\/ /;
503    my @l = split(' ',$line);
504    my @o = () ;
505    foreach (@l)
506    {
507      if ( /^([^\.]+)\.([a-z]+)$/o )
508      {
509        print STDERR "$file: *.$2 in $_\n" ;
510      }
511      elsif ( /^\$\(.*\)$/o )
512      {
513        print STDERR "$file: REF: $_\n" ;
514      }
515      else
516      {
517        print STDERR "$file: UNHANDLED: $_\n" ;
518      }
519    }
520  }
521}
522
523# print STDERR "PASS 2: @buffer" ;
524
525{
526# PASS 3:
527# * output to new Makefile
528# * prettyprint newlines
529
530  my $nl_seen = 0 ;
531  foreach ( @buffer )
532  {
533    if ( /^$/o )
534    {
535      $nl_seen++ ;
536      print "\n" if ( $nl_seen < 2 );
537    }
538    elsif ( /^\§0$/o )
539    {
540      print "\@SET_MAKE\@\n" ;
541      print "srcdir = \@srcdir\@\n" ;
542      print "top_srcdir = \@top_srcdir\@\n" ;
543      print "top_builddir = $top_builddir\n" ;
544      print "subdir = $subdir\n" if "$subdir" ;
545      print "\nRTEMS_ROOT = \@RTEMS_ROOT\@\n" ;
546      print "PROJECT_ROOT = \@PROJECT_ROOT\@\n\n" ;
547      $nl_seen = 1 ;
548    }
549    elsif ( /^\§1$/o )
550    {
551      print "\n" ;
552      print "INSTALL = \@INSTALL\@\n" if ( $install_seen > 0 );
553      print "INSTALL_CHANGE = \@INSTALL_CHANGE\@\n" ;
554      $nl_seen = 0 ;
555    }
556    elsif ( /^\§2$/o )
557    { # Handle installdirs related items
558      if ( $#installdirs >= 0 )
559      {
560        print "mkinstalldirs = \$(SHELL) \$(top_srcdir)/\@RTEMS_TOPdir\@/mkinstalldirs\n\n" ;
561        my $line = join( ' ',@installdirs );
562        print_macro "INSTALLDIRS =", $line ;
563        print "\n\$(INSTALLDIRS):\n\t\@\$(mkinstalldirs) \$(INSTALLDIRS)\n\n" ;
564        $nl_seen = 1 ;
565      }
566    }
567    elsif ( /^\§3(.*)$/o  )
568    { # pretty print a shell script fragment/make production
569      my @l = split(/\\\\/,$1);
570      if ( $#l >= 0 ) { my $i = shift @l ; print "\t$i"; }
571      foreach( @l ) { print "\\\n$_"; }
572      print "\n" ;
573      $nl_seen = 0 ;
574    }
575    elsif ( /^\§4(.*)$/o  )
576    { # pretty print a make variable
577      print_macro "$1 =", ${"var_$1"} ;
578      $nl_seen = 0 ;
579    }
580    elsif ( /^\§5(.*)$/o  )
581    { # pretty print an addition to a make variable
582      print_macro "$1 +=", ${"var_$1+"} ;
583      $nl_seen = 0 ;
584    }
585    else
586    {
587      $nl_seen = 0 ;
588      print "$_" ;
589    }
590  }
591}
592
593# Add rules for config.status generated files
594if ( "$build_pgms_seen" )
595{
596print "%: \$(srcdir)/%.in \$(top_builddir)/config.status\n" ;
597print " cd \$(top_builddir) \\\n" ;
598print "  && CONFIG_FILES=" ;
599print "\$(subdir)/" if ( "$subdir" );
600print "\$@ CONFIG_HEADERS= \$(SHELL) ./config.status\n";
601}
602else
603{
604print "Makefile: \@MAINTAINER_MODE_TRUE\@ \$(srcdir)/Makefile.in \$(top_builddir)/config.status\n" ;
605print " cd \$(top_builddir) \\\n" ;
606print "  && CONFIG_FILES=" ;
607print "\$(subdir)/" if ( "$subdir" );
608print "\$@ CONFIG_HEADERS= \$(SHELL) ./config.status\n";
609}
610
611;1
Note: See TracBrowser for help on using the repository browser.