> From: Andrew Gaffney [mailto:[EMAIL PROTECTED] 
> Sent: Saturday, 21 February 2004 4:53 PM
> To: beginners
> Subject: parsing Makefiles
> 
> I'm looking to write a script that will parse a toplevel 
> Makefile in a source tree and 
> then descend into all the directories and parse those 
> Makefiles in order to determine how 
> many 'make' operations will actually be launched. At the 
> moment, I am just playing around, 

May I suggest, in a helpful way, that this is a rather silly thing
to be doing.  As such its just the sort of thing I love to do.

Suggestions:
1)  Check out the perl 'Make' module which implements the make command.
    You may be able to perform a full 'make -n' using it and count the
    actions.

2)  Rather than implement:
                a) Include files
                b) Variable expansion
                c) Implicit rules and suffixes 
                        etc
                        etc
        Consider launching 'make -p' and parsing the database dump,
        or even 'make -n -d' and parsing the diagnostics (rough guess
can be 
      the count of 'Must remake ...' lines in the output.)

        Depending on your version of Make, '-n' may or may not recurse
        (gnu make ignores the '-n' for commands which are '$(MAKE) -f
<newmakefile>' but
        passes the '-n' to the sub-make to make sure nothing gets built)
        If it doesn't, you may still have to perform the recursion
manually while
        parsing the parent makefile, because each subdirectory Makefile
may depend
        on arguments and ENVIRONMENT passed from the parent.

HTH

Have fun with that.  Send some code to the list when it works!


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to