PDA

View Full Version : What does a 'Makefile.pl' Do?


Pontifex
08-13-2007, 05:19 AM
I did a search on the subject, but as I expected I found many threads talking about what to do if one fails. A search on google return similar results. No definitions.

I know from my work with C that a makefile will build a plethora of different files into a single binary (basically), but I don't truly understand what a makefile.pl is doing in the modules I download.

I've inspected the code and it looks to be building a 'makefile' for use with 'make', but I don't know if it runs any other tests. From using one with a module (http://search.cpan.org/~mirod/XML-Twig-3.29/Twig.pm) I recently downloaded, I found that it appears to do be doing some testing:


$ perl Makefile.PL
Do you want to install 'xml_pp' (XML pretty printer)? [y] y
Do you want to install 'xml_grep' (XML grep - grep XML files using XML::Twig's s
ubset of XPath)? [y] y
Do you want to install 'xml_split' (split big XML files)? [y] y
Do you want to install 'xml_merge' (merge back files created by xml_split)? [y]
y
Do you want to install 'xml_spellcheck' (spellcheck XML files skipping tags)? [y
] y
Checking if your kit is complete...
Looks good
Writing Makefile for XML::Twig


Though it just prompts me to install things. I've seen others that do testing (I'm a bit fuzzy on that point as I'm just getting back into Perl after a Hiatus).

When I used the 'makefile' it generated:


$ make
/usr/bin/perl.exe speedup Twig_pm.slow > Twig.pm
perl version is 5.008008 XML::Parser version is 2.34
/usr/bin/perl.exe -i_bak -p filter_for_5.005 Twig.pm Twig/XPath.pm
/usr/bin/perl.exe check_optional_modules
cp Twig.pm blib/lib/XML/Twig.pm
cp Twig/XPath.pm blib/lib/XML/Twig/XPath.pm
cp tools/xml_merge/xml_merge blib/script/xml_merge
/usr/bin/perl.exe "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/xml_merge
cp tools/xml_grep/xml_grep blib/script/xml_grep
/usr/bin/perl.exe "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/xml_grep
cp tools/xml_pp/xml_pp blib/script/xml_pp
/usr/bin/perl.exe "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/xml_pp
cp tools/xml_spellcheck/xml_spellcheck blib/script/xml_spellcheck
/usr/bin/perl.exe "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/xml_spellch
eck


The only it seems to be doing (or at least what it's telling me about) is to move files around. It seems to be installing things into my include path. I can't be certain with a lot more examination, but it looks as if this particular makefile is installing modules from the archive I downloaded to their proper places in my perl include directories.

I know most makefile are not the same, but is this the general idea behind 'makefile.pl'? To generate a makefile that does not in fact compile anything, but rather just moves the modules to their proper places on my system?

--Pontifex

FishMonger
08-13-2007, 08:20 AM
This is copied from "Writing Perl Modules for CPAN" which you should pick up.
http://www.apress.com/book/bookDisplay.html?bID=14

If you don't come from a UNIX programming background, you might not be familiar with Makefiles. A Makefile is a script processed by a program called make. When make is run, it automatically looks for a file called Makefile in the current directory. Make uses the information stored in the Makefile to perform the steps necessary to build and install programs from source files. To accomplish this task, a Makefile specifies a set of rules and dependencies.

A Makefile rule is a particular step in the build process—examples of rules you've seen so far include “test” and “install”. When you run the command make test, you're instructing make to run the “test” rule in the Makefile. Makefiles also support the notion of a default rule that is run when no rule is explicitly specified, usually called “all”.

Aside from rules that specify activities such as make test and make install, Makefiles also have rules for creating files. One example of this type of rule is the one used to turn a module's POD documentation into a UNIX manual page through the pod2man program.

Makefiles combine rules by laying out rule dependencies. For example, the “all” rule depends on the rule to build manual pages from POD documentation, among others. Dependencies work in two ways. First, they specify a series of steps describing how to complete a requested rule. Second, they allow make to intelligently skip rules when it can tell that the target is ip-to-date. Fro example, make can tell that is doesn't need to rerun pod2man unless the module file containing the POD has been changed since the last time pod2man was run.

For more information about how Makefiles work on your system, see the documentation for your make command.

Pontifex
08-15-2007, 06:41 AM
I know about that. Or at least the meaning behind the explanation. I'm not sure what has to do with my Module though. My Make file is doing something with files certainly. But to what end?

When I tried to use the files the 'make' generated is said I had errors in 'parser.pm', which is of no help to me. I added the directory - that the 'make' created for me - to my include path and it only generated errors. So in order to find out what's going on I need to know what the Makefile did.

I know that rules are executed and the dependency tree is traversed. But what purpose is there in 'making' the files if I don't know how to use them?

If the module came with any sort of install instructions, I'd be set. Or even if the makefile was commented on its use. But there are neither. I gather this is the default state of modules from CPAN (I've used a few and had similar experiences), both from your explanation and examination of said modules' contents.

I have never come across anything that details the use of Makefiles in this particular situation. Thus my question here. I don't need to know what Makefiles do in general, but rather what they're doing here.

--Pontifex

Pontifex
08-17-2007, 01:58 AM
So, re-reading that passage above, I tried to make sense of it in relation to my question. There really isn't a direct connection, but it did put me in mind of an idea. There's no direct link from the CPAN web site about module installation, but the FAQ has something. Their explanation of how to install modules is rather arcane and unusable, at least for what I'm doing:

How_install_Perl_modules (http://www.cpan.org/misc/cpan-faq.html#How_install_Perl_modules)

Installing a new module can be as simple as typing perl -MCPAN -e 'install Chocolate::Belgian'. The CPAN.pm documentation has more complete instructions on how to use this convenient tool. If you are uncomfortable with having something take that much control over your software installation, or it otherwise doesn't work for you, the perlmodinstall documentation covers module installation for UNIX, Windows and Macintosh in more familiar terms.

Finally, if you're using ActivePerl on Windows, the PPM (Perl Package Manager) has much of the same functionality as CPAN.pm.


Since I've downloaded the module already, there's really no need to go into the details of another mysterious installation process. But that's better than the primer above on how makefiles work, for the purpose of answering my question.

A simple google search for 'install cpan modules' showed something very useful though:

http://www.cpan.org/modules/INSTALL.html

Which details steps to go through to install modules with the package already in hand. True it doesn't detail exactly what the makefile generated by makefile.pl actually does; But it does provide some hints. Which is all I'll probably ever get.

This part in particular was very helpful:


D. INSTALL

While still in that directory, type:

make install

Make sure you have the appropriate permissions to install the module in your Perl 5 library directory. Often, you'll need to be root.


Which implies - quite strongly - that the makefile will move the appropriate modules to the correct library directory, at the very least; Nevermind what else it's capable of or what it actually does to the module components to get them ready for use.

At last! Some hint about what's going on with the install process!

In retrospect either one of these links would have been helpful in answering my question.

Thank you.

--Pontifex

FishMonger
08-17-2007, 02:28 AM
If you need detailed info on building and installing modules, then the book I mentioned would be the best resource and it also goes into what the makefile does. If you want to know the gory details, which varies greatly with every makefile, then you need to first look at the code of the Makefile.PL script to see what it does, then look at the make file that it generated. When you get to a section that you don't understand, post the code and ask for an explanation.

I know most makefile are not the same, but is this the general idea behind 'makefile.pl'? To generate a makefile that does not in fact compile anything, but rather just moves the modules to their proper places on my system?That all depends on the module you're installing and its dependencies. If a module is written solely in Perl, then all it needs to do is copy the files to their proper locations. On the other hand, if the module comes with libraries that need to be compiled, then they will be compiled before being moved to their proper location.

FishMonger
08-17-2007, 02:48 AM
BTW, your original question:What does a 'Makefile.pl' Do?Is considerably different from what it now appears what your question should have been.What are the steps to download and manually install a module on a Linux system?

Pontifex
08-18-2007, 01:14 AM
That all depends on the module you're installing and its dependencies. If a module is written solely in Perl, then all it needs to do is copy the files to their proper locations. On the other hand, if the module comes with libraries that need to be compiled, then they will be compiled before being moved to their proper location.


That's excellent! Thank you. I was looking for a broad overview like this, among other things apparently.

I needed a place to start. Having some mysterious commands to type in does almost nothing for me, if I don't know (in a broad sense) what's going on. Really I like to have an idea about what's going on so I have some sense about what's normal and what's not. For example, if this module came with libraries, I would have had no clue what any mysterious messages were, concerning their building; Before this I would have expected all Perl files. Armed with this knowledge, that modules need to: Assert that their dependencies are met, compile code (at times) and to install modules into the appropriate include path; I now have a better understanding of the things that may happen during install time for all future packages.

Prior to this discussion I had thought that all that was needed for successful installation and use of a Perl module would be to copy it into the appropriate directory. Now the use of Makefile.pl is more clear.


BTW, your original question:


You're quite right. My questions evolved as I began to experiment with the module I've since installed. I should have reposted the question in a more condensed form.

--Pontifex