views:

1033

answers:

7

I need to run Perl applications I develop on cygwin Windows on HP unix / Solaris hosts. I am not a superuser on the unix machines and I can't touch the default Perl module location nor can I install modules to the default Perl module location. Also the unix installation lacks most basic modules and I can't change that.

For example, I have a Perl application that needs Expect which has native C compiled parts to it. How would I roll out this application to unix with its required dependencies without having to install anything else on that box?

Is there way to build the entire Perl application under Cygwin Windows and then just roll out one executable to unix and run it from my home directory there?


EDIT addition based on answers so far:

Thanks in particular to brian, the local LIB dir solution seems to work in case of native Perl, but in case of Perl module needing C components, cross platform compiling, ie compiling on cygwin to run on Solaris, is not really possible as I feared.

However would having an other linux installation help, i.e. would this be possible easier between different flavors of Unix like package Perl on linux and then deploy to Solaris/HP? And what about something like lcc ?

Also I'd still like to hear little more if somebody has rolled out a native Perl package on Windows that includes all dependencies for a complicated Perl app that can then be moved to unix as just one file? (I do now understand that it won't work in case native C code is included like in in Expect.pm, but what about in case of app only using pure perl modules?)

Basically for many reasons I am trying to minimize time I need to spend being logged into these "production" unix hosts and do as much as possible locally beforehand.


Added a new cross-compile question, since I felt I was maybe veering too far from the original perl question.


EDIT -- Par looks promising for pure Perl, although same deal, it doesn't look to solve the cross platform compile problem for native extensions

+1  A: 

Set your environment variable PERLLIB to your personnal Perl lib directory or use the -I command line switch to Perl to indicate it.

If you have access to the HP-UX machine you can compile Expect there and install it in your directory. But cross compilation from Windows to HP-UX is probably much more difficult. You would have to build a GCC cross compiler.

kmkaplan
OK, just found this http://faq.perl.org/perlfaq8.html#How_do_I_keep_my_own , but it doesn't solve the native compilation problem
Ville M
+2  A: 

Compiling a Perl script with all its dependencies on Windows with Cygwin and running it Solaris is just not going to work.

Now the question is: do you have access to a compiler on that Solaris computer? It's not because you do not have root access that you cannot compile and install Perl modules in your home directory by using:

perl Makefile.PL PREFIX=$HOME

If you have CPAN available on your Solaris system you can set the prefix in the CPAN shell this way:

  1. start the shell perl -MCPAN -e shell;
  2. change the prefix with conf makepl_arg PREFIX=/path/to/your/home/directory

For your script to run, you can either start perl with the -I $HOME command-line switch, e.g.:

perl -I $HOME script.pl

Your other option would be to place this at the begining of your script

use lib $ENV{'HOME'};
Pierre-Luc Simard
I just realized, to complicated things, other unix is HP, so I got both. Native is the problem. It does have some compiler, cc is the HP-UX C compiler.c89 , but not sure how well that will work. Also there is no cpan command, and perl is old This is perl, v5.6.1 for PA-RISC2.0.Can c89 compile cpan?
Ville M
CPAN is a perl module, you have to run it as one. Thus `perl -MCPAN -e shell`. That should drop you to a `cpan>` prompt.
Jack M.
If you can compile modules, you should also be ablt to compile perl itself. Using the same arguments for the configure command on every platform will give you even more compatibility.
innaM
If you really don't have CPAN installed, you can always install the modules the old fashion way: download, tar xzf module.tgz, cd module, perl Makefile.PL PREFIX=$HOME, make install
Mathieu Longtin
This one, perl -MCPAN -e shell;, actually worked. But, I can't get it to actually install anything. Starting it says: Please, install Net::FTP as soon as possible. But if I run that as recommended:cpan> install Bundle::libnetCan't exec "--decompress...It looks like box can't access outside atall
Ville M
I think you meant -I there instead of -l, which specifies the value of the line-ending characater. I already fixed it for you :)
brian d foy
PREFIX is going to be a bit of a problem here because it will create arch directories where the compiled bits will show up. You have to add those to your @INC too. INSTALL_BASE might be better.
brian d foy
OK, I am slowly getting cpan working on the hpux box, 1 problem was lack of gzip, so took me a while to find binary because it would not compile, then I had to compile wget as well as set proxy port correctly. I am not trying install PAR, but it looks to hang on running tests. updates to come
Ville M
+1  A: 

If you have a compiler on each of your systems (and some other tools needed by configure like grep), you should not only be able to compile modules, but you should also be able to build your own perl executables.

GeorgeM
+2  A: 

I haven't tried this particular feature, but perl2exe says it supports cross platform builds.

daotoad
+1 I've used this in the past and it saves a lot of headaches.
bsruth
Interesting, I was hoping for a free alternative but I will take a look. I assume that perl2exe does something PAR does not?
Ville M
I'm not sure how perl2exe does the cross compilation. My guess is that IndigoStar provides any platform appropriate shared libraries needed, and bundles them in the package, along with the loader executable. Not 100% sure. Contact Indigo support and ask them about it.
daotoad
A: 

You'll want local::lib. Once you've done that, the pure Perl modules should work cross platform, but you'll have to identify and reinstall the compiled modules on the foreign platform. Do the initial install on a real unix, cpan on cygwin is slow.

singingfish
I haven't noticed cpan on Cygwin being slow. Can you explain what you mean by that?
brian d foy
Actually it's in response to a user report on some documentation I wrote. It appears that on a slightly under-specced dev box, using cygwin, things run rather slower than they did on my inadequately specced (512mb ram) G4 iBook, so my evidence is anecdotal at this stage.
singingfish
If it's anecdotal, can you remove the comment in your answer then? I'm happy to respond to problems with my software and I expect people to say truthful and supported things about it.
brian d foy
My comment is not really totally unsubstantiated, it comes from the pain my long suffering tech reviewer went through installing Catalyst and related stuff for my book.
singingfish
+8  A: 

In this case, I'd consider delivering a complete application complete with its own Perl. You get to choose any version you like and any modules you like. Compile everything, organize everything into a directory, then tar the result. To deploy, copy the file and untar. Use the advice that others have already noted about library search paths, etc. In essence, your application gets its own stack.

Now, the trick there is the cross compilation. Why are you developing on Cygwin? Is that a target too? Is there a reason you don't have an HP/UX or Solaris development machine? What architecture are you targeting (RISC, SPARC, Intel, etc). If you can't get hardware to run those, get some virtual machines for your targets and develop there.

Aside from that, you can install modules anywhere you have permissions. See perlfaq8:

brian d foy
"Why are you developing on Cygwin? Is that a target too? ", answer is yes, I'd like these apps to run on windows too, and it seems easiest to stick to cygwin on windows since its most unix like.
Ville M
"What architecture are you targeting (RISC, SPARC, Intel, etc)."For some reason at this organization unix dev machines are tough to get. Architecture of the HP UX is RISC2.0. I gotta check on that solaris.Is there free VM that would run on windows XP for HP ux / Solaris? Recommendations?
Ville M
Why do you need a free VM? Spend $100 and save yourself a lot of time.
brian d foy
got time but not $100 :)
Ville M
Anyways, what do you recommend for $100?
Ville M
I like your approach and I am trying to install a whole local hierarchy as you explained. I ran into problem setting up a new local home Perl, so I added a question here: http://stackoverflow.com/questions/588559/how-to-set-up-different-perl-version-in-home-directory-is-there-perlhome-that-b
Ville M
A: 

I've run across this several times on my work systems. We have a base install of Perl 5.8 and I don't have the ability to add modules. Here's the solution I use:

  1. Create a folder called 'lib' in your project root (ex: ~/projects/MyProject/lib)
  2. Any modules you download from CPAN should have a Makefile as well as a directory called "lib". Copy the contents of the lib folder into your newly created lib folder. Some modules may only contain a single .pm file, and no lib structure. Just copy the .pm file.

Your code should do the following: first, use any modules that have been installed normally, then unshift your @INC environment variable to use your local libraries:

# Declare Includes --------------------------------------------------------------------------------
use Getopt::Long;
use vars qw($VERSION);
use DirHandle;
use FileHandle;


# Force perl to use our local 'lib' directory for imported modules, this allows us to
# use modules without having to install them in th emain perl assembly. However, this
#also prevents these modules from being used in other projects.
BEGIN { unshift @INC, "lib"; }
use Error qw(:try);
use SOAP::Transport::HTTP;
#use LWP::Protocol::https;
use XML::Simple;
use XML::Writer;
use XML::Writer::String;

The caveat to this method is that some Perl modules don't use the 'lib' method or have additional dependencies. If you run into problems, examine the Makefile.PL for the module and see what it's doing.

Tequila Jinx
Don't just copying the lib directory. Build the module then use the contents of blib instead.
brian d foy