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

Last change on this file since 29598 was 29598, checked in by Jeremy Symon, 6 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: 4.1 KB
Line 
1package Greenstone::Package::_pacman;
2
3use strict;
4use warnings;
5use utf8;
6use parent 'Greenstone::Package';
7use Digest::MD5;
8
9sub replacement_array {
10 my $self = shift;
11 my $array = shift;
12 return join "\n", @{$array};
13}
14
15sub add_md5 {
16 my $self = shift;
17 my $md5 = Digest::MD5->new;
18 for my $source (@_) {
19 open my $MD5FH, '<', "$self->{output}/$source";
20 binmode $MD5FH;
21 $md5->addfile ($MD5FH);
22 push @{$self->{config}->{SOURCE_SUMS}}, $md5->hexdigest;
23 close $MD5FH
24 }
25}
26
27sub add_sources {
28 my $self = shift;
29 $self->SUPER::add_sources;
30 $self->{config}->{SOURCE_SUMS} = [];
31 $self->add_md5 (@{$self->{config}->{SOURCES}});
32}
33
34sub add_makefile {
35 my $self = shift;
36 $self->SUPER::add_makefile;
37 $self->add_md5 ('Makefile');
38}
39
40sub write_function {
41 my ($self, $name, $out, @lines) = @_;
42 print $out $name, "() {\n";
43 for my $line (@lines) {
44 $self->subst ($line);
45 print $out "\t", $line, "\n";
46 }
47 print $out "}\n\n";
48}
49
50sub add_install {
51 my $self = shift;
52 if (exists $self->{config}->{PRE_INSTALL} or
53 exists $self->{config}->{POST_INSTALL} or
54 exists $self->{config}->{PRE_REMOVE} or
55 exists $self->{config}->{POST_REMOVE}) {
56 my $file = "$self->{output}/$self->{config}->{NAME}.install";
57 print " - $file\n";
58 open my $INSTALL, '>', $file;
59 exists $self->{config}->{PRE_INSTALL} and do {
60 $self->write_function ("pre_install", $INSTALL, @{$self->{config}->{PRE_INSTALL}});
61 $self->write_function ("pre_upgrade", $INSTALL, @{$self->{config}->{PRE_INSTALL}});
62 };
63 exists $self->{config}->{POST_INSTALL} and do {
64 $self->write_function ("post_install", $INSTALL, @{$self->{config}->{POST_INSTALL}});
65 $self->write_function ("post_upgrade", $INSTALL, @{$self->{config}->{POST_INSTALL}});
66 };
67 exists $self->{config}->{PRE_REMOVE} and
68 $self->write_function ("pre_remove", $INSTALL, @{$self->{config}->{PRE_REMOVE}});
69 exists $self->{config}->{POST_REMOVE} and
70 $self->write_function ("post_remove", $INSTALL, @{$self->{config}->{POST_REMOVE}});
71 close $INSTALL;
72 return "install=$file";
73 } else {
74 return "";
75 }
76}
77
78sub add_package_impl {
79 my ($self, $packages) = @_;
80 if (defined $packages) {
81 $self->{config}->{NAME} = '';
82 for my $package (@{$packages}) {
83 $self->{config}->{NAME} .= " $package->{NAME}";
84 }
85 }
86 my $file = "$self->{output}/PKGBUILD";
87 print " - $file\n";
88 open my $PKGBUILD, '>', $file;
89 for my $line (
90 '# Maintainer: %MAINTAINER_NAME% <%MAINTAINER_EMAIL%>',
91 'pkgname=(%NAME%)',
92 'pkgver=%VERSION%',
93 'pkgrel=%RELEASE%',
94 'url=%HOMEPAGE%',
95 'license=%LICENSE_SHORT%',
96 'arch=(any)',
97 'makedepends=(',
98 '%MAKEDEPENDS%',
99 ')',
100 'source=(',
101 '%SOURCES%',
102 ')',
103 'md5sums=(',
104 '%SOURCE_SUMS%',
105 ')',
106 'build() {',
107 ' cd ${srcdir}',
108 ' make build',
109 '}'
110 ) {
111 my $copy = $line;
112 $self->subst ($copy);
113 print $PKGBUILD $copy, "\n";
114 }
115 if (defined $packages) {
116 my $config = $self->{config};
117 for my $package (@{$packages}) {
118 $self->{config} = $package;
119 $self->write_function ("package_$package->{NAME}", $PKGBUILD,
120 'pkgdesc=%DESCRIPTION%',
121 'arch=(\'%ARCHITECTURE%\')',
122 'depends=(',
123 '%DEPENDS%',
124 ')',
125 'optdepends=(',
126 '%OPTDEPENDS%',
127 ')',
128 'provides=(',
129 '%PROVIDES%',
130 ')',
131 $self->add_install,
132 'DESTDIR=${pkgdir} make install_%NAME%',
133 );
134 }
135 $self->{config} = $config;
136 } else {
137 print $PKGBUILD $self->add_install, "\n";
138 $self->write_function ('package', $PKGBUILD, 'DESTDIR=${pkgdir} make install');
139 }
140 close $PKGBUILD;
141}
142
1431;
Note: See TracBrowser for help on using the repository browser.