blob: e4fd3371df52eff0a5d24f3c772133db778478c8 [file] [log] [blame]
Marian Balakowiczf9328632006-09-01 19:49:50 +02001#
Wolfgang Denkeca3aeb2013-06-21 10:22:36 +02002# (C) Copyright 2006-2013
Marian Balakowiczf9328632006-09-01 19:49:50 +02003# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4#
Wolfgang Denkeca3aeb2013-06-21 10:22:36 +02005# SPDX-License-Identifier: GPL-2.0+
Marian Balakowiczf9328632006-09-01 19:49:50 +02006#
Marian Balakowiczf9328632006-09-01 19:49:50 +02007#########################################################################
8
Masahiro Yamada9e414032014-02-04 17:24:24 +09009_depend: $(obj)/.depend
Marian Balakowiczf9328632006-09-01 19:49:50 +020010
Simon Glass47508842011-10-07 13:53:49 +000011# 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.
Masahiro Yamada9e414032014-02-04 17:24:24 +090014PWD_SRCS := $(foreach f,$(SRCS), $(if \
15 $(filter $(if $(KBUILD_SRC),$(srctree)/)$(src)/$(notdir $f),$f), $f))
16OTHER_SRCS := $(filter-out $(PWD_SRCS),$(SRCS))
Simon Glass47508842011-10-07 13:53:49 +000017
18# This is a list of dependency files to generate
Masahiro Yamada9e414032014-02-04 17:24:24 +090019DEPS := $(basename $(addprefix $(obj)/.depend., $(notdir $(PWD_SRCS))))
Simon Glass47508842011-10-07 13:53:49 +000020
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
Masahiro Yamada9e414032014-02-04 17:24:24 +090025$(obj)/.depend: $(TOPDIR)/config.mk $(DEPS) $(OTHER_SRCS) \
Simon Glasseaeecde2011-10-18 05:50:42 +000026 $(HOSTSRCS)
Simon Glass47508842011-10-07 13:53:49 +000027 cat /dev/null $(DEPS) >$@
28 @for f in $(OTHER_SRCS); do \
29 g=`basename $$f | sed -e 's/\(.*\)\.[[:alnum:]_]/\1.o/'`; \
Masahiro Yamada9e414032014-02-04 17:24:24 +090030 $(CC) -M $(CPPFLAGS) -MQ $(obj)/$$g $$f >> $@ ; \
Simon Glass47508842011-10-07 13:53:49 +000031 done
32 @for f in $(HOSTSRCS); do \
33 g=`basename $$f | sed -e 's/\(.*\)\.[[:alnum:]_]/\1.o/'`; \
Masahiro Yamada9e414032014-02-04 17:24:24 +090034 $(HOSTCC) -M $(HOSTCPPFLAGS) -MQ $(obj)/$$g $$f >> $@ ; \
Simon Glass47508842011-10-07 13:53:49 +000035 done
36
37MAKE_DEPEND = $(CC) -M $(CPPFLAGS) $(EXTRA_CPPFLAGS_DEP) \
38 -MQ $(addsuffix .o,$(obj)$(basename $<)) $< >$@
39
40
Masahiro Yamada9e414032014-02-04 17:24:24 +090041$(obj)/.depend.%: $(src)/%.c
Simon Glass47508842011-10-07 13:53:49 +000042 $(MAKE_DEPEND)
43
Masahiro Yamada9e414032014-02-04 17:24:24 +090044$(obj)/.depend.%: $(src)/%.S
Simon Glass47508842011-10-07 13:53:49 +000045 $(MAKE_DEPEND)
Scott Woodd984fed2009-11-04 18:41:41 -060046
Marian Balakowiczf9328632006-09-01 19:49:50 +020047#########################################################################