Reputation: 1124
I have a series of perl scripts for which I'm writing a Makefile.PL
script, but I'm rather inexperienced with ExtUtils::MakeMaker
.
One of the scripts I wrote makes a system call to a command line utility that must be installed in order for the script to run properly. My script can gracefully detect that the utility is missing and issue an error about installing it and putting it in the user's path, but is there some standard way to handle this in the Makefile.PL script? Could it even gasp attempt to install the third-party utility if I enter the download link in the Makefile.PL script?
At the very least, I'd like the script to warn the user if the external dependency was not found. I know I can write a test case that uses it. Is this as simple as copying and pasting the subroutine I wrote in the script itself that checks for the third party utility and prints an error if it's not found or would that be the "wrong way to do it"?
Upvotes: 3
Views: 646
Reputation: 1124
If you have an external dependency on a command-line utility (i.e. there's no perl module that does what the utility does), ExtUtils::MakeMaker is not designed to handle such a dependency. What you need to do is write an install script or edit the make file to handle the dependency. Here are the considerations in doing so:
Note, you may need to know whether your script is running as root or not, which you can verify using id -u
to check if the user ID is root (i.e. '0').
Upvotes: 0
Reputation: 13664
Let's call this external dependency foobar
, for sake of argument.
As per @KeepCalmAndCarryOn's comment, firstly consider whether foobar
could be replaced by something from CPAN (maybe Foo::Bar
), or a few lines of Perl.
Otherwise, the best course of action is:
Create a new CPAN distribution called Alien::Foobar
. The job of Alien::Foobar
is to download, perhaps compile, and then install foobar
, as part of Alien::Foobar
's Makefile.PL or Build.PL.
(There exists a module called Alien::Base
which aims to make doing this sort of thing easier. It's mostly aimed at installing libraries rather than binaries, though I've had some success using it for the latter.)
Now the Makefile.PL you were originally working on can declare a dependency on Alien::Foobar
.
Upvotes: 1