2013-01-04 45 views
0

便攜式Makefile的clean目標的適當表單是什麼? $(RM)不適用於我。我從Windows(7)命令提示符和Eclipse中都可以工作。他們都報告提出的相同版本(我有我的路多):什麼會在Makefile中創建一個好的可移植的乾淨目標?

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中調用它,兩個環境都會報告相同的路徑。

回答

1

這是迄今爲止最好的。您可以指定UNAME作爲環境變量或在命令行上。如果未指定,它會嘗試運行uname。如果失敗,它將假定Windows。隨後,您對shell環境有合理的猜測,並可以適當地定義相應的命令。

請注意,這已經看到只有有限的測試,我只是認爲它的功能,不優雅或'正確'。此外,使用$(OS)可能更好地識別可執行擴展名(.exe與無)。

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 
相關問題