Makefile: improve make distclean [1/1]

PD#SWPL-61282

Problem:
improve make distclean

Solution:
remove the whole output dir when no environment variables

Verify:
ad401_a113l

Signed-off-by: Kelvin Zhang <kelvin.zhang@amlogic.com>
Change-Id: Ib58dd6375b80e553d49472fdcb4be866f89a1739
diff --git a/Makefile b/Makefile
index c2c3a27..9ba8fbd 100644
--- a/Makefile
+++ b/Makefile
@@ -208,25 +208,23 @@
 .PHONY: clean
 clean: $(CLEAN_TARGETS)
 
+ifndef_any_of = $(filter undefined,$(foreach v,$(1),$(origin $(v))))
+
 .PHONY: distclean
 distclean:
+ifeq ($(call ifndef_any_of,ARCH SOC BOARD PRODUCT),)
 	@ if [ -d $(BUILD_DIR) ]; then rm -rf $(BUILD_DIR); fi
+else
+	@ if [ -d $(output_DIR) ]; then rm -rf $(output_DIR); fi
+endif
 
 .PHONY: project
 project:
-ifndef ARCH
-	$(error ARCH is not set, Please execute source scripts/env.sh)
-endif
-ifndef SOC
-	$(error SOC is not set, Please execute source scripts/env.sh)
-endif
-ifndef BOARD
-	$(error BOARD is not set, Please execute source scripts/env.sh)
-endif
-ifndef PRODUCT
-	$(error PRODUCT is not set, Please execute source scripts/env.sh)
-endif
+ifeq ($(call ifndef_any_of,ARCH SOC BOARD PRODUCT),)
 	@ $(call MESSAGE,"Building $(ARCH) $(SOC) $(BOARD) $(PRODUCT)")
+else
+	$(error Please execute source scripts/env.sh)
+endif
 
 .PHONY: docs
 docs: