5 dh_install - install files into package build directories
11 use Debian::Debhelper::Dh_Lib;
15 B<dh_install> [B<-X>I<item>] [B<--autodest>] [B<--sourcedir=>I<dir>] [S<I<debhelper options>>] [S<I<file [...] dest>>]
19 dh_install is a debhelper program that handles installing files into package
20 build directories. There are many dh_install* commands that handle installing
21 specific types of files such as documentation, examples, man pages, and so on,
22 and they should be used when possible as they often have extra intelligence for
23 those particular tasks. dh_install, then, is useful for installing everything
24 else, for which no particular intelligence is needed. It is a replacement for
25 the old dh_movefiles command.
27 This program may be used in one of two ways. If you just have a file or two
28 that the upstream Makefile does not install for you, you can run dh_install
29 on them to move them into place. On the other hand, maybe you have a large
30 package that builds multiple binary packages. You can use the upstream
31 Makefile to install it all into debian/tmp, and then use dh_install to copy
32 directories and files from there into the proper package build directories.
34 From debhelper compatibility level 7 on, dh_install will fall back to
35 looking in debian/tmp for files, if it doesn't find them in the current
36 directory (or whereever you've told it to look using --sourcedir).
42 =item debian/I<package>.install
44 List the files to install into each package and the directory they should be
45 installed to. The format is a set of lines, where each line lists a file or
46 files to install, and at the end of the line tells the directory it should be
47 installed in. The name of the files (or directories) to install should be given
48 relative to the current directory, while the installation directory is given
49 relative to the package build directory. You may use wildcards in the names of
50 the files to install (in v3 mode and above).
58 =item B<--list-missing>
60 This option makes dh_install keep track of the files it installs, and then at
61 the end, compare that list with the files in the source directory. If any of
62 the files (and symlinks) in the source directory were not installed to
63 somewhere, it will warn on stderr about that.
65 This may be useful if you have a large package and want to make sure that
66 you don't miss installing newly added files in new upstream releases.
68 Note that files that are excluded from being moved via the -X option are not
71 =item B<--fail-missing>
73 This option is like --list-missing, except if a file was missed, it will
74 not only list the missing files, but also fail with a nonzero exit code.
76 =item B<-Xitem>, B<--exclude=item>
78 Exclude files that contain "item" anywhere in their filename from
81 =item B<--sourcedir=dir>
83 Look in the specified directory for files to be installed.
85 Note that this is not the same as the --sourcedirectory option used
86 by the dh_auto_* commands. You rarely need to use this option, since
87 dh_install automatically looks for files in debian/tmp in debhelper
88 compatibility level 7 and above.
92 Guess as the destination directory to install things to. If this is
93 specified, you should not list destination directories in
94 debian/package.install files or on the command line. Instead, dh_install
95 will guess as follows:
97 Strip off debian/tmp (or the sourcedir if one is given) from the front of
98 the filename, if it is present, and install into the dirname of the
99 filename. So if the filename is debian/tmp/usr/bin, then that directory
100 will be copied to debian/package/usr/. If the filename is
101 debian/tmp/etc/passwd, it will be copied to debian/package/etc/.
103 Note that if you list exactly one filename or wildcard-pattern on a line by
105 debian/package.install file, with no explicit destination, then dh_install
106 will automatically guess the destination even if this flag is not set.
108 =item I<file [...] dest>
110 Lists files (or directories) to install and where to install them to.
111 The files will be installed into the first package dh_install acts on.
118 "autodest" => \$dh{AUTODEST},
119 "list-missing" => \$dh{LIST_MISSING},
120 "fail-missing" => \$dh{FAIL_MISSING},
121 "sourcedir=s" => \$dh{SOURCEDIR},
127 $srcdir = $dh{SOURCEDIR} if defined $dh{SOURCEDIR};
129 foreach my $package (getpackages()) {
130 # Look at the install files for all packages to handle
131 # list-missing/fail-missing, but skip really installing for
132 # packages that are not being acted on.
133 my $skip_install=! grep { $_ eq $package } @{$dh{DOPACKAGES}};
135 my $tmp=tmpdir($package);
136 my $file=pkgfile($package,"install");
140 @install=filedoublearray($file); # no globbing yet
143 if (($package eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) {
144 push @install, [@ARGV];
147 # Support for -X flag.
149 if ($dh{EXCLUDE_FIND}) {
150 $exclude = '! \( '.$dh{EXCLUDE_FIND}.' \)';
153 foreach my $set (@install) {
157 if (! defined $dh{AUTODEST} && @$set > 1) {
162 foreach my $glob (@$set) {
163 my @found = glob "$srcdir/$glob";
165 # Fall back to looking in debian/tmp.
166 if (! @found || ! (-e $found[0] || -l $found[0])) {
167 @found = glob "debian/tmp/$glob";
170 push @filelist, @found;
173 if (! compat(4)) { # check added in v5
174 if (! @filelist && ! $skip_install) {
175 error("$package missing files (@$set), aborting");
179 foreach my $src (@filelist) {
180 next if excludefile($src);
182 push @installed, $src;
183 next if $skip_install;
185 if (! defined $dest) {
186 # Guess at destination directory.
188 $dest=~s/^(.*\/)?\Q$srcdir\E\///;
189 $dest=~s/^(.*\/)?debian\/tmp\///;
190 $dest=dirname("/".$dest);
194 # Make sure the destination directory exists.
195 if (! -e "$tmp/$dest") {
196 doit("install","-d","$tmp/$dest");
199 if (-d $src && $exclude) {
200 my $basename = basename($src);
201 my $dir = ($basename eq '.') ? $src : "$src/..";
204 complex_doit("cd '$dir' && find '$basename' $exclude \\( -type f -or -type l \\) -exec cp --parents -dp {} $pwd/$tmp/$dest/ \\;");
205 # cp is annoying so I need a separate pass
206 # just for empty directories
207 complex_doit("cd '$dir' && find '$basename' $exclude \\( -type d -and -empty \\) -exec cp --parents -a {} $pwd/$tmp/$dest/ \\;");
210 doit("cp", "-a", $src, "$tmp/$dest/");
220 if ($dh{LIST_MISSING} || $dh{FAIL_MISSING}) {
221 # . as srcdir makes no sense, so this is a special case.
222 if ($srcdir eq '.') {
223 $srcdir='debian/tmp';
227 my $installed=join("|", map {
228 # Kill any extra slashes, for robustness.
234 $installed=qr{^($installed)$};
237 $_="$File::Find::dir/$_";
238 if (! /$installed/ && ! excludefile($_)) {
240 $file=~s/^\Q$srcdir\E\///;
241 push @missing, $file;
245 warning "$_ exists in $srcdir but is not installed to anywhere" foreach @missing;
246 if ($dh{FAIL_MISSING}) {
247 error("missing files, aborting");
254 Suppose your package's upstream Makefile installs a binary, a man page, and
255 a library into appropriate subdirectories of debian/tmp. You want to put
256 the library into package libfoo, and the rest into package foo. Your rules
257 file will run "dh_install --sourcedir=debian/tmp". Make debian/foo.install
263 While debian/libfoo.install contains:
267 If you want a libfoo-dev package too, debian/libfoo-dev.install might contain:
275 dh_install cannot rename files or directories, it can only install them
276 with the names they already have into wherever you want in the package
283 This program is a part of debhelper.
287 Joey Hess <joeyh@debian.org>