Implement dependency generation in libtools.make.

Automatically generate dependency files for all sources so changes in headers
are picked up automatically. Use one dependency file for each source file,
since that allows to create them without using external tools (except the
compiler of course).

Change-Id: I246c1ceb525692547af22a2e32c4bab0c11507e1
This commit is contained in:
Dominik Riebeling 2013-05-11 20:15:53 +02:00
parent 9a9efefdb2
commit e073bc9484

View file

@ -74,10 +74,12 @@ endif
WINDRES = windres
BUILD_DIR ?= $(TARGET_DIR)build$(COMPILETARGET)
OBJDIR = $(abspath $(BUILD_DIR)/$(RBARCH))/
ifdef RBARCH
CFLAGS += -arch $(RBARCH)
OBJDIR = $(abspath $(BUILD_DIR)/$(RBARCH))/
else
OBJDIR = $(abspath $(BUILD_DIR))/
endif
all: $(BINARY)
@ -85,7 +87,11 @@ all: $(BINARY)
OBJS := $(patsubst %.c,%.o,$(addprefix $(OBJDIR),$(notdir $(SOURCES))))
LIBOBJS := $(patsubst %.c,%.o,$(addprefix $(OBJDIR),$(notdir $(LIBSOURCES))))
# create dependency files. Make sure to use the same prefix as with OBJS!
$(foreach src,$(SOURCES) $(LIBSOURCES),$(eval $(addprefix $(OBJDIR),$(subst .c,.o,$(notdir $(src)))): $(src)))
$(foreach src,$(SOURCES) $(LIBSOURCES),$(eval $(addprefix $(OBJDIR),$(subst .c,.d,$(notdir $(src)))): $(src)))
DEPS = $(addprefix $(OBJDIR),$(subst .c,.d,$(notdir $(SOURCES) $(LIBSOURCES))))
-include $(DEPS)
# additional link dependencies for the standalone executable
# extra dependencies: libucl
@ -135,6 +141,10 @@ clean:
rm -f $(OBJS) $(OUTPUT) $(TARGET_DIR)lib$(OUTPUT)*.a $(OUTPUT).dmg
rm -rf $(OUTPUT)-* i386 ppc $(OBJDIR)
%.d:
$(SILENT)$(call mkdir,$(BUILD_DIR))
$(SILENT)$(CC) -MG -MM -MT $(subst .d,.o,$@) $(CFLAGS) -o $(BUILD_DIR)/$(notdir $@) $<
# extra tools
BIN2C = $(TOP)/tools/bin2c
$(BIN2C):