1use lib qw(inc);
2use ExtUtils::MakeMaker;
3use Devel::CheckLib;
4use Cwd;
5use File::Temp qw/tempdir/;
6use IO::File;
7use strict;
8
9# Check whether we have <attr/attributes.h> and <attr/xattr.h> on Linux.
10# Suggest what the user needs to install, to get these files.
11
12if ($^O eq 'linux') {
13    check_lib_or_exit(
14        lib => [qw(attr)]
15    );
16}
17
18my @DIRS = qw(. /usr/include);
19if ($^O eq 'linux')
20{
21    my %headers = (
22        'attr/attributes.h' => 0,
23        'attr/xattr.h' => 0,
24    );
25    my $incdir;
26    my $missing = 0;
27
28    foreach $incdir (@DIRS)
29    {
30        foreach (keys %headers)
31        {
32            $headers{$_}++ if (-r "$incdir/$_");
33        }
34    }
35
36    foreach (keys %headers)
37    {
38        if ($headers{$_} == 0) {
39            warn "<$_> not found; perhaps you need to install libattr-devel";
40            $missing++;
41        }
42    }
43
44    exit(0) if ($missing > 0);
45}
46
47# OpenBSD does not support extended attributes.
48if ($^O eq 'openbsd') {
49    warn 'OpenBSD does not support extended attributes';
50    die "OS unsupported";
51}
52
53# Check whether extended attributes are supported on this filesystem.
54# If we're running non-interactive there is no point failing all the tests,
55# because the machine is not set up correctly.
56if ($^O eq 'linux') {
57    my $basedir = $ENV{ATTR_TEST_DIR} || getcwd();
58    my $template .= "$basedir/XXXXXXXX";
59    my $dir = tempdir($template, CLEANUP => 1);
60    my $file = "$dir/testfile";
61    my $fh = new IO::File(">$file") or die "Unable to open $file: $!";
62    undef $fh;
63
64    my $output = `setfattr -n user.foo -v foo $file 2>&1`;
65    if ($output =~ /command not found/i) {
66        warn "Please install the attr package (containing the setfattr program)";
67        exit(0) if ($ENV{AUTOMATED_TESTING});
68    }
69    if ($output =~ /Operation not supported/i) {
70        warn "To run the tests, you need mount the filesystem containing $basedir with the user_xattr option";
71        warn "Alternatively set the environment variable ATTR_TEST_DIR to point at a filesystem where user_xattr is enabled";
72        exit(0) if ($ENV{AUTOMATED_TESTING});
73    }
74}
75
76# TODO: Check filesystem on other operating systems
77
78# See lib/ExtUtils/MakeMaker.pm for details of how to influence
79# the contents of the Makefile that is written.
80WriteMakefile(
81    NAME              => 'File::ExtAttr',
82    VERSION_FROM      => 'lib/File/ExtAttr.pm', # finds $VERSION
83    PREREQ_PM         => {
84	# e.g., Module::Name => 1.1
85	'Carp' => 0,
86	'Scalar::Util' => 0
87    },
88    ($] >= 5.005 ?     ## Add these new keywords supported since 5.005
89      (ABSTRACT_FROM  => 'lib/File/ExtAttr.pm', # retrieve abstract from module
90       AUTHOR         => 'Kevin M. Goess <kgoess@ensenda.com>'
91                         .', Richard Dawe <richdawe@cpan.org>') : ()),
92# Don't actually need -lattr on Linux.
93#    LIBS              => ['-lattr'], # e.g., '-lm'
94    OBJECT            => '$(O_FILES)',
95    DEFINE            => '', # e.g., '-DHAVE_SOMETHING'
96    INC               => join(' ', map { "-I$_" } @DIRS),
97#    'MYEXTLIB' => 'mylib/libxattrlib$(LIB_EXT)',
98	# Un-comment this if you add C files to link with later:
99    # OBJECT            => '$(O_FILES)', # link all the C files too
100
101    # Hand-roll META.yml and MANIFEST.
102    NO_META           => 1,
103);
104