aboutsummaryrefslogtreecommitdiffstats
path: root/relink_symlinks
blob: 251fb20a8cb78386cc967d5dde102fa8ed1fb89c (plain)
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
#!/usr/bin/perl
# relativize absolute symlinks

use strict;
use File::Find;

sub relativize {
    return unless -l $_;

    my $link = readlink($_);
    return unless $link =~ m{^/};

    $link =~ s{^/}{};
    my $dirname = $File::Find::dir;
    $dirname =~ s/^\Q$ENV{RPM_BUILD_ROOT}\E//;
    $dirname =~ s{/[^/]+}{../}g;

    unlink $_;
    symlink $dirname . $link, $_;
}

die "No build root defined\n" unless $ENV{RPM_BUILD_ROOT};

$ENV{RPM_BUILD_ROOT} =~ s{/$}{};
find(\&relativize, $ENV{RPM_BUILD_ROOT});