tech-toolchain archive

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

Re: question

On Mon, 6 Jun 2011, David Laight wrote:

> On Mon, Jun 06, 2011 at 12:58:53AM +0000, David Holland wrote:
> > Does anyone know why contains the following logic?
> >
> >    _YLSRCS=        ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
> >       :
> >    DPSRCS+=        ${_YLSRCS}
> >       :
> >
> > It appears that this forces a complete recompile any time a .l or .y
> > file is touched, which seems entirely wrong.
> Might be to ensure anything that depends on the generated .h file
> is recompiled - working around the fact that make has no syntax
> for having one set of commands generate 2 files.

I think that is a separate issue.. the idea here seems to be that a
library including a .y or .l file might have hidden dependencies so just
force a rebuild if the sources change.. in effect, <> is trying
to handle complex cases automagically and I guess it has gone far enough
that it works well for building sources which don't change that much, but
less so for sources in heavy development.


On the separate issue, I've found it best to just ignore the .h file for
dependency calculations when a .[ch] pair is produced at the same time as
it causes problems in parallel builds; just use the .c file as it is the
one that appears in other dependencies, so in the following scenario

.SUFFIXES: .y .c .o

        $(YACC) $(YFLAGS) -d $<
        mv -f $*.c
        mv -f $*.h

        $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<

SRCS= a.c b.c c.y
OBJS= a.o b.o c.o

# b.c includes c.h
b.o: c.c

the files c.c, b.o and c.o will be rebuilt after c.y is touched.. since
make follows rules based on "timestamps", and the yacc output should not
really be manually edited, then the rule will work fine..

the proper fix would be to have it handled automatically with some kind
"multi-output" suffix or manual rule

        $(YACC) $(YFLAGS) -d $<
        mv -f $*.c
        mv -f $*.h

gram.[ch]: gram.y
        $(YACC) $(YFLAGS) -d gram.y
        mv -f gram.c
        mv -f gram.h

and then the real dependency can be listed..

Home | Main Index | Thread Index | Old Index