# Default clean targets for binary build.

# Input parameters:
# - LOCAL_NAME
# - LOCAL_TARGET_NAME
# - _local_output_dir

# Support target-specific goals. LOCAL_TARGET_NAME is custom and supported for multi-target builds.
_local_target:=$(LOCAL_NAME)$(LOCAL_TARGET_NAME:%=-%)

.PHONY: clean
clean: $(LOCAL_NAME)-clean

# To suppress circular dependencies.
ifneq ($(LOCAL_TARGET_NAME),)

# We need to bind target clean to common clean. Otherwise, calling "make clean" runs only
# $(LOCAL_NAME)-clean targets for each module, skipping $(LOCAL_TARGET_NAME)-clean targets
clean: $(LOCAL_TARGET_NAME)-clean

.PHONY: $(LOCAL_NAME)-clean
$(LOCAL_NAME)-clean: $(_local_target)-clean

.PHONY: $(LOCAL_TARGET_NAME)-clean
$(LOCAL_TARGET_NAME)-clean: $(_local_target)-clean
endif

# _local_target = LOCAL_NAME if LOCAL_TARGET_NAME is empty.
.PHONY: $(_local_target)-clean
$(_local_target)-clean: $(_local_output_dir)-clean

.PHONY: $(_local_output_dir)-clean
$(_local_output_dir)-clean: _local_output_dir := $(_local_output_dir)
$(_local_output_dir)-clean:
	rm -rf $(_local_output_dir)
