diff options
author | joey <joey> | 1999-08-17 05:02:07 +0000 |
---|---|---|
committer | joey <joey> | 1999-08-17 05:02:07 +0000 |
commit | 75275ded89f0b456e7e396008af153d26bb35626 (patch) | |
tree | 6cd498453f87dd7f0c091d5aba5af9eeeed929dc /dh_link | |
parent | 0d8d56edc5ad95e9ac110e10b4b3111c5656f958 (diff) | |
download | debhelper-75275ded89f0b456e7e396008af153d26bb35626.tar.gz |
r128: Initial revision
Diffstat (limited to 'dh_link')
-rwxr-xr-x | dh_link | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/dh_link b/dh_link new file mode 100755 index 00000000..8d4c32ad --- /dev/null +++ b/dh_link @@ -0,0 +1,70 @@ +#!/usr/bin/perl -w +# +# Generate symlinks in debian packages, reading debian/links. The +# file contains pairs of files and symlinks. + +BEGIN { push @INC, "debian", "/usr/lib/debhelper" } +use Dh_Lib; +init(); + +foreach $PACKAGE (@{$dh{DOPACKAGES}}) { + $TMP=tmpdir($PACKAGE); + $file=pkgfile($PACKAGE,"links"); + + undef @links; + if ($file) { + @links=filearray($file); + } + + # Make sure it has pairs of symlinks and destinations. If it + # doesn't, $#links will be _odd_ (not even, -- it's zero-based). + if (int($#links/2) eq $#links/2) { + error("$file lists a link without a destination."); + } + + if (($PACKAGE eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) { + push @links, @ARGV; + } + + # Same test as above, including arguments this time. + if (int($#links/2) eq $#links/2) { + error("parameters list a link without a destination."); + } + + # Now I'd prefer to work with a hash. + %links=@links; + + foreach $src (keys %links) { + $dest=$links{$src}; + + # Make sure the directory the link will be in exists. + $basedir=Dh_Lib::dirname("$TMP/$dest"); + if (! -e $basedir) { + doit("install","-d",$basedir); + } + + # Policy says that if the link is all within one toplevel + # directory, it should be relative. If it's between + # top level directories, leave it absolute. + @src_dirs=split(m:/+:,$src); + @dest_dirs=split(m:/+:,$dest); + if ($src_dirs[0] eq $dest_dirs[0]) { + # Figure out how much of a path $src and $dest + # share in common. + for ($x=0; $x<$#src_dirs && $src_dirs[$x] eq $dest_dirs[$x]; $x++) {} + + # Build up the new src. + $src=""; + for (1..$#dest_dirs - $x) { + $src.="../"; + } + # The + 1 is here to include the actual filename. + for (1..$#src_dirs - $x + 1) { + $src.=$src_dirs[$_]."/"; + } + $src=~s:/$::; + } + + doit("ln","-sf",$src,"$TMP/$dest"); + } +} |