package Greenstone::Package::_rpm; use strict; use warnings; use utf8; use parent 'Greenstone::Package'; sub replacement_array { my $self = shift; my $array = shift; return join ", ", @{$array}; } sub replacement { my ($self, $var) = @_; if ($var eq 'FILES') { return join "\n", @{$self->{config}->{$var}}; } return $self->SUPER::replacement ($var); } sub write_function { my ($name, @lines) = @_; my $ret = ""; $ret .= "%" . $name . "\n"; for my $line (@lines) { $ret .= $line . "\n"; } $ret .= "\n"; return $ret; } sub add_install { my $self = shift; my $ret = ''; exists $self->{config}->{PRE_INSTALL} and $ret .= write_function "pre", @{$self->{config}->{PRE_INSTALL}}; exists $self->{config}->{POST_INSTALL} and $ret .= write_function "post", @{$self->{config}->{POST_INSTALL}}; exists $self->{config}->{PRE_REMOVE} and $ret .= write_function "preun", @{$self->{config}->{PRE_INSTALL}}; exists $self->{config}->{POST_REMOVE} and $ret .= write_function "postun", @{$self->{config}->{POST_INSTALL}}; return $ret; } sub add_package_impl { my ($self, $packages) = @_; my $file = "$self->{output}/$self->{config}->{NAME}.spec"; print " - $file\n"; open my $SPEC, '>', $file; for my $line ( 'Name: %NAME%', 'Version: %VERSION%', 'Release: %RELEASE%', 'License: %LICENSE_SHORT%', 'URL: %HOMEPAGE%', 'Source0: %NAME%', 'AutoReqProv: no', 'BuildRequires: %MAKEDEPENDS%', '', '%prep', 'cp -pr %SOURCE0 .', '', '%build', 'cd %NAME%', 'make %{?_smp_mflags}', '', '%install', 'cd %NAME%', '%make_install', '', '%changelog', '' ) { my $copy = $line; $self->subst ($copy); print $SPEC $copy, "\n"; } if (defined $packages) { my $config = $self->{config}; for my $package (@{$packages}) { $self->{config} = $package; for my $line ( '%package %NAME%', '%requires', '%DEPENDS%', '%description', '%DESCRIPTION%', $self->add_install, '%files', '%FILES%' ) { my $copy = $line; $self->subst ($copy); print $SPEC $copy, "\n"; } } $self->{config} = $config; } else { for my $line ( '%requires', '%DEPENDS%', '%description', '%DESCRIPTION%', $self->add_install, '%files', '%FILES%' ) { my $copy = $line; $self->subst ($copy); print $SPEC $copy, "\n"; } } close $SPEC; } 1;