File: dh_lua

package info (click to toggle)
dh-lua 35
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 228 kB
  • sloc: ansic: 110; perl: 93; sh: 57; makefile: 56
file content (114 lines) | stat: -rwxr-xr-x 2,531 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/perl -w

# Copyright © 2012 Enrico Tassi <gareuselesinge@debian.org>
# Heavily based on dh_linktree, 
#   Copyright © 2011-2012 Raphaël Hertzog <hertzog@debian.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This package is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

=head1 NAME

dh_lua - postprocess a lua package

=cut

use strict;
use File::Find::Rule;
use File::Compare;
use Debian::Debhelper::Dh_Lib;
use Dpkg::IPC;

=head1 SYNOPSIS

B<dh_lua> [S<I<debhelper options>>]

=head1 DESCRIPTION

B<dh_lua> is a debhelper program that postprocesses the package build
directories. It performs the following actions:

=over 4

=item deduplication

Files in /usr/share/lua/5.Y/ that are copies of files in /usr/share/lua/5.X/,
where X is the lowest Lua interpreter version the package supports and Y>X,
are replaced by symlinks.

=back

=cut

init();


sub mklfn {
  my ($base, $version, $path) = @_;
  return "$base/usr/share/lua/$version/$path";
}

sub mklrel {
  my ($base,$version, $path) = @_;
  $path=~s:^$base/usr/share/lua/$version/::;
  return $path;
}

sub mklorig {
  my ($path, $ver) = @_;
  my @pieces=split(m:/+:,$path);
  my $res="../";
  for (1..$#pieces) {
    $res.="../";
  }
  $res.="5.$ver/$path";
  return $res;
}

foreach my $package (@{$dh{DOPACKAGES}}) {
  my $tmp=tmpdir($package);

  my $minver=0;
  my @srclinks=();
  foreach my $ver (1..9) {
    if (-d mklfn($tmp,"5.$ver","")) {
      @srclinks = File::Find::Rule->name('*.lua')->in(mklfn($tmp,"5.$ver",""));
      $minver = $ver;
      last;
    }
  }

  while (@srclinks) {
    my $src=shift @srclinks;
    my $what=mklrel($tmp,"5.$minver",$src);
    foreach my $ver (($minver+1)..9) {
      my $dest=mklfn($tmp,"5.$ver",$what);
      if (compare($src, $dest) == 0) {
	print "deduplicating $what\n";
	doit("ln","-sf", mklorig($what,$minver), $dest);
      }
    }
  }
}

=head1 SEE ALSO

L<debhelper(7)>

This program is a part of debhelper.

=head1 AUTHOR

Enrico Tassi <gareuselesinge@debian.org>

=cut