On Perl 5.8, lchown() sometimes ends up with leaked errno; declare $! local.
[perl-fuse.git] / Makefile.PL
1 use ExtUtils::MakeMaker;
2 use POSIX;
3 use Config;
4 # See lib/ExtUtils/MakeMaker.pm for details of how to influence
5 # the contents of the Makefile that is written.
6
7 # Note: This is a hack. This hack is necessary because MacFUSE's libfuse
8 # (and libfuse_ino64, by extension) don't link in libiconv. This wouldn't
9 # be a problem, but it appears the Darwin/OS X dynamic linker won't
10 # satisfy runtime link dependencies in those libraries from libraries
11 # imported by our library, and it uses a symbol from libiconv without
12 # actually linking the library to itself. Awesome.
13 package MY;
14 sub test_via_harness {
15     my($self, $perl, $tests) = @_;
16     local $_ = $self->SUPER::test_via_harness($perl, $tests);
17     s/PERL_DL_NONLAZY=1//g if $^O eq 'darwin';
18     return $_;
19 }
20
21 sub test_via_script {
22     my($self, $perl, $tests) = @_;
23     local $_ = $self->SUPER::test_via_script($perl, $tests);
24     s/PERL_DL_NONLAZY=1//g if $^O eq 'darwin';
25     return $_;
26 }
27
28 package main;
29
30 chomp(my $fusever = `pkg-config --modversion fuse 2> /dev/null`);
31 # Required for refuse on NetBSD
32 unless ($fusever) {
33     chomp($fusever = `fusermount -V`);
34     $fusever =~ s/^.*?version:\s+//;
35 }
36
37 unless ($fusever) {
38     # make CPANPLUS happy and don't report errors if fuse isn't installed
39     my $explanation;
40     if ($^O eq 'linux') {
41         if (-e '/etc/debian_version') {
42             $explanation = 'You need to install "libfuse-dev" to provide build support for this module';
43         }
44         elsif (-e '/etc/redhat-release') {
45             $explanation = 'You need to install "fuse-devel" to provide build support for this module';
46         }
47         else {
48             $explanation = 'I don\'t know your Linux distribution, but please install the FUSE libraries and headers to build this module';
49         }
50     }
51     elsif ($^O eq 'freebsd') {
52         $explanation = 'You need to install the "fusefs-libs" package from ports to support this module';
53     }
54     elsif ($^O eq 'netbsd') {
55         $explanation = 'Could not find librefuse? Maybe install "perfuse" from pkgsrc, or upgrade to newer NetBSD';
56     }
57     elsif ($^O = 'darwin') {
58         $explanation = 'Please install MacFuse from http://code.google.com/p/macfuse/';
59     }
60     else {
61         $explanation = 'There is no FUSE support for your platform to our knowledge, sorry';
62     }
63     die("Cannot build for platform: $^O\n", $explanation, "\n");
64 }
65 if ($fusever && $fusever + 0 < 2.6) {
66     die "FUSE API is ", $fusever, ", must be 2.6 or later\n";
67 } else {
68     warn "fuse version found: ", $fusever, "\n";
69 }
70
71 chomp(my $inc = `pkg-config --cflags-only-I fuse 2> /dev/null` || '-I ../include');
72 chomp(my $libs = `pkg-config --libs-only-L fuse 2> /dev/null`);
73 chomp($libs .= `pkg-config --libs-only-l fuse 2> /dev/null` || (($^O eq 'netbsd') ? '-lrefuse' : '-lfuse'));
74 # Needed for Fuse on OS X 10.6, due to 10.6 and up always using the 64-bit
75 # inode structs; unfortunately MacFuse doesn't just do the right thing
76 # on its own.
77 if ($^O eq 'darwin' && (uname())[2] =~ /^10\./) {
78     $libs =~ s/-lfuse/-lfuse_ino64/;
79 }
80 chomp(my $def = '-Wall -DFUSE_USE_VERSION=26 ' . `pkg-config --cflags-only-other fuse 2> /dev/null` || '-D_FILE_OFFSET_BITS=64');
81 chomp($def .= `pkg-config --libs-only-other fuse 2> /dev/null`);
82 $def .= ' -DPERL_HAS_64BITINT' if $Config{'use64bitint'};
83
84 WriteMakefile(
85     'NAME'          => 'Fuse',
86     'VERSION_FROM'  => 'Fuse.pm', # finds $VERSION
87     'PREREQ_PM'     => { # e.g., Module::Name => 1.1
88         'Lchown'            => 0,
89         'Filesys::Statvfs'  => 0,
90         'Unix::Mknod'       => 0,
91     },
92     ($] >= 5.005 ?  ## Add these new keywords supported since 5.005
93        (ABSTRACT_FROM   => 'Fuse.pm', # retrieve abstract from module
94         AUTHOR          => 'Mark Glines <mark@glines.org>') : ()),
95     ($ExtUtils::MakeMaker::VERSION < 6.46 ? () : (
96         META_MERGE => {
97             resources => {
98                 bugtracker => 'https://rt.cpan.org/Public/Dist/Display.html?Name=Fuse',
99                 repository => 'http://github.com/dpavlin/perl-fuse'
100             },
101         })
102     ),
103     'LIBS'          => '-lpthread ' . $libs, # e.g., '-lm'
104     'DEFINE'        => $def, # e.g., '-DHAVE_SOMETHING'
105     'OPTIMIZE'      => '-g -ggdb',
106     # Insert -I. if you add *.h files later:
107     'INC'           => $inc, # e.g., '-I/usr/include/other'
108     # Un-comment this if you add C files to link with later:
109     'OBJECT'        => 'Fuse$(OBJ_EXT)', # link all the C files too
110 );
111
112 sub MY::postamble {
113     return <<'MAKE_MORE';
114
115 cpan:
116         make clean
117         rm -f Fuse-*.tar.gz
118         perl Makefile.PL
119         make dist
120         make disttest
121         @echo
122         @echo -n "Upload" Fuse-*.tar.gz "to CPAN? [y/N]:"
123         @read upload && test "$$upload" == "y" && cpan-upload -verbose Fuse-*.tar.gz
124
125
126
127 sf:
128         svn2cvs.pl file:///home/dpavlin/private/svn/fuse/perl-llin :ext:dpavlin@fuse.cvs.sourceforge.net:/cvsroot/fuse perl
129
130 MAKE_MORE
131 };
132
133 # vim: ts=4 ai et hls