aboutsummaryrefslogtreecommitdiffstats
path: root/relink_symlinks
blob: 5ad5234683e26f2f5381500d65a8326d1a237eeb (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/^$ENV{RPM_BUILD_ROOT}//;
    $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});