便携式Makefile的clean
目标的适当形式是什么? $(RM)
对我不起作用。我从Windows(7)命令提示符和Eclipse中工作。他们都报告相同版本的make(我的路径上有多个):
make --version
GNU Make 3.82
Built for i386-pc-mingw32
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
在Eclipse中:
make clean
rm -f *.o testScaffolding_* runner.cpp runner.exe *.d
来自cmd:
rm -f *.o testScaffolding_* runner.cpp runner.exe *.d
process_begin: CreateProcess(NULL, rm -f *.o testScaffolding_* runner.cpp runner.exe *.d, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [clean] Error 2
报告$(OS)
为Windows_NT
,$(RM)
为rm -f
。我也安装了它,如果我在Makefile中调用它,两个环境都会报告相同的路径。
答案 0 :(得分:1)
这是迄今为止我提出的最好的。您可以将UNAME
指定为环境变量,也可以在命令行中指定。如果未指定,则尝试运行uname。如果失败则假定Windows。随后,您可以合理地猜测shell环境,并可以相应地定义相应的命令。
请注意,这只是有限的测试,我只是认为它是功能性的,不优雅或“正确”。此外,使用.exe
可能更好地识别可执行扩展名($(OS)
与无)之类的内容。
ifeq ($(strip $(UNAME)),)
# if not already specified, try running uname
UNAME = $(shell uname)
endif
ifeq ($(strip $(UNAME)),)
# if still not specified, assume Windows
UNAME = Windows
endif
ifeq ($(UNAME),Windows)
define TO_WIN
$(subst /,\,$1)
endef
define MKDIR
-mkdir $(call TO_WIN,$1)
endef
define RM
del $(call TO_WIN,$1)
endef
CAT := type
else
define MKDIR
mkdir -p $1
endef
define RM
rm -f $1
endef
CAT := cat
endif