Blob Blame History Raw
From 9b80126d33174059a03502521d5cb1fdc9b2c3a1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Thu, 12 Jan 2012 17:05:19 +0100
Subject: [PATCH] Do not set RPATH by default
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Former behavior can be forced by setting USE_MM_LD_RUN_PATH
environment variable to 1.

This is copy from `perl' package.
See <https://bugzilla.redhat.com/show_bug.cgi?id=773622>.

Signed-off-by: Petr Písař <ppisar@redhat.com>
---
 lib/ExtUtils/Liblist.pm   |  5 ++++
 lib/ExtUtils/MM_Unix.pm   |  2 +-
 lib/ExtUtils/MakeMaker.pm | 56 ++++++++++++++++++++++++++++++++++++++-
 3 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/lib/ExtUtils/Liblist.pm b/lib/ExtUtils/Liblist.pm
index 44c4c39..3983194 100644
--- a/lib/ExtUtils/Liblist.pm
+++ b/lib/ExtUtils/Liblist.pm
@@ -89,6 +89,11 @@ libraries.  LD_RUN_PATH is a colon separated list of the directories
 in LDLOADLIBS. It is passed as an environment variable to the process
 that links the shared library.
 
+Fedora extension: This generation of LD_RUN_PATH is disabled by default.
+To use the generated LD_RUN_PATH for all links, set the USE_MM_LD_RUN_PATH
+MakeMaker object attribute / argument, (or set the $USE_MM_LD_RUN_PATH
+environment variable).
+
 =head2 BSLOADLIBS
 
 List of those libraries that are needed but can be linked in
diff --git a/lib/ExtUtils/MM_Unix.pm b/lib/ExtUtils/MM_Unix.pm
index a0a2ee1..dda54bb 100644
--- a/lib/ExtUtils/MM_Unix.pm
+++ b/lib/ExtUtils/MM_Unix.pm
@@ -1076,7 +1076,7 @@ sub xs_make_dynamic_lib {
     }
 
     my $ld_run_path_shell = "";
-    if ($self->{LD_RUN_PATH} ne "") {
+    if (($self->{LD_RUN_PATH} ne "") && ($self->{USE_MM_LD_RUN_PATH})) {
         $ld_run_path_shell = 'LD_RUN_PATH="$(LD_RUN_PATH)" ';
     }
 
diff --git a/lib/ExtUtils/MakeMaker.pm b/lib/ExtUtils/MakeMaker.pm
index 90790d4..f5459eb 100644
--- a/lib/ExtUtils/MakeMaker.pm
+++ b/lib/ExtUtils/MakeMaker.pm
@@ -317,7 +317,7 @@ sub full_setup {
     PERM_DIR PERM_RW PERM_RWX MAGICXS
     PL_FILES PM PM_FILTER PMLIBDIRS PMLIBPARENTDIRS POLLUTE
     PREREQ_FATAL PREREQ_PM PREREQ_PRINT PRINT_PREREQ PUREPERL_ONLY
-    SIGN SKIP TEST_REQUIRES TYPEMAPS UNINST VERSION VERSION_FROM XS
+    SIGN SKIP TEST_REQUIRES TYPEMAPS UNINST USE_MM_LD_RUN_PATH VERSION VERSION_FROM XS
     XSBUILD XSMULTI XSOPT XSPROTOARG XS_VERSION
     clean depend dist dynamic_lib linkext macro realclean tool_autosplit
 
@@ -503,6 +503,26 @@ sub new {
         $self->_PRINT_PREREQ;
    }
 
+    # USE_MM_LD_RUN_PATH - another RedHatism to disable automatic RPATH generation
+    if ( ( ! $self->{USE_MM_LD_RUN_PATH} )
+       &&( ("@ARGV" =~ /\bUSE_MM_LD_RUN_PATH(=([01]))?\b/)
+        ||( exists( $ENV{USE_MM_LD_RUN_PATH} )
+           &&( $ENV{USE_MM_LD_RUN_PATH} =~ /([01])?$/ )
+           )
+        )
+       )
+    {
+       my $v = $1;
+       if( $v )
+       {
+           $v = ($v=~/=([01])$/)[0];
+       }else
+       {
+           $v = 1;
+       };
+       $self->{USE_MM_LD_RUN_PATH}=$v;
+    };
+
     print "MakeMaker (v$VERSION)\n" if $Verbose;
     if (-f "MANIFEST" && ! -f "Makefile" && ! $UNDER_CORE){
         check_manifest();
@@ -2839,6 +2859,40 @@ precedence.  A typemap in the current directory has highest
 precedence, even if it isn't listed in TYPEMAPS.  The default system
 typemap has lowest precedence.
 
+=item USE_MM_LD_RUN_PATH
+
+boolean
+The Fedora perl MakeMaker distribution differs from the standard
+upstream release in that it disables use of the MakeMaker generated
+LD_RUN_PATH by default, UNLESS this attribute is specified , or the
+USE_MM_LD_RUN_PATH environment variable is set during the MakeMaker run.
+
+The upstream MakeMaker will set the ld(1) environment variable LD_RUN_PATH
+to the concatenation of every -L ld(1) option directory in which a -l ld(1)
+option library is found, which is used as the ld(1) -rpath option if none
+is specified. This means that, if your application builds shared libraries
+and your MakeMaker application links to them, that the absolute paths of the
+libraries in the build tree will be inserted into the RPATH header of all
+MakeMaker generated binaries, and that such binaries will be unable to link
+to these libraries if they do not still reside in the build tree directories
+(unlikely) or in the system library directories (/lib or /usr/lib), regardless
+of any LD_LIBRARY_PATH setting. So if you specified -L../mylib -lmylib , and
+ your 'libmylib.so' gets installed into /some_directory_other_than_usr_lib,
+ your MakeMaker application will be unable to link to it, even if LD_LIBRARY_PATH
+is set to include /some_directory_other_than_usr_lib, because RPATH overrides
+LD_LIBRARY_PATH.
+
+So for Fedora MakeMaker builds LD_RUN_PATH is NOT generated by default for
+every link. You can still use explicit -rpath ld options or the LD_RUN_PATH
+environment variable during the build to generate an RPATH for the binaries.
+
+You can set the USE_MM_LD_RUN_PATH attribute to 1 on the MakeMaker command
+line or in the WriteMakefile arguments to enable generation of LD_RUN_PATH
+for every link command.
+
+USE_MM_LD_RUN_PATH will default to 1 (LD_RUN_PATH will be used) IF the
+$USE_MM_LD_RUN_PATH environment variable is set during a MakeMaker run.
+
 =item VENDORPREFIX
 
 Like PERLPREFIX, but only for the vendor install locations.
-- 
2.20.1