source: main/trunk/package-kits/linux/perllib/Greenstone/Package/_rpm.pm@ 29598

Last change on this file since 29598 was 29598, checked in by Jeremy Symon, 9 years ago

Changed package generators to not use the tmp directory needlessly, and fixed some problems with the debian generator. Still need to test on systems with rpm/apt and fix all the problems.

File size: 2.9 KB
Line 
1package Greenstone::Package::_rpm;
2
3use strict;
4use warnings;
5use utf8;
6use parent 'Greenstone::Package';
7
8sub replacement_array {
9 my $self = shift;
10 my $array = shift;
11 return join ", ", @{$array};
12}
13
14sub 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
22sub 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
33sub add_install {
34 my $self = shift;
35 my $ret = '';
36 exists $self->{config}->{PRE_INSTALL} and
37 $ret .= write_function "pre", @{$self->{config}->{PRE_INSTALL}};
38 exists $self->{config}->{POST_INSTALL} and
39 $ret .= write_function "post", @{$self->{config}->{POST_INSTALL}};
40 exists $self->{config}->{PRE_REMOVE} and
41 $ret .= write_function "preun", @{$self->{config}->{PRE_INSTALL}};
42 exists $self->{config}->{POST_REMOVE} and
43 $ret .= write_function "postun", @{$self->{config}->{POST_INSTALL}};
44 return $ret;
45}
46
47sub add_package_impl {
48 my ($self, $packages) = @_;
49 my $file = "$self->{output}/$self->{config}->{NAME}.spec";
50 print " - $file\n";
51 open my $SPEC, '>', $file;
52 for my $line (
53 'Name: %NAME%',
54 'Version: %VERSION%',
55 'Release: %RELEASE%',
56 'License: %LICENSE_SHORT%',
57 'URL: %HOMEPAGE%',
58 'Source0: %NAME%',
59 'AutoReqProv: no',
60 'BuildRequires: %MAKEDEPENDS%',
61 '',
62 '%prep',
63 'cp -pr %SOURCE0 .',
64 '',
65 '%build',
66 'cd %NAME%',
67 'make %{?_smp_mflags}',
68 '',
69 '%install',
70 'cd %NAME%',
71 '%make_install',
72 '',
73 '%changelog',
74 ''
75 ) {
76 my $copy = $line;
77 $self->subst ($copy);
78 print $SPEC $copy, "\n";
79 }
80 if (defined $packages) {
81 my $config = $self->{config};
82 for my $package (@{$packages}) {
83 $self->{config} = $package;
84 for my $line (
85 '%package %NAME%',
86 '%requires',
87 '%DEPENDS%',
88 '%description',
89 '%DESCRIPTION%',
90 $self->add_install,
91 '%files',
92 '%FILES%'
93 ) {
94 my $copy = $line;
95 $self->subst ($copy);
96 print $SPEC $copy, "\n";
97 }
98 }
99 $self->{config} = $config;
100 } else {
101 for my $line (
102 '%requires',
103 '%DEPENDS%',
104 '%description',
105 '%DESCRIPTION%',
106 $self->add_install,
107 '%files',
108 '%FILES%'
109 ) {
110 my $copy = $line;
111 $self->subst ($copy);
112 print $SPEC $copy, "\n";
113 }
114 }
115 close $SPEC;
116}
117
1181;
Note: See TracBrowser for help on using the repository browser.