3 # Generate symlinks in debian packages, reading debian/links. The
4 # file contains pairs of files and symlinks.
6 use Debian::Debhelper::Dh_Lib;
9 foreach $PACKAGE (@{$dh{DOPACKAGES}}) {
10 $TMP=tmpdir($PACKAGE);
11 $file=pkgfile($PACKAGE,"links");
15 @links=filearray($file);
18 # Make sure it has pairs of symlinks and destinations. If it
19 # doesn't, $#links will be _odd_ (not even, -- it's zero-based).
20 if (int($#links/2) eq $#links/2) {
21 error("$file lists a link without a destination.");
24 if (($PACKAGE eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) {
28 # Same test as above, including arguments this time.
29 if (int($#links/2) eq $#links/2) {
30 error("parameters list a link without a destination.");
37 # Relivatize src and dest.
41 # Make sure the directory the link will be in exists.
42 $basedir=Debian::Debhelper::Dh_Lib::dirname("$TMP/$dest");
44 doit("install","-d",$basedir);
47 # Policy says that if the link is all within one toplevel
48 # directory, it should be relative. If it's between
49 # top level directories, leave it absolute.
50 @src_dirs=split(m:/+:,$src);
51 @dest_dirs=split(m:/+:,$dest);
52 if ($src_dirs[0] eq $dest_dirs[0]) {
53 # Figure out how much of a path $src and $dest
55 for ($x=0; $x<$#src_dirs && $src_dirs[$x] eq $dest_dirs[$x]; $x++) {}
56 # Build up the new src.
58 for (1..$#dest_dirs - $x) {
61 for ($x .. $#src_dirs) {
62 $src.=$src_dirs[$_]."/";
67 # Make sure it's properly absolute.
71 doit("ln","-sf",$src,"$TMP/$dest");