From 851a02bcb77a091667e11d3f4233ac4a248af03d Mon Sep 17 00:00:00 2001
From: Ludwig Ortmann <ludwig.ortmann@fu-berlin.de>
Date: Mon, 4 Aug 2014 22:03:05 +0200
Subject: [PATCH] make: add clean, distclean for RIOT

distclean
removes all build products, also depends on docclean

clean
removes all build products for the current board

also, silence clean target from Makefile.include and let it ignore errors
---
 Makefile         | 8 ++++++++
 Makefile.include | 8 ++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 0df2757190..2fec53cd53 100644
--- a/Makefile
+++ b/Makefile
@@ -12,6 +12,14 @@ doc:
 docclean:
 	"$(MAKE)" -BC doc/doxygen clean
 
+clean:
+	@echo "Cleaning all build products for the current board"
+	@find ./pkg/ ./examples/ ./tests/ -maxdepth 2 -mindepth 2 -type f -name Makefile -execdir "${MAKE}" clean ';'
+
+distclean: docclean
+	@echo "Cleaning all build products"
+	@find ./pkg/ ./examples/ ./tests/ -maxdepth 2 -mindepth 2 -type f -name Makefile -execdir "${MAKE}" distclean ';'
+
 welcome:
 	@echo "Welcome to RIOT - The friendly OS for IoT!"
 	@echo ""
diff --git a/Makefile.include b/Makefile.include
index 45f0e07c65..067a860ec8 100644
--- a/Makefile.include
+++ b/Makefile.include
@@ -174,8 +174,12 @@ $(USEPKG:%=${BINDIR}%.a):
 	"$(MAKE)" -C $(RIOTBASE)/pkg/$(patsubst ${BINDIR}%.a,%,$@)
 
 clean:
-	@for i in $(USEPKG) ; do "$(MAKE)" -C $(RIOTBASE)/pkg/$$i clean || exit 1; done
-	rm -rf $(BINDIR) $(CLEANFILES)
+	-@for i in $(USEPKG) ; do "$(MAKE)" -C $(RIOTBASE)/pkg/$$i clean ; done
+	-@rm -rf $(BINDIR) $(CLEANFILES)
+
+distclean:
+	-@for i in $(USEPKG) ; do "$(MAKE)" -C $(RIOTBASE)/pkg/$$i distclean ; done
+	-@rm -rf $(BINDIRBASE) $(CLEANFILES)
 
 flash: all
 	$(FLASHER) $(FFLAGS)
-- 
GitLab