"be consistent" | |
PerlMonks |
MakeMaker-Makefile Reform Schoolby Intrepid (Deacon) |
on Mar 30, 2005 at 22:38 UTC ( [id://443626]=CUFP: print w/replies, xml ) | Need Help?? |
Reforming the Makefile Madness for my specific machine / OSNOTE: Updated Sat Apr 26 10:43:42 UTC 2008 to fix broken links pointed out in child node 682635 make and Makefiles and all pertaining to that are so uncool that for me they've wrapped right around back into cool. This node documents what I have invented to serve the end purpose of having builds of perl modules go more smoothly (well, builds either "go" or "not go", so let's say "smoothly" == "to proper completion") on my non-Unix system. The description of that system follows below, but for now let's skip forward to avoid bad bogged-downnesses. The old standard for creating a Perl module (or other) distribution is to create a file Makefile.PL in the toplevel of the distro tree. I'm not going to discuss Module::Build in this node (or its children) because I do not use it and am interested in (a fan of) GNU make. So this writeup is about the efficient use of the generated Makefile that we'll have after running the classic first-step of the module-building invocation triplet (perl Makefile.PL; make test; make install). It's not about other theoretical or half-realized approaches to installing perl modules. The Makefile that is generated by MakeMaker.pm's WriteMakefile function is a big water buffalo, there is no debate about that from this corner. This does not make it impossible to comprehend, however. Yours Truly has spent many hours poring over Makefiles for many packages, both perl and non-perl in nature, and can say this much: there is a method (heheh) to the madness. Unlike what the Camel says about trying to read the output of some of the Perl-to-C generators, one will not go blind trying to read this generated Makefile. One may well want to beat one's dogs afterwards, but one will not go blind! Before going much further the author feels obligated to allow the reader to sample what a classic perl MakeMaker-generated Makefile looks like. So one is provided for inspection here. One was pulled at random out of the .cpan/build directory. It's to the Data::Dumper package, which does not (in the authors opinion) sin particularly in regards to MakeMaker.pm misuse. The woes that can afflict the user (installer, admin or otherwise) of this system can include having a Makefile generated which does not give correct or complete directives for telling the C tools (cc, ld) how to compile and link the C code part of the module. On the particular system in question this problem was ameliorated in part by a completely separate scheme which will someday be described in greater detail elsewhere, but which in brief, uses the interesting package ExtUtils::FakeConfig (not CORE and not carried on PPM in its up to date revision, at time of this writing) to override some of the key %Config::Config hash values. By replacing the ones shipped by a vendor (which were supposedly correct for the system on which the Perl was built) with ones correct for the system on which Perl was installed (and on which the attempt is being made to install additional modules), this useful tool has allowed the author to rather painlessly add quite complex modules to his Perl installation. It being high time to describe this "non-Unix" system, it shall be done: it is a ActiveState Perl downloaded and installed in the standard manner (standard for AS), and the one used for development was specifically perl 5.8.0, AS build 806. The system is Windows XP. The twist is that the build environment is not similar to the one which most users familiar with Perl on Win32 expect to be limited to:
Here are a few issues that such a system causes to arise:
We can use the fact that Makefile.PL is just a Perl program to create better, prettier and more accurate Makefiles by placing overrides for some of these things into the Makefile.PL. How to override the overridable MakeMaker methods is fully documented in other places (such as the manpage for MakeMaker) so it will not be elicudated extensively here. But item (1) in the list above is a thornier problem: there is no global method or tactic for making all those perverted backslashes lean in the correct direction ;-), and that's a showstopper if we do not repair it. The more severe means that author has devised rewrite the entire Makefile (and incidentally output it under a different name: GNUmakefile) with several types of mutations performed on it. The slash problem is corrected this way. Because GNU make when invoked with no -f (as we customarily do it in the perl world) prefers GNUmakefile to plain "Makefile" or "makefile", our reformulated input to make is what gets used to build, test and install the module package's files. The tasks that need to be accomplished to cause perl Makefile.PL to generate this nicer GNUmakefile for any given module package should not be too burdensome for the author, or he won't do it (Perl impatience: "don't make me repeat lengthy procedures in duplicate instances"). What has worked so far is described next. There are some things which the author needs to tell Perl about before the WriteMakefile() subroutine is invoked in the Makefile.PL, and there are some things which much take place after that WriteMakefile() has been invoked and created the Makefile. To accomplish this any module's Makefile.PL can just have two alterations made to it at appropriate locations in the file (before and after). These alterations are the addition of a single line in each case: a perl require() statement. Here's an example, for the CPAN module C::Scan:
There are two require statements that don't exist in the distributed (CPAN/upstream) unaltered Makefile.PL file. These "pull in" perl code at the right points in the flow of compilation and execution. That perl code is contained in two files which can be viewed at the links below. By keeping them in a common location their reuse is facilitated. Other, better ways of making this possible may yet be devised by the author. This is a work-in-progress. YMMV. Caveat Scriptor.
Disclamers and NoticesThere is every likelihood that the author will be needing to make revisions to this node after its initial posting. No debates about Module::Build please. And please try to take debates about the merits of using "external tools like make" to other threads, as well. These areas have all been thoroughly discussed in the past. Difference in opinion exist. While the author relishes a rousing flamewar as much as the next Monk, he will consider raising those issue on this node a form of defacement or vandalism or at minimum, deep disrespect. The ExtUtils::FakeConfig package provides a "template-driven" way to override Perl buid parameters. The package provides starting points for the MinGW tools, but I found that I needed to add and make changes to the provided Config_m file. My changes as they currently exist may be seen here. May the Force be with you. Subvert the Dark Side to noble ends! ;-) Soren A / somian / perlspinr / Intrepid
-- Now, 2005: The 3 least meaningful terms in online jargon are: troll flame rant These used to mean something; but then they were highjacked by the kind of inferior intellects who, when faced with a more erudite opponent employing superior arguments (or simply hanging in there with a disagreeable contention), abuse these terms as merely another form of name-calling. ;-)
Back to
Cool Uses for Perl
|
|