[29539] | 1 | package Greenstone::Package::_rpm;
|
---|
| 2 |
|
---|
| 3 | use strict;
|
---|
| 4 | use warnings;
|
---|
| 5 | use utf8;
|
---|
| 6 | use parent 'Greenstone::Package';
|
---|
| 7 |
|
---|
| 8 | sub replacement_array {
|
---|
| 9 | my $self = shift;
|
---|
| 10 | my $array = shift;
|
---|
| 11 | return join ", ", @{$array};
|
---|
| 12 | }
|
---|
| 13 |
|
---|
[29559] | 14 | sub replacement {
|
---|
| 15 | my ($self, $var) = @_;
|
---|
| 16 | if ($var eq 'FILES') {
|
---|
| 17 | return join "\n", @{$self->{config}->{$var}};
|
---|
| 18 | }
|
---|
| 19 | return $self->SUPER::replacement ($var);
|
---|
| 20 | }
|
---|
| 21 |
|
---|
[29546] | 22 | sub write_function {
|
---|
| 23 | my ($name, @lines) = @_;
|
---|
| 24 | my $ret = "";
|
---|
| 25 | $ret .= "%" . $name . "\n";
|
---|
| 26 | for my $line (@lines) {
|
---|
| 27 | $ret .= $line . "\n";
|
---|
| 28 | }
|
---|
| 29 | $ret .= "\n";
|
---|
| 30 | return $ret;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | sub add_install {
|
---|
| 34 | my $self = shift;
|
---|
[29595] | 35 | my $ret = '';
|
---|
[29546] | 36 | exists $self->{config}->{PRE_INSTALL} and
|
---|
[29595] | 37 | $ret .= write_function "pre", @{$self->{config}->{PRE_INSTALL}};
|
---|
[29546] | 38 | exists $self->{config}->{POST_INSTALL} and
|
---|
[29595] | 39 | $ret .= write_function "post", @{$self->{config}->{POST_INSTALL}};
|
---|
[29546] | 40 | exists $self->{config}->{PRE_REMOVE} and
|
---|
[29595] | 41 | $ret .= write_function "preun", @{$self->{config}->{PRE_INSTALL}};
|
---|
[29546] | 42 | exists $self->{config}->{POST_REMOVE} and
|
---|
[29595] | 43 | $ret .= write_function "postun", @{$self->{config}->{POST_INSTALL}};
|
---|
| 44 | return $ret;
|
---|
[29546] | 45 | }
|
---|
| 46 |
|
---|
[29595] | 47 | sub add_package_impl {
|
---|
| 48 | my ($self, $packages) = @_;
|
---|
| 49 | open my $SPEC, '>', '/tmp/gspkg.spec';
|
---|
| 50 | for my $line (
|
---|
| 51 | 'Name: %NAME%',
|
---|
| 52 | 'Version: %VERSION%',
|
---|
| 53 | 'Release: %RELEASE%',
|
---|
| 54 | 'License: %LICENSE_SHORT%',
|
---|
| 55 | 'URL: %HOMEPAGE%',
|
---|
| 56 | 'Source0: %NAME%',
|
---|
| 57 | 'AutoReqProv: no',
|
---|
| 58 | 'BuildRequires: %MAKEDEPENDS%',
|
---|
| 59 | '',
|
---|
| 60 | '%prep',
|
---|
| 61 | 'cp -pr %SOURCE0 .',
|
---|
| 62 | '',
|
---|
| 63 | '%build',
|
---|
| 64 | 'cd %NAME%',
|
---|
| 65 | 'make %{?_smp_mflags}',
|
---|
| 66 | '',
|
---|
| 67 | '%install',
|
---|
| 68 | 'cd %NAME%',
|
---|
| 69 | '%make_install',
|
---|
| 70 | '',
|
---|
| 71 | '%changelog',
|
---|
| 72 | ''
|
---|
| 73 | ) {
|
---|
| 74 | my $copy = $line;
|
---|
| 75 | $self->subst ($copy);
|
---|
| 76 | print $SPEC $copy, "\n";
|
---|
| 77 | }
|
---|
| 78 | if (defined $packages) {
|
---|
| 79 | my $config = $self->{config};
|
---|
| 80 | for my $package (@{$packages}) {
|
---|
| 81 | $self->{config} = $package;
|
---|
| 82 | for my $line (
|
---|
| 83 | '%package %NAME%',
|
---|
| 84 | '%requires',
|
---|
| 85 | '%DEPENDS%',
|
---|
| 86 | '%description',
|
---|
| 87 | '%DESCRIPTION%',
|
---|
| 88 | $self->add_install,
|
---|
| 89 | '%files',
|
---|
| 90 | '%FILES%'
|
---|
| 91 | ) {
|
---|
| 92 | my $copy = $line;
|
---|
| 93 | $self->subst ($copy);
|
---|
| 94 | print $SPEC $copy, "\n";
|
---|
| 95 | }
|
---|
| 96 | }
|
---|
| 97 | $self->{config} = $config;
|
---|
| 98 | } else {
|
---|
| 99 | for my $line (
|
---|
| 100 | '%requires',
|
---|
| 101 | '%DEPENDS%',
|
---|
| 102 | '%description',
|
---|
| 103 | '%DESCRIPTION%',
|
---|
| 104 | $self->add_install,
|
---|
| 105 | '%files',
|
---|
| 106 | '%FILES%'
|
---|
| 107 | ) {
|
---|
| 108 | my $copy = $line;
|
---|
| 109 | $self->subst ($copy);
|
---|
| 110 | print $SPEC $copy, "\n";
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
| 113 | close $SPEC;
|
---|
| 114 | $self->add ("/tmp/gspkg.spec", "$self->{output}/$self->{config}->{NAME}.spec");
|
---|
| 115 | }
|
---|
| 116 |
|
---|
[29539] | 117 | 1;
|
---|