source: rtems/contrib/crossrpms/specstrip @ 8747e99a

4.104.114.84.95
Last change on this file since 8747e99a was 8747e99a, checked in by Ralf Corsepius <ralf.corsepius@…>, on 07/20/06 at 05:16:29

Add --enable/disable-infos.

  • Property mode set to 100755
File size: 4.7 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 $sources = 0;
32my $newlib = 0;
33my $infos = 0;
34my $prefix = '/usr';
35
36my $verbose = 0;
37my @languages = ();
38my %options = ();
39
40GetOptions(
41  \%options,
42  'prefix=s' => \$prefix,
43  'enable-infos' => sub { $options{infos} = 1 },
44  'disable-infos' => sub { $options{infos} = 0 },
45  'newlib!',
46  'languages=s' => \@languages,
47  'sources!',
48  'verbose+' => \$verbose
49) or die( "failed to GetOptions" );
50
51if ( !defined($options{infos}) )
52{ # User did not override, use defaults
53  if ( $prefix =~ m/^\/usr$/ ) {
54    $infos = 0;
55  } elsif ( $prefix =~ m/^\/usr\/local$/ ) {
56    $infos = 0;
57  } else {
58    $infos = 1;
59  }
60} else {
61  $infos = int($options{infos});
62}
63
64if ( defined($options{sources}) )
65{
66  $sources = $options{sources};
67} else {
68  $sources = ( $prefix =~ m/\/opt\/rtems.*/ ) ? 0 : 1;
69}
70
71if ( defined($options{newlib}) )
72{
73  $newlib = $options{newlib};
74} else {
75  $newlib = 0;
76}
77
78if ( $verbose ) {
79  print STDERR "SOURCES: $sources\n";
80  print STDERR "INFOS  : $infos\n";
81  print STDERR "PREFIX : $prefix\n";
82}
83
84my %langs;
85
86foreach ( split(/,/,join(',',@languages)) ){
87  $langs{$_} = 1;
88}
89
90my @condstack ;
91my @actionstack ;
92
93push @condstack,'<>';
94
95my @npatterns = (
96  "(\"%\{_prefix\}\" (!=|==) \"/usr\")",
97
98  "(%build_cxx)",
99  "(%build_gnat)",
100  "(%build_objc)",
101  "(%build_gcj)",
102  "(%build_libgcj)",
103  "(%build_f95)",
104  "(%build_g77)",
105  "(%build_newlib)",
106  "(%build_infos)"
107);
108
109my @ppatterns = (
110);
111
112push @ppatterns,  "(\"%\{_prefix\}\" " . (("$prefix" eq '/usr') ? '!=' : '==' ) . " \"/usr\")";
113
114push @ppatterns, "(%build_gnat "   . ( ($langs{gnat}) ? "==" : "!=" ) . " 0)";
115push @ppatterns, "(%build_cxx "    . ( ($langs{cxx}) ? "==" : "!=" ) . " 0)";
116push @ppatterns, "(%build_objc "   . ( ($langs{objc}) ? "==" : "!=" ) . " 0)";
117push @ppatterns, "(%build_gcj "    . ( ($langs{gcj}) ? "==" : "!=" ) . " 0)";
118push @ppatterns, "(%build_libgcj " . ( ($langs{libgcj}) ? "==" : "!=" ) . " 0)";
119push @ppatterns, "(%build_f95 "    . ( ($langs{f95}) ? "==" : "!=" ) . " 0)";
120push @ppatterns, "(%build_g77 "    . ( ($langs{g77}) ? "==" : "!=" ) . " 0)";
121
122push @ppatterns, "(%build_newlib " . ( ($newlib) ? "==" : "!=" ) . " 0)";
123push @ppatterns, "(%build_infos " . ( ($infos) ? "==" : "!=" ) . " 0)";
124
125my $npat = join('|',@npatterns);
126my $ppat = join('|',@ppatterns);
127
128if ( $verbose > 1 ) {
129  print STDERR "PPAT: ", $ppat, "\n";
130  print STDERR "NPAT: ", $npat, "\n";
131}
132
133my @buffer0 = <> ;
134
135my $buffer1 = join( '', @buffer0 );
136
137foreach (split /\n/, $buffer1)
138{
139#  print STDERR ">$_<\n";
140}
141
142my @buffer2 ;
143foreach (split /\n/, $buffer1)
144{
145   if ( /^%if(os|)\s+(.*)$/ )
146   {
147     push @condstack,"<$2>";
148     if ( $condstack[$#condstack] =~ m/$npat/ ) {
149       # transform unary conditionals into binary conditionals
150       if ( $condstack[$#condstack] =~/.*<(%[a-zA-Z_0-9]+)>.*/ ) {
151         $condstack[$#condstack] = "<$1 != 0>";
152       }
153     } else {
154       push @buffer2, { state => join('',@condstack), line => "$_" };
155     }
156   } elsif ( /^%else.*$/ )
157   {
158     my %ops = (
159         "!=" => "==",
160         "==" => "!="
161       );
162
163     if ( $condstack[$#condstack] =~/.*<(.*) (!=|==) (.*)>.*/ ) {
164       $condstack[$#condstack] = "<$1 " .  $ops{$2} . " $3>";
165       if ( $condstack[$#condstack] =~ m/$npat/ ) {
166       } else {
167         push @buffer2, { state => join('',@condstack), line => "$_" };
168       }
169     } else {
170         push @buffer2, { state => join('',@condstack), line => "$_" };
171     }
172   } elsif ( /^%endif.*$/ )
173   {
174     if ( $condstack[$#condstack] =~ m/$npat/ ) {
175     } else {
176       push @buffer2, { state => join('',@condstack), line => "$_" };
177     }
178     pop @condstack;
179   } else {
180     push @buffer2, { state => join('',@condstack), line => "$_" };
181   }
182}
183
184my @buffer3;
185foreach my $i ( @buffer2 )
186{
187#  print STDERR $i->{state}, $i->{line}, "\n";
188  if ( $i->{state} =~ m/($ppat)/ ) {
189  } else {
190    push @buffer3, $i->{line}, "\n"
191  }
192}
193
194print STDOUT @buffer3;
Note: See TracBrowser for help on using the repository browser.