source: rtems/contrib/crossrpms/specstrip @ 2d5910f5

4.104.115
Last change on this file since 2d5910f5 was 34a0e1d, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/28/07 at 03:27:30

Remove unused code.

  • Property mode set to 100755
File size: 4.4 KB
Line 
1#!/usr/bin/perl -w
2
3
4# Helper script to strip unused parts out of crossrpms's rpm.specs
5#
6# Usage: specstrip < infile > outfile
7
8
9# Copyright (C) 2005,2006       Ralf Corsépius, Ulm, Germany,
10#
11# This program is free software; you can redistribute it and/or
12# modify it under the terms of the GNU General Public License
13# as published by the Free Software Foundation; either version 2
14# of the License, or (at your option) any later version.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19# GNU General Public License for more details.
20#
21# For a copy of the GNU General Public License, visit
22# http://www.gnu.org or write to the Free Software Foundation, Inc.,
23# 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24
25# $Id$
26
27use Getopt::Long;
28
29use strict;
30
31my $newlib = 0;
32my $infos = 0;
33my $prefix = '/usr';
34
35my $verbose = 0;
36my @languages = ();
37my %options = ();
38
39GetOptions(
40  \%options,
41  'prefix=s' => \$prefix,
42  'enable-infos' => sub { $options{infos} = 1 },
43  'disable-infos' => sub { $options{infos} = 0 },
44  'newlib!',
45  'languages=s' => \@languages,
46  'verbose+' => \$verbose
47) or die( "failed to GetOptions" );
48
49if ( !defined($options{infos}) )
50{ # User did not override, use defaults
51  if ( $prefix =~ m/^\/usr$/ ) {
52    $infos = 0;
53  } elsif ( $prefix =~ m/^\/usr\/local$/ ) {
54    $infos = 0;
55  } else {
56    $infos = 1;
57  }
58} else {
59  $infos = int($options{infos});
60}
61
62if ( defined($options{newlib}) )
63{
64  $newlib = $options{newlib};
65} else {
66  $newlib = 0;
67}
68
69if ( $verbose ) {
70  print STDERR "INFOS  : $infos\n";
71  print STDERR "PREFIX : $prefix\n";
72}
73
74my %langs;
75
76foreach ( split(/,/,join(',',@languages)) ){
77  $langs{$_} = 1;
78}
79
80my @condstack ;
81my @actionstack ;
82
83push @condstack,'<>';
84
85my @npatterns = (
86  "(\"%\{_prefix\}\" (!=|==) \"/usr\")",
87
88  "(%build_cxx)",
89  "(%build_gnat)",
90  "(%build_objc)",
91  "(%build_gcj)",
92  "(%build_libgcj)",
93  "(%build_f95)",
94  "(%build_g77)",
95  "(%build_newlib)",
96  "(%build_infos)"
97);
98
99my @ppatterns = (
100);
101
102push @ppatterns,  "(\"%\{_prefix\}\" " . (("$prefix" eq '/usr') ? '!=' : '==' ) . " \"/usr\")";
103
104push @ppatterns, "(%build_gnat "   . ( ($langs{gnat}) ? "==" : "!=" ) . " 0)";
105push @ppatterns, "(%build_cxx "    . ( ($langs{cxx}) ? "==" : "!=" ) . " 0)";
106push @ppatterns, "(%build_objc "   . ( ($langs{objc}) ? "==" : "!=" ) . " 0)";
107push @ppatterns, "(%build_gcj "    . ( ($langs{gcj}) ? "==" : "!=" ) . " 0)";
108push @ppatterns, "(%build_libgcj " . ( ($langs{libgcj}) ? "==" : "!=" ) . " 0)";
109push @ppatterns, "(%build_f95 "    . ( ($langs{f95}) ? "==" : "!=" ) . " 0)";
110push @ppatterns, "(%build_g77 "    . ( ($langs{g77}) ? "==" : "!=" ) . " 0)";
111
112push @ppatterns, "(%build_newlib " . ( ($newlib) ? "==" : "!=" ) . " 0)";
113push @ppatterns, "(%build_infos " . ( ($infos) ? "==" : "!=" ) . " 0)";
114
115my $npat = join('|',@npatterns);
116my $ppat = join('|',@ppatterns);
117
118if ( $verbose > 1 ) {
119  print STDERR "PPAT: ", $ppat, "\n";
120  print STDERR "NPAT: ", $npat, "\n";
121}
122
123my @buffer0 = <> ;
124
125my @buffer2 ;
126foreach (@buffer0)
127{
128   chomp $_;
129   if ( /^%if(os|)\s+(.*)$/ )
130   {
131     push @condstack,"<$2>";
132     if ( $condstack[$#condstack] =~ m/$npat/ ) {
133       # transform unary conditionals into binary conditionals
134       if ( $condstack[$#condstack] =~/.*<(%[a-zA-Z_0-9]+)>.*/ ) {
135         $condstack[$#condstack] = "<$1 != 0>";
136       }
137     } else {
138       push @buffer2, { state => join('',@condstack), line => "$_" };
139     }
140   } elsif ( /^%else.*$/ )
141   {
142     my %ops = (
143         "!=" => "==",
144         "==" => "!="
145       );
146
147     if ( $condstack[$#condstack] =~/.*<(.*) (!=|==) (.*)>.*/ ) {
148       $condstack[$#condstack] = "<$1 " .  $ops{$2} . " $3>";
149       if ( $condstack[$#condstack] =~ m/$npat/ ) {
150       } else {
151         push @buffer2, { state => join('',@condstack), line => "$_" };
152       }
153     } else {
154         push @buffer2, { state => join('',@condstack), line => "$_" };
155     }
156   } elsif ( /^%endif.*$/ )
157   {
158     if ( $condstack[$#condstack] =~ m/$npat/ ) {
159     } else {
160       push @buffer2, { state => join('',@condstack), line => "$_" };
161     }
162     pop @condstack;
163   } else {
164     push @buffer2, { state => join('',@condstack), line => "$_" };
165   }
166}
167
168my @buffer3;
169foreach my $i ( @buffer2 )
170{
171#  print STDERR $i->{state}, $i->{line}, "\n";
172  if ( $i->{state} =~ m/($ppat)/ ) {
173  } else {
174    push @buffer3, $i->{line}, "\n"
175  }
176}
177
178print STDOUT @buffer3;
Note: See TracBrowser for help on using the repository browser.