szabgab has asked for the wisdom of the Perl Monks concerning the following question:

I am playing with the idea of creating a compiled version of perl with loads of modules that can be installed on a Linux system and used similar to what Strawberry Perl provides for Windows but I have an issue:

After a relocatable perl 5.10 built using -Duserelocatableinc both the scripts that come with perl and scripts that are installed by modules have the following lines at the beginning of the file:

bin/cpan that comes with perl:

#!/tmp/xl/perl-5.10.0-xl-03/bin/perl eval 'exec /tmp/xl/perl-5.10.0-xl-03/bin/perl -S $0 ${1+"$@"}' if $running_under_some_shell; #!/usr/bin/perl
bin/padre that was installed later:
#!/tmp/xl/perl-5.10.0-xl-03/bin/perl eval 'exec /tmp/xl/perl-5.10.0-xl-03/bin/perl -S $0 ${1+"$@"}' if 0; # not running under some shell
Once I move the whole installation to some other place these will stop working and I'll have to write /path/to/new/location/bin/perl /path/to/new/location/bin/cpan I guess it could be fixed by running an update script after relocating the code but is there a better way that does not require making changes after moving the files?

Replies are listed 'Best First'.
Re: scripts in relocatable perl
by ambrus (Abbot) on Jun 28, 2009 at 11:11 UTC

    I've never tried this with perl, but you can usually move a ruby installation if you always give it -I parameters with the module directories. All I needed is a wrapper which figures out which directory your ruby is and adds the necessary -I parameters to the command line. Also, I compiled all the modules statically in the ruby executable, which is ugly, but you may be able to avoid this too. There may of course be problems with particular modules that assume they aren't moved after they're installed and search for data files (not ruby code or shared libraries) in particular paths, but in practice this doesn't come up so often. As I've said, I haven't tried this with perl, but I imagine it's possible with some work too.

    One more hint. It may help if you check out how the makefiles test perl before installing it, because these scripts have to do something similar. The commands are quite complicated, but they may still help.

Re: scripts in relocatable perl
by szabgab (Priest) on Jun 28, 2009 at 12:55 UTC
    As I can actually assume that there is a system perl installed (at least for now) I came up with this solution:
    #!/usr/bin/perl if (not $ENV{PORTABLE_XL_PERL}) { require FindBin; local $ENV{PORTABLE_XL_PERL} = 1; local $ENV{PERL5LIB} = ''; local $ENV{PERLLIB} = ''; exec("$FindBin::Bin/perl", $0, @ARGV); } print $^X;
    At first sight it seems to work though I still have to find out how to make this the beginning of all the scripts.

      Copy this file into your Perl core lib directory:

      package CORE::Relocatable; sub import { return if $^O eq 'MSWin32' # or whatever check you deem necessary if (not $ENV{PORTABLE_XL_PERL}) { require FindBin; local $ENV{PORTABLE_XL_PERL} = 1; local $ENV{PERL5LIB} = ''; local $ENV{PERLLIB} = ''; exec("$FindBin::Bin/perl", $0, @ARGV); } } 1

      ... and have all your scripts

      use CORE::Relocatable;

      Duh - I don't know whether a relocated Perl on Unix will know where its site/lib directory is, so this might still be a nonstarter :-(

Re: scripts in relocatable perl
by mzedeler (Pilgrim) on Jun 29, 2009 at 13:05 UTC

    Maybe its possible to cook up something with the env command?