From c0641c8513dbbf37026bbe2e04e4a441fd6e640c Mon Sep 17 00:00:00 2001
From: Andre Noll <maan@tuebingen.mpg.de>
Date: Wed, 1 Jan 2025 22:24:03 +0100
Subject: [PATCH] build: Improve clean targets.

In a "fresh build" (e.g. after a make clean) we create the .d and the
.o file in one go to speed up this common case. However if one runs
"make clean" followed by e.g. "make para_audioc", this will create
*all* object and dependency files, not just the ones needed to build
para_audioc. This behaviour is unfortunate because most dependencies
are irrelevant for a single target, and even the few which do matter
are ignored as well in this case because the object file does not
exist and needs to be recreated anyway,

Work around this shortcoming by shuffling the commands of the four
rules a little so that the clean target only removes object files
but keeps the dependency files.

Also remove the calls to SAY because with the rm commands spellt out
it is clear what is being removed.
---
 Makefile.real | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/Makefile.real b/Makefile.real
index 6f914293..513d4bbe 100644
--- a/Makefile.real
+++ b/Makefile.real
@@ -32,6 +32,7 @@ SEVERITIES := \"debug\",\"info\",\"notice\",\"warning\",\"error\",\"crit\",\"eme
 vardir := /var/paraslash
 mandir := $(datarootdir)/man/man1
 MKDIR_P := mkdir -p
+RM := rm -f
 
 ifeq ("$(origin O)", "command line")
 	build_dir := $(O)
@@ -562,20 +563,13 @@ $(prefixed_executables):
 	$(CC) $^ -o $@ $(LDFLAGS)
 
 mostlyclean:
-	$(call SAY, MOSTLYCLEAN)
-	rm -f para_*
-	rm -rf $(object_dir)
+	$(RM) para_* *.tar.bz2 *.tar.xz
 clean: mostlyclean
-	$(call SAY, CLEAN)
-	rm -rf $(build_dir)
-distclean: clean
-	$(call SAY, DISTCLEAN)
-	rm -f Makefile autoscan.log config.status config.log
-	rm -f config.h configure config.h.in
-maintainer-clean: distclean test-clean
-	$(call SAY, MAINTAINER-CLEAN)
-	rm -f *.tar.bz2 *.tar.xz
-	rm -f GPATH GRTAGS GSYMS GTAGS
+	$(RM) -r $(object_dir)
+distclean: clean test-clean
+	$(RM) -r $(build_dir)
+maintainer-clean: distclean
+	$(RM) Makefile config.status config.log config.h configure config.h.in
 
 INSTALL ?= install
 INSTALL_PROGRAM ?= $(INSTALL)
@@ -592,7 +586,7 @@ install install-strip: all man
 
 $(tarball) dist tarball:
 	$(call SAY, DIST)
-	rm -rf $(tarball) $(tarball_pfx)
+	$(RM) -r $(tarball) $(tarball_pfx)
 	git archive --format=tar --prefix=$(tarball_pfx)/ HEAD \
 	   | tar --delete $(tarball_delete) > $(tarball_pfx).tar
 	$(MKDIR_P) $(tarball_pfx)
@@ -602,4 +596,4 @@ $(tarball) dist tarball:
 	xz -9 $(tarball_pfx).tar
 	ls -l $(tarball)
 	ln -sf $(tarball) paraslash-git.tar.xz
-	rm -rf $(tarball_pfx)
+	$(RM) -f $(tarball_pfx)
-- 
2.39.5