From bc0d271274c8da670a1595490e7ddd169b209e20 Mon Sep 17 00:00:00 2001 From: Jerome Forissier Date: Wed, 25 Oct 2017 11:31:25 +0200 Subject: [PATCH] make clean: split file list into manageable chunks "make clean" might fail with the following error: make[2]: execvp: /bin/bash: Argument list too long This error was observed on a platform that has lots of additional source files compared to upstream (drivers, etc.), and that sets a long output path on the command line (make ... O=/some/long/path). Fix the error by splitting the file list into more manageable chunks. Note that removing one file at a time is not reasonable, because spawning too may shells takes quite a long time (up to 7-10 seconds to "make clean"). Signed-off-by: Jerome Forissier Reported-by: Lijianhui Reviewed-by: Jens Wiklander --- Makefile | 2 +- mk/cleandirs.mk | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c9bf9127ae3..069519a4a21 100644 --- a/Makefile +++ b/Makefile @@ -86,7 +86,7 @@ include mk/cleandirs.mk .PHONY: clean clean: @$(cmd-echo-silent) ' CLEAN $(out-dir)' - ${q}rm -f $(cleanfiles) + $(call do-rm-f, $(cleanfiles)) ${q}dirs="$(call cleandirs-for-rmdir)"; if [ "$$dirs" ]; then $(RMDIR) $$dirs; fi @if [ "$(out-dir)" != "$(O)" ]; then $(cmd-echo-silent) ' CLEAN $(O)'; fi ${q}if [ -d "$(O)" ]; then $(RMDIR) $(O); fi diff --git a/mk/cleandirs.mk b/mk/cleandirs.mk index 39c1ab4dd93..f0e1d8ea8f6 100644 --- a/mk/cleandirs.mk +++ b/mk/cleandirs.mk @@ -26,3 +26,17 @@ $(eval _O:=$(if $(O),$(O),.))$(wildcard $(addprefix $(_O)/,$(call _reverse, endef RMDIR := rmdir --ignore-fail-on-non-empty + +# Remove files with "rm -f". +# Split (possibly huge) file list into more manageable lines +# (200 files at a time), to minimize the odds of having: +# "/bin/bash: Argument list too long" +define do-rm-f + $(call _do-rm-f, $(wordlist 1, 200, $(1))) + $(eval _tail := $(wordlist 201, $(words $(1)), $(1))) + $(if $(_tail), $(call do-rm-f, $(_tail))) +endef + +define _do-rm-f + ${q}rm -f $1 +endef