summaryrefslogtreecommitdiffstats
path: root/contrib/crossrpms/specstrip
diff options
context:
space:
mode:
authorRalf Corsepius <ralf.corsepius@rtems.org>2006-06-25 03:51:37 +0000
committerRalf Corsepius <ralf.corsepius@rtems.org>2006-06-25 03:51:37 +0000
commitff5bd6310f1150df30b0da3dca2fe8ad61577894 (patch)
treea60839f600ad2fb7ad27a88f80df45ae85e5f16a /contrib/crossrpms/specstrip
parent2006-06-24 Joel Sherrill <joel@OARcorp.com> (diff)
downloadrtems-ff5bd6310f1150df30b0da3dca2fe8ad61577894.tar.bz2
New.
Diffstat (limited to 'contrib/crossrpms/specstrip')
-rwxr-xr-xcontrib/crossrpms/specstrip189
1 files changed, 189 insertions, 0 deletions
diff --git a/contrib/crossrpms/specstrip b/contrib/crossrpms/specstrip
new file mode 100755
index 0000000000..21d680b6c1
--- /dev/null
+++ b/contrib/crossrpms/specstrip
@@ -0,0 +1,189 @@
+#!/usr/bin/perl -w
+
+
+# Helper script to strip unused parts out of crossrpms's rpm.specs
+#
+# Usage: specstrip < infile > outfile
+
+
+# Copyright (C) 2005,2006 Ralf Corsépius, Ulm, Germany,
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# For a copy of the GNU General Public License, visit
+# http://www.gnu.org or write to the Free Software Foundation, Inc.,
+# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+# $Id$
+
+use Getopt::Long;
+
+use strict;
+
+my $sources = 0;
+my $newlib = 0;
+my $infos = 0;
+my $prefix = '/usr';
+
+my $verbose = 0;
+my @languages = ();
+my %options = ();
+
+GetOptions(
+ \%options,
+ 'infos!',
+ 'newlib!',
+ 'languages=s' => \@languages,
+ 'prefix=s' => \$prefix,
+ 'sources!',
+ 'verbose+' => \$verbose
+) or die( "failed to GetOptions" );
+
+if ( defined($options{infos}) )
+{
+ $infos = $options{infos};
+} else {
+ $infos = ( $prefix =~ m/\/opt\/rtems.*/ ) ? 1 : 0;
+}
+
+if ( defined($options{sources}) )
+{
+ $sources = $options{sources};
+} else {
+ $sources = ( $prefix =~ m/\/opt\/rtems.*/ ) ? 0 : 1;
+}
+
+if ( defined($options{newlib}) )
+{
+ $newlib = $options{newlib};
+} else {
+ $newlib = 0;
+}
+
+if ( $verbose ) {
+ print STDERR "SOURCES: $sources\n";
+ print STDERR "INFOS : $infos\n";
+ print STDERR "PREFIX : $prefix\n";
+}
+
+my %langs;
+
+foreach ( split(/,/,join(',',@languages)) ){
+ $langs{$_} = 1;
+}
+
+my @condstack ;
+my @actionstack ;
+
+push @condstack,'<>';
+
+my @npatterns = (
+ "(\"%\{_prefix\}\" (!=|==) \"/usr\")",
+
+ "(%build_cxx)",
+ "(%build_gnat)",
+ "(%build_objc)",
+ "(%build_gcj)",
+ "(%build_libgcj)",
+ "(%build_f95)",
+ "(%build_g77)",
+ "(%build_newlib)",
+ "(%build_infos)"
+);
+
+my @ppatterns = (
+);
+
+push @ppatterns, "(\"%\{_prefix\}\" " . (("$prefix" eq '/usr') ? '!=' : '==' ) . " \"/usr\")";
+
+push @ppatterns, "(%build_gnat " . ( ($langs{gnat}) ? "==" : "!=" ) . " 0)";
+push @ppatterns, "(%build_cxx " . ( ($langs{cxx}) ? "==" : "!=" ) . " 0)";
+push @ppatterns, "(%build_objc " . ( ($langs{objc}) ? "==" : "!=" ) . " 0)";
+push @ppatterns, "(%build_gcj " . ( ($langs{gcj}) ? "==" : "!=" ) . " 0)";
+push @ppatterns, "(%build_libgcj " . ( ($langs{libgcj}) ? "==" : "!=" ) . " 0)";
+push @ppatterns, "(%build_f95 " . ( ($langs{f95}) ? "==" : "!=" ) . " 0)";
+push @ppatterns, "(%build_g77 " . ( ($langs{g77}) ? "==" : "!=" ) . " 0)";
+
+push @ppatterns, "(%build_newlib " . ( ($newlib) ? "==" : "!=" ) . " 0)";
+push @ppatterns, "(%build_infos " . ( ($infos) ? "==" : "!=" ) . " 0)";
+
+my $npat = join('|',@npatterns);
+my $ppat = join('|',@ppatterns);
+
+if ( $verbose > 1 ) {
+ print STDERR "PPAT: ", $ppat, "\n";
+ print STDERR "NPAT: ", $npat, "\n";
+}
+
+my @buffer0 = <> ;
+
+my $buffer1 = join( '', @buffer0 );
+# print STDERR $buffer1;
+
+foreach (split /\n/, $buffer1)
+{
+# print STDERR ">$_<\n";
+}
+# exit 1;
+
+my @buffer2 ;
+foreach (split /\n/, $buffer1)
+{
+ if ( /^%if(os|)\s+(.*)$/ )
+ {
+ push @condstack,"<$2>";
+ if ( $condstack[$#condstack] =~ m/$npat/ ) {
+ # transform unary conditionals into binary conditionals
+ if ( $condstack[$#condstack] =~/.*<(%[a-zA-Z_0-9]+)>.*/ ) {
+ $condstack[$#condstack] = "<$1 != 0>";
+ }
+ } else {
+ push @buffer2, { state => join('',@condstack), line => "$_" };
+ }
+ } elsif ( /^%else.*$/ )
+ {
+ my %ops = (
+ "!=" => "==",
+ "==" => "!="
+ );
+
+ if ( $condstack[$#condstack] =~/.*<(.*) (!=|==) (.*)>.*/ ) {
+ $condstack[$#condstack] = "<$1 " . $ops{$2} . " $3>";
+ if ( $condstack[$#condstack] =~ m/$npat/ ) {
+ } else {
+ push @buffer2, { state => join('',@condstack), line => "$_" };
+ }
+ } else {
+ push @buffer2, { state => join('',@condstack), line => "$_" };
+ }
+ } elsif ( /^%endif.*$/ )
+ {
+ if ( $condstack[$#condstack] =~ m/$npat/ ) {
+ } else {
+ push @buffer2, { state => join('',@condstack), line => "$_" };
+ }
+ pop @condstack;
+ } else {
+ push @buffer2, { state => join('',@condstack), line => "$_" };
+ }
+}
+
+my @buffer3;
+foreach my $i ( @buffer2 )
+{
+# print STDERR $i->{state}, $i->{line}, "\n";
+ if ( $i->{state} =~ m/($ppat)/ ) {
+ } else {
+ push @buffer3, $i->{line}, "\n"
+ }
+}
+
+print STDOUT @buffer3;