From 63879e1c82e777d708378fa059e727abcef69d11 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Tue, 17 Feb 2009 11:29:43 +0100 Subject: [PATCH] build system: Added some serious voodoo to make MakeMaker behave. It is now, at last, possible to build the Perl module before installing liboping and still have it linked correctly. --- bindings/Makefile.am | 8 ++-- bindings/perl/Makefile.PL | 93 ++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 88 insertions(+), 13 deletions(-) diff --git a/bindings/Makefile.am b/bindings/Makefile.am index 2378c74..0c1c660 100644 --- a/bindings/Makefile.am +++ b/bindings/Makefile.am @@ -2,7 +2,7 @@ EXTRA_DIST = perl/Changes perl/MANIFEST perl/META.yml perl/Makefile.PL \ perl/Oping.xs perl/README perl/lib/Net/Oping.pm perl/t/Oping.t \ perl/typemap -all-local: +all-local: @BINDINGS@ [ ! -f perl/Makefile ] || ( cd perl && $(MAKE) all ) install-exec-local: @@ -19,6 +19,8 @@ perl: perl-bindings perl-bindings: perl/Makefile cd perl && $(MAKE) +# Check if the `perl' directory exists in the _build_ directory. If not, copy +# the files from the _source_ directory. perl/Makefile: perl/Makefile.PL $(top_builddir)/config.status if test ! -d perl; then \ for file in $(EXTRA_DIST); do \ @@ -26,9 +28,7 @@ perl/Makefile: perl/Makefile.PL $(top_builddir)/config.status cp $(srcdir)/$$file `dirname $$file`; \ done \ fi - - cd perl && @PERL@ Makefile.PL PREFIX=$(prefix) @PERL_BINDINGS_OPTIONS@ - + cd perl && @PERL@ Makefile.PL PREFIX="$(prefix)" TOP_BUILDDIR="$(top_builddir)" TARGET_LIBDIR="$(libdir)" @PERL_BINDINGS_OPTIONS@ .PHONY: perl perl-bindings diff --git a/bindings/perl/Makefile.PL b/bindings/perl/Makefile.PL index 2d272a8..c406112 100644 --- a/bindings/perl/Makefile.PL +++ b/bindings/perl/Makefile.PL @@ -1,9 +1,20 @@ 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; + +# 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=(.*[^/])#) @@ -12,21 +23,72 @@ for (my $i = 0; $i < @ARGV; $i++) 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--; + } } -for (my $i = 0; $i < @OPING_PREFIX; $i++) +if (!$TOP_BUILDDIR) { - if (!-e $OPING_PREFIX[$i] . '/include/oping.h') + for (my $i = 0; $i < @OPING_PREFIX; $i++) { - next; + if (!-e $OPING_PREFIX[$i] . '/include/oping.h') + { + next; + } + + $OPING_PREFIX = $OPING_PREFIX[$i]; + print "Found in $OPING_PREFIX/include\n"; + last; } +} - $OPING_PREFIX = $OPING_PREFIX[$i]; - print "Found 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"); + } +} +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_PREFIX) +if (!$OPING_CPPFLAGS) { my $search_path = join (', ', @OPING_PREFIX); print STDERR < 'lib/Net/Oping.pm', AUTHOR => 'Florian Forster ') : ()), - LIBS => ["-L$OPING_PREFIX/lib -loping"], + LIBS => [$OPING_LIBS], + ($OPING_LDDLFLAGS ? (LDDLFLAGS => "$OPING_LDDLFLAGS") : ()), DEFINE => '', - INC => "-I$OPING_PREFIX/include" + INC => "$OPING_CPPFLAGS" ); + +sub is_system_libdir +{ + my $path = shift; + for (split (' ', $Config{'libsdirs'})) + { + if ($path eq $_) + { + return (1); + } + } +} -- 2.11.0