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