]> git.donarmstrong.com Git - debhelper.git/blob - dh_install
r518: * dh_movefiles has long been a sore point in debhelper. Inherited
[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 Debian::Debhelper::Dh_Lib;
11
12 =head1 SYNOPSIS
13
14 B<dh_install> [B<-X>I<item>] [S<I<debhelper options>>] [S<I<file [...] dest>>]
15
16 =head1 DESCRIPTION
17
18 dh_install is a debhelper program that handles installing files into package
19 build directories. There are many dh_install* commands that handle installing
20 specific types of files such as documentation, examples, man pages, and so on,
21 and they should be used when possible as they often have extra intelligence for
22 those particular tasks. dh_install, then, is useful for installing everything
23 else, for which no particular intelligence is needed. It is a replacement for
24 the old dh_movefiles command.
25
26 Files named debian/package.install list the files to install into each
27 package and where they should be installed to. The format is a set of
28 lines, where each line lists a file or files to install, and at the end of
29 the line tells the directory it should be installed in. The name of the
30 files (or directories) to install should be given relative to the current
31 directory, while the installation directory is given relative to the
32 package build directory. You may use wildcards in the names of the files to
33 install.
34
35 This program may be used in one of two ways. If you just have a file or two
36 that the upstream Makefile does not install for you, you can run dh_install
37 on them to move them into place. On the other hand, maybe you have a large
38 package that builds multiple binary packages. You can use the upstream Makefile
39 to install it all into debian/tmp, and then use dh_install to copy
40 directories and files from there into the proper package build directories.
41
42 =head1 OPTIONS
43
44 =over 4
45
46 =item B<-Xitem>, B<--exclude=item>
47
48 Exclude files that contain "item" anywhere in their filename from
49 being installed.
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 from the front of the filename, of it is present, and
59 install into the dirname of the filename. So if the filename is
60 debian/tmp/usr/bin, then that directory will be copied to 
61 debian/package/usr/. If the filename is debian/tmp/etc/passwd, it will be 
62 copied to debian/package/etc/.
63
64 Note that if you list only a filename on a line by itself in a
65 debian/package.install file, with no explicit destination, then dh_install
66 will automatically guess the destination even if this flag is not set.
67
68 =item I<file [...] dest>
69
70 Lists files (or directories) to install and where to install them to.
71 The files will be installed into the first package dh_install acts on.
72
73 =back
74
75 =cut
76
77 init();
78
79 my $ret=0;
80
81 foreach my $package (@{$dh{DOPACKAGES}}) {
82         my $tmp=tmpdir($package);
83         my $file=pkgfile($package,"install");
84
85         my @install;
86         if ($file) {
87                 @install=filedoublearray($file, ".");
88         }
89         
90         if (($package eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) {
91                 push @install, [@ARGV];
92         }
93
94         # Support for -X flag.
95         my $exclude = '';
96         if ($dh{EXCLUDE_FIND}) {
97                 $exclude = ' -and ! \( '.$dh{EXCLUDE_FIND}.' \)';
98         }
99         
100         foreach my $set (@install) {
101                 my $dest;
102                 
103                 if (! defined $dh{AUTODEST} && @$set > 1) {
104                         $dest=pop @$set;
105                 }
106                 
107                 foreach my $src (@$set) {
108                         next if excludefile($src);
109                 
110                         if (! defined $dest) {
111                                 # Guess at destination directory.
112                                 $dest=$src;
113                                 $dest=~s/^(.*\/)?debian\/tmp//;
114                                 $dest=dirname($dest);
115                         }
116                         
117                         # Make sure the destination directory exists.
118                         if (! -e "$tmp/$dest") {
119                                 doit("install","-d","$tmp/$dest");
120                         }
121
122                         if (-d $src && $exclude) {
123                                 my ($dir_basename) = basename($src);
124                                 # Pity there's no cp --exclude ..
125                                 my $pwd=`pwd`;
126                                 chomp $pwd;
127                                 complex_doit("cd $src/.. && find $dir_basename -type f$exclude -exec cp --parents -dp {} $pwd/$tmp/$dest/ \\;");
128                         }
129                         else {
130                                 doit("cp", "-a", $src, "$tmp/$dest/");
131                         }
132                 }
133         }
134 }
135
136 =head1 SEE ALSO
137
138 L<debhelper(1)>
139
140 This program is a part of debhelper.
141
142 =head1 AUTHOR
143
144 Joey Hess <joeyh@debian.org>
145
146 =cut