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

Last change on this file since 29595 was 29595, checked in by Jeremy Symon, 6 years ago

Modifying package generation to use sub-packages in order to avoid compiling the same source multiple times. Currently works for Pacman. Needs testing (and fixing) for other package managers.

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 $name = "$self->{config}->{NAME}.install";
57 open my $INSTALL, '>', "/tmp/gspkg.$name";
58 exists $self->{config}->{PRE_INSTALL} and do {
59 $self->write_function ("pre_install", $INSTALL, @{$self->{config}->{PRE_INSTALL}});
60 $self->write_function ("pre_upgrade", $INSTALL, @{$self->{config}->{PRE_INSTALL}});
61 };
62 exists $self->{config}->{POST_INSTALL} and do {
63 $self->write_function ("post_install", $INSTALL, @{$self->{config}->{POST_INSTALL}});
64 $self->write_function ("post_upgrade", $INSTALL, @{$self->{config}->{POST_INSTALL}});
65 };
66 exists $self->{config}->{PRE_REMOVE} and
67 $self->write_function ("pre_remove", $INSTALL, @{$self->{config}->{PRE_REMOVE}});
68 exists $self->{config}->{POST_REMOVE} and
69 $self->write_function ("post_remove", $INSTALL, @{$self->{config}->{POST_REMOVE}});
70 close $INSTALL;
71 $self->add ("/tmp/gspkg.$name", "$self->{output}/$name");
72 return "install=$name";
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 open my $PKGBUILD, '>', "/tmp/gspkg.PKGBUILD";
87 for my $line (
88 '# Maintainer: %MAINTAINER_NAME% <%MAINTAINER_EMAIL%>',
89 'pkgname=(%NAME%)',
90 'pkgver=%VERSION%',
91 'pkgrel=%RELEASE%',
92 'url=%HOMEPAGE%',
93 'license=%LICENSE_SHORT%',
94 'arch=(any)',
95 'makedepends=(',
96 '%MAKEDEPENDS%',
97 ')',
98 'source=(',
99 '%SOURCES%',
100 ')',
101 'md5sums=(',
102 '%SOURCE_SUMS%',
103 ')',
104 'build() {',
105 ' cd ${srcdir}',
106 ' make build',
107 '}'
108 ) {
109 my $copy = $line;
110 $self->subst ($copy);
111 print $PKGBUILD $copy, "\n";
112 }
113 if (defined $packages) {
114 my $config = $self->{config};
115 for my $package (@{$packages}) {
116 $self->{config} = $package;
117 $self->write_function ("package_$package->{NAME}", $PKGBUILD,
118 'pkgdesc=%DESCRIPTION%',
119 'arch=(\'%ARCHITECTURE%\')',
120 'depends=(',
121 '%DEPENDS%',
122 ')',
123 'optdepends=(',
124 '%OPTDEPENDS%',
125 ')',
126 'provides=(',
127 '%PROVIDES%',
128 ')',
129 $self->add_install,
130 'DESTDIR=${pkgdir} make install_%NAME%',
131 );
132 }
133 $self->{config} = $config;
134 } else {
135 print $PKGBUILD $self->add_install, "\n";
136 $self->write_function ('package', $PKGBUILD, 'DESTDIR=${pkgdir} make install');
137 }
138 close $PKGBUILD;
139 $self->add ("/tmp/gspkg.PKGBUILD", "$self->{output}/PKGBUILD");
140}
141
1421;
Note: See TracBrowser for help on using the repository browser.