]> git.donarmstrong.com Git - debhelper.git/blob - dh_movefiles
r420: big monsta changes
[debhelper.git] / dh_movefiles
1 #!/usr/bin/perl -w
2 #
3 # Move files out of debian/tmp, into subpackages.
4
5 use strict;
6 use Debian::Debhelper::Dh_Lib;
7 init();
8
9 my $ret=0;
10
11 foreach my $package (@{$dh{DOPACKAGES}}) {
12         my $tmp=tmpdir($package);
13         my $files=pkgfile($package,"files");
14
15         my $sourcedir="debian/tmp";
16         if ($dh{SOURCEDIR}) {
17                 if ($dh{SOURCEDIR}=~m:^/:) {
18                         error("The sourcedir must be a relative filename, not starting with `/'.");
19                 }
20                 $sourcedir=$dh{SOURCEDIR};
21         }
22
23         if (! -d $sourcedir) {
24                 error("$sourcedir does not exist.");
25         }
26
27         my @tomove;
28
29         # debian/files has a different purpose, so ignore it.
30         if ($files && $files ne "debian/files" ) {
31                 @tomove=filearray($files, $sourcedir);
32         }
33         
34         if (($package eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) {
35                 push @tomove, @ARGV;
36         }
37
38         if (@tomove && $tmp eq $sourcedir) {
39                 error("I was asked to move files from $sourcedir to $sourcedir. Perhaps you should set DH_COMAPT=2?");
40         }
41
42         # Now we need to expand wildcards in @tomove.
43         # This is only necessary in pre-v3 land -- as of v3, the
44         # expension is automatically done by filearray().
45         if (@tomove && compat(2)) {
46                 my @filelist=();
47                 foreach (@tomove) {
48                         push @filelist, glob("$sourcedir/$_");
49                 }
50                 @tomove=@filelist;
51         }
52         else {
53                 # However, filearray() does not add the sourcedir,
54                 # which we need.
55                 @tomove = map { "$sourcedir/$_" } @tomove;
56         }
57
58         if (@tomove) {
59                 if (! -d $tmp) {
60                         doit("install","-d",$tmp);
61                 }
62
63                 doit("rm","-f","debian/movelist");
64                 foreach (@tomove) {
65                         my $file=$_;
66                         if (! -e $file && ! -l $file) {
67                                 $ret=1;
68                                 warning("$file not found");
69                         }
70                         $file=~s:^\Q$sourcedir\E/+::;
71                         complex_doit("(cd $sourcedir >/dev/null ; find $file ! -type d -print || true) >> debian/movelist");
72                 }
73                 complex_doit("(cd $sourcedir >/dev/null ; tar --create --remove-files --files-from=../movelist --file -) | (cd $tmp >/dev/null ;tar xpf -)");
74                 doit("rm","-f","debian/movelist");
75         }
76 }
77
78 # If $ret is set, we wern't actually able to find some 
79 # files that were specified to be moved, and we should
80 # exit with the code in $ret. This program puts off 
81 # exiting with an error until all files have been tried
82 # to be moved, because this makes it easier for some 
83 # packages that arn't always sure exactly which files need
84 # to be moved.
85 exit $ret;