$NetBSD: patch-aa,v 1.4 2010/03/16 09:53:02 sno Exp $

--- inc/MyBuilder.pm.orig	2010-03-14 18:20:38.000000000 +0000
+++ inc/MyBuilder.pm
@@ -74,9 +74,10 @@ sub ACTION_compile_xscode {
     # .o => .(a|bundle)
     my $lib_file = catfile( $archdir, "BibTeX.$Config{dlext}" );
     if ( !$self->up_to_date( [ @$objects ], $lib_file ) ) {
+	my $btparselibdir = $self->install_path('usrlib');
         $cbuilder->link(
                         module_name => 'Text::BibTeX',
-                        extra_linker_flags => '-Lbtparse/src -lbtparse ',
+                        extra_linker_flags => "-Lbtparse/src -Wl,-R${btparselibdir} -lbtparse ",
                         objects     => $objects,
                         lib_file    => $lib_file,
                        );
@@ -145,11 +146,12 @@ sub ACTION_create_binaries {
     my $exe_file = catfile("btparse","progs","dumpnames$EXEEXT");
     push @toinstall, $exe_file;
     my $object   = catfile("btparse","progs","dumpnames.o");
+    my $btparselibdir = $self->install_path('usrlib');
     if (!$self->up_to_date($object, $exe_file)) {
         $CCL->($cbuilder,
                exe_file => $exe_file,
                objects  => [ $object ],
-               extra_linker_flags => '-Lbtparse/src -lbtparse ');
+               extra_linker_flags => "-Lbtparse/src -Wl,-R${btparselibdir} -lbtparse ");
     }
 
     $exe_file = catfile("btparse","progs","biblex$EXEEXT");
@@ -159,7 +161,7 @@ sub ACTION_create_binaries {
         $CCL->($cbuilder,
                exe_file => $exe_file,
                objects  => [ $object ],
-               extra_linker_flags => '-Lbtparse/src -lbtparse ');
+               extra_linker_flags => "-Lbtparse/src -Wl,-R${btparselibdir} -lbtparse ");
     }
 
     $exe_file = catfile("btparse","progs","bibparse$EXEEXT");
@@ -168,7 +170,7 @@ sub ACTION_create_binaries {
     if (!$self->up_to_date($object, $exe_file)) {
         $CCL->($cbuilder,
                exe_file => $exe_file,
-               extra_linker_flags => '-Lbtparse/src -lbtparse ',
+               extra_linker_flags => "-Lbtparse/src -Wl,-R${btparselibdir} -lbtparse ",
                objects => $object);
     }
 
@@ -299,9 +301,13 @@ sub ACTION_test {
     if ($^O =~ /darwin/i) {
         $ENV{DYLD_LIBRARY_PATH} = catdir($self->blib,"usrlib");
     }
-    if ($^O =~ /(freebsd|solaris|linux)/i) {
+    elsif ($^O =~ /(?:linux|bsd|sun|sol|dragonfly|hpux|irix)/i) {
         $ENV{LD_LIBRARY_PATH} = catdir($self->blib,"usrlib");
     }
+    elsif ($^O =~ /aix/i) {
+        my $oldlibpath = $ENV{LIBPATH} || '/lib:/usr/lib';
+        $ENV{LIBPATH} = catdir($self->blib,"usrlib").":$oldlibpath";
+    }
 
     $self->SUPER::ACTION_test
 }
