[I'm sorry, I took us off-list a couple messages ago. Back on now.]

On 9 January 2014 16:36, Ben Pfaff <b...@cs.stanford.edu> wrote:

> >
> > OK, do you need me to resend the patch?
>
> If you don't mind.
>

Attached.


>
> > > It looks to me like you don't have direct access to the gnulib Git
> > > repository.  Do you want me to apply this on your behalf?
> >
> > Yes please.
>
> OK, I'll do that tonight.
>

Thanks!

-- 
http://rrt.sc3d.org
From 339742ed86847abbd52d8bcd8093b5201b3dc66f Mon Sep 17 00:00:00 2001
From: Reuben Thomas <r...@sc3d.org>
Date: Thu, 9 Jan 2014 22:31:42 +0000
Subject: [PATCH] relocatable-perl: like relocatable-script, but for Perl
 scripts

* build-aux/relocatable.pl.in: Add.
* doc/relocatable-maint.texi: Add documentation.
* modules/relocatable-perl: Add.
---
 ChangeLog                   |  7 +++++
 build-aux/relocatable.pl.in | 64 +++++++++++++++++++++++++++++++++++++++++++++
 doc/relocatable-maint.texi  | 30 +++++++++++++++++++++
 modules/relocatable-perl    | 26 ++++++++++++++++++
 4 files changed, 127 insertions(+)
 create mode 100644 build-aux/relocatable.pl.in
 create mode 100644 modules/relocatable-perl

diff --git a/ChangeLog b/ChangeLog
index 67bbf7b..4a2ccf9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2014-01-09  Reuben Thomas  <r...@sc3d.org>
+
+	relocatable-perl: like relocatable-script, but for Perl scripts
+	* build-aux/relocatable.pl.in: Add.
+	* doc/relocatable-maint.texi: Add documentation.
+	* modules/relocatable-perl: Add.
+
 2014-01-07  Paul Eggert  <egg...@cs.ucla.edu>
 
 	tests: fix export bug in previous patch
diff --git a/build-aux/relocatable.pl.in b/build-aux/relocatable.pl.in
new file mode 100644
index 0000000..5472468
--- /dev/null
+++ b/build-aux/relocatable.pl.in
@@ -0,0 +1,64 @@
+# The functions in this file provide support for relocatability of
+# Perl scripts.  They should be included near the beginning of each
+# Perl script in a relocatable program, by adding @relocatable_pl@
+# and causing the script to be expanded with AC_CONFIG_FILES.  A
+# small amount of additional code must be added and adapted to the
+# package by hand; see doc/relocatable-maint.texi (in Gnulib) for
+# details.
+#
+# This code is based on relocatable.sh.in, and design changes (and
+# bugs) should probably be cross-checked with it.
+#
+# Copyright (C) 2013 Free Software Foundation, Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+use Config;
+use File::Basename;
+use File::Spec::Functions;
+use Cwd 'realpath';
+
+# Support for relocatability.
+sub find_curr_installdir {
+  # Determine curr_installdir, even taking into account symlinks.
+  my $curr_executable = $0;
+  my $basename = basename($0);
+  if ($curr_executable eq $basename) {
+    LOOP: for my $dir (split /$Config{path_sep}/, $ENV{PATH}) {
+      $dir = "." unless $dir;
+      for my $ext ('') {
+        my $filename = catfile($dir, "$curr_executable$ext");
+        if (-f $filename) {
+          $curr_executable = $filename;
+          last LOOP;
+        }
+      }
+    }
+  }
+  # Resolve symlinks and canonicalize.
+  return realpath(dirname($curr_executable));
+}
+sub find_prefixes {
+  # Compute the original/current installation prefixes by stripping the
+  # trailing directories off the original/current installation directories.
+  my ($orig_installprefix, $curr_installprefix) = @_;
+  my $orig_last = basename($orig_installprefix);
+  my $curr_last = basename($curr_installprefix);
+  if ($orig_last && $curr_last && $orig_last eq $curr_last) {
+    $orig_installprefix = dirname($orig_installprefix);
+    $curr_installprefix = dirname($curr_installprefix);
+  }
+  return $orig_installprefix, $curr_installprefix;
+}
diff --git a/doc/relocatable-maint.texi b/doc/relocatable-maint.texi
index f972b2f..75b1318 100644
--- a/doc/relocatable-maint.texi
+++ b/doc/relocatable-maint.texi
@@ -144,6 +144,36 @@ where the script gets installed.  Also, at the end, instead of
 that you need.
 
 @item
+If your package installs Perl scripts, also import the
+@code{relocatable-perl} module.  Then, near the beginning of each
+Perl script that your package installs, add the following:
+
+@example
+@@relocatable_pl@@
+if ("@@RELOCATABLE@@" eq "yes") {
+  my $exec_prefix = "@@exec_prefix@@";
+  my $orig_installdir = "@@bindir@@"; # see Makefile.am's *_SCRIPTS variables
+  my ($orig_installprefix, $curr_installprefix) = find_prefixes($orig_installdir, find_curr_installdir());
+  sub relocate { # the subroutine is defined whether or not the enclosing block is executed
+    my ($dir) = @@_;
+    if ("@@RELOCATABLE@@" eq "yes") {
+      $dir =~ s%^$orig_installprefix/%$curr_installprefix/%;
+      $dir =~ s,/$,,;
+    }
+    return $dir;
+  }
+}
+
+# Get some relocated directory names.
+$sysconfdir = relocate("@@sysconfdir@@");
+$some_datadir = relocate(@@datadir@@/something");
+@end example
+
+You must adapt the definition of @code{$orig_installdir}, depending on
+where the script gets installed.  Also, at the end, instead of
+@code{$gettext_dir}, transform those variables that you need.
+
+@item
 In your @file{Makefile.am}, for every program @command{foo} that gets
 installed in, say, @file{$(bindir)}, you add:
 
diff --git a/modules/relocatable-perl b/modules/relocatable-perl
new file mode 100644
index 0000000..e131394
--- /dev/null
+++ b/modules/relocatable-perl
@@ -0,0 +1,26 @@
+Description:
+Help make Perl scripts relocatable, that is, to allow them to
+function properly when copied to an arbitrary directory.
+
+Files:
+doc/relocatable.texi
+build-aux/relocatable.pl.in
+m4/relocatable-lib.m4
+
+Depends-on:
+
+configure.ac:
+AC_REQUIRE([gl_RELOCATABLE_NOP])
+relocatable_pl=$ac_aux_dir/relocatable.pl.in
+AC_SUBST_FILE([relocatable_pl])
+
+Makefile.am:
+
+Include:
+
+License:
+GPL
+
+Maintainer:
+Bruno Haible, Ben Pfaff, Reuben Thomas
+
-- 
1.8.3.2

Reply via email to