![]() |
MakeMaker made easy |
||||
![]() |
|
||||
|
|
||||
This document describes how Perl's MakeMaker facility can be used to
provide a Makefile to easily install your Perl modules and scripts.
Copyright 1999 Johan Vromans, Squirrel Consultancy. IntroductionMost Perl modules and scripts come in packages, usually compressed (gzipped) tar archives. To install such a package, the following commands are required (on a Unix system): perl Makefile.PL make all; make test make install This sounds easy, and, in fact, it is easy. Until you try to roll your own Makefile.PL for your own package... The quick wayWith a couple of simple guidelines a setup can be quickly realised that satisfies the MakeMaker facility. Of course, there is more than one way to do it...
As an example I will use the PostScript::Font package. This package contains
three modules, PostScript::Font, PostScript::FontMetrics and
PostScript::FontInfo, and three scripts: fontsampler, pfb2pfa and pfa2pfb. For
this, I have set up a source directory
The source directory itself contains the
The module PostScript::Font is phisically located in a file
MANIFEST Makefile.PL lib/PostScript/Font.pm lib/PostScript/FontMetrics.pm lib/PostScript/FontInfo.pm script/fontsampler script/pfb2pfa script/pfa2pfb t/basic.t
The contents of use ExtUtils::MakeMaker; WriteMakefile ( NAME => 'PostScript::Font', VERSION => "0.03", EXE_FILES => [ qw(script/fontsampler script/pfb2pfa script/pfa2pfb) ], );
First of all, the '
Then the function WriteMakefile is called. This function will write the actual
Note that the modules are not mentioned. This is because WriteMakefile looks
for modules (files with names that end with ' Let's give it a try. % perl Makefile.PL Checking if your kit is complete... Looks good Writing Makefile for PostScript::Font
What happened? MakeMaker has first checked if your kit is complete. It does
that by reading the file % make mkdir blib mkdir blib/lib mkdir blib/lib/PostScript mkdir ...some more directories... mkdir blib/man1 mkdir blib/man3 cp lib/PostScript/FontMetrics.pm blib/lib/PostScript/FontMetrics.pm cp lib/PostScript/Font.pm blib/lib/PostScript/Font.pm cp lib/PostScript/FontInfo.pm blib/lib/PostScript/FontInfo.pm Manifying blib/man3/PostScript::FontMetrics.3 Manifying blib/man3/PostScript::Font.3 Manifying blib/man1/pfb2pfa.1 Manifying blib/man1/pfa2pfb.1 Manifying blib/man3/PostScript::FontInfo.3 Manifying blib/man1/fontsampler.1 mkdir blib/script cp script/pfa2pfb blib/script/pfa2pfb perl -MExtUtils::MakeMaker -e "MY->fixin(shift)" blib/script/pfa2pfb cp script/pfb2pfa blib/script/pfb2pfa perl -MExtUtils::MakeMaker -e "MY->fixin(shift)" blib/script/pfb2pfa cp script/fontsampler blib/script/fontsampler perl -MExtUtils::MakeMaker -e "MY->fixin(shift)" blib/script/fontsampler Impressive, isn't it? We see that the following things happened:
Next, we can test the package: % make test perl -Iblib/lib -e 'use Test::Harness; runtests @ARGV;' t/*.t t/basic.............ok All tests successful. Files=1, Tests=6
What happens is that Perl runs all scripts in the directory # make install Installing /usr/lib/perl5/site_perl/5.005/PostScript/FontMetrics.pm Installing /usr/lib/perl5/site_perl/5.005/PostScript/Font.pm Installing /usr/lib/perl5/site_perl/5.005/PostScript/FontInfo.pm Installing /usr/man/man1/pfb2pfa.1 Installing /usr/man/man1/pfa2pfb.1 Installing /usr/man/man1/fontsampler.1 Installing /usr/lib/perl5/5.00502/man/man3/PostScript::FontMetrics.3 Installing /usr/lib/perl5/5.00502/man/man3/PostScript::Font.3 Installing /usr/lib/perl5/5.00502/man/man3/PostScript::FontInfo.3 Installing /usr/bin/pfa2pfb Installing /usr/bin/pfb2pfa Installing /usr/bin/fontsampler Writing /usr/lib/perl5/site_perl/5.005/i586-linux/auto/PostScript/Font/.packlist Appending installation info to /usr/lib/perl5/5.00502/i586-linux/perllocal.pod Another thing we can do is create a new package for distribution: % make tardist rm -rf PostScript-Font-0.03 perl -MExtUtils::Manifest=manicopy,maniread \ -e "manicopy(maniread(),'PostScript-Font-0.03', 'best');" mkdir PostScript-Font-0.03 mkdir PostScript-Font-0.03/lib mkdir PostScript-Font-0.03/lib/PostScript mkdir PostScript-Font-0.03/script mkdir PostScript-Font-0.03/t tar cvf PostScript-Font-0.03.tar PostScript-Font-0.03 PostScript-Font-0.03/ PostScript-Font-0.03/lib/ PostScript-Font-0.03/lib/PostScript/ PostScript-Font-0.03/lib/PostScript/Font.pm PostScript-Font-0.03/lib/PostScript/FontMetrics.pm PostScript-Font-0.03/lib/PostScript/FontInfo.pm PostScript-Font-0.03/script/ PostScript-Font-0.03/script/pfa2pfb PostScript-Font-0.03/script/pfb2pfa PostScript-Font-0.03/script/fontsampler PostScript-Font-0.03/t/basic.t PostScript-Font-0.03/MANIFEST PostScript-Font-0.03/Makefile.PL PostScript-Font-0.03/README rm -rf PostScript-Font-0.03 gzip --best PostScript-Font-0.03.tar
Using the Manifest facility, a temporary, directory hierarchy is set
up named Writing the test scriptsTest scripts are important, since they can verify that a package was correctly installed. Writing test scripts can be quite complex, depending on the functionality of the package.
With regard to the test harness that runs the test scripts, each script has to
print a line to the standard output that denotes the number of tests in this
script, for example: ' Real lifeReality is not always as simple. Although everything described above is perfectly okay, my real set up is a little more complicated, though not much.
First of all, I have a directory
Also, all sources are under version control. In the main directory a
subdirectory
Finally, I have a MANIFEST Makefile.PL RCS/Font.pm,v RCS/FontInfo.pm,v RCS/FontMetrics.pm,v RCS/MANIFEST,v RCS/Makefile.PL,v RCS/fontsampler.pl,v RCS/pfb2pfa.pl,v README Released/PostScript-Font-0.02.tar.gz Released/PostScript-Font-0.03.tar.gz lib/PostScript/Font.pm -> ../../../src/Font.pm lib/PostScript/FontInfo.pm -> ../../../src/FontInfo.pm lib/PostScript/FontMetrics.pm -> ../../../src/FontMetrics.pm script/fontsampler -> ../../src/fontsampler.pl script/pfa2pfb -> ../../src/pfb2pfa.pl script/pfb2pfa -> ../../src/pfb2pfa.pl src/Font.pm src/FontInfo.pm src/FontMetrics.pm src/RCS -> ../RCS src/fontsampler.pl src/pfb2pfa.pl Indeed, pfb2pfa and pfa2pfb are one single program. Also, Makefile.PL has a little bit more info in it: # Verify perl version. require 5.000; use ExtUtils::MakeMaker; my @scripts = qw(fontsampler pfb2pfa pfa2pfb); WriteMakefile ( NAME => 'PostScript::Font', ($[ >= 5.005) ? (AUTHOR => 'Johan Vromans (jvromans@squirrel.nl)', ABSTRACT => 'Modules to get info from PostScript fonts') : (), VERSION => "0.03", PREREQ_PM => { 'Getopt::Long' => 2.00, 'IO' => 0 }, EXE_FILES => [ map { "script/$_" } @scripts ], # *.pm files will be picked up automatically from ./lib ); Major additions are:
PitfallsWriteMakefile does a great job in making one's life easy. Unfortunately, it can be too helpful.
Do not place files with extension '
Also, do not place any ![]() This work is licensed under a Creative Commons License. |
|||||
|
|
||||
© Copyright 2003-2018 Johan Vromans. All Rights Reserved. |