00a2dc
From 83b4921f10f9df96ec359e20489864080f7b37ca Mon Sep 17 00:00:00 2001
00a2dc
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
00a2dc
Date: Thu, 12 Jan 2012 17:05:19 +0100
00a2dc
Subject: [PATCH] Do not set RPATH by default
00a2dc
MIME-Version: 1.0
00a2dc
Content-Type: text/plain; charset=UTF-8
00a2dc
Content-Transfer-Encoding: 8bit
00a2dc
00a2dc
Former behavior can be forced by setting USE_MM_LD_RUN_PATH
00a2dc
environment variable to 1.
00a2dc
00a2dc
This is copy from `perl' package.
00a2dc
See <https://bugzilla.redhat.com/show_bug.cgi?id=773622>.
00a2dc
00a2dc
Signed-off-by: Petr Písař <ppisar@redhat.com>
00a2dc
---
00a2dc
 lib/ExtUtils/Liblist.pm   |  5 +++++
00a2dc
 lib/ExtUtils/MM_Unix.pm   |  2 +-
00a2dc
 lib/ExtUtils/MakeMaker.pm | 56 ++++++++++++++++++++++++++++++++++++++++++++++-
00a2dc
 3 files changed, 61 insertions(+), 2 deletions(-)
00a2dc
00a2dc
diff --git a/lib/ExtUtils/Liblist.pm b/lib/ExtUtils/Liblist.pm
00a2dc
index 15eed3c..219e96b 100644
00a2dc
--- a/lib/ExtUtils/Liblist.pm
00a2dc
+++ b/lib/ExtUtils/Liblist.pm
00a2dc
@@ -89,6 +89,11 @@ libraries.  LD_RUN_PATH is a colon separated list of the directories
00a2dc
 in LDLOADLIBS. It is passed as an environment variable to the process
00a2dc
 that links the shared library.
00a2dc
 
00a2dc
+Fedora extension: This generation of LD_RUN_PATH is disabled by default.
00a2dc
+To use the generated LD_RUN_PATH for all links, set the USE_MM_LD_RUN_PATH
00a2dc
+MakeMaker object attribute / argument, (or set the $USE_MM_LD_RUN_PATH
00a2dc
+environment variable).
00a2dc
+
00a2dc
 =head2 BSLOADLIBS
00a2dc
 
00a2dc
 List of those libraries that are needed but can be linked in
00a2dc
diff --git a/lib/ExtUtils/MM_Unix.pm b/lib/ExtUtils/MM_Unix.pm
00a2dc
index 6233513..198f05e 100644
00a2dc
--- a/lib/ExtUtils/MM_Unix.pm
00a2dc
+++ b/lib/ExtUtils/MM_Unix.pm
00a2dc
@@ -1045,7 +1045,7 @@ sub xs_make_dynamic_lib {
00a2dc
     }
00a2dc
 
00a2dc
     my $ld_run_path_shell = "";
00a2dc
-    if ($self->{LD_RUN_PATH} ne "") {
00a2dc
+    if (($self->{LD_RUN_PATH} ne "") && ($self->{USE_MM_LD_RUN_PATH})) {
00a2dc
         $ld_run_path_shell = 'LD_RUN_PATH="$(LD_RUN_PATH)" ';
00a2dc
     }
00a2dc
 
00a2dc
diff --git a/lib/ExtUtils/MakeMaker.pm b/lib/ExtUtils/MakeMaker.pm
00a2dc
index 3d4913e..b52c96d 100644
00a2dc
--- a/lib/ExtUtils/MakeMaker.pm
00a2dc
+++ b/lib/ExtUtils/MakeMaker.pm
00a2dc
@@ -317,7 +317,7 @@ sub full_setup {
00a2dc
     PERM_DIR PERM_RW PERM_RWX MAGICXS
00a2dc
     PL_FILES PM PM_FILTER PMLIBDIRS PMLIBPARENTDIRS POLLUTE
00a2dc
     PREREQ_FATAL PREREQ_PM PREREQ_PRINT PRINT_PREREQ
00a2dc
-    SIGN SKIP TEST_REQUIRES TYPEMAPS UNINST VERSION VERSION_FROM XS
00a2dc
+    SIGN SKIP TEST_REQUIRES TYPEMAPS UNINST USE_MM_LD_RUN_PATH VERSION VERSION_FROM XS
00a2dc
     XSBUILD XSMULTI XSOPT XSPROTOARG XS_VERSION
00a2dc
     clean depend dist dynamic_lib linkext macro realclean tool_autosplit
00a2dc
 
00a2dc
@@ -503,6 +503,26 @@ sub new {
00a2dc
         $self->_PRINT_PREREQ;
00a2dc
    }
00a2dc
 
00a2dc
+    # USE_MM_LD_RUN_PATH - another RedHatism to disable automatic RPATH generation
00a2dc
+    if ( ( ! $self->{USE_MM_LD_RUN_PATH} )
00a2dc
+       &&( ("@ARGV" =~ /\bUSE_MM_LD_RUN_PATH(=([01]))?\b/)
00a2dc
+        ||( exists( $ENV{USE_MM_LD_RUN_PATH} )
00a2dc
+           &&( $ENV{USE_MM_LD_RUN_PATH} =~ /([01])?$/ )
00a2dc
+           )
00a2dc
+        )
00a2dc
+       )
00a2dc
+    {
00a2dc
+       my $v = $1;
00a2dc
+       if( $v )
00a2dc
+       {
00a2dc
+           $v = ($v=~/=([01])$/)[0];
00a2dc
+       }else
00a2dc
+       {
00a2dc
+           $v = 1;
00a2dc
+       };
00a2dc
+       $self->{USE_MM_LD_RUN_PATH}=$v;
00a2dc
+    };
00a2dc
+
00a2dc
     print "MakeMaker (v$VERSION)\n" if $Verbose;
00a2dc
     if (-f "MANIFEST" && ! -f "Makefile" && ! $UNDER_CORE){
00a2dc
         check_manifest();
00a2dc
@@ -2797,6 +2817,40 @@ precedence.  A typemap in the current directory has highest
00a2dc
 precedence, even if it isn't listed in TYPEMAPS.  The default system
00a2dc
 typemap has lowest precedence.
00a2dc
 
00a2dc
+=item USE_MM_LD_RUN_PATH
00a2dc
+
00a2dc
+boolean
00a2dc
+The Fedora perl MakeMaker distribution differs from the standard
00a2dc
+upstream release in that it disables use of the MakeMaker generated
00a2dc
+LD_RUN_PATH by default, UNLESS this attribute is specified , or the
00a2dc
+USE_MM_LD_RUN_PATH environment variable is set during the MakeMaker run.
00a2dc
+
00a2dc
+The upstream MakeMaker will set the ld(1) environment variable LD_RUN_PATH
00a2dc
+to the concatenation of every -L ld(1) option directory in which a -l ld(1)
00a2dc
+option library is found, which is used as the ld(1) -rpath option if none
00a2dc
+is specified. This means that, if your application builds shared libraries
00a2dc
+and your MakeMaker application links to them, that the absolute paths of the
00a2dc
+libraries in the build tree will be inserted into the RPATH header of all
00a2dc
+MakeMaker generated binaries, and that such binaries will be unable to link
00a2dc
+to these libraries if they do not still reside in the build tree directories
00a2dc
+(unlikely) or in the system library directories (/lib or /usr/lib), regardless
00a2dc
+of any LD_LIBRARY_PATH setting. So if you specified -L../mylib -lmylib , and
00a2dc
+ your 'libmylib.so' gets installed into /some_directory_other_than_usr_lib,
00a2dc
+ your MakeMaker application will be unable to link to it, even if LD_LIBRARY_PATH
00a2dc
+is set to include /some_directory_other_than_usr_lib, because RPATH overrides
00a2dc
+LD_LIBRARY_PATH.
00a2dc
+
00a2dc
+So for Fedora MakeMaker builds LD_RUN_PATH is NOT generated by default for
00a2dc
+every link. You can still use explicit -rpath ld options or the LD_RUN_PATH
00a2dc
+environment variable during the build to generate an RPATH for the binaries.
00a2dc
+
00a2dc
+You can set the USE_MM_LD_RUN_PATH attribute to 1 on the MakeMaker command
00a2dc
+line or in the WriteMakefile arguments to enable generation of LD_RUN_PATH
00a2dc
+for every link command.
00a2dc
+
00a2dc
+USE_MM_LD_RUN_PATH will default to 1 (LD_RUN_PATH will be used) IF the
00a2dc
+$USE_MM_LD_RUN_PATH environment variable is set during a MakeMaker run.
00a2dc
+
00a2dc
 =item VENDORPREFIX
00a2dc
 
00a2dc
 Like PERLPREFIX, but only for the vendor install locations.
00a2dc
-- 
00a2dc
2.13.6
00a2dc