3 # Copyright (C) 2004-2008, Parrot Foundation.
8 symlink.pl - create a symlink shadow of the Parrot source.
12 # when in directory containing the checked out source in 'trunk'
15 perl ../trunk/tools/dev/symlink.pl
19 Create a symlink tree shadowing the Parrot source tree. Nifty for
20 having just one (read-only) copy of the sources but several different
21 build trees. The -v option displays the created symlinks.
26 - being called with a relative path
27 - being called through a symlink
45 $self = readlink($self) while -l
$self;
47 $self = File
::Spec
->catfile( $cwd, $self )
48 unless File
::Spec
->file_name_is_absolute($self);
50 my $toolsrcdir = dirname
($self);
51 my $toolsrcbase = basename
($self);
55 if ( $toolsrcdir ne '' && -d $toolsrcdir && lc $toolsrcbase eq 'symlink.pl' ) {
56 my $trydir = File::Spec->catdir( 'include', 'parrot' );
57 my $tryfile = File::Spec->catfile( 'src', 'main.c' );
58 die "$0: Do not run this under the original Parrot tree.\n"
59 if ( -d $trydir ) && ( -f $tryfile && !-l $tryfile );
62 die "$0: I am very confused.\n";
65 my @toolsrcdir = File::Spec->splitdir($toolsrcdir);
66 die "$self: not in tools/dev\n"
67 unless @toolsrcdir >= 2
68 && lc( $toolsrcdir[-1] ) eq 'dev'
69 && lc( $toolsrcdir[-2] ) eq 'tools';
70 my @topsrcdir = @toolsrcdir[ 0 .. $#toolsrcdir - 2 ];
71 my $topsrcdir = File::Spec->catdir(@topsrcdir);
72 my $manifest = File::Spec->catfile( $topsrcdir, 'MANIFEST' );
74 if ( open( my $MANIFEST, '<', $manifest ) ) {
80 my @manifile = split( m!/!, $manifile );
81 my $dstfile = File::Spec->catfile(@manifile);
82 my $srcfile = File::Spec->catfile( $topsrcdir, @manifile );
83 unless ( -f $srcfile ) {
84 warn "$self: cannot find $dstfile\n";
87 push @srcfiles, $srcfile;
88 if ( @manifile > 1 ) {
89 for my $i ( 0 .. $#manifile - 1 ) {
90 my $dstdir = File::Spec->catdir( @manifile[ 0 .. $i ] );
91 if ( !-d $dstdir && !$dstdir{$dstdir}++ ) {
92 unless ( mkdir( $dstdir, 0755 ) ) {
93 warn "$self: mkdir $dstdir failed: $!\n";
101 unless ( defined( $readlink = readlink($dstfile) ) ) {
102 warn "$self: readlink $dstfile failed: $!\n";
106 warn "$self: $dstfile exists but is not a symlink\n";
109 if ( !defined $readlink || $readlink ne $srcfile ) {
110 print "$dstfile\n" if $v;
111 if ( defined $readlink ) {
112 unless ( unlink($dstfile) ) {
113 warn "$self: unlink $dstfile failed: $!\n";
116 unless ( symlink( $srcfile, $dstfile ) ) {
117 warn "$self: symlink $srcfile $dstfile failed: $!\n";
122 warn "$self: could not find any files to symlink\n" unless @srcfiles;
126 die "$self: Failed to open $manifest: $!\n";
133 # cperl-indent-level: 4
136 # vim: expandtab shiftwidth=4: