help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Pre-including a generated file


From: Leandro Lucarella
Subject: Re: Pre-including a generated file
Date: Wed, 12 Aug 2009 14:37:40 -0300
User-agent: mutt-ng/devel-r804 (Debian)

Paul Smith, el 12 de agosto a las 12:22 me escribiste:
> On Wed, 2009-08-12 at 11:46 -0300, Leandro Lucarella wrote:
> > Hi. I would like to be able to include a generated file each time I run
> > make. I have a small script that generates some make rules. The file
> > should be generated *always*, and the results of the file should be
> > included by make.
> > 
> > I tried something like this:
> > 
> > file:
> >     ./gen_file
> > 
> > include file
> > 
> > .PHONY: file
> > 
> > But it doesn't work. It seems that make first includes the (old) file,
> > then regenerate it. I tried to add a rule like Makefile: file to tell make
> > to remake the Makefile itself when "file" is changed but it doesn't work
> > either.
> > 
> > This usually works with "automatic dependencies", so I guess there should
> > be any way to get arround, but I tried and tried and came up with nothing.
> 
> This is not how it works with automatic dependencies: as John points out
> make always reads all its makefiles, then it tries to rebuild them all,
> then (if it rebuilds any of them) it re-execs itself.
> 
> There is no way to change this such that it won't read any makefiles
> before trying to rebuild them.
> 
> If you really want that command run every single time, probably simpler
> is to remove the rule to build it and just use $(shell ...), like this:
> 
>       __dummy := $(shell ./gen_file)
>       include file

I tried to do that too, but I had some problems. The thing is, I use make
to generate the file. Maybe it's time to explain what I'm trying to do
with some more detail =)

The script I'm working on is supposed to find automatically when
a command-line to build some target has changed, so the target get
rebuilt.

The idea is to use make itself with -Bn to "peek" at what targets have to
be built to fulfill the make goal. Using --debug I can get the (target,
command) tuples. Then I store that information into a file and in the next
make run, I load the previous commands, compare them to the new ones
(parsing make -Bn --debug again) and see if something changes. In that
case, I write a makefile with ".PHONY: target" for each changed target.

To invoke the script I use:

        ./gen_file $(MAKE) $(MAKECMDGOALS)

If I put this in the Makefile:

        __dummy := $(shell ./gen_file $(MAKE) $(MAKECMDGOALS))
        include file

And then run make CFLAGS=-Wall, for example, it looks like the make -Bn
that I run inside gen_file is not getting the CFLAGS, and thus not
detecting any changes in the command line used to build the targets.

When I use $(MAKE) inside a target action, it seems that make passes the
CFLAGS to child processes just fine.

Thank you.

PS: I know there are other ways to figure out if the flags have changed to
    rebuild stuff, I just thought this could be an interesting idea to
    play with, so I'm not looking for alternative way of detecting when
    flags changes.

-- 
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
Qué sabía Galileo de astronomía, Mendieta! Lo que pasa es que en este
país habla cualquiera.
        -- Inodoro Pereyra





reply via email to

[Prev in Thread] Current Thread [Next in Thread]