]> git.donarmstrong.com Git - debhelper.git/blob - dh_install
New v7 mode, which only has one change from v6, and is the new recommended default.
[debhelper.git] / dh_install
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_install - install files into package build directories
6
7 =cut
8
9 use strict;
10 use File::Find;
11 use Debian::Debhelper::Dh_Lib;
12
13 =head1 SYNOPSIS
14
15 B<dh_install> [B<-X>I<item>] [B<--autodest>] [B<--sourcedir=>I<dir>] [S<I<debhelper options>>] [S<I<file [...] dest>>]
16
17 =head1 DESCRIPTION
18
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.
26
27 Files named debian/package.install list the files to install into each
28 package and the directory they should be installed to. The format is a set
29 of lines, where each line lists a file or files to install, and at the end
30 of the line tells the directory it should be installed in. The name of the
31 files (or directories) to install should be given relative to the current
32 directory, while the installation directory is given relative to the
33 package build directory. You may use wildcards in the names of the files to
34 install (in v3 mode and above).
35
36 This program may be used in one of two ways. If you just have a file or two
37 that the upstream Makefile does not install for you, you can run dh_install
38 on them to move them into place. On the other hand, maybe you have a large
39 package that builds multiple binary packages. You can use the upstream
40 Makefile to install it all into debian/tmp, and then use dh_install to copy
41 directories and files from there into the proper package build directories.
42
43 From debhelper compatability level 7 on, if --sourcedir is not specified,
44 dh_install will install files from debian/tmp if the directory contains the
45 files. Otherwise, it will install files from the current directory.
46
47 =head1 OPTIONS
48
49 =over 4
50
51 =item B<-Xitem>, B<--exclude=item>
52
53 Exclude files that contain "item" anywhere in their filename from
54 being installed.
55
56 =item B<--autodest>
57
58 Guess as the destination directory to install things to. If this is
59 specified, you should not list destination directories in
60 debian/package.install files or on the command line. Instead, dh_install
61 will guess as follows:
62
63 Strip off debian/tmp (or the sourcedir if one is given) from the front of
64 the filename, if it is present, and install into the dirname of the
65 filename. So if the filename is debian/tmp/usr/bin, then that directory
66 will be copied to debian/package/usr/. If the filename is
67 debian/tmp/etc/passwd, it will be copied to debian/package/etc/.
68
69 Note that if you list exactly one filename or wildcard-pattern on a line by
70 itself in a
71 debian/package.install file, with no explicit destination, then dh_install
72 will automatically guess the destination even if this flag is not set.
73
74 =item B<--list-missing>
75
76 This option makes dh_install keep track of the files it installs, and then at
77 the end, compare that list with the files in the source directory. If any of
78 the files (and symlinks) in the source directory were not installed to
79 somewhere, it will warn on stderr about that.
80
81 This may be useful if you have a large package and want to make sure that
82 you don't miss installing newly added files in new upstream releases.
83
84 Note that files that are excluded from being moved via the -X option are not
85 warned about.
86
87 =item B<--fail-missing>
88
89 This option is like --list-missing, except if a file was missed, it will
90 not only list the missing files, but also fail with a nonzero exit code. 
91
92 =item B<--sourcedir=dir>
93
94 Makes all source files be found under dir. If this is specified, it is
95 akin to all the source filenames having "dir/" prepended to them.
96
97 To make dh_install behave like the old dh_movefiles, move your
98 package.files file to package.install and call dh_install with
99 "--sourcedir=debian/tmp" appended to the command. This will
100 approximate dh_movefiles behaviour, except it will copy files instead
101 of moving them.
102
103 =item I<file [...] dest>
104
105 Lists files (or directories) to install and where to install them to.
106 The files will be installed into the first package dh_install acts on.
107
108 =back
109
110 =cut
111
112 init();
113
114 my @installed;
115
116 my $srcdir = '.';
117 $srcdir = $dh{SOURCEDIR}."/" if defined $dh{SOURCEDIR};
118
119 foreach my $package (@{$dh{DOPACKAGES}}) {
120         my $tmp=tmpdir($package);
121         my $file=pkgfile($package,"install");
122
123         my @install;
124         if ($file) {
125                 @install=filedoublearray($file); # no globbing yet
126         }
127         
128         if (($package eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) {
129                 push @install, [@ARGV];
130         }
131
132         # Support for -X flag.
133         my $exclude = '';
134         if ($dh{EXCLUDE_FIND}) {
135                 $exclude = '! \( '.$dh{EXCLUDE_FIND}.' \)';
136         }
137         
138         foreach my $set (@install) {
139                 my $dest;
140                 my $tmpdest=0;
141                 
142                 if (! defined $dh{AUTODEST} && @$set > 1) {
143                         $dest=pop @$set;
144                 }
145
146                 my @filelist;
147                 foreach my $glob (@$set) {
148                         my @found = glob "$srcdir/$glob";
149                         if (! compat(6)) {
150                                 # Fall back to looking in debian/tmp.
151                                 if (! @found || ! -e $found[0]) {
152                                         @found = glob "debian/tmp/$glob";
153                                 }
154                         }
155                         push @filelist, @found;
156                 }
157
158                 if (! compat(4)) { # check added in v5
159                         # glob now, relative to srcdir
160                         if (! @filelist) {
161                                 error("$package missing files (@$set), aborting");
162                         }
163                 }
164                 foreach my $src (@filelist) { 
165                         next if excludefile($src);
166                 
167                         if (! defined $dest) {
168                                 # Guess at destination directory.
169                                 $dest=$src;
170                                 my $strip=$srcdir;
171                                 if ($strip eq '.') {
172                                         $strip = "debian/tmp";
173                                 }
174                                 $dest=~s/^(.*\/)?\Q$strip\E//;
175                                 $dest=dirname($dest);
176                                 $tmpdest=1;
177                         }
178                         
179                         # Make sure the destination directory exists.
180                         if (! -e "$tmp/$dest") {
181                                 doit("install","-d","$tmp/$dest");
182                         }
183
184                         # Keep track of what's installed.
185                         if ($dh{LIST_MISSING} || $dh{FAIL_MISSING}) {
186                                 # Kill any extra slashes. Makes the
187                                 # @installed stuff more robust.
188                                 $src=~y:/:/:s;
189                                 $src=~s:/+$::;
190                                 $src=~s:^(\./)*::;
191                                 push @installed, "\Q$src\E\/.*|\Q$src\E";
192                         }
193                         
194                         if (-d $src && $exclude) {
195                                 my $basename = basename($src);
196                                 my $dir = ($basename eq '.') ? $src : "$src/..";
197                                 my $pwd=`pwd`;
198                                 chomp $pwd;
199                                 complex_doit("cd '$dir' && find '$basename' $exclude \\( -type f -or -type l \\) -exec cp --parents -dp {} $pwd/$tmp/$dest/ \\;");
200                                 # cp is annoying so I need a separate pass
201                                 # just for empty directories
202                                 complex_doit("cd '$dir' && find '$basename' $exclude \\( -type d -and -empty \\) -exec cp --parents -a {} $pwd/$tmp/$dest/ \\;");
203                         }
204                         else {
205                                 doit("cp", "-a", $src, "$tmp/$dest/");
206                         }
207
208                         if ($tmpdest) {
209                                 $dest=undef;
210                         }
211                 }
212         }
213 }
214
215 if ($dh{LIST_MISSING} || $dh{FAIL_MISSING}) {
216         # . as srcdir makes no sense, so this is a special case.
217         if ($srcdir eq '.') {
218                 $srcdir='debian/tmp';
219         }
220         
221         my @missing;
222         my $installed=join("|", @installed);
223         $installed=qr{^($installed)$};
224         find(sub {
225                 -f || -l || return;
226                 $_="$File::Find::dir/$_";
227                 if (! /$installed/ && ! excludefile($_)) {
228                         my $file=$_;
229                         $file=~s/^\Q$srcdir\E\///;
230                         push @missing, $file;
231                 }
232         }, $srcdir);
233         if (@missing) {
234                 warning "$_ exists in $srcdir but is not installed to anywhere" foreach @missing;
235                 if ($dh{FAIL_MISSING}) {
236                         error("missing files, aborting");
237                 }
238         }
239 }
240
241 =head1 EXAMPLE
242
243 Suppose your package's upstream Makefile installs a binary, a man page, and
244 a library into appropriate subdirectories of debian/tmp. You want to put
245 the library into package libfoo, and the rest into package foo. Your rules
246 file will run "dh_install --sourcedir=debian/tmp". Make debian/foo.install
247 contain:
248
249   usr/bin
250   usr/share/man/man1
251
252 While debian/libfoo.install contains:
253
254   usr/lib/libfoo*.so.*
255
256 If you want a libfoo-dev package too, debian/libfoo-dev.install might contain:
257
258   usr/include
259   usr/lib/libfoo*.so
260   usr/share/man/man3
261
262 =head1 LIMITATIONS
263
264 dh_install cannot rename files or directories, it can only install them
265 with the names they already have into wherever you want in the package
266 build tree.
267   
268 =head1 SEE ALSO
269
270 L<debhelper(7)>
271
272 This program is a part of debhelper.
273
274 =head1 AUTHOR
275
276 Joey Hess <joeyh@debian.org>
277
278 =cut