]> git.donarmstrong.com Git - debhelper.git/blob - dh_install
r522: * Set DH_ALWAYS_EXCLUDE=CVS and debhelper will exclude CVS directories
[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 (in v3 mode and above).
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 B<--sourcedir=dir>
69
70 Makes all source files relative to "dir". If this is specified, it is akin 
71 to all the source files having "dir" prepended to them. By default, "dir"
72 is '.'.
73
74 To make dh_install behave like the old dh_movefiles, move your
75 package.files file to package.install and call dh_install with
76 "--sourcedir=debian/tmp" appended to the command. This will
77 approximate dh_movefiles behaviour, except it will copy files instead
78 of moving them.
79
80 =item I<file [...] dest>
81
82 Lists files (or directories) to install and where to install them to.
83 The files will be installed into the first package dh_install acts on.
84
85 =back
86
87 =cut
88
89 init();
90
91 my $ret=0;
92
93 foreach my $package (@{$dh{DOPACKAGES}}) {
94         my $tmp=tmpdir($package);
95         my $file=pkgfile($package,"install");
96         my $srcdir = '.';
97
98         my @install;
99         if ($file) {
100                 @install=filedoublearray($file); # no globbing yet
101         }
102         
103         $srcdir = $dh{SOURCEDIR} if defined $dh{SOURCEDIR};
104         
105         if (($package eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) {
106                 push @install, [@ARGV];
107         }
108
109         # Support for -X flag.
110         my $exclude = '';
111         if ($dh{EXCLUDE_FIND}) {
112                 $exclude = ' -and ! \( '.$dh{EXCLUDE_FIND}.' \)';
113         }
114         
115         foreach my $set (@install) {
116                 my $dest;
117                 
118                 if (! defined $dh{AUTODEST} && @$set > 1) {
119                         $dest=pop @$set;
120                 }
121                 
122                 foreach my $src (map { glob } @$set) { # glob now
123                         next if excludefile($src);
124                 
125                         if (! defined $dest) {
126                                 # Guess at destination directory.
127                                 $dest=$src;
128                                 $dest=~s/^(.*\/)?debian\/tmp//;
129                                 $dest=dirname($dest);
130                         }
131                         
132                         $src = "$srcdir/$src"; # do this now, to avoid the parsing above
133                         
134                         # Make sure the destination directory exists.
135                         if (! -e "$tmp/$dest") {
136                                 doit("install","-d","$tmp/$dest");
137                         }
138
139                         if (-d $src && $exclude) {
140                                 my ($dir_basename) = basename($src);
141                                 # Pity there's no cp --exclude ..
142                                 my $pwd=`pwd`;
143                                 chomp $pwd;
144                                 complex_doit("cd $src/.. && find $dir_basename -type f$exclude -exec cp --parents -dp {} $pwd/$tmp/$dest/ \\;");
145                         }
146                         else {
147                                 doit("cp", "-a", $src, "$tmp/$dest/");
148                         }
149                 }
150         }
151 }
152
153 =head1 SEE ALSO
154
155 L<debhelper(1)>
156
157 This program is a part of debhelper.
158
159 =head1 AUTHOR
160
161 Joey Hess <joeyh@debian.org>
162
163 =cut