On Mon, Jan 13, 2014 at 9:56 PM, Christian Eggers <cegg...@gmx.de> 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 > > EOF
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 _______________________________________________ Bug-make mailing list Bug-make@gnu.org https://lists.gnu.org/mailman/listinfo/bug-make