Skip to contentSkip to conversation

Makefile: fix "make clean" for old GNU find

PATCH In review Brian Norris 3 participants 3 messages Mar 9, 2012 – Mar 12, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Makefile: fix "make clean" for old GNU find

findutils v4.1.x does not have the -exec CMD {} +' syntax. We can just as easily use the -exec CMD {} \;' syntax. However, it will launch a lot more rm' processes, so we only use it if the first form fails with an error. This isn't a perfect solution (find -exec +' can fail for other reasons) but it works well enough.

This problem manifests itself in RHEL 4, findutils 4.1.20:

  $ make clean
  rm -f /XXX/mtd-utils/*.o /XXX/mtd-utils/ftl_format  ...
  find: missing argument to `-exec'
  make: *** [clean] Error 1
Cc Mike Frysinger <[email protected]>

---
v2: try '+' syntax, then fall back to old format

 Makefile |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
Makefile +5 -3
index 17a1216..7506ed4 100644
@@ -42,6 +42,8 @@ OBJDEPS = $(BUILDDIR)/include/version.h
 
 include common.mk
 
+CLEAN_FIND = find "$(BUILDDIR)/" -xdev '(' -name '*.[ao]' -o -name '.*.c.dep' ')'
+
 clean::
 ifneq ($(BUILDDIR)/.git,)
 ifneq ($(BUILDDIR),.)
@@ -50,10 +52,10 @@ ifneq ($(BUILDDIR),$(CURDIR))
 endif
 endif
 endif
+	# findutils v4.1.x (RHEL 4) do not have '+' syntax
 	@if test -d "$(BUILDDIR)/"; then \
-		find $(BUILDDIR)/ -xdev \
-			'(' -name '*.[ao]' -o -name '.*.c.dep' ')' \
-			-exec rm -f {} + ; \
+		$(CLEAN_FIND) -exec rm -f {} + 2> /dev/null || \
+		$(CLEAN_FIND) -exec rm -f {} \; ; \
 	fi
 	rm -f $(BUILDDIR)/include/version.h
 	$(MAKE) -C $(TESTS) clean
Signature · 1 line
1.7.5.4.2.g519b1
Acked-by on v2 1/1
#1 lore raw
Quoted 7 lines · Brian Norris

findutils v4.1.x does not have the -exec CMD {} +' syntax. We can just as easily use the -exec CMD {} \;' syntax. However, it will launch a lot more rm' processes, so we only use it if the first form fails with an error. This isn't a perfect solution (find -exec +' can fail for other reasons) but it works well enough.

This problem manifests itself in RHEL 4, findutils 4.1.20:

-mike

#2 lore raw
In reply to Brian Norris
Quoted 7 lines · Brian Norris

findutils v4.1.x does not have the -exec CMD {} +' syntax. We can just as easily use the -exec CMD {} \;' syntax. However, it will launch a lot more rm' processes, so we only use it if the first form fails with an error. This isn't a perfect solution (find -exec +' can fail for other reasons) but it works well enough.

This problem manifests itself in RHEL 4, findutils 4.1.20:

Pushed, thanks you!

Signature · 2 lines
Best Regards,
Artem Bityutskiy