[Top][All Lists]

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

Re: make doesn't complain if target cannot be built

From: Philip Guenther
Subject: Re: make doesn't complain if target cannot be built
Date: Mon, 13 Jan 2014 22:24:52 -0800

On Mon, Jan 13, 2014 at 9:56 PM, Christian Eggers <address@hidden> wrote:
> Is there a workaround for this? Using explicit rules seems to be difficult in
> my case because some objects are built from .c sources, other from .cpp.
> Is there a better way instead of this:
> SOURCES_C := foo.c
> SOURCES_CPP := bar.cpp
> SOURCES_ASM := ...
> OBJS := $(SOURCES_C:%.c=%.o) $(SOURCES_CPP:%.cpp=%.o) ...
> $(SOURCES_C:%.c=%.o):
>         $(COMPILE.c) ...
> $(SOURCES_CPP:%.cpp=%.o):
>         $(COMPILE.cpp) ...
> $(OBJS): generated.h

In many cases, I've found it completely unnecessary to list the source
files.  Just list the objects that should be built and provide pattern
rules for the source types, then let make figure out which source
files generate which objects from the patterns, ala:

OBJS = foo.o bar.o ...
%.o: %.c:
        $(COMPILE.c) ....
%.o: %.cpp
        $(COMPILE.cpp) ....
$(OBJS): generated.h

You only need to match sources to objects if there's a naming
conflict...which I would tend to solve by renaming the file that
doesn't belong.

Side point: you only list an explicit dependency for a file named
generated.h, which suggests you're using some sort of automated
dependency technique (gcc -MD, make depend, etc) for handling
dependency tracking for other .h files.  If that's the case, then it
can be slightly better to use an order-only prerequisite for the
generated file, ala:

$(OBJS): | generated.h

That guarantees the generated.h file will exist before trying to build
any objects, but if generated.h gets rebuilt, only the objects that
have real dependencies from the automated dependency tracking setup
will get rebuilt.

Philip Guenther

reply via email to

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