1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | # |
---|
4 | # Perl script to beautify and enhance RTEMS autoconf Makefile.ins |
---|
5 | # |
---|
6 | # Reads from stdin and writes to stdout |
---|
7 | # |
---|
8 | # usage: |
---|
9 | # acpolish <Makefile.in >Makefile.in~ |
---|
10 | # mv Makefile.in~ Makefile.in |
---|
11 | # |
---|
12 | # ATTENTION: This file contains embedded tabs |
---|
13 | |
---|
14 | if ( -f "Makefile.am" ) |
---|
15 | { |
---|
16 | # Refuse to work on autoconfiscated Makefile.ins; |
---|
17 | # redirecting STDOUT to Makefile.in will trash the Makefile.in ;- |
---|
18 | |
---|
19 | die "acpolish must not be run in autoconfiscated directories" ; |
---|
20 | } |
---|
21 | |
---|
22 | |
---|
23 | my $build_pgms_seen = "" ; |
---|
24 | my $top_builddir = ""; |
---|
25 | my $subdir = ""; |
---|
26 | |
---|
27 | sub find_root |
---|
28 | { |
---|
29 | $top_builddir = "." ; |
---|
30 | $subdir=""; |
---|
31 | my $pwd = `pwd`; chomp $pwd; |
---|
32 | $pwd .= "/" ; |
---|
33 | my $len ; |
---|
34 | |
---|
35 | if ( -f "configure.in" ) { return $top_builddir ; } |
---|
36 | my $i = rindex($pwd,'/'); |
---|
37 | |
---|
38 | $len = $i; |
---|
39 | $pwd = substr($pwd,0,$len); |
---|
40 | $i = rindex($pwd,'/'); |
---|
41 | $subdir = substr($pwd,$i+1,$len - 1); |
---|
42 | $top_builddir = ".." ; |
---|
43 | |
---|
44 | while( -d "$top_builddir" ) |
---|
45 | { |
---|
46 | if ( -f "${top_builddir}/configure.in" ) |
---|
47 | { |
---|
48 | return $top_builddir ; |
---|
49 | } |
---|
50 | $len=$i; |
---|
51 | $pwd = substr($pwd,0,$len); |
---|
52 | $i = rindex($pwd,'/'); |
---|
53 | $subdir = substr($pwd,$i+1,$len - 1) . "/$subdir"; |
---|
54 | $top_builddir .= "/.." ; |
---|
55 | } ; |
---|
56 | die "Can't find configure.in\n" ; |
---|
57 | } |
---|
58 | |
---|
59 | find_root(); |
---|
60 | |
---|
61 | my $nl_seen = 0 ; |
---|
62 | |
---|
63 | while( <> ) |
---|
64 | { |
---|
65 | if ( /^[ ]*$/o ) |
---|
66 | { |
---|
67 | $nl_seen = $nl_seen+1; |
---|
68 | } |
---|
69 | |
---|
70 | if ( /^(.*)\$\(RTEMS_BSP\)(.*)$/o ) |
---|
71 | { |
---|
72 | $_ = "$1\$\{RTEMS_BSP\}$2\n" ; |
---|
73 | } |
---|
74 | |
---|
75 | if ( /^(.*)\$\(PROJECT_ROOT\)\/\$\{RTEMS_BSP\}\/lib\/include(.*)$/o ) |
---|
76 | { |
---|
77 | $_ = "$1\$\(PROJECT_INCLUDE\)$2\n" ; |
---|
78 | } |
---|
79 | |
---|
80 | if ( /^(.*)\$\{PROJECT_RELEASE\}(.*)$/o ) |
---|
81 | { |
---|
82 | $_ = "$1\$\{PROJECT_RELEASE\}$2\n" ; |
---|
83 | } |
---|
84 | |
---|
85 | if ( /^[ ]*srcdir[ ]*=.*$/o ) |
---|
86 | { |
---|
87 | print "\@SET_MAKE\@\n" ; |
---|
88 | print "$_" ; |
---|
89 | print "top_srcdir = \@top_srcdir\@\n" ; |
---|
90 | print "top_builddir = $top_builddir\n" ; |
---|
91 | print "subdir = $subdir\n" if "$subdir" ; |
---|
92 | print "\nINSTALL = \@INSTALL\@\n\n"; |
---|
93 | print "RTEMS_ROOT = \$(top_srcdir)/\@RTEMS_TOPdir\@\n" ; |
---|
94 | print "PROJECT_ROOT = \@PROJECT_ROOT\@\n\n" ; |
---|
95 | $nl_seen=1; |
---|
96 | } |
---|
97 | elsif ( /^[ ]*top_srcdir[ ]*=.*$/o ) |
---|
98 | { |
---|
99 | # remove the line |
---|
100 | } |
---|
101 | elsif ( /^[ ]*top_builddir[ ]*=.*$/o ) |
---|
102 | { |
---|
103 | # remove the line |
---|
104 | } |
---|
105 | elsif ( /^[ ]*Makefile:.*/o ) |
---|
106 | { # consume the block |
---|
107 | while( <> ) { last if /^[ ]*$/o ; } |
---|
108 | } |
---|
109 | elsif ( /^[ ]*%:[ ]\$\(srcdir\)\/%\.in.*$/o ) |
---|
110 | { # consume the block |
---|
111 | while( <> ) { last if /^[ ]*$/o ; } |
---|
112 | } |
---|
113 | elsif ( /^[ ]*RTEMS_ROOT[ ]*=.*$/o ) |
---|
114 | { |
---|
115 | # remove the line |
---|
116 | } |
---|
117 | elsif ( /^[ ]*PROJECT_ROOT[ ]*=.*$/o ) |
---|
118 | { |
---|
119 | # remove the line |
---|
120 | } |
---|
121 | elsif ( /^[ ]*INSTALL[ ]*=[ ]*\@INSTALL\@.*$/o ) |
---|
122 | { |
---|
123 | # remove the line |
---|
124 | } |
---|
125 | elsif ( /^[ ]*subdir[ ]*=.*$/o ) |
---|
126 | { |
---|
127 | # remove the line |
---|
128 | } |
---|
129 | elsif ( /^[ ]*\@SET_MAKE\@.*$/o ) |
---|
130 | { |
---|
131 | # remove the line |
---|
132 | } |
---|
133 | elsif ( /^include[ ]*.*rtems\.cfg.*$/o ) |
---|
134 | { |
---|
135 | # remove the line |
---|
136 | } |
---|
137 | elsif ( /^[ ]*BUILD_PGMS.*=.*$/o ) |
---|
138 | { |
---|
139 | $build_pgms_seen = "true" ; |
---|
140 | print "$_" ; |
---|
141 | $nl_seen=0; |
---|
142 | } |
---|
143 | elsif ( /^[ ]*$/o ) |
---|
144 | { |
---|
145 | print "$_" if $nl_seen < 2 ; |
---|
146 | } |
---|
147 | else |
---|
148 | { |
---|
149 | print "$_" ; |
---|
150 | $nl_seen = 0; |
---|
151 | } |
---|
152 | } # while |
---|
153 | |
---|
154 | print "\n" if $nl_seen < 1 ; |
---|
155 | |
---|
156 | # Add rules for config.status generated files |
---|
157 | if ( "$build_pgms_seen" ) |
---|
158 | { |
---|
159 | print "%: \$(srcdir)/%.in \$(top_builddir)/config.status\n" ; |
---|
160 | print " cd \$(top_builddir) \\\n" ; |
---|
161 | print " && CONFIG_FILES=" ; |
---|
162 | print "\$(subdir)/" if ( "$subdir" ); |
---|
163 | print "\$@ CONFIG_HEADERS= \$(SHELL) ./config.status\n"; |
---|
164 | } |
---|
165 | else |
---|
166 | { |
---|
167 | print "Makefile: \$(srcdir)/Makefile.in \$(top_builddir)/config.status\n" ; |
---|
168 | print " cd \$(top_builddir) \\\n" ; |
---|
169 | print " && CONFIG_FILES=" ; |
---|
170 | print "\$(subdir)/" if ( "$subdir" ); |
---|
171 | print "\$@ CONFIG_HEADERS= \$(SHELL) ./config.status\n"; |
---|
172 | } |
---|
173 | |
---|
174 | ;1 |
---|