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

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

Building for correct architecture for RPM. Kind of. Subpackage architectures don't work due to a flaw in RPM subpackages (see rant in perllib/Greenstone/Package/_rpm.pm for details)

File size: 4.6 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 = "\n";
25 $ret .= "%" . $name . "\n";
26 for my $line (@lines) {
27 $ret .= $line . "\n";
28 }
29 return $ret;
30}
31
32sub add_install {
33 my ($self, $package) = shift;
34 my $suffix = (defined $package ? " $package" : "");
35 my $ret = '';
36 exists $self->{config}->{PRE_INSTALL} and
37 $ret .= write_function "pre$suffix", @{$self->{config}->{PRE_INSTALL}};
38 exists $self->{config}->{POST_INSTALL} and
39 $ret .= write_function "post$suffix", @{$self->{config}->{POST_INSTALL}};
40 exists $self->{config}->{PRE_REMOVE} and
41 $ret .= write_function "preun$suffix", @{$self->{config}->{PRE_INSTALL}};
42 exists $self->{config}->{POST_REMOVE} and
43 $ret .= write_function "postun$suffix", @{$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 {
53 my @optional;
54 scalar(@{$self->{config}->{DEPENDS}}) gt 0 and
55 push @optional, 'Requires: %DEPENDS%';
56 # Cannot set architecture for subpackages because RPM's subpackages
57 # implementation is broken.
58 # Greenstone core gets split into three packages:
59 # - The main web servlets (java classes) - noarch
60 # - The native libraries used by the servlets - native
61 # - The tools for building collections - native
62 # As RPM forces subpackages to inherit their name from a root package,
63 # the main web servlets must be set as the root package
64 # (in order for everything to get the right name).
65 # This means that the root package should be noarch, and the subpackages
66 # must be native.
67 # But this is impossible with RPM (subpackages must be either the same
68 # architecture as the root package, or noarch)
69 # To avoid this until someone fixes RPM into an actual working package
70 # manager, we will just make the core greenstone package pretend to
71 # be native.
72 unless (defined $packages) {
73 $self->{config}->{ARCHITECTURE} eq $self->{config}->{ARCH_ANY} and
74 push @optional, 'BuildArch: %ARCHITECTURE%';
75 }
76 for my $line (
77 'Name: %NAME%',
78 'Version: %VERSION%',
79 'Release: %RELEASE%',
80 'License: %LICENSE_SHORT%',
81 'URL: %HOMEPAGE%',
82 'Source0: %NAME%',
83 'AutoReqProv: no',
84 'BuildRequires: %MAKEDEPENDS%',
85 @optional,
86 'Summary: %DESCRIPTION_SHORT%',
87 '',
88 '%description',
89 '%DESCRIPTION%',
90 '',
91 '%prep',
92 'cp -pr %SOURCE0 .',
93 '',
94 '%build',
95 'cd %NAME%',
96 'make %{?_smp_mflags}',
97 '',
98 '%install',
99 'cd %NAME%',
100 '%make_install',
101 $self->add_install,
102 '%files',
103 '%FILES%',
104 '',
105 ''
106 ) {
107 my $copy = $line;
108 $self->subst ($copy);
109 print $SPEC $copy, "\n";
110 }
111 }
112 if (defined $packages) {
113 my $config = $self->{config};
114 for my $package (@{$packages}) {
115 $self->{config} = $package;
116 my @optional;
117 scalar(@{$self->{config}->{DEPENDS}}) gt 0 and
118 push @optional, 'Requires: %DEPENDS%';
119 for my $line (
120 '%package %NAME%',
121 'Summary: %DESCRIPTION_SHORT%',
122 'AutoReqProv: no',
123 @optional,
124 '',
125 '%description %NAME%',
126 '%DESCRIPTION%',
127 $self->add_install ($package->{NAME}),
128 '%files %NAME%',
129 '%FILES%',
130 '',
131 ''
132 ) {
133 my $copy = $line;
134 $self->subst ($copy);
135 print $SPEC $copy, "\n";
136 }
137 }
138 $self->{config} = $config;
139 }
140 print $SPEC '%changelog', "\n";
141 close $SPEC;
142}
143
1441;
Note: See TracBrowser for help on using the repository browser.