Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 7/7] gdb, gdbserver: create the dependency directories from the Makefiles
Date: Mon, 31 Aug 2026 14:51:46 -0400	[thread overview]
Message-ID: <20260831185300.572297-8-simon.marchi@efficios.com> (raw)
In-Reply-To: <20260831185300.572297-1-simon.marchi@efficios.com>

Some .deps directories are created at configure time:

 - gdb/configure.ac and gdbserver/configure.ac call ZW_CREATE_DEPDIR,
   which creates the top-level one from config.status.

 - gdbserver/configure.ac has an additional AC_CONFIG_COMMANDS to create
   the .deps dirs for its subdirectories listed in CONFIG_SRC_SUBDIR
   (arch, gdbsupport, nat and target).

Meanwhile, gdb creates the sub-directory ones from the Makefile, through an
order-only prerequisite on the rule for compiling .c files.

If the user deletes a .deps directory created by configure
(config.status, really), then the build breaks:

    $ rm -rf gdb/.deps
    $ make
      CXX    gdb.o
    gdb.c:39:1: fatal error: opening dependency file ./.deps/gdb.Tpo: No such file or directory

On the other hand, it works for those .deps created by a Makefile (they
are re-created as needed).

This patch changes how we create .deps directories to make it simpler,
more robust and consistent.

In both gdb and gdbserver:

 - Add an ALL_DEPDIRS variable, listing the .deps directories, and a
   rule to create them.

 - Make ALL_DEPDIRS an order-only prerequisite of $(all_object_files),
   such that the .deps directories will be created before compiling any
   .o file.

 - Since we now have a variable (ALL_DEPDIRS) listing all .deps
   directories, use it where convenient in the clean and distclean
   targets.

Note that this changes the command to create directories from "$(SHELL)
$(srcdir)/../install-sh -d" to "mkdir -p".  If there is a reason to use
install-sh to create directories in the build directory, I think it
should be documented, otherwise it just looks strange.

The configure-time creation is not needed anymore.  Replace the
ZW_CREATE_DEPDIR calls with AM_SET_DEPDIR, which is what actually
provides DEPDIR, and drop gdbserver's gdbdepdir AC_CONFIG_COMMANDS.

That leaves gdbserver's CONFIG_SRC_SUBDIR with no user in configure, so
define it directly in gdbserver/Makefile.in, like gdb already does.

Change-Id: I71e76a9a37a525f58c9c66e5556e8da965cc2ca3
---
 gdb/Makefile.in        | 33 +++++++++++++++------------------
 gdb/configure          |  6 ------
 gdb/configure.ac       |  2 +-
 gdbserver/Makefile.in  | 25 ++++++++++++++-----------
 gdbserver/configure    | 21 ---------------------
 gdbserver/configure.ac | 13 +------------
 6 files changed, 31 insertions(+), 69 deletions(-)

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index cf10bc17320b..3585f2015ff0 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -590,7 +590,6 @@ HAVE_GSTACK = @HAVE_GSTACK@
 
 CONFIG_SRC_SUBDIR = arch cli dwarf2 mi compile tui unittests guile python \
 	target nat gdbtk/generic
-CONFIG_DEP_SUBDIR = $(addsuffix /$(DEPDIR),$(CONFIG_SRC_SUBDIR))
 
 # -I. for config files.
 # -I$(srcdir) for gdb internal headers.
@@ -2092,15 +2091,11 @@ PYTHON_CFLAGS = @PYTHON_CFLAGS@
 all: gdb$(EXEEXT) $(CONFIG_ALL) gdb-gdb.gdb gcore gstack gdb-add-index
 	@$(MAKE) $(FLAGS_TO_PASS) DO=all "DODIRS=$(SUBDIRS)" subdir_do
 
-# Rule for compiling .c files in the top-level gdb directory.
-# The order-only dependencies ensure that we create the build subdirectories.
-%.o: %.c | $(CONFIG_DEP_SUBDIR)
+# Rule for compiling .c files.
+%.o: %.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
 
-$(CONFIG_DEP_SUBDIR):
-	$(ECHO_GEN) $(SHELL) $(srcdir)/../install-sh -d $@
-
 # Python files need special flags.
 python/%.o: INTERNAL_CFLAGS += $(PYTHON_CFLAGS)
 
@@ -2413,11 +2408,8 @@ clean mostlyclean: $(CONFIG_CLEAN)
 	rm -f gdb$(EXEEXT) core make.log
 	rm -f gdb[0-9]$(EXEEXT)
 	rm -f xml-builtin.c stamp-xml
-	rm -f $(DEPDIR)/*
-	for i in $(CONFIG_SRC_SUBDIR); do \
-		rm -f $$i/*.o;	\
-		rm -f $$i/$(DEPDIR)/*; \
-	done
+	rm -f $(addsuffix /*,$(ALL_DEPDIRS))
+	rm -f $(addsuffix /*.o,$(CONFIG_SRC_SUBDIR))
 
 # This used to depend on c-exp.c m2-exp.c TAGS
 # I believe this is wrong; the makefile standards for distclean just
@@ -2431,10 +2423,7 @@ distclean: clean
 	rm -f config.log config.cache
 	rm -f config.lt libtool
 	rm -f Makefile
-	rm -rf $(DEPDIR)
-	for i in $(CONFIG_SRC_SUBDIR); do \
-		if test -d $$i/$(DEPDIR); then rmdir $$i/$(DEPDIR); fi \
-	done
+	rm -rf $(ALL_DEPDIRS)
 
 maintainer-clean: local-maintainer-clean do-maintainer-clean distclean
 realclean: maintainer-clean
@@ -2816,12 +2805,20 @@ all_gdbtk_cflags = $(IDE_CFLAGS) $(ITCL_CFLAGS) \
 # dependency tracking.
 all_object_files = gdb.o $(LIBGDB_OBS) gdbtk/generic/gdbtk-main.o
 
+# All the directories in which we put dependency files.
+ALL_DEPDIRS = $(DEPDIR) $(addsuffix /$(DEPDIR),$(CONFIG_SRC_SUBDIR))
+
+$(ALL_DEPDIRS):
+	$(ECHO_GEN) mkdir -p $@
+
 # All the .deps files to include.
 all_deps_files = $(foreach dep,$(patsubst %.o,%.Po,$(all_object_files)),\
     $(dir $(dep))/$(DEPDIR)/$(notdir $(dep)))
 
-# Ensure that generated files are created early.
-$(all_object_files): | $(generated_files)
+# Ensure that the generated files and the dependency directories are created
+# early.  Creating a dependency directory also creates the directory the
+# objects go in.
+$(all_object_files): | $(generated_files) $(ALL_DEPDIRS)
 
 # Dependencies.
 -include $(all_deps_files)
diff --git a/gdb/configure b/gdb/configure
index 94cc893a8715..4078a8af9f4a 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -22696,9 +22696,6 @@ rmdir .tst 2>/dev/null
 
 DEPDIR="${am__leading_dot}deps"
 
-ac_config_commands="$ac_config_commands depdir"
-
-
 
 # Since the first call to PKG_CHECK_MODULES may not happen (is guarded by
 # a condition), we must call PKG_PROG_PKG_CONFIG explicitly to probe for
@@ -34692,7 +34689,6 @@ fi
 ac_aux_dir='$ac_aux_dir'
 
 
-ac_aux_dir=$ac_aux_dir DEPDIR=$DEPDIR
 # Capture the value of obsolete ALL_LINGUAS because we need it to compute
     # POFILES, GMOFILES, UPDATEPOFILES, DUMMYPOFILES, CATALOGS. But hide it
     # from automake.
@@ -34712,7 +34708,6 @@ do
   case $ac_config_target in
     "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h:config.in" ;;
     "libtool") CONFIG_COMMANDS="$CONFIG_COMMANDS libtool" ;;
-    "depdir") CONFIG_COMMANDS="$CONFIG_COMMANDS depdir" ;;
     "default-1") CONFIG_COMMANDS="$CONFIG_COMMANDS default-1" ;;
     "jit-reader.h") CONFIG_FILES="$CONFIG_FILES jit-reader.h:jit-reader.in" ;;
     "nm.h") CONFIG_LINKS="$CONFIG_LINKS nm.h:$GDB_NM_FILE" ;;
@@ -36161,7 +36156,6 @@ compiler_lib_search_path=$lt_compiler_lib_search_path_CXX
 _LT_EOF
 
  ;;
-    "depdir":C) $SHELL $ac_aux_dir/mkinstalldirs $DEPDIR ;;
     "default-1":C)
     for ac_file in $CONFIG_FILES; do
       # Support "outfile[:infile[:infile...]]"
diff --git a/gdb/configure.ac b/gdb/configure.ac
index d8b2498f415b..f15a2e16947c 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -60,7 +60,7 @@ AX_CXX_COMPILE_STDCXX(17, , mandatory)
 GDB_AC_COMMON
 
 # Dependency checking.
-ZW_CREATE_DEPDIR
+AM_SET_DEPDIR
 
 # Since the first call to PKG_CHECK_MODULES may not happen (is guarded by
 # a condition), we must call PKG_PROG_PKG_CONFIG explicitly to probe for
diff --git a/gdbserver/Makefile.in b/gdbserver/Makefile.in
index 5054597bf6ef..9417a93268cd 100644
--- a/gdbserver/Makefile.in
+++ b/gdbserver/Makefile.in
@@ -27,7 +27,7 @@ program_transform_name = @program_transform_name@
 bindir = @bindir@
 libdir = @libdir@
 
-CONFIG_SRC_SUBDIR = @CONFIG_SRC_SUBDIR@
+CONFIG_SRC_SUBDIR = arch gdbsupport nat target
 
 install_sh = @install_sh@
 
@@ -428,17 +428,12 @@ mostlyclean clean:
 	rm -f $(IPA_LIB)
 	rm -f *-generated.cc
 	rm -f stamp-xml
-	rm -f $(DEPDIR)/*.Po
-	for i in $(CONFIG_SRC_SUBDIR); do \
-		rm -f $$i/*.o;	\
-		rm -f $$i/$(DEPDIR)/*; \
-	done
+	rm -f $(addsuffix /*,$(ALL_DEPDIRS))
+	rm -f $(addsuffix /*.o,$(CONFIG_SRC_SUBDIR))
 
 maintainer-clean realclean distclean: clean
 	rm -f Makefile config.status config.h stamp-h config.log config.cache
-	for i in $(CONFIG_SRC_SUBDIR); do \
-		rmdir $$i/$(DEPDIR); \
-	done
+	rm -rf $(ALL_DEPDIRS)
 
 config.h: stamp-h ; @true
 stamp-h: config.in config.status
@@ -596,8 +591,16 @@ gdbreplay.o: gdbreplay.cc
 # dependency tracking.
 all_object_files = $(OBS) $(GDBREPLAY_OBS) $(IPA_OBJS)
 
-# Ensure that generated files are created early.
-$(all_object_files): | $(generated_files)
+# All the directories in which we put dependency files.
+ALL_DEPDIRS = $(DEPDIR) $(addsuffix /$(DEPDIR),$(CONFIG_SRC_SUBDIR))
+
+$(ALL_DEPDIRS):
+	$(ECHO_GEN) mkdir -p $@
+
+# Ensure that the generated files and the dependency directories are created
+# early.  Creating a dependency directory also creates the directory the
+# objects go in.
+$(all_object_files): | $(generated_files) $(ALL_DEPDIRS)
 
 # All the .deps files to include.
 all_deps_files = $(foreach dep,$(patsubst %.o,%.Po,$(all_object_files)),\
diff --git a/gdbserver/configure b/gdbserver/configure
index 3cf8df2c3ae1..dd749fcb55bc 100755
--- a/gdbserver/configure
+++ b/gdbserver/configure
@@ -637,7 +637,6 @@ REPORT_BUGS_TO
 PKGVERSION
 WERROR_CFLAGS
 WARN_CFLAGS
-CONFIG_SRC_SUBDIR
 CATOBJEXT
 GENCAT
 INSTOBJEXT
@@ -10956,9 +10955,6 @@ rmdir .tst 2>/dev/null
 
 DEPDIR="${am__leading_dot}deps"
 
-ac_config_commands="$ac_config_commands depdir"
-
-
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5
 $as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; }
@@ -12813,13 +12809,6 @@ $as_echo "$LINGUAS" >&6; }
 
 fi
 
-# Create sub-directories for objects and dependencies.
-CONFIG_SRC_SUBDIR="arch gdbsupport nat target"
-
-
-ac_config_commands="$ac_config_commands gdbdepdir"
-
-
 for ac_header in  \
   arpa/inet.h \
   fcntl.h \
@@ -15459,7 +15448,6 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 #
 # INIT-COMMANDS
 #
-ac_aux_dir=$ac_aux_dir DEPDIR=$DEPDIR
 # Capture the value of obsolete ALL_LINGUAS because we need it to compute
     # POFILES, GMOFILES, UPDATEPOFILES, DUMMYPOFILES, CATALOGS. But hide it
     # from automake.
@@ -15467,7 +15455,6 @@ ac_aux_dir=$ac_aux_dir DEPDIR=$DEPDIR
     # Capture the value of LINGUAS because we need it to compute CATALOGS.
     LINGUAS="${LINGUAS-%UNSET%}"
 
-ac_aux_dir=$ac_aux_dir DEPDIR=$DEPDIR CONFIG_SRC_SUBDIR="$CONFIG_SRC_SUBDIR"
 
 _ACEOF
 
@@ -15478,9 +15465,7 @@ for ac_config_target in $ac_config_targets
 do
   case $ac_config_target in
     "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h:config.in" ;;
-    "depdir") CONFIG_COMMANDS="$CONFIG_COMMANDS depdir" ;;
     "default-1") CONFIG_COMMANDS="$CONFIG_COMMANDS default-1" ;;
-    "gdbdepdir") CONFIG_COMMANDS="$CONFIG_COMMANDS gdbdepdir" ;;
     "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
 
   *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
@@ -16038,7 +16023,6 @@ $as_echo "$as_me: executing $ac_file commands" >&6;}
 
   case $ac_file$ac_mode in
     "config.h":H) echo > stamp-h ;;
-    "depdir":C) $SHELL $ac_aux_dir/mkinstalldirs $DEPDIR ;;
     "default-1":C)
     for ac_file in $CONFIG_FILES; do
       # Support "outfile[:infile[:infile...]]"
@@ -16140,11 +16124,6 @@ $as_echo "$as_me: executing $ac_file commands" >&6;}
         ;;
       esac
     done ;;
-    "gdbdepdir":C)
-  for subdir in ${CONFIG_SRC_SUBDIR}
-  do
-      $SHELL $ac_aux_dir/mkinstalldirs $subdir/$DEPDIR
-  done ;;
 
   esac
 done # for ac_tag
diff --git a/gdbserver/configure.ac b/gdbserver/configure.ac
index a549a8712fc1..f1466e8568d4 100644
--- a/gdbserver/configure.ac
+++ b/gdbserver/configure.ac
@@ -60,22 +60,11 @@ ACX_NONCANONICAL_TARGET
 ACX_NONCANONICAL_HOST
 
 # Dependency checking.
-ZW_CREATE_DEPDIR
+AM_SET_DEPDIR
 
 dnl Set up for gettext.
 ZW_GNU_GETTEXT_SISTER_DIR
 
-# Create sub-directories for objects and dependencies.
-CONFIG_SRC_SUBDIR="arch gdbsupport nat target"
-AC_SUBST(CONFIG_SRC_SUBDIR)
-
-AC_CONFIG_COMMANDS([gdbdepdir],[
-  for subdir in ${CONFIG_SRC_SUBDIR}
-  do
-      $SHELL $ac_aux_dir/mkinstalldirs $subdir/$DEPDIR
-  done],
-  [ac_aux_dir=$ac_aux_dir DEPDIR=$DEPDIR CONFIG_SRC_SUBDIR="$CONFIG_SRC_SUBDIR"])
-
 AC_CHECK_HEADERS([ \
   arpa/inet.h \
   fcntl.h \
-- 
2.55.0


  parent reply	other threads:[~2026-08-31 18:54 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31 18:51 [PATCH 0/7] Some Makefile cleanups Simon Marchi
2026-08-31 18:51 ` [PATCH 1/7] gdb: update README about the GNU make requirement Simon Marchi
2026-09-01 12:26   ` Eli Zaretskii
2026-09-01 13:36     ` Simon Marchi
2026-08-31 18:51 ` [PATCH 2/7] gdb, gdbserver: require gcc-style dependency generation, drop the depcomp fallback Simon Marchi
2026-09-01 16:32   ` Tom Tromey
2026-09-01 20:16     ` Simon Marchi
2026-09-02  7:37       ` Rainer Orth
2026-09-02 12:26         ` Simon Marchi
2026-08-31 18:51 ` [PATCH 3/7] gdbserver: fix missing dependency tracking for gdbreplay.o Simon Marchi
2026-09-01 16:33   ` Tom Tromey
2026-08-31 18:51 ` [PATCH 4/7] gdb, gdbserver: always use order-only prerequisites for generated files Simon Marchi
2026-09-01 16:34   ` Tom Tromey
2026-08-31 18:51 ` [PATCH 5/7] gdb, gdbserver: remove the .NOEXPORT target Simon Marchi
2026-09-01 16:37   ` Tom Tromey
2026-08-31 18:51 ` [PATCH 6/7] gdb: remove the explicit ada-exp.o rule Simon Marchi
2026-09-01 16:38   ` Tom Tromey
2026-08-31 18:51 ` Simon Marchi [this message]
2026-09-01 16:47   ` [PATCH 7/7] gdb, gdbserver: create the dependency directories from the Makefiles Tom Tromey
2026-09-01 20:18     ` Simon Marchi
2026-09-01 20:37       ` Simon Marchi
2026-09-02 18:36         ` Tom Tromey
2026-09-03 13:45           ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260831185300.572297-8-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox