2 # (C) Copyright 2006-2013
3 # Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 # SPDX-License-Identifier: GPL-2.0+
7 #########################################################################
9 _depend: $(obj)/.depend
11 # Split the source files into two camps: those in the current directory, and
12 # those somewhere else. For the first camp we want to support CPPFLAGS_<fname>
13 # and for the second we don't / can't.
14 PWD_SRCS := $(foreach f,$(SRCS), $(if \
15 $(filter $(if $(KBUILD_SRC),$(srctree)/)$(src)/$(notdir $f),$f), $f))
16 OTHER_SRCS := $(filter-out $(PWD_SRCS),$(SRCS))
18 # This is a list of dependency files to generate
19 DEPS := $(basename $(addprefix $(obj)/.depend., $(notdir $(PWD_SRCS))))
21 # Join all the dependencies into a single file, in three parts
22 # 1 .Concatenate all the generated depend files together
23 # 2. Add in the deps from OTHER_SRCS which we couldn't process
24 # 3. Add in the HOSTSRCS
25 $(obj)/.depend: $(TOPDIR)/config.mk $(DEPS) $(OTHER_SRCS) \
27 cat /dev/null $(DEPS) >$@
28 @for f in $(OTHER_SRCS); do \
29 g=`basename $$f | sed -e 's/\(.*\)\.[[:alnum:]_]/\1.o/'`; \
30 $(CC) -M $(CPPFLAGS) -MQ $(obj)/$$g $$f >> $@ ; \
32 @for f in $(HOSTSRCS); do \
33 g=`basename $$f | sed -e 's/\(.*\)\.[[:alnum:]_]/\1.o/'`; \
34 $(HOSTCC) -M $(HOSTCPPFLAGS) -MQ $(obj)/$$g $$f >> $@ ; \
37 MAKE_DEPEND = $(CC) -M $(CPPFLAGS) $(EXTRA_CPPFLAGS_DEP) \
38 -MQ $(addsuffix .o,$(obj)$(basename $<)) $< >$@
41 $(obj)/.depend.%: $(src)/%.c
44 $(obj)/.depend.%: $(src)/%.S
47 #########################################################################