0

clean可移植 Makefile 目标 的适当形式是什么?$(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

从命令:

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 中调用它,两个环境都会报告相同的路径。

4

1 回答 1

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
于 2013-01-22T20:40:29.313 回答