Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-12-SP2:GA
openmpi-gnu-ohpc
spec_fix.pl
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File spec_fix.pl of Package openmpi-gnu-ohpc
#! /usr/bin/perl # # Copyright © 2016 Egbert Eich <eich@suse.com> # # Permission to use, copy, modify, distribute, and sell this software and its # documentation for any purpose is hereby granted without fee, provided that # the above copyright notice appear in all copies and that both that copyright # notice and this permission notice appear in supporting documentation, and # that the name of the copyright holders not be used in advertising or # publicity pertaining to distribution of the software without specific, # written prior permission. The copyright holders make no representations # about the suitability of this software for any purpose. It is provided "as # is" without express or implied warranty. # # THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, # INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO # EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, # DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER # TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE # OF THIS SOFTWARE. use File::Find; sub find_spec_in { if (/^\.$/) { return; } elsif (/.*.spec.in/) { push @spec_in_list, ($File::Find::name); } $File::Find::prune = 1; return; } sub fill_rep { my %replacements; my $specfile =""; my $baselibs_template =""; my $specfile_template =""; local $file = shift @_; open (FILE, $file); while ((chop($line = <FILE>))) { if ($line =~ /specfile:\s(.*)/) { $specfile=$1; } elsif ($line =~ /specfile_template:\s(.*)/) { $specfile_template=$1; } elsif ($line =~ /baselib_template:\s(.*)/) { $baselibs_template=$1; } elsif ($line =~ /(^[A-Z_]+)\s(.*)$/) { $replacements{$1} = $2; } } return ( $specfile, $specfile_template, $baselibs_template, %replacements ); } sub replace_line { my $line = shift @_; my $replace = shift @_; local @fields; local $i, $start, $end, $tmp; @fields = split /\@\@/, $line; $outline = $fields[0]; if ( $line =~ /.*\@\@$/ ) { $fields[@fields] = ""; } for ( $i = 1; $i < @fields; $i++ ) { if ((!($i == (@fields - 1)) || ($line =~ /.*\@\@$/)) && ($tmp = $$replace{$fields[$i]})) { $outline .= $tmp . $fields[$i + 1]; $i++; } else { $outline .= "@@" . $fields[$i]; } } $cnt = @fields; return $outline; } sub replace_file { my $infile = shift @_; my $outfile = shift @_; my $replace = shift @_; local $outline; open (INFILE, '<', $infile) or die ("cannot open $infile for reading\n"); open (OUTFILE, '>', $outfile) or die ("cannot open $outfile\n"); while (chop($line = <INFILE>)) { $outline = replace_line ($line, $replace); # print "$outline\n"; print OUTFILE "$outline\n"; } close OUTFILE; } sub check_arg { local $opt = shift @_; local $arg = shift @_; die ("no argument to $opt" ) unless ( $arg ); die ("$opt requires an argument" ) if ( $arg =~ /-.*/ ); } while ( $a = shift @ARGV ) { if ( $a =~ /-r/ || $a =~ /--replacementlist/ ) { $replacementfile = shift @ARGV; check_arg $a, $replacementfile; } elsif ( $a =~ /-s/ || $a =~ /--specfile-template/ ) { $specfile_template = shift @ARGV; check_arg $a, $specfile_template; } elsif ( $a =~ /-b/ || $a =~ /--baselib-template/ ) { $baselibs_template = shift @ARGV; check_arg $a, $baselibs_template; } } if ( !$replacementfile ) { die ("no replacement file specified"); } ($tmp1, $tmp2, $tmp2, %rep) = fill_rep($replacementfile); if ( $tmp1 && !$specfile ) { $specfile = $tmp1; } if ( $tmp2 && !$specfile_template ) { $specfile_template = $tmp2; } if ( $tmp3 && !$baselibs_template ) { $baselibs_template = $tmp3; } if ( !$specfile_template ) { if ( $specfile && -e $specfile . ".spec.in" ) { $specfile_template = $specfile . ".spec.in"; } else { find (\&find_spec_in, './'); if ( @spec_in_list == 1 ) { $specfile_template = @spec_in_list[0]; } elsif ( @spec_in_list > 1 ) { if ( $specfile ) { foreach $tmp (@spec_in_list) { if ( $tmp eq ($specfile . ".in")) { $specfile_template = $tmp; last; } } } } die ("no specfile_template file specified") unless ( $specfile_template ); } } if ( !$specfile ) { if ( $specfile_template =~ /(.+)\.spec\.in/ ) { $specfile = $1 . ".spec"; } else { die ("no specfile file specified"); } } $specfile = replace_line $specfile, \%rep ; ( -e $specfile_template ) || die ("specfile_template doesn't exist\n"); ( $baselibs_template && ! -e $baselibs_template ) && die ("$baselibs_template doesn't exist\n"); print "Specfile template: $specfile_template\n"; print "Writing $specfile\n"; replace_file ($specfile_template, $specfile, \%rep); if ( $baselibs_template ) { print "baselibs.conf template: $baselibs_template"; replace_file ($baselibs_template, baselibs.conf, \%rep); }
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor