Nowadays, GDB build tree is almost flat, but source tree isn't. We
have arch/ nat/ target/ common/ cli/ mi/ tui/ python/ guile/
directories.
We need to some rules in Makefile for source files in different source
directories, like,
# Rules for compiling .c files in the various source subdirectories.
%.o: ${srcdir}/arch/%.c
$(COMPILE) $<
$(POSTCOMPILE)
%.o: ${srcdir}/nat/%.c
$(COMPILE) $<
$(POSTCOMPILE)
so we should take care of some special case that files' base name is
the
same, like,
# Specify an explicit rule for gdb/common/agent.c, to avoid a clash
with the
# object file generate by gdb/agent.c.
common-agent.o: $(srcdir)/common/agent.c
$(COMPILE) $(srcdir)/common/agent.c
$(POSTCOMPILE)
As we add more and more files in different directories, it becomes
tricky
to name files, because we need take this into account.
This patch takes the first step toward "Replicate src dir in build
dir",
that is, we create arch/ directory in buildtree, and put amd64.o there
as an example. Dependency tracking is updated for files with directory
name. Currently, when we build amd64.o,
"-c -o amd64.o -MT amd64.o -MMD -MP -MF .deps/amd64.Tpo"
with this patch applied, it becomes,
"-c -o arch/amd64.o -MT arch/amd64.o -MMD -MP -MF
arch/.deps/amd64.o.Tpo"
"make clean" removes the object files, and "make distclean" removes
.deps
additionally. configure file create .deps directory in each of
CONFIG_SRC_SUBDIR, and pass it to Makefile.in, so that "make clean" and
"make distclean" can remove stuffs there.
If people agree with this change, I'll add more directories to
CONFIG_SRC_SUBDIR. I want to do the same to GDBserver, but I haven't
looked at GDBserver configure/Makefile yet.
maintainer-clean: local-maintainer-clean do-maintainer-clean distclean
realclean: maintainer-clean
@@ -2941,9 +2949,9 @@ ifeq ($(DEPMODE),depmode=gcc3)
# into place if the compile succeeds. We need this because gcc does
# not atomically write the dependency output file.
override COMPILE.post = -c -o $@ -MT $@ -MMD -MP \
- -MF $(DEPDIR)/$(basename $(@F)).Tpo
-override POSTCOMPILE = @mv $(DEPDIR)/$(basename $(@F)).Tpo \
- $(DEPDIR)/$(basename $(@F)).Po
+ -MF $(@D)/$(DEPDIR)/$(@F).Tpo
+override POSTCOMPILE = @mv $(@D)/$(DEPDIR)/$(@F).Tpo \
+ $(@D)/$(DEPDIR)/$(@F).Po
else
override COMPILE.pre = source='$<' object='$@' libtool=no \
DEPDIR=$(DEPDIR) $(DEPMODE) $(depcomp) $(CC)