Code

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