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