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