Description: Check makeflags before running `rm` in distclean-recursive
 Debhelper command dh_auto_clean run "make -s -n (dry-run opt) distclean"
 before running "make distclean". Without this patch, when the first make
 runs, some Makefiles will be removed, and then when running the second make,
 some compiled files will not be removed, causing a failure in the build
 process.
Author: Marcos Talau <talau@debian.org>
Bug-Debian: https://bugs.debian.org/1046780
Last-Update: 2025-02-23

--- ns2-2.35+dfsg.orig/Makefile.in
+++ ns2-2.35+dfsg/Makefile.in
@@ -82,6 +82,14 @@ LIB	= \
 	-lm @LIBS@
 #	-L@libdir@ \
 
+
+ifeq ($(findstring n,$(MAKEFLAGS)),n)
+	DRY_RUN=1
+else
+	DRY_RUN=0
+endif
+
+
 CFLAGS	+= $(CCOPT) $(DEFINE) 
 
 # Explicitly define compilation rules since SunOS 4's make doesn't like gcc.
@@ -567,7 +575,8 @@ distclean: distclean-recursive
 	echo "Moved .configure to .configure-"
 
 distclean-recursive:
-	for i in $(SUBDIRS); do ( cd $$i; $(MAKE) clean; $(RM) Makefile; ) done
+	for i in $(SUBDIRS); do ( cd $$i && \
+		$(MAKE) clean && test $(DRY_RUN) -eq 0 && $(RM) Makefile; ) done
 
 tags:	force
 	ctags -wtd *.cc *.h webcache/*.cc webcache/*.h dsdv/*.cc dsdv/*.h \
