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

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

Changes to get Ubuntu working.

File size: 3.0 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 ''
95 ) {
96 my $copy = $line;
97 $self->subst ($copy);
98 print $SPEC $copy, "\n";
99 }
100 }
101 $self->{config} = $config;
102 } else {
103 for my $line (
104 '%requires',
105 '%DEPENDS%',
106 '%description',
107 '%DESCRIPTION%',
108 $self->add_install,
109 '%files',
110 '%FILES%'
111 ) {
112 my $copy = $line;
113 $self->subst ($copy);
114 print $SPEC $copy, "\n";
115 }
116 }
117 close $SPEC;
118}
119
1201;
Note: See TracBrowser for help on using the repository browser.