]> git.donarmstrong.com Git - debhelper.git/blob - dh_auto_install
dh_auto_install: Improve check for MakeMaker, to avoid passing PREFIX if the Makefile...
[debhelper.git] / dh_auto_install
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_auto_install - automatically runs make install or similar
6
7 =cut
8
9 use strict;
10 use Debian::Debhelper::Dh_Lib;
11 use Cwd;
12
13 =head1 SYNOPSIS
14
15 B<dh_auto_install> [S<I<debhelper options>>] [S<B<--> I<params>>]
16
17 =head1 DESCRIPTION
18
19 dh_auto_install is a debhelper program that tries to automatically install
20 built files. If there's a Makefile and it contains a "install" target,
21 then this is done by running make (or MAKE, if the environment variable is
22 set). If there is a setup.py or Build.PL, it is used.
23
24 The files are installed into debian/<package>/ if there is only one binary
25 package. In the multiple binary package case, the files are instead
26 installed into debian/tmp/, and should be moved from there to the
27 appropriate package build directory using L<dh_install(1)> or
28 L<dh_movefiles(1)>.
29
30 DESTDIR is used to tell make where to install the files. 
31 If the Makefile was generated by MakeMaker from a Makefile.PL, it will
32 automatically set PREFIX=/usr too, since such Makefiles need that.
33
34 This is intended to work for about 90% of packages. If it doesn't work, or
35 tries to use the wrong install target, you're encouraged to skip using
36 dh_auto_install at all, and just run make install manually.
37
38 =head1 OPTIONS
39
40 =over 4
41
42 =item B<--> I<params>
43
44 Pass "params" to the program that is run. These can be used to supplement
45 or override the any standard parameters that dh_auto_install passes.
46
47 =back
48
49 =cut
50
51 init();
52
53 my $destdir;
54 my @allpackages=getpackages();
55 if (@allpackages > 1) {
56         $destdir="debian/tmp";
57 }
58 else {
59         $destdir=tmpdir($dh{MAINPACKAGE});
60 }
61 $destdir=cwd()."/".$destdir;
62
63 if (-e "Makefile" || -e "makefile" || -e "GNUmakefile") {
64         $ENV{MAKE}="make" unless exists $ENV{MAKE};
65         my @params="DESTDIR=$destdir";
66
67         # Special case for MakeMaker generated Makefiles.
68         if (-e "Makefile" &&
69             system('grep -q "generated automatically by MakeMaker" Makefile') == 0) {
70                 push @params, "PREFIX=/usr";
71         }
72
73         foreach my $target (qw{install}) {
74                 # Use make -n to check to see if the target would do
75                 # anything. There's no good way to test if a target exists.
76                 my $ret=`$ENV{MAKE} -s -n $target 2>/dev/null`;
77                 chomp $ret;
78                 if (length $ret) {
79                         doit($ENV{MAKE}, $target,
80                                 @params,
81                                 @{$dh{U_PARAMS}});
82                         last;
83                 }
84         }
85 }
86 elsif (-e "setup.py") {
87         doit("python", "setup.py", "install", 
88                 "--root=$destdir",
89                 "--no-compile", "-O0",
90                 @{$dh{U_PARAMS}});
91 }
92 elsif (-e "Build.PL" && -e "Build") {
93         doit("perl", "Build", "install", "destdir=$destdir",
94                 "create_packlist=0", @{$dh{U_PARAMS}});
95 }
96
97 =head1 SEE ALSO
98
99 L<debhelper(7)>
100
101 This program is a part of debhelper.
102
103 =head1 AUTHOR
104
105 Joey Hess <joeyh@debian.org>
106
107 =cut