~ubuntu-branches/debian/stretch/ccache/stretch

« back to all changes in this revision

Viewing changes to debian/update-ccache-symlinks

  • Committer: Bazaar Package Importer
  • Author(s): Joel Rosdahl
  • Date: 2010-12-02 21:05:17 UTC
  • mfrom: (5.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20101202210517-ji5owl2qa3s5c1rg
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
use strict;
 
4
use warnings FATAL => "all";
 
5
 
 
6
my $ccache_dir = "/usr/lib/ccache";
 
7
my $gcc_dir = "/usr/lib/gcc";
 
8
my %old_symlinks; # Current compiler names in /usr/lib/ccache
 
9
my %new_symlinks; # Compiler names that should be in /usr/lib/ccache
 
10
my @standard_names = qw(cc c++);
 
11
 
 
12
sub consider {
 
13
    my ($name) = @_;
 
14
    if (-x "/usr/bin/$name") {
 
15
        $new_symlinks{$name} = 1;
 
16
    }
 
17
}
 
18
 
 
19
sub consider_gcc {
 
20
    my ($prefix, $suffix) = @_;
 
21
    consider "${prefix}gcc${suffix}";
 
22
    consider "${prefix}g++${suffix}";
 
23
}
 
24
 
 
25
# Find existing standard compiler names.
 
26
foreach (@standard_names) {
 
27
    consider $_;
 
28
}
 
29
 
 
30
# Find existing GCC variants.
 
31
consider_gcc "", "";
 
32
consider_gcc "c89-", "";
 
33
consider_gcc "c99-", "";
 
34
foreach my $dir (<$gcc_dir/*>) {
 
35
    (my $kind = $dir) =~ s|.*/||;
 
36
    consider_gcc "$kind-", "";
 
37
    foreach (<$dir/*>) {
 
38
        if (! -l $_ and -d $_) {
 
39
            s|.*/||;
 
40
            consider_gcc "$kind-", "-$_";
 
41
        }
 
42
    }
 
43
}
 
44
 
 
45
# Find existing symlinks.
 
46
foreach (<$ccache_dir/*>) {
 
47
    if (-l) {
 
48
        s|.*/||;
 
49
        $old_symlinks{$_} = 1;
 
50
    }
 
51
}
 
52
 
 
53
# Remove obsolete symlinks.
 
54
foreach (keys %old_symlinks) {
 
55
    if (! exists $new_symlinks{$_}) {
 
56
        unlink "$ccache_dir/$_";
 
57
    }
 
58
}
 
59
 
 
60
# Add missing symlinks.
 
61
foreach (keys %new_symlinks) {
 
62
    if (! exists $old_symlinks{$_}) {
 
63
        symlink "../../bin/ccache", "$ccache_dir/$_";
 
64
    }
 
65
}