Mercurial > forge
view admin/make_rpm @ 12702:29b7963bf748 octave-forge
define typeof() when missing; support for clang compiler added
author | schloegl |
---|---|
date | Tue, 22 Dec 2015 10:28:53 +0000 |
parents | c16f98afec98 |
children |
line wrap: on
line source
#!/usr/bin/env perl # # David Bateman Sep 12 2006 # # Creates a source RPM from an octave package. use strict; use Cwd; use File::Basename; use File::Glob; use Text::Wrap; use FileHandle; my $pkg = shift @ARGV; my $template = shift @ARGV; my $rpmdir = shift @ARGV; my $platform = shift @ARGV; my $tmpdir = "rpm_tmp"; my $rpmdesc = sprintf("%s/DESCRIPTION", $tmpdir); my $old_pwd = cwd(); system ("rm -rf $tmpdir"); mkdir($tmpdir); chdir($tmpdir); system ("tar xpzf $old_pwd/$pkg"); system ("mv */DESCRIPTION ."); my $noarch = "true"; my @srcdir = <*/src>; if (@srcdir) { $noarch = "false"; } chdir($old_pwd); mkdir($rpmdir); mkdir(sprintf("%s/SPECS", $rpmdir)); mkdir(sprintf("%s/SOURCES", $rpmdir)); mkdir(sprintf("%s/SRPMS", $rpmdir)); system(sprintf("cp %s %s/SOURCES", $pkg, $rpmdir)); my %desc = parse_description ($rpmdesc, $pkg); my $spec = sprintf("%s/SPECS/octave_%s.spec", $rpmdir, $desc{"NAME"}); system ("rm -rf $tmpdir"); create_spec ($spec, $template, $noarch, %desc); create_srpm ($spec, $pkg, $rpmdir); sub date { my ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime(); my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); my @weekdays = qw(Sun Mon Tue Wed Thu Fri Sat Sun); my $dstr = sprintf("%s %s %d %d", $weekdays[$dayOfWeek], $months[$month], $dayOfMonth, $yearOffset+1900); return $dstr; } sub create_srpm { # {{{1 my ($spec, # The spec file to write $pkg, # The binary octave package itself $rpmdir # Where the rpm's are built ) = @_; system (sprintf("rpmbuild -bs --define '_topdir %s' %s", $rpmdir, $spec)); } # 1}}} sub create_spec { # {{{1 my ($spec, # The spec file to write $template, # The location of the template $noarch, # Is the package architecture dependent %desc, # The hash of the description file @deps # Array of hashs of the dependencies ) = @_; open (OUT,sprintf(">%s",$spec)) or die "Couldn't open $spec"; open (RPM,$template) or die "Could not open file $template"; while (<RPM>) { while ( /@\w+@/ ) { my $keyword = $_; $keyword =~ s/^.*@(\w*)@.*$/\1/; chomp $keyword; my $key = sprintf("@%s@", $keyword); if (! defined $desc{$keyword} ) { s/$key//; } else { my $value = $desc{$keyword}; s/$key/$value/; } } if ( /^>>REQUIRES<<$/ ) { # Write the additional octave run time dependencies my $depstr = ""; if (defined $desc{"DEPENDS"}) { my @deps = cleanup_depends ($desc{"DEPENDS"}); foreach my $i ( 0 .. $#deps ) { my $hash = $deps[$i]; next if $hash->{"package"} =~ /^octave$/; $depstr = sprintf("%sRequires: octave_%s", $depstr, lc ($hash->{"package"})); if ( $hash->{"version"} !~ /^0.0.0$/ ) { $depstr = sprintf("%s %s %s", $depstr, $hash->{"operator"}, $hash->{"version"}); } $depstr = sprintf("%s\n", $depstr); } } if (defined $desc{"SYSTEMREQUIREMENTS"}) { my @deps = cleanup_depends ($desc{"SYSTEMREQUIREMENTS"}); foreach my $i ( 0 .. $#deps ) { my $hash = $deps[$i]; $depstr = sprintf("%sRequires: %s", $depstr, $hash->{"package"}); if ( $hash->{"version"} !~ /^0.0.0$/ ) { $depstr = sprintf("%s %s %s", $depstr, $hash->{"operator"}, $hash->{"version"}); } $depstr = sprintf("%s\n", $depstr); } } $_ = $depstr; } if ( /^>>BUILDREQUIRES<<$/ ) { # Write the additional build dependencies my $depstr = ""; if (defined $desc{"BUILDREQUIRES"}) { my @deps = cleanup_depends ($desc{"BUILDREQUIRES"}); foreach my $i ( 0 .. $#deps ) { my $hash = $deps[$i]; $depstr = sprintf("%sBuildRequires: %s", $depstr, $hash->{"package"}); if ( $hash->{"version"} !~ /^0.0.0$/ ) { $depstr = sprintf("%s %s %s", $depstr, $hash->{"operator"}, $hash->{"version"}); } $depstr = sprintf("%s\n", $depstr); } } $_ = $depstr; } if ( /^>>BUILDARCH<<$/ ) { if ($noarch =~ /true/) { $_ = "BuildArch: noarch\n"; } else { $_ = ""; } } if ( /^>>BUILD<<$/ ) { if ($noarch =~ /true/) { $_ = "%build\n"; } else { $_ = "%build\nunset TERM\n%configure\nmake TMPDIR=%{_tmppath} DESTDIR=%{buildroot} DISTPKG=%{octave_distpkg}\n"; } } if ( /^>>INSTALL<<$/ ) { if ($noarch =~ /true/) { $_ = "make install PACKAGE=%{SOURCE0} TMPDIR=%{_tmppath} DESTDIR=%{buildroot} DISTPKG=%{octave_distpkg}"; } else { $_ = "make install TMPDIR=%{_tmppath} DESTDIR=%{buildroot} DISTPKG=%{octave_distpkg}"; } } if ( /^>>ARCHFILES<<$/ ) { if ($noarch =~ /true/) { $_ = ""; } else { $_ = "%{_libexecdir}/octave/packages/*\n"; } } print OUT sprintf("%s", $_); } close (OUT); close (RPM); } # 1}}} sub parse_description { # {{{1 my ($rpmdesc, # The package description file $pkg # The binary octave package itself ) = @_; my %desc = (); open(DESC,$rpmdesc) or die "Could not open file $rpmdesc\n"; my $keyword = ""; while (<DESC>) { # Comments next if /^#/; if ( /^\s+/ ) { # Continuation line if ( $keyword !~ /^$/ && defined $desc{$keyword}) { chomp; s/^\s*//; if ($keyword =~ /(DEPENDS|SYSTEMREQUIREMENTS|BUILDREQUIRES)/) { $desc{$keyword} = sprintf("%s,%s", $desc{$keyword}, $_); } else { $desc{$keyword} = sprintf("%s %s", $desc{$keyword}, $_); } } } else { # Keyword/value pair $keyword = $_; $keyword =~ s/^\s*(\w+)\s*:.*$/\1/; chomp $keyword; my $value = $_; $value =~ s/^\s*\w+\s*:\s*(.*)$/\1/; chomp $value; if ( $keyword !~ /^$/ ) { $keyword = uc $keyword; # Convert to uppercase if (exists $desc{$keyword}) { if ($keyword =~ /(DEPENDS|SYSTEMREQUIREMENTS|BUILDREQUIRES)/) { $desc{$keyword} = sprintf("%s,%s", $desc{$keyword}, $value); } else { $desc{$keyword} = sprintf("%s %s", $desc{$keyword}, $value); } } else { $desc{$keyword} = $value; } } } } close (DESC); # Do the cleanup that is needed $desc{"NAME"} = lc $desc{"NAME"}; # Name must be lower-case $desc{"NAME"} =~ s/\s*$//; # Name must not have trailing white spaces # There are two special keywords that must be set $desc{"DATE"} = date(); $pkg =~ s/^.*\///; # Remove main/, extra/, etc from package $desc{"PACKAGE"} = $pkg; return %desc; } # 1}}} sub cleanup_depends { # {{{1 my ($depstr, # The string with the dependencies ) = @_; my @deps = (); foreach my $d ( split (/,/,$depstr) ) { my $hash; # Is there a platform specific depends? if ($d =~ /^.*\[[\w\s]*$platform[\w\s]*\]/i) { $d =~ s/^.*\[[\w\s]*$platform[\w\s]*\]//i; } $d =~ s/^(.*?)\[.*$/\1/; my $p = $d; $p =~ s/^\s*([_-\w\.]*).*$/\1/; $hash->{"package"} = $p; if ($d =~ /^.*\(\s*[<>=]+\s*(.*)\).*$/) { my $o = $d; $o =~ s/^.*\(\s*([<>=]+).*$/\1/; $o =~ s/==/=/; $hash->{"operator"} = $o; my $v = $d; $v =~ s/^.*\(\s*[<>=]+\s*(.*)\).*$/\1/; $hash->{"version"} = $v; } else { $hash->{"operator"} = "="; $hash->{"version"} = "0.0.0"; } push @deps, $hash; } return @deps; } # 1}}} __END__ 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. You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>. This program is granted to the public domain. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.