aboutsummaryrefslogtreecommitdiffstats
path: root/relink_symlinks
blob: 4f8dad4f8e3c905d5fa29a7bd4c6a242c686f933 (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
26
#!/usr/bin/perl
# relativize absolute symlinks

use strict;
use warnings;
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});