[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Relocatable Perl scripts

From: Reuben Thomas
Subject: Relocatable Perl scripts
Date: Thu, 21 Nov 2013 23:50:44 +0000

I wanted to make a relocatable Perl script. My first thought was to rewrite the relocatable-sh module for Perl, but of course that would be some work.

My second thought was to have a relocatable-sh wrapper. For most scripting languages, that would probably be necessary, and would work OK, although depending on the language, getting the variables in in a way that doesn't interfere with command-line arguments might be a problem. In Lua, for example, you can set variables on the command line.

With Perl, you can avoid a separate wrapper, because of its parsing tricks, and I used this to pass the relocated paths.

Maybe this is useful enough to be worth documenting? A collection of such templates for different languages could be quite helpful. I can feel a similar trick coming on for Lua to get it all in one file, but even for languages requiring a separate wrapper, all that's needed is to make bindir one of the relocated variables, and use that to find the "real" script.

# -*- perl -*- this line sets the syntax mode for Emacs
# Perl script with relocatable header

if test "@RELOCATABLE@" = yes; then
  orig_installdir="$sbindir" # see Makefile.am's *_SCRIPTS variables
  func_find_curr_installdir # determine curr_installdir
  # Relocate the directory variables that we use.
    echo "$gettext_dir/" \
    | sed -e "s%^${orig_installprefix}/%${curr_installprefix}/%" \
    | sed -e 's,/$,,'`

# The next line tells Perl to start parsing
eval 'exec perl -x -wS $0 "$gettext_dir" ${1+"$@"}'
    if 0;

my $gettext_dir = shift;

# "real" script starts here
print STDOUT "gettext_dir: $gettext_dir; ARGV[0]: $ARGV[0]\n";


reply via email to

[Prev in Thread] Current Thread [Next in Thread]