source: rtems/contrib/crossrpms/specstrip @ da52805

4.104.114.84.95
Last change on this file since da52805 was da52805, checked in by Ralf Corsepius <ralf.corsepius@…>, on 07/05/06 at 08:22:27

Cosmetics.

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