1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | # |
---|
4 | # Perl script to beautify and enhance RTEMS automake Makefile.ams |
---|
5 | # |
---|
6 | # Reads from stdin and writes to stdout |
---|
7 | # |
---|
8 | # usage: |
---|
9 | # <path-to>/ampolish <Makefile.am >Makefile.am~ |
---|
10 | # mv Makefile.am~ Makefile.am |
---|
11 | # |
---|
12 | # ATTENTION: This file contains embedded tabs |
---|
13 | |
---|
14 | my $subdirs_seen = "" ; |
---|
15 | |
---|
16 | # find a relative up-path to a file $file, starting at directory $pre |
---|
17 | sub find_file |
---|
18 | { |
---|
19 | my $pre = $_[0] ; |
---|
20 | my $file= $_[1] ; |
---|
21 | |
---|
22 | my $top = "." ; |
---|
23 | if (not "$pre") { $pre = "." ; } |
---|
24 | |
---|
25 | for ( $str = "$pre" . "/" . "$top" ; |
---|
26 | ( -d "$str" ) ; |
---|
27 | $str = "$pre" . "/" . "$top" ) |
---|
28 | { |
---|
29 | if ( -f "${str}/${file}" ) |
---|
30 | { |
---|
31 | return $top ; |
---|
32 | } |
---|
33 | if ( "$top" eq "." ) |
---|
34 | { |
---|
35 | $top = ".." ; |
---|
36 | } |
---|
37 | else |
---|
38 | { |
---|
39 | $top .= "/.." ; |
---|
40 | } |
---|
41 | } ; |
---|
42 | die "Can't find file ${file}\n" ; |
---|
43 | } |
---|
44 | |
---|
45 | # find relative up-path to configure.in |
---|
46 | my $rtems_cfg = find_file(".","configure.in"); |
---|
47 | |
---|
48 | # find relative up-path from configure.in to VERSION |
---|
49 | my $rtems_top = find_file("$rtems_cfg","VERSION"); |
---|
50 | |
---|
51 | if ( "$rtems_top" eq "." ) |
---|
52 | { $rtems_top = "" ; } |
---|
53 | else { $rtems_top .= "/" ; } |
---|
54 | |
---|
55 | my $nl_seen = 0 ; |
---|
56 | |
---|
57 | while( <> ) |
---|
58 | { # consume header |
---|
59 | last if ( /^[^#].*$/ ) ; |
---|
60 | print "$_" ; |
---|
61 | } |
---|
62 | |
---|
63 | print "\nAUTOMAKE_OPTIONS = foreign 1.4\n"; |
---|
64 | if ( "$rtems_cfg" eq "." ) |
---|
65 | { |
---|
66 | print "ACLOCAL_AMFLAGS = -I \$(RTEMS_TOPdir)/aclocal\n" |
---|
67 | } |
---|
68 | |
---|
69 | while( <> ) |
---|
70 | { |
---|
71 | if ( /^[\s\t]*$/o ) |
---|
72 | { |
---|
73 | $nl_seen = $nl_seen+1; |
---|
74 | } |
---|
75 | |
---|
76 | if ( /^[\s\t]*AUTOMAKE_OPTIONS.*$/o ) |
---|
77 | { # remove the line |
---|
78 | } |
---|
79 | elsif ( /^[\s\t]*ACLOCAL[\s\t]*=[\s\t]*\@ACLOCAL\@.*$/o ) |
---|
80 | { # remove the line |
---|
81 | } |
---|
82 | elsif ( /^[\s\t]*ACLOCAL_AMFLAGS[\s\t]*=[\s\t]*.*$/o ) |
---|
83 | { # remove the line |
---|
84 | } |
---|
85 | elsif ( /^[\s\t]*include[\s\t]*\$\(top_srcdir\)[\.\/]*automake\/(.*)\.am$/o ) |
---|
86 | { |
---|
87 | if ( "$1" eq "lib" ) |
---|
88 | { |
---|
89 | print "include \$(top_srcdir)/${rtems_top}automake/$1.am\n" ; |
---|
90 | } |
---|
91 | } |
---|
92 | elsif ( /^[\s\t]*include[\s\t]*\$\(RTEMS_ROOT\)\/make\/lib.cfg$/o ) |
---|
93 | { |
---|
94 | print "include \$(top_srcdir)/${rtems_top}automake/lib.am\n" ; |
---|
95 | } |
---|
96 | elsif ( /^[\s\t]*SUBDIRS.*$/o ) |
---|
97 | { |
---|
98 | $subdirs_seen = "yes" ; |
---|
99 | print "$_" ; |
---|
100 | $nl_seen = 0 ; |
---|
101 | } |
---|
102 | elsif ( /^[ ]*$/o ) |
---|
103 | { |
---|
104 | print "$_" if $nl_seen < 2 ; |
---|
105 | } |
---|
106 | else |
---|
107 | { |
---|
108 | print "$_" ; |
---|
109 | $nl_seen = 0; |
---|
110 | } |
---|
111 | } # while |
---|
112 | |
---|
113 | if ( "$subdirs_seen" ) |
---|
114 | { |
---|
115 | print "include \$(top_srcdir)/${rtems_top}automake/subdirs.am\n" ; |
---|
116 | } |
---|
117 | print "include \$(top_srcdir)/${rtems_top}automake/local.am\n" ; |
---|
118 | |
---|
119 | ;1 |
---|