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

This question doesn't have much to do w/ Perl, but since many computer savvy people read this, it's worth a try. I'm working on a project that has to do with the make command in UNIX to build projects. There are makefiles involved - in fact, a makefile tree where there subdirectories with their own makefiles which are called upon by the main makefile (recursive makes).

What I need to do is figure out which files in the project are used for which applications - each build can consist of several applications. I'll be writing a Perl script (if this is possible) that basically spits out info about the files used for each application in the whole build - some files might be shared.

Is there any possible way from reading the main makefile (root directory of the project) and extracting this information? I'm on HP-UX, but I use ClearCase which, in turn, provides clearmake - their own version of the UNIX make(1). I figured out that by running clearmake w/ the -w -d and -n optionas, I get a dry run that gives me the names of all the directories and files used in the build for the project, but I still haven't found a way to separate this by application or executable, IF possible at all. I know this is mostly a Perl board, but maybe someone can point me to a place where I can get an answer to my question or where I can make sure that there is no one solution.

Thanx for any help I can get!!!

Replies are listed 'Best First'.
Re: The dreadful Makefiles
by bikeNomad (Priest) on Jul 03, 2001 at 00:26 UTC
    You could use the CPAN Make module, which knows how to parse makefiles.
Re: The dreadful Makefiles
by clemburg (Curate) on Jul 03, 2001 at 13:13 UTC

    For some background on what you are trying to do, you might be interested in this article on Black: a make replacement.

    One big problem here is the ability of make to execute arbitrary, even dynamically built, commands to build a target.

    You might want to have a look at the "-np" switch of make, which prints out the internal database of make, with all rules, targets, etc. (a lot of output). In my make's output (GNU make that is), the output is preceded by a standard comment indicating the source of the rule/assignment, like "# makefile", "# environment". By recursive grepping over this output, you might achieve some of your goals. For visualization of your results, I heartily recommend GraphViz.

    Christian Lemburg
    Brainbench MVP for Perl
    http://www.brainbench.com