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