| 1 |
#!/usr/bin/perl -w |
| 2 |
|
| 3 |
# Copyright © 2012 Enrico Tassi <[email protected]> |
| 4 |
# Heavily based on dh_linktree, |
| 5 |
# Copyright © 2011-2012 Raphaël Hertzog <[email protected]> |
| 6 |
# |
| 7 |
# This program is free software: you can redistribute it and/or modify |
| 8 |
# it under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation, either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# This package is distributed in the hope that it will be useful, |
| 13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
=head1 NAME |
| 21 |
|
| 22 |
dh_lua - postprocess a lua package |
| 23 |
|
| 24 |
=cut |
| 25 |
|
| 26 |
use strict; |
| 27 |
use File::Find::Rule; |
| 28 |
use File::Compare; |
| 29 |
use Debian::Debhelper::Dh_Lib; |
| 30 |
use Dpkg::IPC; |
| 31 |
|
| 32 |
=head1 SYNOPSIS |
| 33 |
|
| 34 |
B<dh_lua> [S<I<debhelper options>>] |
| 35 |
|
| 36 |
=head1 DESCRIPTION |
| 37 |
|
| 38 |
B<dh_lua> is a debhelper program that postprocesses the package build |
| 39 |
directories. It performs the following actions: |
| 40 |
|
| 41 |
=over 4 |
| 42 |
|
| 43 |
=item deduplication |
| 44 |
|
| 45 |
Files in /usr/share/lua/5.Y/ that are copies of files in /usr/share/lua/5.X/, |
| 46 |
where X is the lowest Lua interpreter version the package supports and Y>X, |
| 47 |
are replaced by symlinks. |
| 48 |
|
| 49 |
=back |
| 50 |
|
| 51 |
=cut |
| 52 |
|
| 53 |
init(); |
| 54 |
|
| 55 |
|
| 56 |
sub mklfn { |
| 57 |
my ($base, $version, $path) = @_; |
| 58 |
return "$base/usr/share/lua/$version/$path"; |
| 59 |
} |
| 60 |
|
| 61 |
sub mklrel { |
| 62 |
my ($base,$version, $path) = @_; |
| 63 |
$path=~s:^$base/usr/share/lua/$version/::; |
| 64 |
return $path; |
| 65 |
} |
| 66 |
|
| 67 |
sub mklorig { |
| 68 |
my ($path, $ver) = @_; |
| 69 |
my @pieces=split(m:/+:,$path); |
| 70 |
my $res="../"; |
| 71 |
for (1..$#pieces) { |
| 72 |
$res.="../"; |
| 73 |
} |
| 74 |
$res.="5.$ver/$path"; |
| 75 |
return $res; |
| 76 |
} |
| 77 |
|
| 78 |
foreach my $package (@{$dh{DOPACKAGES}}) { |
| 79 |
my $tmp=tmpdir($package); |
| 80 |
|
| 81 |
my $minver=0; |
| 82 |
my @srclinks=(); |
| 83 |
foreach my $ver (1..9) { |
| 84 |
if (-d mklfn($tmp,"5.$ver","")) { |
| 85 |
@srclinks = File::Find::Rule->name('*.lua')->in(mklfn($tmp,"5.$ver","")); |
| 86 |
$minver = $ver; |
| 87 |
last; |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
while (@srclinks) { |
| 92 |
my $src=shift @srclinks; |
| 93 |
my $what=mklrel($tmp,"5.$minver",$src); |
| 94 |
foreach my $ver (($minver+1)..9) { |
| 95 |
my $dest=mklfn($tmp,"5.$ver",$what); |
| 96 |
if (compare($src, $dest) == 0) { |
| 97 |
print "deduplicating $what\n"; |
| 98 |
doit("ln","-sf", mklorig($what,$minver), $dest); |
| 99 |
} |
| 100 |
} |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
=head1 SEE ALSO |
| 105 |
|
| 106 |
L<debhelper(7)> |
| 107 |
|
| 108 |
This program is a part of debhelper. |
| 109 |
|
| 110 |
=head1 AUTHOR |
| 111 |
|
| 112 |
Enrico Tassi <[email protected]> |
| 113 |
|
| 114 |
=cut |