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

In our installation, we have perl installed as a multi-platform setup:
/net/tools/perl/perl-5.8.8/bin/perl (wrapper) /net/tools/perl/perl-5.8.8/lib/... /net/tools/perl/perl-5.8.8/sparc/bin/perl /net/tools/perl/perl-5.8.8/i386/bin/perl /net/tools/perl/perl-5.8.8/linux/bin/perl
The perl wrapper is a bourne shell script that runs "uname" to determine what architecture one is in, and then does an exec to the binary specific perl in either sparc (Solaris), i386 (Solaris), or linux. Scripts that use this installation, need to have custom shebang ("#!") headers, so that the script will run on any of the platforms. We're using this setup:
#!/bin/sh -- # -*- perl -*- eval 'exec /net/tools/perl/perl-5.8.8/bin/perl -xw $0 ${1+"$@"}' if 0;
Using this format, our scripts can run without modification on any of our three platforms. There are numerous reasons why we've settled on this setup. Without Linux support, the header is simpler, and can just be as follows (Note the "perl" magic line can be added behind the bourne shell shebang, and the "-x" is not needed.):
#!/bin/sh -- # -*- perl -*- eval 'exec /net/tools/perl/perl-5.8.8/bin/perl -w $0 ${1+"$@"}' if 0;
The Linux bourne shell however doesn't allow arguments, so the "perl" magic string has to be commented as line #2, and then we have to add "-x" so that perl can figure out where it needs to start executing perl correctly. (Read perlrun for more information.) What I'm writing for advice and help with, is that when we try to debug a script with this header, the debugging structure croaks:
% myscript.pl
will run just fine. But to debug, we try this:
% /net/tools/perl/perl-5.8.8/linux/bin/perl -d myscript.pl
This doesn't work. It starts the debugger OK, but then tries to open "-d" as if it's a file. Here's the code:
% cat test-debug.pl #!/bin/sh #!-*- perl -*- eval 'exec /net/tools/perl/perl-5.8.8/bin/perl -wx $0 ${1+"$@"}' if 0; print "$^X\n"; print "HI THERE\n"; exit; % /net/tools/perl/perl-5.8.8/bin/perl -d test-debug.pl Loading DB routines from perl5db.pl version 1.28 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. -d: bad option(s)
This fails the same on all platforms.

So, any advice on how to improve this setup?

Here are some additional points:
So, just curious if anyone in the Monastery has some special sauce that works for both Linux and Solaris... thanks! Cadphile...

Replies are listed 'Best First'.
Re: multi-platform perl header for linux and solaris
by graff (Chancellor) on Feb 19, 2011 at 02:10 UTC
    In our installation, we have perl installed as a multi-platform setup:... How hard/bad would it be to set up your network paths like this:
    /net/sparc/tools/perl-5.8.8/{bin,lib,...} /net/i386/tools/perl-5.8.8/... /net/linux/tools/perl-5.8.8/... # symbolic link: /net/tools -> /etc/tools # on solaris: /etc/tools -> /net/sparc/tools # on freebsd: /etc/tools -> /net/i386/tools # on linux: /etc/tools -> /net/linux/tools
    The idea is that /etc is (presumably) always a local device/volume on any given machine, so you can use a symlink called /etc/tools that points to the appropriate directory tree for a given OS, and still keep all the OS-dependent trees on a common network drive.

    You might want to tweak how you structure it -- what directory level is the best one for isolating the OS-dependent binaries. There might be better solutions, but I've seen this one used to reasonably good effect in a multi-OS setup.