From 9ac870c9bb8ed00492cb57eb2c6ee399bf24ef36 Mon Sep 17 00:00:00 2001 From: Jerome Forissier Date: Fri, 6 Jan 2017 09:33:29 +0100 Subject: Make sure "make clean" removes everything "make" has created under $(O) "make clean" would leave behind some files and many directories. Fix this by correctly tracking the files and directories created under $(O) during the build process: - Fix incorrect file names in $(cleanfiles) and add a few missing ones. - Introduce a makefile macro: $(cleandirs-for-rmdir), defined in a new file: mk/cleandirs.mk. It returns the list of directories that should be removed, given a list of files. The clean target removes the files, then all the directories in depth- first order. $(O) is also removed, if found to be empty. Note that a more straightforward approach was discussed in [1]: use "rm -rf $(O)/some_dir" and get rid of the whole file and directory tracking via $(cleanfiles) and $(cleandirs). Although it was agreed it would be safe, doing so would necessarily break the backward compatibility for build scripts relying on "make O=", due to the additional level ($(O)/some_dir). Finally, mk/cleandirs.mk is exported to the TA dev kit and the clean rule for the TAs is updated. [1] https://github.com/OP-TEE/optee_os/pull/1270 Signed-off-by: Jerome Forissier Reviewed-by: Etienne Carriere Reviewed-by: Jens Wiklander Acked-by: Andy Green --- Makefile | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 33f434f7..bfea8989 100644 --- a/Makefile +++ b/Makefile @@ -38,14 +38,15 @@ endif ARCH ?= arm PLATFORM ?= vexpress # Default value for PLATFORM_FLAVOR is set in plat-$(PLATFORM)/conf.mk -O ?= out/$(ARCH)-plat-$(PLATFORM) +ifeq ($O,) +O := out +out-dir := $(O)/$(ARCH)-plat-$(PLATFORM) +else +out-dir := $(O) +endif arch_$(ARCH) := y -ifneq ($O,) -out-dir := $O -endif - ifneq ($V,1) q := @ cmd-echo := true @@ -80,10 +81,15 @@ endef $(foreach t, $(ta-targets), $(eval $(call build-ta-target, $(t)))) endif +include mk/cleandirs.mk + .PHONY: clean clean: - @$(cmd-echo-silent) ' CLEAN .' + @$(cmd-echo-silent) ' CLEAN $(out-dir)' ${q}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 --ignore-fail-on-non-empty $(O); fi .PHONY: cscope cscope: -- cgit v1.2.3