summaryrefslogtreecommitdiffstats
path: root/c/update-tools/acpolish
blob: 485ba2131c861c91efa29c7de8e0cfe639fa5d08 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/perl

#
# Perl script to beautify and enhance RTEMS autoconf Makefile.ins
#
# Reads from stdin and writes to stdout
#
# usage: 
# acpolish <Makefile.in >Makefile.in~
# mv Makefile.in~ Makefile.in
#
# ATTENTION: This file contains embedded tabs

if ( -f "Makefile.am" )
{
  # Refuse to work on autoconfiscated Makefile.ins;
  # redirecting STDOUT to Makefile.in will trash the Makefile.in ;-

  die "acpolish must not be run in autoconfiscated directories" ;
}


my $build_pgms_seen = "" ;
my $top_builddir = "";
my $subdir = "";

sub find_root
{
  $top_builddir = "." ;
  $subdir="";
  my $pwd = `pwd`; chomp $pwd;
  $pwd .= "/" ;
  my $len ;

  if ( -f "configure.in" )  { return $top_builddir ; }
  my $i = rindex($pwd,'/');

  $len = $i;
  $pwd = substr($pwd,0,$len);
  $i = rindex($pwd,'/');
  $subdir = substr($pwd,$i+1,$len - 1);
  $top_builddir = ".." ;  

  while( -d "$top_builddir" ) 
  {
    if ( -f "${top_builddir}/configure.in" )  
    { 
      return $top_builddir ; 
    }
    $len=$i;
    $pwd = substr($pwd,0,$len);
    $i = rindex($pwd,'/');
    $subdir = substr($pwd,$i+1,$len - 1) . "/$subdir";
    $top_builddir .= "/.." ;  
  } ;
  die "Can't find configure.in\n" ;
}

find_root();

my $nl_seen = 0 ;

while( <> )
{ 
  if ( /^[ 	]*$/o )
  {
    $nl_seen = $nl_seen+1;
  }

  if ( /^[ 	]*srcdir[ 	]*=.*$/o ) 
  {
    print "\@SET_MAKE\@\n" ;
    print "$_" ;
    print "top_srcdir = \@top_srcdir\@\n" ; 
    print "top_builddir = $top_builddir\n" ;
    print "subdir = $subdir\n" if "$subdir" ;
    print "\nINSTALL = \@INSTALL\@\n\n";
    print "RTEMS_ROOT = \$(top_srcdir)/\@RTEMS_TOPdir\@\n" ;
    print "PROJECT_ROOT = \@PROJECT_ROOT\@\n\n" ;
    $nl_seen=1;
  }
  elsif ( /^[ 	]*top_srcdir[ 	]*=.*$/o )
  {
    # remove the line 
  }
  elsif ( /^[ 	]*top_builddir[ 	]*=.*$/o )
  {
    # remove the line
  }
  elsif ( /^[ 	]*Makefile:.*/o )
  { # consume the block
    while( <> ) { last if /^[ 	]*$/o ; }
  }
  elsif ( /^[ 	]*%:[ 	]\$\(srcdir\)\/%\.in.*$/o )
  { # consume the block
    while( <> ) { last if /^[ 	]*$/o ; }
  }
  elsif ( /^[ 	]*RTEMS_ROOT[ 	]*=.*$/o )
  {
    # remove the line
  }
  elsif ( /^[ 	]*PROJECT_ROOT[ 	]*=.*$/o )
  {
    # remove the line
  }
  elsif ( /^[ 	]*INSTALL[ 	]*=[ 	]*\@INSTALL\@.*$/o )
  {
    # remove the line
  }
  elsif ( /^[ 	]*subdir[ 	]*=.*$/o )
  {
    # remove the line
  }
  elsif ( /^[ 	]*\@SET_MAKE\@.*$/o )
  {
    # remove the line
  }
  elsif ( /^include[ 	]*.*rtems\.cfg.*$/o )
  {
    # remove the line
  }
  elsif ( /^[ 	]*BUILD_PGMS.*=.*$/o )
  {
    $build_pgms_seen = "true" ;
    print "$_" ;
    $nl_seen=0;
  }
  elsif ( /^[ 	]*$/o )
  {
    print "$_" if $nl_seen < 2 ;
  }
  else
  {
    print "$_" ;
    $nl_seen = 0;
  }
} # while

print "\n" if $nl_seen < 1 ;

# Add rules for config.status generated files
if ( "$build_pgms_seen" )
{
print "%: \$(srcdir)/%.in \$(top_builddir)/config.status\n" ;
print "	cd \$(top_builddir) \\\n" ;
print "	 && CONFIG_FILES=" ;
print "\$(subdir)/" if ( "$subdir" );
print "\$@ CONFIG_HEADERS= \$(SHELL) ./config.status\n";
}
else
{
print "Makefile: \$(srcdir)/Makefile.in \$(top_builddir)/config.status\n" ;
print "	cd \$(top_builddir) \\\n" ;
print "	 && CONFIG_FILES=" ;
print "\$(subdir)/" if ( "$subdir" );
print "\$@ CONFIG_HEADERS= \$(SHELL) ./config.status\n";
}

;1