]> git.donarmstrong.com Git - debhelper.git/blob - dh_movefiles
r518: * dh_movefiles has long been a sore point in debhelper. Inherited
[debhelper.git] / dh_movefiles
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_movefiles - move files out of debian/tmp into subpackages
6
7 =cut
8
9 use strict;
10 use Debian::Debhelper::Dh_Lib;
11
12 =head1 SYNOPSIS
13
14 B<dh_movefiles> [S<I<debhelper options>>] [B<--sourcedir=>I<dir>] [S<I<file ...>>]
15
16 =head1 DESCRIPTION
17
18 dh_movefiles is a debhelper program that is responsible for moving files
19 out of debian/tmp or some other directory and into other package build
20 directories. This may be useful if your package has a Makefile that installs
21 everything into debian/tmp, and you need to break that up into subpackages.
22
23 Files named debian/package.files list the files to be moved, separated by
24 whitespace. The filenames listed should be relative to debian/tmp/. You can
25 also list directory names, and the whole directory will be moved. If you
26 prefer, you can list the files to move on the command line and this will
27 apply to the first package dh_movefiles is told to act on.
28
29 Note: dh_install is a much better program that can do everything this one can,
30 and more.
31
32 =head1 OPTIONS
33
34 =over 4
35
36 =item B<--sourcedir=>I<dir>
37
38 Instead of moving files out of debian/tmp (the default), this option makes
39 it move files out of some other directory. Since the entire contents of
40 the sourcedir is moved, specifiying something like --sourcedir=/ is very
41 unsafe, so to prevent mistakes, the sourcedir must be a relative filename;
42 it cannot begin with a `/'.
43
44 =item I<file ...>
45
46 Lists files to move. The filenames listed should be relative to
47 debian/tmp/. You can also list directory names, and the whole directory will
48 be moved. It is an error to list files here unless you use -p, -i, or -a to
49 tell dh_movefiles which subpackage to put them in.
50
51 =back
52
53 =head1 NOTES
54
55 Note that files are always moved out of debian/tmp by default (even if you
56 have instructed debhelper to use a compatibility level higher than one,
57 which does not otherwise use debian/tmp for anything at all). The idea
58 behind this is that the package that is being built can be told to install
59 into debian/tmp, and then files can be moved by dh_movefiles from that
60 directory. Any files or directories that remain are ignored, and get
61 deleted by dh_clean later.
62
63 =cut
64
65 init();
66
67 my $ret=0;
68
69 foreach my $package (@{$dh{DOPACKAGES}}) {
70         my $tmp=tmpdir($package);
71         my $files=pkgfile($package,"files");
72
73         my $sourcedir="debian/tmp";
74         if ($dh{SOURCEDIR}) {
75                 if ($dh{SOURCEDIR}=~m:^/:) {
76                         error("The sourcedir must be a relative filename, not starting with `/'.");
77                 }
78                 $sourcedir=$dh{SOURCEDIR};
79         }
80
81         if (! -d $sourcedir) {
82                 error("$sourcedir does not exist.");
83         }
84
85         my @tomove;
86
87         # debian/files has a different purpose, so ignore it.
88         if ($files && $files ne "debian/files" ) {
89                 @tomove=filearray($files, $sourcedir);
90         }
91         
92         if (($package eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) {
93                 push @tomove, @ARGV;
94         }
95
96         if (@tomove && $tmp eq $sourcedir) {
97                 error("I was asked to move files from $sourcedir to $sourcedir. Perhaps you should set DH_COMPAT=2?");
98         }
99
100         # Now we need to expand wildcards in @tomove.
101         # This is only necessary in pre-v3 land -- as of v3, the
102         # expension is automatically done by filearray().
103         if (@tomove && compat(2)) {
104                 my @filelist=();
105                 foreach (@tomove) {
106                         push @filelist, glob("$sourcedir/$_");
107                 }
108                 @tomove=@filelist;
109         }
110         else {
111                 # However, filearray() does not add the sourcedir,
112                 # which we need.
113                 @tomove = map { "$sourcedir/$_" } @tomove;
114         }
115
116         if (@tomove) {
117                 if (! -d $tmp) {
118                         doit("install","-d",$tmp);
119                 }
120
121                 doit("rm","-f","debian/movelist");
122                 foreach (@tomove) {
123                         my $file=$_;
124                         if (! -e $file && ! -l $file) {
125                                 $ret=1;
126                                 warning("$file not found (supposed to put it in $package)");
127                         }
128                         $file=~s:^\Q$sourcedir\E/+::;
129                         complex_doit("(cd $sourcedir >/dev/null ; find $file ! -type d -print || true) >> debian/movelist");
130                 }
131                 my $pwd=`pwd`;
132                 chomp $pwd;
133                 complex_doit("(cd $sourcedir >/dev/null ; tar --create --remove-files --files-from=$pwd/debian/movelist --file -) | (cd $tmp >/dev/null ;tar xpf -)");
134                 doit("rm","-f","debian/movelist");
135         }
136 }
137
138 # If $ret is set, we wern't actually able to find some 
139 # files that were specified to be moved, and we should
140 # exit with the code in $ret. This program puts off 
141 # exiting with an error until all files have been tried
142 # to be moved, because this makes it easier for some 
143 # packages that arn't always sure exactly which files need
144 # to be moved.
145 exit $ret;
146
147 =head1 SEE ALSO
148
149 L<debhelper(1)>
150
151 This program is a part of debhelper.
152
153 =head1 AUTHOR
154
155 Joey Hess <joeyh@debian.org>
156
157 =cut