5 dh_link - create symlinks in package build directories
10 use Debian::Debhelper::Dh_Lib;
14 dh_link [debhelper options] [-A] [source destination ...]
18 dh_link is a debhelper program that creates symlinks in package build
21 dh_link accepts a list of pairs of source and destination files. The source
22 files are the already existing files that will be symlinked from. The
23 destination files are the symlinks that will be created. There B<must> be
24 an equal number of source and destination files specified.
26 The list can be specified in two ways. A file named debian/package.links
27 can list pairs of files. If you use this file, you should put each pair
28 of files on its own line, and separate the files within the pair with
29 whitespace. Also, pairs of files can be specified as parameters - these
30 pairs will only be created in the package build directory of the first
31 package dh_link is told to act on. By default, this is the first binary
32 package in debian/control, but if you use -p, -i, or -a flags, it will be
33 the first package specified by those flags.
35 Be sure you B<do> specify the full filename to both the source and
36 destination files (unlike you would do if you were using something like
39 dh_link will generate symlinks that comply with debian policy - absolute
40 when policy says they should be absolute, and relative links with as short
41 a path as possible. It will also create any subdirectories it needs to to put
50 Create any links specified by command line parameters in ALL packages
51 acted on, not just the first.
53 =item I<source destination ...>
55 Create a file named "destination" as a link to a file named "source". Do
56 this in the package build directory of the first package acted on.
57 (Or in all packages if -A is specified.)
63 dh_link usr/share/man/man1/foo.1 usr/share/man/man1/bar.1
65 Make bar.1 be a symlink to foo.1
67 dh_link var/lib/foo usr/lib/foo \
68 usr/X11R6/man/man1/foo.1x usr/share/man/man1/bar.1
70 Make /usr/lib/foo/ be a link to /var/lib/foo/, and bar.1 be a symlink to
77 foreach my $package (@{$dh{DOPACKAGES}}) {
78 my $tmp=tmpdir($package);
79 my $file=pkgfile($package,"links");
83 @links=filearray($file);
86 # Make sure it has pairs of symlinks and destinations. If it
87 # doesn't, $#links will be _odd_ (not even, -- it's zero-based).
88 if (int($#links/2) eq $#links/2) {
89 error("$file lists a link without a destination.");
92 if (($package eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) {
96 # Same test as above, including arguments this time.
97 if (int($#links/2) eq $#links/2) {
98 error("parameters list a link without a destination.");
105 # Relavatize src and dest.
109 # Make sure the directory the link will be in exists.
110 my $basedir=Debian::Debhelper::Dh_Lib::dirname("$tmp/$dest");
112 doit("install","-d",$basedir);
115 # Policy says that if the link is all within one toplevel
116 # directory, it should be relative. If it's between
117 # top level directories, leave it absolute.
118 my @src_dirs=split(m:/+:,$src);
119 my @dest_dirs=split(m:/+:,$dest);
120 if ($src_dirs[0] eq $dest_dirs[0]) {
121 # Figure out how much of a path $src and $dest
124 for ($x=0; $x<$#src_dirs && $src_dirs[$x] eq $dest_dirs[$x]; $x++) {}
125 # Build up the new src.
127 for (1..$#dest_dirs - $x) {
130 for ($x .. $#src_dirs) {
131 $src.=$src_dirs[$_]."/";
136 # Make sure it's properly absolute.
140 doit("ln","-sf",$src,"$tmp/$dest");
148 This program is a part of debhelper.
152 Joey Hess <joeyh@debian.org>