制作干净的'要求确认

时间:2017-12-15 17:21:16

标签: makefile cmake

有没有办法让命令make clean需要用户确认?我错误地执行了它,现在我必须等待6个小时才能再次完成构建。

Makefilecmake创建。

所需的工作流程:

> 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.

1 个答案:

答案 0 :(得分:9)

我不熟悉cmake,但对于gnu make,一个可能的黑客将是:

clean: check_clean

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

.PHONY: clean check_clean

如果check_clean失败(用户未输入y),则make会在执行清除之前退出并显示错误。