Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making 'make clean' ask for confirmation

Tags:

makefile

cmake

Is there a way to make the command make clean require user confirmation? I mistakenly executed it and now I have to wait 6 hours for the build to complete again.

The Makefiles were created by cmake.

Desired workflow:

> make clean
> [make] Are you sure you want to remove all the built files? [Y/N]
> N
> [make] Target 'make clean' not executed.

> make clean
> [make] Are you sure you want to remove all the built files? [Y/N]
> Y
> [make] Target 'make clean' executed.
like image 799
Banex Avatar asked Dec 15 '17 17:12

Banex


1 Answers

I'm not familiar with cmake, but for gnu make, one possible hack would be:

clean: check_clean

check_clean:
    @echo -n "Are you sure? [y/N] " && read ans && [ $${ans:-N} = y ]

.PHONY: clean check_clean

If check_clean fails (user does not type in y), then make will exit with an error before performing the clean.

like image 153
HardcoreHenry Avatar answered Dec 31 '22 22:12

HardcoreHenry