1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
use 5.006;
use ExtUtils::MakeMaker;
use Config (%Config);
my @OPING_PREFIX = (qw(/opt/oping /usr /usr/local));
my $OPING_PREFIX;
my $OPING_CPPFLAGS;
my $OPING_LDDLFLAGS;
my $OPING_LIBS;
my $OPING_DEPEND;
# TOP_BUILDDIR is set by liboping's build system, so Net::Oping can link with
# the yet uninstalled library.
my $TOP_BUILDDIR;
my $TARGET_LIBDIR;
# Parse custom command line arguments.
for (my $i = 0; $i < @ARGV; $i++)
{
if ($ARGV[$i] =~ m#^OPING_PREFIX=(.*[^/])#)
{
unshift (@OPING_PREFIX, $1);
splice (@ARGV, $i, 1);
$i--;
}
elsif ($ARGV[$i] =~ m#^TOP_BUILDDIR=(.*[^/])#)
{
$TOP_BUILDDIR = $1;
# TOP_BUILDDIR is passed from bindings/, but we're currently in
# bindings/perl/. If it is a relative path, we need to add an
# extra `../' in order to compensate for this.
if ($TOP_BUILDDIR !~ m#^/#)
{
$TOP_BUILDDIR = "../$TOP_BUILDDIR";
}
splice (@ARGV, $i, 1);
$i--;
}
elsif ($ARGV[$i] =~ m#^TARGET_LIBDIR=(.*[^/])#)
{
# Only save TARGET_LIBDIR if it's not a standard system library
# directory, such as /usr/lib.
if (!is_system_libdir ($1))
{
$TARGET_LIBDIR = $1;
}
splice (@ARGV, $i, 1);
$i--;
}
}
if (!$TOP_BUILDDIR)
{
for (my $i = 0; $i < @OPING_PREFIX; $i++)
{
if (!-e $OPING_PREFIX[$i] . '/include/oping.h')
{
next;
}
$OPING_PREFIX = $OPING_PREFIX[$i];
print "Found <oping.h> in $OPING_PREFIX/include\n";
last;
}
}
if ($TOP_BUILDDIR)
{
# Use LDDLFLAGS here instead of LIBS, because:
# 1) We need to make sure our library path comes first (and no locally
# installed version is used).
# 2) Prevent MakeMaker from stipping the -rpath option when the
# library is to be installed in a non-standard path. Standard-paths
# are read from $Config{'libsdirs'} above.
$OPING_CPPFLAGS = "-I$TOP_BUILDDIR/src";
$OPING_LDDLFLAGS = "-L$TOP_BUILDDIR/src/.libs " . $Config{'lddlflags'};
$OPING_LIBS = "-L$TOP_BUILDDIR/src/.libs -loping";
if ($TARGET_LIBDIR)
{
$OPING_LDDLFLAGS .= qq( -Wl,-rpath -Wl,"$TARGET_LIBDIR");
}
$OPING_DEPEND = { 'Oping.o' => "$TOP_BUILDDIR/src/liboping.la" };
}
elsif ($OPING_PREFIX)
{
# -rpath is automagically set in this case.
$OPING_CPPFLAGS = "-I$OPING_PREFIX/include";
$OPING_LIBS = "-L$OPING_PREFIX/lib -loping";
}
if (!$OPING_CPPFLAGS)
{
my $search_path = join (', ', @OPING_PREFIX);
print STDERR <<EOF;
******************************************************************************
* ERROR: COULD NOT FIND THE NEEDED HEADER FILE <oping.h>! *
******************************************************************************
The <oping.h> header file could not be found in the usual places. The prefix
paths searched right now are:
$search_path
Please rerun Makefile.PL giving the prefix to the oping library using the
`OPING_PREFIX' argument. If you, for example, had installed the oping library
to /tmp/oping, the header file would be at /tmp/oping/include/oping.h; you'd
then need to run the Makefile.PL as follows:
perl Makefile.PL OPING_PREFIX=/tmp/oping
As you can see, the argument passed via `OPING_PREFIX' must be the same
directory you passed to the liboping configure script using the `--prefix'
argument.
No Makefile has been created.
EOF
exit (0);
}
WriteMakefile(
NAME => 'Net::Oping',
VERSION_FROM => 'lib/Net/Oping.pm',
PREREQ_PM => {},
($] >= 5.005
? (ABSTRACT_FROM => 'lib/Net/Oping.pm',
AUTHOR => 'Florian Forster <octo@verplant.org>')
: ()),
($OPING_DEPEND ? (depend => $OPING_DEPEND) : ()),
LIBS => [$OPING_LIBS],
($OPING_LDDLFLAGS ? (LDDLFLAGS => "$OPING_LDDLFLAGS") : ()),
DEFINE => '',
INC => "$OPING_CPPFLAGS"
);
sub is_system_libdir
{
my $path = shift;
for (split (' ', $Config{'libsdirs'}))
{
if ($path eq $_)
{
return (1);
}
}
return;
}
|