1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | # |
---|
4 | # Perl script to beautify and enhance RTEMS configure.in |
---|
5 | # |
---|
6 | # Reads from stdin and writes to stdout |
---|
7 | # |
---|
8 | # usage: |
---|
9 | # acpolish <configure.in >configure.in~ |
---|
10 | # mv configure.in~ configure.in |
---|
11 | # |
---|
12 | |
---|
13 | # $Id$ |
---|
14 | |
---|
15 | use strict ; |
---|
16 | |
---|
17 | my @vars = () ; |
---|
18 | my @buffer = () ; |
---|
19 | |
---|
20 | # find relative up-path to VERSION |
---|
21 | my $rtems_cfg = &find_file(".","VERSION"); |
---|
22 | my $rtems_root = &find_root() ; |
---|
23 | $rtems_root =~ tr/\//\-/ ; |
---|
24 | my $rtems_name = "rtems" ; |
---|
25 | $rtems_name .= "-" . "$rtems_root" if (length($rtems_root) > 0 ) ; |
---|
26 | |
---|
27 | while ( <> ) |
---|
28 | { |
---|
29 | push @buffer, "$_" ; |
---|
30 | } |
---|
31 | |
---|
32 | { |
---|
33 | my @tbuf = () ; |
---|
34 | |
---|
35 | foreach ( @buffer ) |
---|
36 | { |
---|
37 | if ( /^#.*list.*Makefile.*$/o ) {} |
---|
38 | elsif ( /^dnl[\s]+check.*target.*cc.*$/o ) {} |
---|
39 | elsif ( /^[\s]*AC_CONFIG_AUX_DIR\(.*\)[\s]*$/o ) |
---|
40 | { |
---|
41 | push @tbuf, "AC_CONFIG_AUX_DIR($rtems_cfg)\n" ; |
---|
42 | } |
---|
43 | elsif ( /^[\s]*RTEMS_TOP\(.*\)[\s]*$/o ) |
---|
44 | { |
---|
45 | push @tbuf, "RTEMS_TOP($rtems_cfg)\n" ; |
---|
46 | } |
---|
47 | elsif ( /^[\s]*AM_INIT_AUTOMAKE\(.*\)[\s]*$/o ) |
---|
48 | { |
---|
49 | push @tbuf, "AM_INIT_AUTOMAKE($rtems_name,\$RTEMS_VERSION,no)\n" ; |
---|
50 | } |
---|
51 | elsif ( /^[\s]*AC_SUBST\(RTEMS_HAS_POSIX_API\)[\s]*$/o ) |
---|
52 | { |
---|
53 | #remove the line |
---|
54 | } |
---|
55 | elsif ( /^[\s]*AC_SUBST\(RTEMS_HAS_ITRON_API\)[\s]*$/o ) |
---|
56 | { |
---|
57 | #remove the line |
---|
58 | } |
---|
59 | elsif ( /^[\s]*AC_SUBST\(RTEMS_HAS_HWAPI\)[\s]*$/o ) |
---|
60 | { |
---|
61 | #remove the line |
---|
62 | } |
---|
63 | elsif ( /^[\s]*AC_SUBST\(RTEMS_USE_MACROS\)[\s]*$/o ) |
---|
64 | { |
---|
65 | #remove the line |
---|
66 | } |
---|
67 | elsif ( /^[\s]*AC_SUBST\(RTEMS_HAS_MULTIPROCESSING\)[\s]*$/o ) |
---|
68 | { |
---|
69 | #remove the line |
---|
70 | } |
---|
71 | elsif ( /^[\s]*AC_SUBST\(RTEMS_HAS_RDBG\)[\s]*$/o ) |
---|
72 | { |
---|
73 | #remove the line |
---|
74 | } |
---|
75 | elsif ( /^[\s\t]*AC_SUBST\(RTEMS_USE_OWN_PDIR\)[\s]*$/o ) |
---|
76 | { # obsolete option |
---|
77 | #remove the line |
---|
78 | } |
---|
79 | elsif ( /^[\s\t]*RTEMS_ENABLE_GMAKE_PRINT[ ]*$/o ) |
---|
80 | { # obsolete macro |
---|
81 | #remove the line |
---|
82 | } |
---|
83 | elsif ( /^[\s]*AC_SUBST\(RTEMS_HAS_NETWORKING\)[\s]*$/o ) |
---|
84 | { |
---|
85 | #remove the line |
---|
86 | } |
---|
87 | elsif ( /^[\s]*AC_SUBST\(RTEMS_LIBC_DIR\)[\s]*$/o ) |
---|
88 | { |
---|
89 | #remove the line |
---|
90 | } |
---|
91 | elsif ( /^[\s]*AC_SUBST\(PROJECT_ROOT\)[\s]*$/o ) |
---|
92 | { |
---|
93 | #remove the line |
---|
94 | } |
---|
95 | elsif ( /^[\s]*AC_SUBST\(RTEMS_GAS_CODE16\)[\s]*$/o ) |
---|
96 | { |
---|
97 | #remove the line |
---|
98 | } |
---|
99 | elsif ( /^[\s]*PROJECT_ROOT[\s]*=.*$/o ) |
---|
100 | { |
---|
101 | #remove the line |
---|
102 | } |
---|
103 | elsif ( /^[\s]*(RTEMS_ENABLE_LIBCDIR).*$/o ) |
---|
104 | { #remove the line |
---|
105 | &define_variable("$1",""); |
---|
106 | push @tbuf, "$_" ; |
---|
107 | } |
---|
108 | elsif ( /^[\s]*(RTEMS_PROG_CC_FOR_TARGET).*$/o ) |
---|
109 | { |
---|
110 | &define_variable("$1",""); |
---|
111 | push @tbuf, "$_" ; |
---|
112 | } |
---|
113 | elsif ( /^[\s]*(RTEMS_PROG_CXX_FOR_TARGET).*$/o ) |
---|
114 | { |
---|
115 | &define_variable("$1",""); |
---|
116 | push @tbuf, "$_" ; |
---|
117 | } |
---|
118 | else |
---|
119 | { |
---|
120 | push @tbuf, "$_" ; |
---|
121 | } |
---|
122 | } # foreach |
---|
123 | @buffer = @tbuf ; |
---|
124 | } |
---|
125 | |
---|
126 | { |
---|
127 | my @tbuf = () ; |
---|
128 | foreach ( @buffer ) |
---|
129 | { |
---|
130 | if ( /^[\s]*(RTEMS_ENABLE_LIBCDIR).*$/o ) |
---|
131 | { |
---|
132 | if ( ( not defined $main::var_RTEMS_PROG_CC_FOR_TARGET ) |
---|
133 | and ( not defined $main::var_RTEMS_PROG_CXX_FOR_TARGET ) |
---|
134 | ) |
---|
135 | { |
---|
136 | push @tbuf, "$_" ; |
---|
137 | } |
---|
138 | } |
---|
139 | elsif ( /^AC_OUTPUT.*$/o ) |
---|
140 | { |
---|
141 | push @tbuf, "# Explicitly list all Makefiles here\n" ; |
---|
142 | push @tbuf, "$_" ; |
---|
143 | } |
---|
144 | else |
---|
145 | { |
---|
146 | push @tbuf, "$_" ; |
---|
147 | } |
---|
148 | } |
---|
149 | @buffer = @tbuf ; |
---|
150 | } |
---|
151 | |
---|
152 | { ## pretty print |
---|
153 | my $out = join ('',@buffer) ; |
---|
154 | $out =~ s/\s\#\n(\#\n)+/\n/g ; |
---|
155 | $out =~ s/\n\n\#\n\n/\n/g ; |
---|
156 | $out =~ s/\n\n[\n]*/\n\n/g ; |
---|
157 | print $out ; |
---|
158 | } |
---|
159 | |
---|
160 | exit 1 ; |
---|
161 | |
---|
162 | # find a relative up-path to a file $file, starting at directory $pre |
---|
163 | sub find_file($$) |
---|
164 | { |
---|
165 | my $pre = $_[0] ; |
---|
166 | my $file= $_[1] ; |
---|
167 | |
---|
168 | my $top = "." ; |
---|
169 | if (not "$pre") { $pre = "." ; } |
---|
170 | |
---|
171 | for ( my $str = "$pre" . "/" . "$top" ; |
---|
172 | ( -d "$str" ) ; |
---|
173 | $str = "$pre" . "/" . "$top" ) |
---|
174 | { |
---|
175 | if ( -f "${str}/${file}" ) |
---|
176 | { |
---|
177 | return $top ; |
---|
178 | } |
---|
179 | if ( "$top" eq "." ) |
---|
180 | { |
---|
181 | $top = ".." ; |
---|
182 | } |
---|
183 | else |
---|
184 | { |
---|
185 | $top .= "/.." ; |
---|
186 | } |
---|
187 | } ; |
---|
188 | die "Can't find file ${file}\n" ; |
---|
189 | } |
---|
190 | |
---|
191 | sub find_root() |
---|
192 | { |
---|
193 | my $top_builddir = "." ; |
---|
194 | my $subdir=""; |
---|
195 | my $pwd = `pwd`; chomp $pwd; |
---|
196 | $pwd .= "/" ; |
---|
197 | my $len ; |
---|
198 | |
---|
199 | if ( -f "VERSION" ) { return $subdir ; } |
---|
200 | my $i = rindex($pwd,'/'); |
---|
201 | |
---|
202 | $len = $i; |
---|
203 | $pwd = substr($pwd,0,$len); |
---|
204 | $i = rindex($pwd,'/'); |
---|
205 | $subdir = substr($pwd,$i+1,$len - 1); |
---|
206 | $top_builddir = ".." ; |
---|
207 | |
---|
208 | while( -d "$top_builddir" ) |
---|
209 | { |
---|
210 | if ( -f "${top_builddir}/VERSION" ) |
---|
211 | { |
---|
212 | return $subdir ; |
---|
213 | } |
---|
214 | $len=$i; |
---|
215 | $pwd = substr($pwd,0,$len); |
---|
216 | $i = rindex($pwd,'/'); |
---|
217 | $subdir = substr($pwd,$i+1,$len - 1) . "/$subdir"; |
---|
218 | $top_builddir .= "/.." ; |
---|
219 | } ; |
---|
220 | die "Can't find VERSION\n" ; |
---|
221 | } |
---|
222 | |
---|
223 | sub define_variable |
---|
224 | { |
---|
225 | my ($name,$value) = @_ ; |
---|
226 | |
---|
227 | if ( not defined ${"var_$name"} ) |
---|
228 | { |
---|
229 | # print STDERR "DEFINING $name = $value\n" ; |
---|
230 | push @vars, "$name" ; |
---|
231 | ${"var_$name"} = "$value" ; |
---|
232 | } |
---|
233 | else |
---|
234 | { |
---|
235 | # print STDERR "APPENDING <$name> <- <$value>\n" ; |
---|
236 | ${"var_$name"} .= " $value" ; |
---|
237 | } |
---|
238 | } |
---|
239 | |
---|