5 dh_movefiles - move files out of debian/tmp into subpackages
10 use Debian::Debhelper::Dh_Lib;
14 B<dh_movefiles> [S<I<debhelper options>>] [B<--sourcedir=>I<dir>] [B<-X>I<item>] S<I<file> ...>]
18 B<dh_movefiles> is a debhelper program that is responsible for moving files
19 out of F<debian/tmp> or some other directory and into other package build
20 directories. This may be useful if your package has a F<Makefile> that installs
21 everything into F<debian/tmp>, and you need to break that up into subpackages.
23 Note: B<dh_install> is a much better program, and you are recommended to use
24 it instead of B<dh_movefiles>.
30 =item debian/I<package>.files
32 Lists the files to be moved into a package, separated by whitespace. The
33 filenames listed should be relative to F<debian/tmp/>. You can also list
34 directory names, and the whole directory will be moved.
42 =item B<--sourcedir=>I<dir>
44 Instead of moving files out of F<debian/tmp> (the default), this option makes
45 it move files out of some other directory. Since the entire contents of
46 the sourcedir is moved, specifying something like B<--sourcedir=/> is very
47 unsafe, so to prevent mistakes, the sourcedir must be a relative filename;
48 it cannot begin with a `B</>'.
50 =item B<-Xitem>, B<--exclude=item>
52 Exclude files that contain B<item> anywhere in their filename from
57 Lists files to move. The filenames listed should be relative to
58 F<debian/tmp/>. You can also list directory names, and the whole directory will
59 be moved. It is an error to list files here unless you use B<-p>, B<-i>, or B<-a> to
60 tell B<dh_movefiles> which subpackage to put them in.
66 Note that files are always moved out of F<debian/tmp> by default (even if you
67 have instructed debhelper to use a compatibility level higher than one,
68 which does not otherwise use debian/tmp for anything at all). The idea
69 behind this is that the package that is being built can be told to install
70 into F<debian/tmp>, and then files can be moved by B<dh_movefiles> from that
71 directory. Any files or directories that remain are ignored, and get
72 deleted by B<dh_clean> later.
77 "sourcedir=s" => \$dh{SOURCEDIR},
82 foreach my $package (@{$dh{DOPACKAGES}}) {
83 my $tmp=tmpdir($package);
84 my $files=pkgfile($package,"files");
86 my $sourcedir="debian/tmp";
88 if ($dh{SOURCEDIR}=~m:^/:) {
89 error("The sourcedir must be a relative filename, not starting with `/'.");
91 $sourcedir=$dh{SOURCEDIR};
94 if (! -d $sourcedir) {
95 error("$sourcedir does not exist.");
100 # debian/files has a different purpose, so ignore it.
101 if ($files && $files ne "debian/files" ) {
102 @tomove=filearray($files, $sourcedir);
105 if (($package eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) {
109 if (@tomove && $tmp eq $sourcedir) {
110 error("I was asked to move files from $sourcedir to $sourcedir. Perhaps you should set DH_COMPAT=2?");
113 # Now we need to expand wildcards in @tomove.
114 # This is only necessary in pre-v3 land -- as of v3, the
115 # expension is automatically done by filearray().
116 if (@tomove && compat(2)) {
119 push @filelist, glob("$sourcedir/$_");
124 # However, filearray() does not add the sourcedir,
126 @tomove = map { "$sourcedir/$_" } @tomove;
131 doit("install","-d",$tmp);
134 doit("rm","-f","debian/movelist");
137 if (! -e $file && ! -l $file && ! $dh{NO_ACT}) {
139 warning("$file not found (supposed to put it in $package)");
142 $file=~s:^\Q$sourcedir\E/+::;
143 my $cmd="(cd $sourcedir >/dev/null ; find $file ! -type d ";
144 if ($dh{EXCLUDE_FIND}) {
145 $cmd.="-a ! \\( $dh{EXCLUDE_FIND} \\) ";
147 $cmd.="-print || true) >> debian/movelist";
153 complex_doit("(cd $sourcedir >/dev/null ; tar --create --files-from=$pwd/debian/movelist --file -) | (cd $tmp >/dev/null ;tar xpf -)");
154 # --remove-files is not used above because tar then doesn't
155 # preserve hard links
156 complex_doit("(cd $sourcedir >/dev/null ; tr '\\n' '\\0' < $pwd/debian/movelist | xargs -0 -i rm -f '{}')");
157 doit("rm","-f","debian/movelist");
161 # If $ret is set, we wern't actually able to find some
162 # files that were specified to be moved, and we should
163 # exit with the code in $ret. This program puts off
164 # exiting with an error until all files have been tried
165 # to be moved, because this makes it easier for some
166 # packages that arn't always sure exactly which files need
174 This program is a part of debhelper.
178 Joey Hess <joeyh@debian.org>