Subject: Please review: perl patch to make mod_perl.so more painless
To: None <tech-pkg@netbsd.org>
From: Johnny Lam <jlam@jgrind.org>
List: tech-pkg
Date: 10/01/2001 10:57:14
I've included below a patch to the perl package that causes perl modules
from CPAN to link directly against -lperl when built.  Combined with the
recent update of perl to add ${LOCALBASE}/lib to the rpath when creating
shared libraries/modules, these two changes make using mod_perl.so (ap-perl)
more painless.  Instead of needing:

	LoadFile !/usr/lib/libm.so
	LoadFile lib/perl5/5.6.1/i386-netbsd/CORE/libperl.so
	...
	# Any other libraries needed by perl shared modules need to listed
	# with LoadFile here.
	...
	LoadModule perl_module lib/httpd/mod_perl.so
	AddModule mod_perl.c

you'd need only the last two lines as the mod_perl authors intended.

I've tested this patch for several weeks now, and I haven't noticed any
problems with normal perl usage.  However, I admit that I'm a light perl
user at best, so it's not tested thoroughly at all.

I'd like for others to test this patch, or at least view it and tell me
of any potential problems with the patch, or with the whole idea or linking
perl modules against libperl.so.  To test this, please save this patch as
lang/perl5/patches/patch-af and recompile perl.  If I don't hear any
problems over the next two weeks, I'm going to commit this to the tree.

	Thanks,

	-- Johnny Lam <jlam@jgrind.org>

$NetBSD$

--- lib/ExtUtils/MM_Unix.pm.orig	Thu Mar 15 10:25:20 2001
+++ lib/ExtUtils/MM_Unix.pm	Mon Oct  1 03:51:12 2001
@@ -1059,6 +1059,22 @@
     my($ldfrom) = '$(LDFROM)';
     $armaybe = 'ar' if ($^O eq 'dec_osf' and $armaybe eq ':');
     my(@m);
+
+    # Set LLIBPERL to nothing on static perl platforms, and to the flags
+    # needed to link against the shared libperl library on shared perl
+    # platforms.  We peek at lddlflags to see if we need -Wl,-R or -R
+    # to add paths to the run-time library search path.
+    #
+    my($llibperl) = '';
+    if (($^O eq 'netbsd') and ($Config{'useshrplib'} eq 'true')) {
+	if ($Config{'lddlflags'} =~ /-Wl,-R/) {
+	    $llibperl = '-L$(PERL_INC) -Wl,-R$(INSTALLARCHLIB)/CORE -lperl';
+	} elsif ($Config{'lddlflags'} =~ /-R/) {
+	    $llibperl = '-L$(PERL_INC) -R$(INSTALLARCHLIB)/CORE -lperl';
+	}
+    }
+    push(@m,'LLIBPERL = '.$llibperl."\n");
+
     push(@m,'
 # This section creates the dynamically loadable $(INST_DYNAMIC)
 # from $(OBJECT) and possibly $(MYEXTLIB).
@@ -1088,7 +1104,7 @@
 ');
 
     push(@m,'	LD_RUN_PATH="$(LD_RUN_PATH)" $(LD) '.$ldrun.' $(LDDLFLAGS) '.$ldfrom.
-		' $(OTHERLDFLAGS) -o $@ $(MYEXTLIB) $(PERL_ARCHIVE) $(LDLOADLIBS) $(PERL_ARCHIVE_AFTER) $(EXPORT_LIST)');
+		' $(OTHERLDFLAGS) -o $@ $(MYEXTLIB) $(PERL_ARCHIVE) $(LLIBPERL) $(LDLOADLIBS) $(PERL_ARCHIVE_AFTER) $(EXPORT_LIST)');
     push @m, '
 	$(CHMOD) $(PERM_RWX) $@
 ';