]> git.donarmstrong.com Git - debhelper.git/blob - dh_install
Merge branch 'master' into buildsystems
[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 compatibility level 7 on, dh_install will fall back to
44 looking in debian/tmp for files, if it doesn't find them in the current
45 directory (or whereever you've told it to look using --sourcedir).
46
47 =head1 OPTIONS
48
49 =over 4
50
51 =item B<--autodest>
52
53 Guess as the destination directory to install things to. If this is
54 specified, you should not list destination directories in
55 debian/package.install files or on the command line. Instead, dh_install
56 will guess as follows:
57
58 Strip off debian/tmp (or the sourcedir if one is given) from the front of
59 the filename, if it is present, and install into the dirname of the
60 filename. So if the filename is debian/tmp/usr/bin, then that directory
61 will be copied to debian/package/usr/. If the filename is
62 debian/tmp/etc/passwd, it will be copied to debian/package/etc/.
63
64 Note that if you list exactly one filename or wildcard-pattern on a line by
65 itself in a
66 debian/package.install file, with no explicit destination, then dh_install
67 will automatically guess the destination even if this flag is not set.
68
69 =item B<--fail-missing>
70
71 This option is like --list-missing, except if a file was missed, it will
72 not only list the missing files, but also fail with a nonzero exit code. 
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<--sourcedir=dir>
88
89 Makes all files to be installed be found under dir. If this is
90 specified, it is akin to all the filenames having "dir/" prepended
91 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 B<-Xitem>, B<--exclude=item>
100
101 Exclude files that contain "item" anywhere in their filename from
102 being installed.
103
104 =item I<file [...] dest>
105
106 Lists files (or directories) to install and where to install them to.
107 The files will be installed into the first package dh_install acts on.
108
109 =back
110
111 =cut
112
113 init(options => {
114         "autodest" => \$dh{AUTODEST},
115         "list-missing" => \$dh{LIST_MISSING},
116         "fail-missing" => \$dh{FAIL_MISSING},
117 });
118
119 my @installed;
120
121 my $srcdir = '.';
122 $srcdir = $dh{SOURCEDIR}."/" if defined $dh{SOURCEDIR};
123
124 foreach my $package (@{$dh{DOPACKAGES}}) {
125         my $tmp=tmpdir($package);
126         my $file=pkgfile($package,"install");
127
128         my @install;
129         if ($file) {
130                 @install=filedoublearray($file); # no globbing yet
131         }
132         
133         if (($package eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) {
134                 push @install, [@ARGV];
135         }
136
137         # Support for -X flag.
138         my $exclude = '';
139         if ($dh{EXCLUDE_FIND}) {
140                 $exclude = '! \( '.$dh{EXCLUDE_FIND}.' \)';
141         }
142         
143         foreach my $set (@install) {
144                 my $dest;
145                 my $tmpdest=0;
146                 
147                 if (! defined $dh{AUTODEST} && @$set > 1) {
148                         $dest=pop @$set;
149                 }
150
151                 my @filelist;
152                 foreach my $glob (@$set) {
153                         my @found = glob "$srcdir/$glob";
154                         if (! compat(6)) {
155                                 # Fall back to looking in debian/tmp.
156                                 if (! @found || ! -e $found[0]) {
157                                         @found = glob "debian/tmp/$glob";
158                                 }
159                         }
160                         push @filelist, @found;
161                 }
162
163                 if (! compat(4)) { # check added in v5
164                         # glob now, relative to srcdir
165                         if (! @filelist) {
166                                 error("$package missing files (@$set), aborting");
167                         }
168                 }
169                 foreach my $src (@filelist) { 
170                         next if excludefile($src);
171                 
172                         if (! defined $dest) {
173                                 # Guess at destination directory.
174                                 $dest=$src;
175                                 my $strip=$srcdir;
176                                 if ($strip eq '.') {
177                                         $strip = "debian/tmp";
178                                 }
179                                 $dest=~s/^(.*\/)?\Q$strip\E//;
180                                 $dest=dirname($dest);
181                                 $tmpdest=1;
182                         }
183                         
184                         # Make sure the destination directory exists.
185                         if (! -e "$tmp/$dest") {
186                                 doit("install","-d","$tmp/$dest");
187                         }
188
189                         # Keep track of what's installed.
190                         if ($dh{LIST_MISSING} || $dh{FAIL_MISSING}) {
191                                 # Kill any extra slashes. Makes the
192                                 # @installed stuff more robust.
193                                 $src=~y:/:/:s;
194                                 $src=~s:/+$::;
195                                 $src=~s:^(\./)*::;
196                                 push @installed, "\Q$src\E\/.*|\Q$src\E";
197                         }
198                         
199                         if (-d $src && $exclude) {
200                                 my $basename = basename($src);
201                                 my $dir = ($basename eq '.') ? $src : "$src/..";
202                                 my $pwd=`pwd`;
203                                 chomp $pwd;
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/ \\;");
208                         }
209                         else {
210                                 doit("cp", "-a", $src, "$tmp/$dest/");
211                         }
212
213                         if ($tmpdest) {
214                                 $dest=undef;
215                         }
216                 }
217         }
218 }
219
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';
224         }
225         
226         my @missing;
227         my $installed=join("|", @installed);
228         $installed=qr{^($installed)$};
229         find(sub {
230                 -f || -l || return;
231                 $_="$File::Find::dir/$_";
232                 if (! /$installed/ && ! excludefile($_)) {
233                         my $file=$_;
234                         $file=~s/^\Q$srcdir\E\///;
235                         push @missing, $file;
236                 }
237         }, $srcdir);
238         if (@missing) {
239                 warning "$_ exists in $srcdir but is not installed to anywhere" foreach @missing;
240                 if ($dh{FAIL_MISSING}) {
241                         error("missing files, aborting");
242                 }
243         }
244 }
245
246 =head1 EXAMPLE
247
248 Suppose your package's upstream Makefile installs a binary, a man page, and
249 a library into appropriate subdirectories of debian/tmp. You want to put
250 the library into package libfoo, and the rest into package foo. Your rules
251 file will run "dh_install --sourcedir=debian/tmp". Make debian/foo.install
252 contain:
253
254   usr/bin
255   usr/share/man/man1
256
257 While debian/libfoo.install contains:
258
259   usr/lib/libfoo*.so.*
260
261 If you want a libfoo-dev package too, debian/libfoo-dev.install might contain:
262
263   usr/include
264   usr/lib/libfoo*.so
265   usr/share/man/man3
266
267 =head1 LIMITATIONS
268
269 dh_install cannot rename files or directories, it can only install them
270 with the names they already have into wherever you want in the package
271 build tree.
272   
273 =head1 SEE ALSO
274
275 L<debhelper(7)>
276
277 This program is a part of debhelper.
278
279 =head1 AUTHOR
280
281 Joey Hess <joeyh@debian.org>
282
283 =cut