对make(Linux)和nmake(Windows)使用相同的makefile [英] Use the same makefile for make (Linux) and nmake (Windows)

查看:408
本文介绍了对make(Linux)和nmake(Windows)使用相同的makefile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的C程序(一个源文件),我想分别通过make和nmake在Linux和Windows上进行编译.是否有可能通过单个makefile来完成此操作?

I have a simple C program (one source file) which I want to compile on Linux and on Windows via make and nmake, respectively. Is there a possibility to accomplish this with a single makefile?

我想到了类似的东西

ifeq($(MAKE), nmake)
    // nmake code here
else
    // make code here
endif

不幸的是,nmake似乎不了解ifeq,所以我不能使用它.我有一个可以正常使用的makefile,但是生成的结果非常难看:

Unfortunately nmake seems not to understand ifeq, so I cannot use that. I have a working makefile, but that produces very ugly results:

hello: hello.c
    $(CC) hello.c

在两个系统上均适用.问题在于结果取决于各个编译器的默认行为.在Linux下,我得到一个名为"a.out"而不是"hello"的可执行文件.在Windows下,我得到的是'hello.exe',但是我也不想拥有'hello.obj'.

That works on both systems. The problem is that the outcome depends on the default behaviors of the respective compilers. Under Linux I get an executeable named 'a.out' rather than 'hello'. Under Windows I get 'hello.exe' but there is also 'hello.obj' which I do not want to have.

还有其他方法吗?还是我要尝试的东西绝对不可能?

Is there an alternative way? Or is what I'm trying absolutely impossible?

推荐答案

这也许并非不可能,但很可能如此困难,以至于无论如何都要编写两个makefile.

It's probably not impossible, but most likely so hard that it would be easier to write two makefiles anyway.

尽管GNU make(在Linux中使用)和nmake都包含了include指令,所以可以将一些常见的东西放入一个由主makefile包含的通用makefile中.

Both GNU make (used in Linux) and nmake have include directives though, so some common things can be put in a common makefile that is included by the main makefile.

这篇关于对make(Linux)和nmake(Windows)使用相同的makefile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆