]> git.donarmstrong.com Git - debhelper.git/blob - dh_install
r541: * Typo, Closes: #155323
[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<--list-missing>] [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 where they should be installed to. The format is a set of
29 lines, where each line lists a file or files to install, and at the end of
30 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 Makefile
40 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 from the front of the filename, of it is present, and
60 install into the dirname of the filename. So if the filename is
61 debian/tmp/usr/bin, then that directory will be copied to 
62 debian/package/usr/. If the filename is debian/tmp/etc/passwd, it will be 
63 copied to debian/package/etc/.
64
65 Note that if you list only a filename on a line by 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<--list-missing>
70
71 This option makes dh_install keep track of the files it installs, and then at
72 the end, compare that list with the files in debian/tmp. If any of the files
73 (and symlinks) in debian/tmp were not installed to somewhere, it will
74 warn on stderr about that.
75
76 This may be useful if you have a large package and want to make sure that
77 you don't miss installing newly added files in new upstream releases.
78
79 Note that files that are excluded from being moved via the -X option are not
80 warned about.
81
82 =item B<--sourcedir=dir>
83
84 Makes all source files relative to "dir". If this is specified, it is akin 
85 to all the source files having "dir" prepended to them. By default, "dir"
86 is '.'.
87
88 To make dh_install behave like the old dh_movefiles, move your
89 package.files file to package.install and call dh_install with
90 "--sourcedir=debian/tmp" appended to the command. This will
91 approximate dh_movefiles behaviour, except it will copy files instead
92 of moving them.
93
94 =item I<file [...] dest>
95
96 Lists files (or directories) to install and where to install them to.
97 The files will be installed into the first package dh_install acts on.
98
99 =back
100
101 =cut
102
103 init();
104
105 my @installed;
106
107 foreach my $package (@{$dh{DOPACKAGES}}) {
108         my $tmp=tmpdir($package);
109         my $file=pkgfile($package,"install");
110         my $srcdir = '.';
111
112         my @install;
113         if ($file) {
114                 @install=filedoublearray($file); # no globbing yet
115         }
116         
117         $srcdir = $dh{SOURCEDIR}."/" if defined $dh{SOURCEDIR};
118         
119         if (($package eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) {
120                 push @install, [@ARGV];
121         }
122
123         # Support for -X flag.
124         my $exclude = '';
125         if ($dh{EXCLUDE_FIND}) {
126                 $exclude = '-and ! \( '.$dh{EXCLUDE_FIND}.' \)';
127         }
128         
129         foreach my $set (@install) {
130                 my $dest;
131                 
132                 if (! defined $dh{AUTODEST} && @$set > 1) {
133                         $dest=pop @$set;
134                 }
135                 # glob now, relative to srcdir
136                 foreach my $src (map { glob "$srcdir/$_" } @$set) { 
137                         next if excludefile($src);
138                 
139                         if (! defined $dest) {
140                                 # Guess at destination directory.
141                                 $dest=$src;
142                                 $dest=~s/^(.*\/)?debian\/tmp//;
143                                 $dest=dirname($dest);
144                         }
145                         
146                         # Make sure the destination directory exists.
147                         if (! -e "$tmp/$dest") {
148                                 doit("install","-d","$tmp/$dest");
149                         }
150
151                         # Keep track of what's installed.
152                         if ($dh{LIST_MISSING}) {
153                                 # Kill any extra slashes. Makes the
154                                 # @installed stuff more robust.
155                                 $src=~y:/:/:s;
156                                 $src=~s:/+$::;
157                                 push @installed, "\Q$src\E\/.*|\Q$src\E";
158                         }
159                         
160                         if (-d $src && $exclude) {
161                                 my ($dir_basename) = basename($src);
162                                 # Pity there's no cp --exclude ..
163                                 my $pwd=`pwd`;
164                                 chomp $pwd;
165                                 complex_doit("cd $src/.. && find $dir_basename \\( -type f -or -type l \\) $exclude -exec cp --parents -dp {} $pwd/$tmp/$dest/ \\;");
166                         }
167                         else {
168                                 doit("cp", "-a", $src, "$tmp/$dest/");
169                         }
170                 }
171         }
172 }
173
174 if ($dh{LIST_MISSING}) {
175         my @missing;
176         my $installed=join("|", @installed);
177         $installed=qr{^$installed$};
178         find(sub {
179                 -f || -l || return;
180                 $_="$File::Find::dir/$_";
181                 push @missing, $_ unless /$installed/;
182         }, './debian/tmp');
183         if (@missing) {
184                 warning "$_ not installed" foreach @missing;
185         }
186 }
187
188 =head1 SEE ALSO
189
190 L<debhelper(1)>
191
192 This program is a part of debhelper.
193
194 =head1 AUTHOR
195
196 Joey Hess <joeyh@debian.org>
197
198 =cut