Makefile重新编译所有内容

时间:2018-04-09 09:13:15

标签: gcc makefile gnu-make

我知道这个问题多次出现,但无论如何我似乎无法找到问题。

对象和依赖项文件在自己的文件夹中创建。但似乎在重新编译时不使用它们。我做错了什么?

我已关注http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#combine生成依赖项文件。

APP = test

OBJDIR = obj

DEPDIR = dep

HDRS =  -Ibuild/src_generated -Isrc -Isrc/client -Isrc/server -Ideps -Iinclude -Iplugins
SRCS =  $(wildcard build/src_generated/*.c) \
        $(wildcard src/*.c) \
        $(wildcard src/client/*.c) \
        $(wildcard src/server/*.c) \
        $(wildcard deps/*.c) \
        plugins/ua_accesscontrol_default.c \
        plugins/ua_clock.c \
        plugins/ua_config_default.c \
        plugins/ua_debug_dump_pkgs.c \
        plugins/ua_log_stdout.c \
        plugins/ua_network_tcp.c \
        plugins/ua_nodestore_default.c \
        plugins/ua_pki_certificate.c \
        plugins/ua_securitypolicy_none.c \
        tutorial_server_datasource.c
SRCDIRS = ./build/src_generated ./src ./src/client ./src/server ./deps ./plugins
OBJS = $(patsubst %.c,$(OBJDIR)/%.o,$(SRCS))

POSTCOMPILE = @mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d && touch $@

CFLAGS = -Os -std=c99 -DUA_NO_AMALGAMATION 
DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td

$(APP): buildrepo $(OBJS)
    $(CC) $(OBJS) -o $@ $(CFLAGS) $(HDRS) -s

$(OBJDIR)/%.o: %.c $(DEPDIR)/%.d
    $(CC) $(DEPFLAGS) $(CFLAGS) $(HDRS) -o $@ -c $<
    $(POSTCOMPILE)

$(DEPDIR)/%.d: ;
.PRECIOUS: $(DEPDIR)/%.d


include $(wildcard $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS))))

.PHONY: clean
clean:
    rm -rf $(OBJDIR)/*
    rm -rf $(DEPDIR)/*
    rm -rf $(APP)

buildrepo:
    @$(call make-repo)

define make-repo
   for dir in $(SRCDIRS); \
   do \
    mkdir -p $(OBJDIR)/$$dir; \
    mkdir -p $(DEPDIR)/$$dir; \
   done
endef

1 个答案:

答案 0 :(得分:0)

这一行:

include $(wildcard $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS))))

预计所有依赖项文件都在一个文件夹中。你可能想要:

-include ${SRCS:%.c=$(OBJDIR)/%.d} # Note the leading -