Windows和Cygwin的Makefile [英] Makefile for Windows and Cygwin
问题描述
我需要在Windows和Cygwin下运行 makefile
。我在makefile正确检测操作系统并设置适当的变量时遇到问题。
I need to have a makefile
work under Windows and Cygwin. I having problems with the makefile detecting the OS correctly and setting appropriate variables.
目标是为以下命令设置变量,然后使用变量在规则中调用命令:
The objective is to set variables for the following commands, then invoke the commands in rules using the variables:
- 删除文件:在Cygwin中为
rm
,在Windows中为del
。 - 删除目录:
rmdir
(在Cygwin和Windows中,不同的
参数) - 复制文件:在Cygwin中为
cp
,在
Windows中为副本
。 - 测试文件是否存在:在Cygwin中进行
test
,在Windows中进行IF EXIST
。 - 列出文件的内容:
Cygwin中的cat
,Windows中的type
。
- Delete file:
rm
in Cygwin,del
in Windows. - Remove directory:
rmdir
(different parameters in Cygwin and Windows) - Copy file:
cp
in Cygwin,copy
in Windows. - Testing for file existance:
test
in Cygwin,IF EXIST
in Windows. - Listing contents of a file:
cat
in Cygwin,type
in Windows.
这是我的尝试,始终使用 else
子句:
Here is my attempt, which always uses the else
clause:
OS_KIND = $(OSTYPE) #OSTYPE is an environment variable set by Cygwin.
ifeq ($(OS_KIND), cygwin)
ENV_OS = Cygwin
RM = rm -f
RMDIR = rmdir -r
CP = cp
REN = mv
IF_EXIST = test -a
IF_NOT_EXIST = ! test -a
LIST_FILE = cat
else
ENV_OS = Win_Cmd
RM = del -f -Q
RMDIR = rmdir /S /Q
IF_EXIST = if exist
IF_NOT_EXIST = if not exist
LIST_FILE = type
endif
我使用正斜杠字符 /作为目录分隔符。这是Windows命令的问题,因为它将命令解释为程序参数而不是分隔符。有人知道如何解决此问题吗?
I'm using the forward slash character, '/', as a directory separator. This is a problem with the Windows command, as it is interpreting it as program argument rather than a separator. Anybody know how to resolve this issue?
我在Windows控制台和Cygwin中都使用Mingw的make。
I am using make with Mingw in both Windows Console and Cygwin.
推荐答案
CMake ,是其中之一这个问题的正确答案。其他正确的答案是 SCons , Jam 和 Bakefile 。
CMake, suggested by Matt B., is one of the right answers to this question. Other right answers are SCons, Jam, and Bakefile.
因为您使用的是Cygwin,所以 Autoconf + Automake 还为您提供了解决问题的工具。但是,它比起现成的解决方案更像是解决问题的工具包。
Since you're using Cygwin, Autoconf+Automake also gives you the tools to solve your problem. It's more of a toolkit for solving the problem than an out-of-the-box solution, though.
总的要点是向上抽象一层,这样您就可以只能从一个来源支持很多构建系统。
The overarching point is to move up a layer of abstraction so you can support lots of build systems from only a single source.
这篇关于Windows和Cygwin的Makefile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!